Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit a4487d8

Browse files
nonsenseacud
authored andcommitted
merge master to swarm-network-rewrite (#655)
* params: release go-ethereum v1.8.9 * VERSION, params: begin 1.8.10 release cycle * ethereum: fix a typo in FilterQuery{} (#16827) Fix a spelling mistake in comment * eth/fetcher: reuse variables for hash and number (#16819) * whisper/shhclient: update call to shh_post to expect string instead of bool (#16757) Fixes #16756 * common: improve documentation comments (#16701) This commit adds many comments and removes unused code. It also removes the EmptyHash function, which had some uses but was silly. * core/vm: fix typo in comment * p2p/discv5: add egress/ingress traffic metrics to discv5 udp transport (#16369) * core: improve test for TransactionPriceNonceSort (#16413) * trie: rename TrieSync to Sync and improve hexToKeybytes (#16804) This removes a golint warning: type name will be used as trie.TrieSync by other packages, and that stutters; consider calling this Sync. In hexToKeybytes len(hex) is even and (even+1)/2 == even/2, remove the +1. * core: fix transaction event asynchronicity * params: release Geth 1.8.10 hotfix * VERSION, params: begin 1.8.11 release cycle * ethstats: fix last golint warning (#16837)
1 parent c35aa32 commit a4487d8

File tree

25 files changed

+154
-216
lines changed

25 files changed

+154
-216
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.8.9
1+
1.8.11

common/bytes.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,22 @@ package common
1919

2020
import (
2121
"encoding/hex"
22-
"fmt"
2322
)
2423

24+
// ToHex returns the hex representation of b, prefixed with '0x'.
25+
// For empty slices, the return value is "0x0".
26+
//
27+
// Deprecated: use hexutil.Encode instead.
2528
func ToHex(b []byte) string {
2629
hex := Bytes2Hex(b)
27-
// Prefer output of "0x0" instead of "0x"
2830
if len(hex) == 0 {
2931
hex = "0"
3032
}
3133
return "0x" + hex
3234
}
3335

36+
// FromHex returns the bytes represented by the hexadecimal string s.
37+
// s may be prefixed with "0x".
3438
func FromHex(s string) []byte {
3539
if len(s) > 1 {
3640
if s[0:2] == "0x" || s[0:2] == "0X" {
@@ -43,9 +47,7 @@ func FromHex(s string) []byte {
4347
return Hex2Bytes(s)
4448
}
4549

46-
// Copy bytes
47-
//
48-
// Returns an exact copy of the provided bytes
50+
// CopyBytes returns an exact copy of the provided bytes.
4951
func CopyBytes(b []byte) (copiedBytes []byte) {
5052
if b == nil {
5153
return nil
@@ -56,14 +58,17 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
5658
return
5759
}
5860

61+
// hasHexPrefix validates str begins with '0x' or '0X'.
5962
func hasHexPrefix(str string) bool {
6063
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
6164
}
6265

66+
// isHexCharacter returns bool of c being a valid hexadecimal.
6367
func isHexCharacter(c byte) bool {
6468
return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
6569
}
6670

71+
// isHex validates whether each byte is valid hexadecimal string.
6772
func isHex(str string) bool {
6873
if len(str)%2 != 0 {
6974
return false
@@ -76,19 +81,18 @@ func isHex(str string) bool {
7681
return true
7782
}
7883

84+
// Bytes2Hex returns the hexadecimal encoding of d.
7985
func Bytes2Hex(d []byte) string {
8086
return hex.EncodeToString(d)
8187
}
8288

89+
// Hex2Bytes returns the bytes represented by the hexadecimal string str.
8390
func Hex2Bytes(str string) []byte {
84-
h, err := hex.DecodeString(str)
85-
if err != nil {
86-
panic(fmt.Sprintf("cannot hex decode the string %s, got error %v", str, err))
87-
}
88-
91+
h, _ := hex.DecodeString(str)
8992
return h
9093
}
9194

95+
// Hex2BytesFixed returns bytes of a specified fixed length flen.
9296
func Hex2BytesFixed(str string, flen int) []byte {
9397
h, _ := hex.DecodeString(str)
9498
if len(h) == flen {
@@ -102,6 +106,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
102106
return hh
103107
}
104108

109+
// RightPadBytes zero-pads slice to the right up to length l.
105110
func RightPadBytes(slice []byte, l int) []byte {
106111
if l <= len(slice) {
107112
return slice
@@ -113,6 +118,7 @@ func RightPadBytes(slice []byte, l int) []byte {
113118
return padded
114119
}
115120

121+
// LeftPadBytes zero-pads slice to the left up to length l.
116122
func LeftPadBytes(slice []byte, l int) []byte {
117123
if l <= len(slice) {
118124
return slice

common/math/big.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func ParseBig256(s string) (*big.Int, bool) {
7878
return bigint, ok
7979
}
8080

81-
// MustParseBig parses s as a 256 bit big integer and panics if the string is invalid.
81+
// MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
8282
func MustParseBig256(s string) *big.Int {
8383
v, ok := ParseBig256(s)
8484
if !ok {
@@ -186,9 +186,8 @@ func U256(x *big.Int) *big.Int {
186186
func S256(x *big.Int) *big.Int {
187187
if x.Cmp(tt255) < 0 {
188188
return x
189-
} else {
190-
return new(big.Int).Sub(x, tt256)
191189
}
190+
return new(big.Int).Sub(x, tt256)
192191
}
193192

194193
// Exp implements exponentiation by squaring.

common/number/int.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@ func limitUnsigned256(x *Number) *Number {
3434
func limitSigned256(x *Number) *Number {
3535
if x.num.Cmp(tt255) < 0 {
3636
return x
37-
} else {
38-
x.num.Sub(x.num, tt256)
39-
return x
4037
}
38+
x.num.Sub(x.num, tt256)
39+
return x
4140
}
4241

43-
// Number function
42+
// Initialiser is a Number function
4443
type Initialiser func(n int64) *Number
4544

4645
// A Number represents a generic integer with a bounding function limiter. Limit is called after each operations
@@ -51,79 +50,79 @@ type Number struct {
5150
limit func(n *Number) *Number
5251
}
5352

54-
// Returns a new initialiser for a new *Number without having to expose certain fields
53+
// NewInitialiser returns a new initialiser for a new *Number without having to expose certain fields
5554
func NewInitialiser(limiter func(*Number) *Number) Initialiser {
5655
return func(n int64) *Number {
5756
return &Number{big.NewInt(n), limiter}
5857
}
5958
}
6059

61-
// Return a Number with a UNSIGNED limiter up to 256 bits
60+
// Uint256 returns a Number with a UNSIGNED limiter up to 256 bits
6261
func Uint256(n int64) *Number {
6362
return &Number{big.NewInt(n), limitUnsigned256}
6463
}
6564

66-
// Return a Number with a SIGNED limiter up to 256 bits
65+
// Int256 returns Number with a SIGNED limiter up to 256 bits
6766
func Int256(n int64) *Number {
6867
return &Number{big.NewInt(n), limitSigned256}
6968
}
7069

71-
// Returns a Number with a SIGNED unlimited size
70+
// Big returns a Number with a SIGNED unlimited size
7271
func Big(n int64) *Number {
7372
return &Number{big.NewInt(n), func(x *Number) *Number { return x }}
7473
}
7574

76-
// Sets i to sum of x+y
75+
// Add sets i to sum of x+y
7776
func (i *Number) Add(x, y *Number) *Number {
7877
i.num.Add(x.num, y.num)
7978
return i.limit(i)
8079
}
8180

82-
// Sets i to difference of x-y
81+
// Sub sets i to difference of x-y
8382
func (i *Number) Sub(x, y *Number) *Number {
8483
i.num.Sub(x.num, y.num)
8584
return i.limit(i)
8685
}
8786

88-
// Sets i to product of x*y
87+
// Mul sets i to product of x*y
8988
func (i *Number) Mul(x, y *Number) *Number {
9089
i.num.Mul(x.num, y.num)
9190
return i.limit(i)
9291
}
9392

94-
// Sets i to the quotient prodject of x/y
93+
// Div sets i to the quotient prodject of x/y
9594
func (i *Number) Div(x, y *Number) *Number {
9695
i.num.Div(x.num, y.num)
9796
return i.limit(i)
9897
}
9998

100-
// Sets i to x % y
99+
// Mod sets i to x % y
101100
func (i *Number) Mod(x, y *Number) *Number {
102101
i.num.Mod(x.num, y.num)
103102
return i.limit(i)
104103
}
105104

106-
// Sets i to x << s
105+
// Lsh sets i to x << s
107106
func (i *Number) Lsh(x *Number, s uint) *Number {
108107
i.num.Lsh(x.num, s)
109108
return i.limit(i)
110109
}
111110

112-
// Sets i to x^y
111+
// Pow sets i to x^y
113112
func (i *Number) Pow(x, y *Number) *Number {
114113
i.num.Exp(x.num, y.num, big.NewInt(0))
115114
return i.limit(i)
116115
}
117116

118117
// Setters
119118

120-
// Set x to i
119+
// Set sets x to i
121120
func (i *Number) Set(x *Number) *Number {
122121
i.num.Set(x.num)
123122
return i.limit(i)
124123
}
125124

126-
// Set x bytes to i
125+
// SetBytes sets x bytes to i
127126
func (i *Number) SetBytes(x []byte) *Number {
128127
i.num.SetBytes(x)
129128
return i.limit(i)
@@ -140,12 +139,12 @@ func (i *Number) Cmp(x *Number) int {
140139

141140
// Getters
142141

143-
// Returns the string representation of i
142+
// String returns the string representation of i
144143
func (i *Number) String() string {
145144
return i.num.String()
146145
}
147146

148-
// Returns the byte representation of i
147+
// Bytes returns the byte representation of i
149148
func (i *Number) Bytes() []byte {
150149
return i.num.Bytes()
151150
}
@@ -160,17 +159,17 @@ func (i *Number) Int64() int64 {
160159
return i.num.Int64()
161160
}
162161

163-
// Returns the signed version of i
162+
// Int256 returns the signed version of i
164163
func (i *Number) Int256() *Number {
165164
return Int(0).Set(i)
166165
}
167166

168-
// Returns the unsigned version of i
167+
// Uint256 returns the unsigned version of i
169168
func (i *Number) Uint256() *Number {
170169
return Uint(0).Set(i)
171170
}
172171

173-
// Returns the index of the first bit that's set to 1
172+
// FirstBitSet returns the index of the first bit that's set to 1
174173
func (i *Number) FirstBitSet() int {
175174
for j := 0; j < i.num.BitLen(); j++ {
176175
if i.num.Bit(j) > 0 {

common/path.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func MakeName(name, version string) string {
3030
return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
3131
}
3232

33+
// FileExist checks if a file exists at filePath.
3334
func FileExist(filePath string) bool {
3435
_, err := os.Stat(filePath)
3536
if err != nil && os.IsNotExist(err) {
@@ -39,9 +40,10 @@ func FileExist(filePath string) bool {
3940
return true
4041
}
4142

42-
func AbsolutePath(Datadir string, filename string) string {
43+
// AbsolutePath returns datadir + filename, or filename if it is absolute.
44+
func AbsolutePath(datadir string, filename string) string {
4345
if filepath.IsAbs(filename) {
4446
return filename
4547
}
46-
return filepath.Join(Datadir, filename)
48+
return filepath.Join(datadir, filename)
4749
}

0 commit comments

Comments
 (0)