Compare commits

..

13 Commits

Author SHA1 Message Date
Péter Szilágyi
eae63c511c params: release Geth 1.8.10 hotfix 2018-05-30 11:00:07 +03:00
Péter Szilágyi
ca34e8230e Merge pull request #16843 from karalabe/txpool-fix-deadlock
core: fix transaction event asynchronicity
2018-05-30 10:45:02 +03:00
Péter Szilágyi
342ec83d67 core: fix transaction event asynchronicity 2018-05-30 10:14:00 +03:00
Wenbiao Zheng
38c7eb0f26 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.
2018-05-29 17:48:43 +02:00
Péter Szilágyi
d51faee240 Merge pull request #16831 from abeln/patch-1
core/vm: fix typo in comment
2018-05-29 15:44:30 +03:00
kimmylin
426f62f1a8 core: improve test for TransactionPriceNonceSort (#16413) 2018-05-29 14:21:04 +02:00
Dmitry Shulyak
7677ec1f34 p2p/discv5: add egress/ingress traffic metrics to discv5 udp transport (#16369) 2018-05-29 13:46:09 +02:00
Abel Nieto
d258eee211 core/vm: fix typo in comment 2018-05-29 13:22:00 +02:00
kiel barry
84f8c0cc1f 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.
2018-05-29 12:42:21 +02:00
Andrea Franz
998f6564b2 whisper/shhclient: update call to shh_post to expect string instead of bool (#16757)
Fixes #16756
2018-05-29 04:36:31 -04:00
Smilenator
40a2c52397 eth/fetcher: reuse variables for hash and number (#16819) 2018-05-29 10:57:08 +03:00
Mohanson
a9c6ef6905 ethereum: fix a typo in FilterQuery{} (#16827)
Fix a spelling mistake in comment
2018-05-29 10:44:06 +03:00
Péter Szilágyi
ccc0debb63 VERSION, params: begin 1.8.10 release cycle 2018-05-28 13:01:20 +03:00
24 changed files with 152 additions and 210 deletions

View File

@@ -1 +1 @@
1.8.9 1.8.10

View File

@@ -19,15 +19,20 @@ package common
import "encoding/hex" import "encoding/hex"
// ToHex returns the hex representation of b, prefixed with '0x'.
// For empty slices, the return value is "0x0".
//
// Deprecated: use hexutil.Encode instead.
func ToHex(b []byte) string { func ToHex(b []byte) string {
hex := Bytes2Hex(b) hex := Bytes2Hex(b)
// Prefer output of "0x0" instead of "0x"
if len(hex) == 0 { if len(hex) == 0 {
hex = "0" hex = "0"
} }
return "0x" + hex return "0x" + hex
} }
// FromHex returns the bytes represented by the hexadecimal string s.
// s may be prefixed with "0x".
func FromHex(s string) []byte { func FromHex(s string) []byte {
if len(s) > 1 { if len(s) > 1 {
if s[0:2] == "0x" || s[0:2] == "0X" { if s[0:2] == "0x" || s[0:2] == "0X" {
@@ -40,9 +45,7 @@ func FromHex(s string) []byte {
return Hex2Bytes(s) return Hex2Bytes(s)
} }
// Copy bytes // CopyBytes returns an exact copy of the provided bytes.
//
// Returns an exact copy of the provided bytes
func CopyBytes(b []byte) (copiedBytes []byte) { func CopyBytes(b []byte) (copiedBytes []byte) {
if b == nil { if b == nil {
return nil return nil
@@ -53,14 +56,17 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
return return
} }
// hasHexPrefix validates str begins with '0x' or '0X'.
func hasHexPrefix(str string) bool { func hasHexPrefix(str string) bool {
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X') return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
} }
// isHexCharacter returns bool of c being a valid hexadecimal.
func isHexCharacter(c byte) bool { func isHexCharacter(c byte) bool {
return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F') return ('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')
} }
// isHex validates whether each byte is valid hexadecimal string.
func isHex(str string) bool { func isHex(str string) bool {
if len(str)%2 != 0 { if len(str)%2 != 0 {
return false return false
@@ -73,16 +79,18 @@ func isHex(str string) bool {
return true return true
} }
// Bytes2Hex returns the hexadecimal encoding of d.
func Bytes2Hex(d []byte) string { func Bytes2Hex(d []byte) string {
return hex.EncodeToString(d) return hex.EncodeToString(d)
} }
// Hex2Bytes returns the bytes represented by the hexadecimal string str.
func Hex2Bytes(str string) []byte { func Hex2Bytes(str string) []byte {
h, _ := hex.DecodeString(str) h, _ := hex.DecodeString(str)
return h return h
} }
// Hex2BytesFixed returns bytes of a specified fixed length flen.
func Hex2BytesFixed(str string, flen int) []byte { func Hex2BytesFixed(str string, flen int) []byte {
h, _ := hex.DecodeString(str) h, _ := hex.DecodeString(str)
if len(h) == flen { if len(h) == flen {
@@ -96,6 +104,7 @@ func Hex2BytesFixed(str string, flen int) []byte {
return hh return hh
} }
// RightPadBytes zero-pads slice to the right up to length l.
func RightPadBytes(slice []byte, l int) []byte { func RightPadBytes(slice []byte, l int) []byte {
if l <= len(slice) { if l <= len(slice) {
return slice return slice
@@ -107,6 +116,7 @@ func RightPadBytes(slice []byte, l int) []byte {
return padded return padded
} }
// LeftPadBytes zero-pads slice to the left up to length l.
func LeftPadBytes(slice []byte, l int) []byte { func LeftPadBytes(slice []byte, l int) []byte {
if l <= len(slice) { if l <= len(slice) {
return slice return slice

View File

@@ -78,7 +78,7 @@ func ParseBig256(s string) (*big.Int, bool) {
return bigint, ok return bigint, ok
} }
// MustParseBig parses s as a 256 bit big integer and panics if the string is invalid. // MustParseBig256 parses s as a 256 bit big integer and panics if the string is invalid.
func MustParseBig256(s string) *big.Int { func MustParseBig256(s string) *big.Int {
v, ok := ParseBig256(s) v, ok := ParseBig256(s)
if !ok { if !ok {
@@ -186,9 +186,8 @@ func U256(x *big.Int) *big.Int {
func S256(x *big.Int) *big.Int { func S256(x *big.Int) *big.Int {
if x.Cmp(tt255) < 0 { if x.Cmp(tt255) < 0 {
return x return x
} else {
return new(big.Int).Sub(x, tt256)
} }
return new(big.Int).Sub(x, tt256)
} }
// Exp implements exponentiation by squaring. // Exp implements exponentiation by squaring.

View File

@@ -34,13 +34,12 @@ func limitUnsigned256(x *Number) *Number {
func limitSigned256(x *Number) *Number { func limitSigned256(x *Number) *Number {
if x.num.Cmp(tt255) < 0 { if x.num.Cmp(tt255) < 0 {
return x return x
} else {
x.num.Sub(x.num, tt256)
return x
} }
x.num.Sub(x.num, tt256)
return x
} }
// Number function // Initialiser is a Number function
type Initialiser func(n int64) *Number type Initialiser func(n int64) *Number
// A Number represents a generic integer with a bounding function limiter. Limit is called after each operations // A Number represents a generic integer with a bounding function limiter. Limit is called after each operations
@@ -51,65 +50,65 @@ type Number struct {
limit func(n *Number) *Number limit func(n *Number) *Number
} }
// Returns a new initialiser for a new *Number without having to expose certain fields // NewInitialiser returns a new initialiser for a new *Number without having to expose certain fields
func NewInitialiser(limiter func(*Number) *Number) Initialiser { func NewInitialiser(limiter func(*Number) *Number) Initialiser {
return func(n int64) *Number { return func(n int64) *Number {
return &Number{big.NewInt(n), limiter} return &Number{big.NewInt(n), limiter}
} }
} }
// Return a Number with a UNSIGNED limiter up to 256 bits // Uint256 returns a Number with a UNSIGNED limiter up to 256 bits
func Uint256(n int64) *Number { func Uint256(n int64) *Number {
return &Number{big.NewInt(n), limitUnsigned256} return &Number{big.NewInt(n), limitUnsigned256}
} }
// Return a Number with a SIGNED limiter up to 256 bits // Int256 returns Number with a SIGNED limiter up to 256 bits
func Int256(n int64) *Number { func Int256(n int64) *Number {
return &Number{big.NewInt(n), limitSigned256} return &Number{big.NewInt(n), limitSigned256}
} }
// Returns a Number with a SIGNED unlimited size // Big returns a Number with a SIGNED unlimited size
func Big(n int64) *Number { func Big(n int64) *Number {
return &Number{big.NewInt(n), func(x *Number) *Number { return x }} return &Number{big.NewInt(n), func(x *Number) *Number { return x }}
} }
// Sets i to sum of x+y // Add sets i to sum of x+y
func (i *Number) Add(x, y *Number) *Number { func (i *Number) Add(x, y *Number) *Number {
i.num.Add(x.num, y.num) i.num.Add(x.num, y.num)
return i.limit(i) return i.limit(i)
} }
// Sets i to difference of x-y // Sub sets i to difference of x-y
func (i *Number) Sub(x, y *Number) *Number { func (i *Number) Sub(x, y *Number) *Number {
i.num.Sub(x.num, y.num) i.num.Sub(x.num, y.num)
return i.limit(i) return i.limit(i)
} }
// Sets i to product of x*y // Mul sets i to product of x*y
func (i *Number) Mul(x, y *Number) *Number { func (i *Number) Mul(x, y *Number) *Number {
i.num.Mul(x.num, y.num) i.num.Mul(x.num, y.num)
return i.limit(i) return i.limit(i)
} }
// Sets i to the quotient prodject of x/y // Div sets i to the quotient prodject of x/y
func (i *Number) Div(x, y *Number) *Number { func (i *Number) Div(x, y *Number) *Number {
i.num.Div(x.num, y.num) i.num.Div(x.num, y.num)
return i.limit(i) return i.limit(i)
} }
// Sets i to x % y // Mod sets i to x % y
func (i *Number) Mod(x, y *Number) *Number { func (i *Number) Mod(x, y *Number) *Number {
i.num.Mod(x.num, y.num) i.num.Mod(x.num, y.num)
return i.limit(i) return i.limit(i)
} }
// Sets i to x << s // Lsh sets i to x << s
func (i *Number) Lsh(x *Number, s uint) *Number { func (i *Number) Lsh(x *Number, s uint) *Number {
i.num.Lsh(x.num, s) i.num.Lsh(x.num, s)
return i.limit(i) return i.limit(i)
} }
// Sets i to x^y // Pow sets i to x^y
func (i *Number) Pow(x, y *Number) *Number { func (i *Number) Pow(x, y *Number) *Number {
i.num.Exp(x.num, y.num, big.NewInt(0)) i.num.Exp(x.num, y.num, big.NewInt(0))
return i.limit(i) return i.limit(i)
@@ -117,13 +116,13 @@ func (i *Number) Pow(x, y *Number) *Number {
// Setters // Setters
// Set x to i // Set sets x to i
func (i *Number) Set(x *Number) *Number { func (i *Number) Set(x *Number) *Number {
i.num.Set(x.num) i.num.Set(x.num)
return i.limit(i) return i.limit(i)
} }
// Set x bytes to i // SetBytes sets x bytes to i
func (i *Number) SetBytes(x []byte) *Number { func (i *Number) SetBytes(x []byte) *Number {
i.num.SetBytes(x) i.num.SetBytes(x)
return i.limit(i) return i.limit(i)
@@ -140,12 +139,12 @@ func (i *Number) Cmp(x *Number) int {
// Getters // Getters
// Returns the string representation of i // String returns the string representation of i
func (i *Number) String() string { func (i *Number) String() string {
return i.num.String() return i.num.String()
} }
// Returns the byte representation of i // Bytes returns the byte representation of i
func (i *Number) Bytes() []byte { func (i *Number) Bytes() []byte {
return i.num.Bytes() return i.num.Bytes()
} }
@@ -160,17 +159,17 @@ func (i *Number) Int64() int64 {
return i.num.Int64() return i.num.Int64()
} }
// Returns the signed version of i // Int256 returns the signed version of i
func (i *Number) Int256() *Number { func (i *Number) Int256() *Number {
return Int(0).Set(i) return Int(0).Set(i)
} }
// Returns the unsigned version of i // Uint256 returns the unsigned version of i
func (i *Number) Uint256() *Number { func (i *Number) Uint256() *Number {
return Uint(0).Set(i) return Uint(0).Set(i)
} }
// Returns the index of the first bit that's set to 1 // FirstBitSet returns the index of the first bit that's set to 1
func (i *Number) FirstBitSet() int { func (i *Number) FirstBitSet() int {
for j := 0; j < i.num.BitLen(); j++ { for j := 0; j < i.num.BitLen(); j++ {
if i.num.Bit(j) > 0 { if i.num.Bit(j) > 0 {

View File

@@ -30,6 +30,7 @@ func MakeName(name, version string) string {
return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version()) return fmt.Sprintf("%s/v%s/%s/%s", name, version, runtime.GOOS, runtime.Version())
} }
// FileExist checks if a file exists at filePath.
func FileExist(filePath string) bool { func FileExist(filePath string) bool {
_, err := os.Stat(filePath) _, err := os.Stat(filePath)
if err != nil && os.IsNotExist(err) { if err != nil && os.IsNotExist(err) {
@@ -39,9 +40,10 @@ func FileExist(filePath string) bool {
return true return true
} }
func AbsolutePath(Datadir string, filename string) string { // AbsolutePath returns datadir + filename, or filename if it is absolute.
func AbsolutePath(datadir string, filename string) string {
if filepath.IsAbs(filename) { if filepath.IsAbs(filename) {
return filename return filename
} }
return filepath.Join(Datadir, filename) return filepath.Join(datadir, filename)
} }

View File

@@ -42,19 +42,30 @@ var (
// Hash represents the 32 byte Keccak256 hash of arbitrary data. // Hash represents the 32 byte Keccak256 hash of arbitrary data.
type Hash [HashLength]byte type Hash [HashLength]byte
// BytesToHash sets b to hash.
// If b is larger than len(h), b will be cropped from the left.
func BytesToHash(b []byte) Hash { func BytesToHash(b []byte) Hash {
var h Hash var h Hash
h.SetBytes(b) h.SetBytes(b)
return h return h
} }
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
// Get the string representation of the underlying hash // BigToHash sets byte representation of b to hash.
func (h Hash) Str() string { return string(h[:]) } // If b is larger than len(h), b will be cropped from the left.
func BigToHash(b *big.Int) Hash { return BytesToHash(b.Bytes()) }
// HexToHash sets byte representation of s to hash.
// If b is larger than len(h), b will be cropped from the left.
func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) }
// Bytes gets the byte representation of the underlying hash.
func (h Hash) Bytes() []byte { return h[:] } func (h Hash) Bytes() []byte { return h[:] }
// Big converts a hash to a big integer.
func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) } func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) }
func (h Hash) Hex() string { return hexutil.Encode(h[:]) }
// Hex converts a hash to a hex string.
func (h Hash) Hex() string { return hexutil.Encode(h[:]) }
// TerminalString implements log.TerminalStringer, formatting a string for console // TerminalString implements log.TerminalStringer, formatting a string for console
// output during logging. // output during logging.
@@ -89,7 +100,8 @@ func (h Hash) MarshalText() ([]byte, error) {
return hexutil.Bytes(h[:]).MarshalText() return hexutil.Bytes(h[:]).MarshalText()
} }
// Sets the hash to the value of b. If b is larger than len(h), 'b' will be cropped (from the left). // SetBytes sets the hash to the value of b.
// If b is larger than len(h), b will be cropped from the left.
func (h *Hash) SetBytes(b []byte) { func (h *Hash) SetBytes(b []byte) {
if len(b) > len(h) { if len(b) > len(h) {
b = b[len(b)-HashLength:] b = b[len(b)-HashLength:]
@@ -98,16 +110,6 @@ func (h *Hash) SetBytes(b []byte) {
copy(h[HashLength-len(b):], b) copy(h[HashLength-len(b):], b)
} }
// Set string `s` to h. If s is larger than len(h) s will be cropped (from left) to fit.
func (h *Hash) SetString(s string) { h.SetBytes([]byte(s)) }
// Sets h to other
func (h *Hash) Set(other Hash) {
for i, v := range other {
h[i] = v
}
}
// Generate implements testing/quick.Generator. // Generate implements testing/quick.Generator.
func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value { func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value {
m := rand.Intn(len(h)) m := rand.Intn(len(h))
@@ -117,10 +119,6 @@ func (h Hash) Generate(rand *rand.Rand, size int) reflect.Value {
return reflect.ValueOf(h) return reflect.ValueOf(h)
} }
func EmptyHash(h Hash) bool {
return h == Hash{}
}
// UnprefixedHash allows marshaling a Hash without 0x prefix. // UnprefixedHash allows marshaling a Hash without 0x prefix.
type UnprefixedHash Hash type UnprefixedHash Hash
@@ -139,13 +137,21 @@ func (h UnprefixedHash) MarshalText() ([]byte, error) {
// Address represents the 20 byte address of an Ethereum account. // Address represents the 20 byte address of an Ethereum account.
type Address [AddressLength]byte type Address [AddressLength]byte
// BytesToAddress returns Address with value b.
// If b is larger than len(h), b will be cropped from the left.
func BytesToAddress(b []byte) Address { func BytesToAddress(b []byte) Address {
var a Address var a Address
a.SetBytes(b) a.SetBytes(b)
return a return a
} }
// BigToAddress returns Address with byte values of b.
// If b is larger than len(h), b will be cropped from the left.
func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) } func BigToAddress(b *big.Int) Address { return BytesToAddress(b.Bytes()) }
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
// HexToAddress returns Address with byte values of s.
// If s is larger than len(h), s will be cropped from the left.
func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
// IsHexAddress verifies whether a string can represent a valid hex-encoded // IsHexAddress verifies whether a string can represent a valid hex-encoded
// Ethereum address or not. // Ethereum address or not.
@@ -156,11 +162,14 @@ func IsHexAddress(s string) bool {
return len(s) == 2*AddressLength && isHex(s) return len(s) == 2*AddressLength && isHex(s)
} }
// Get the string representation of the underlying address // Bytes gets the string representation of the underlying address.
func (a Address) Str() string { return string(a[:]) }
func (a Address) Bytes() []byte { return a[:] } func (a Address) Bytes() []byte { return a[:] }
// Big converts an address to a big integer.
func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) } func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) }
func (a Address) Hash() Hash { return BytesToHash(a[:]) }
// Hash converts an address to a hash by left-padding it with zeros.
func (a Address) Hash() Hash { return BytesToHash(a[:]) }
// Hex returns an EIP55-compliant hex string representation of the address. // Hex returns an EIP55-compliant hex string representation of the address.
func (a Address) Hex() string { func (a Address) Hex() string {
@@ -184,7 +193,7 @@ func (a Address) Hex() string {
return "0x" + string(result) return "0x" + string(result)
} }
// String implements the stringer interface and is used also by the logger. // String implements fmt.Stringer.
func (a Address) String() string { func (a Address) String() string {
return a.Hex() return a.Hex()
} }
@@ -195,7 +204,8 @@ func (a Address) Format(s fmt.State, c rune) {
fmt.Fprintf(s, "%"+string(c), a[:]) fmt.Fprintf(s, "%"+string(c), a[:])
} }
// Sets the address to the value of b. If b is larger than len(a) it will panic // SetBytes sets the address to the value of b.
// If b is larger than len(a) it will panic.
func (a *Address) SetBytes(b []byte) { func (a *Address) SetBytes(b []byte) {
if len(b) > len(a) { if len(b) > len(a) {
b = b[len(b)-AddressLength:] b = b[len(b)-AddressLength:]
@@ -203,16 +213,6 @@ func (a *Address) SetBytes(b []byte) {
copy(a[AddressLength-len(b):], b) copy(a[AddressLength-len(b):], b)
} }
// Set string `s` to a. If s is larger than len(a) it will panic
func (a *Address) SetString(s string) { a.SetBytes([]byte(s)) }
// Sets a to other
func (a *Address) Set(other Address) {
for i, v := range other {
a[i] = v
}
}
// MarshalText returns the hex representation of a. // MarshalText returns the hex representation of a.
func (a Address) MarshalText() ([]byte, error) { func (a Address) MarshalText() ([]byte, error) {
return hexutil.Bytes(a[:]).MarshalText() return hexutil.Bytes(a[:]).MarshalText()
@@ -228,7 +228,7 @@ func (a *Address) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(addressT, input, a[:]) return hexutil.UnmarshalFixedJSON(addressT, input, a[:])
} }
// UnprefixedHash allows marshaling an Address without 0x prefix. // UnprefixedAddress allows marshaling an Address without 0x prefix.
type UnprefixedAddress Address type UnprefixedAddress Address
// UnmarshalText decodes the address from hex. The 0x prefix is optional. // UnmarshalText decodes the address from hex. The 0x prefix is optional.

View File

@@ -1,64 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// +build none
//sed -e 's/_N_/Hash/g' -e 's/_S_/32/g' -e '1d' types_template.go | gofmt -w hash.go
package common
import "math/big"
type _N_ [_S_]byte
func BytesTo_N_(b []byte) _N_ {
var h _N_
h.SetBytes(b)
return h
}
func StringTo_N_(s string) _N_ { return BytesTo_N_([]byte(s)) }
func BigTo_N_(b *big.Int) _N_ { return BytesTo_N_(b.Bytes()) }
func HexTo_N_(s string) _N_ { return BytesTo_N_(FromHex(s)) }
// Don't use the default 'String' method in case we want to overwrite
// Get the string representation of the underlying hash
func (h _N_) Str() string { return string(h[:]) }
func (h _N_) Bytes() []byte { return h[:] }
func (h _N_) Big() *big.Int { return new(big.Int).SetBytes(h[:]) }
func (h _N_) Hex() string { return "0x" + Bytes2Hex(h[:]) }
// Sets the hash to the value of b. If b is larger than len(h) it will panic
func (h *_N_) SetBytes(b []byte) {
// Use the right most bytes
if len(b) > len(h) {
b = b[len(b)-_S_:]
}
// Reverse the loop
for i := len(b) - 1; i >= 0; i-- {
h[_S_-len(b)+i] = b[i]
}
}
// Set string `s` to h. If s is larger than len(h) it will panic
func (h *_N_) SetString(s string) { h.SetBytes([]byte(s)) }
// Sets h to other
func (h *_N_) Set(other _N_) {
for i, v := range other {
h[i] = v
}
}

View File

@@ -99,7 +99,7 @@ func (s *StateSuite) TestNull(c *checker.C) {
s.state.SetState(address, common.Hash{}, value) s.state.SetState(address, common.Hash{}, value)
s.state.Commit(false) s.state.Commit(false)
value = s.state.GetState(address, common.Hash{}) value = s.state.GetState(address, common.Hash{})
if !common.EmptyHash(value) { if value != (common.Hash{}) {
c.Errorf("expected empty hash. got %x", value) c.Errorf("expected empty hash. got %x", value)
} }
} }

View File

@@ -25,8 +25,8 @@ import (
) )
// NewStateSync create a new state trie download scheduler. // NewStateSync create a new state trie download scheduler.
func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.TrieSync { func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.Sync {
var syncer *trie.TrieSync var syncer *trie.Sync
callback := func(leaf []byte, parent common.Hash) error { callback := func(leaf []byte, parent common.Hash) error {
var obj Account var obj Account
if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil { if err := rlp.Decode(bytes.NewReader(leaf), &obj); err != nil {
@@ -36,6 +36,6 @@ func NewStateSync(root common.Hash, database trie.DatabaseReader) *trie.TrieSync
syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent) syncer.AddRawEntry(common.BytesToHash(obj.CodeHash), 64, parent)
return nil return nil
} }
syncer = trie.NewTrieSync(root, database, callback) syncer = trie.NewSync(root, database, callback)
return syncer return syncer
} }

View File

@@ -962,7 +962,7 @@ func (pool *TxPool) promoteExecutables(accounts []common.Address) {
} }
// Notify subsystem for new promoted transactions. // Notify subsystem for new promoted transactions.
if len(promoted) > 0 { if len(promoted) > 0 {
pool.txFeed.Send(NewTxsEvent{promoted}) go pool.txFeed.Send(NewTxsEvent{promoted})
} }
// If the pending limit is overflown, start equalizing allowances // If the pending limit is overflown, start equalizing allowances
pending := uint64(0) pending := uint64(0)

View File

@@ -165,28 +165,13 @@ func TestTransactionPriceNonceSort(t *testing.T) {
t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce()) t.Errorf("invalid nonce ordering: tx #%d (A=%x N=%v) < tx #%d (A=%x N=%v)", i, fromi[:4], txi.Nonce(), i+j, fromj[:4], txj.Nonce())
} }
} }
// Find the previous and next nonce of this account
prev, next := i-1, i+1 // If the next tx has different from account, the price must be lower than the current one
for j := i - 1; j >= 0; j-- { if i+1 < len(txs) {
if fromj, _ := Sender(signer, txs[j]); fromi == fromj { next := txs[i+1]
prev = j fromNext, _ := Sender(signer, next)
break if fromi != fromNext && txi.GasPrice().Cmp(next.GasPrice()) < 0 {
} t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", i, fromi[:4], txi.GasPrice(), i+1, fromNext[:4], next.GasPrice())
}
for j := i + 1; j < len(txs); j++ {
if fromj, _ := Sender(signer, txs[j]); fromi == fromj {
next = j
break
}
}
// Make sure that in between the neighbor nonces, the transaction is correctly positioned price wise
for j := prev + 1; j < next; j++ {
fromj, _ := Sender(signer, txs[j])
if j < i && txs[j].GasPrice().Cmp(txi.GasPrice()) < 0 {
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) < tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
}
if j > i && txs[j].GasPrice().Cmp(txi.GasPrice()) > 0 {
t.Errorf("invalid gasprice ordering: tx #%d (A=%x P=%v) > tx #%d (A=%x P=%v)", j, fromj[:4], txs[j].GasPrice(), i, fromi[:4], txi.GasPrice())
} }
} }
} }

View File

@@ -124,12 +124,12 @@ func gasSStore(gt params.GasTable, evm *EVM, contract *Contract, stack *Stack, m
// 1. From a zero-value address to a non-zero value (NEW VALUE) // 1. From a zero-value address to a non-zero value (NEW VALUE)
// 2. From a non-zero value address to a zero-value address (DELETE) // 2. From a non-zero value address to a zero-value address (DELETE)
// 3. From a non-zero to a non-zero (CHANGE) // 3. From a non-zero to a non-zero (CHANGE)
if common.EmptyHash(val) && !common.EmptyHash(common.BigToHash(y)) { if val == (common.Hash{}) && y.Sign() != 0 {
// 0 => non 0 // 0 => non 0
return params.SstoreSetGas, nil return params.SstoreSetGas, nil
} else if !common.EmptyHash(val) && common.EmptyHash(common.BigToHash(y)) { } else if val != (common.Hash{}) && y.Sign() == 0 {
// non 0 => 0
evm.StateDB.AddRefund(params.SstoreRefundGas) evm.StateDB.AddRefund(params.SstoreRefundGas)
return params.SstoreClearGas, nil return params.SstoreClearGas, nil
} else { } else {
// non 0 => non 0 (or 0 => 0) // non 0 => non 0 (or 0 => 0)

View File

@@ -33,7 +33,7 @@ type (
var errGasUintOverflow = errors.New("gas uint64 overflow") var errGasUintOverflow = errors.New("gas uint64 overflow")
type operation struct { type operation struct {
// op is the operation function // execute is the operation function
execute executionFunc execute executionFunc
// gasCost is the gas function and returns the gas required for execution // gasCost is the gas function and returns the gas required for execution
gasCost gasFunc gasCost gasFunc

View File

@@ -680,7 +680,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err
} }
} }
// If the head fetch already found an ancestor, return // If the head fetch already found an ancestor, return
if !common.EmptyHash(hash) { if hash != (common.Hash{}) {
if int64(number) <= floor { if int64(number) <= floor {
p.log.Warn("Ancestor below allowance", "number", number, "hash", hash, "allowance", floor) p.log.Warn("Ancestor below allowance", "number", number, "hash", hash, "allowance", floor)
return 0, errInvalidAncestor return 0, errInvalidAncestor

View File

@@ -214,7 +214,7 @@ func (d *Downloader) runStateSync(s *stateSync) *stateSync {
type stateSync struct { type stateSync struct {
d *Downloader // Downloader instance to access and manage current peerset d *Downloader // Downloader instance to access and manage current peerset
sched *trie.TrieSync // State trie sync scheduler defining the tasks sched *trie.Sync // State trie sync scheduler defining the tasks
keccak hash.Hash // Keccak256 hasher to verify deliveries with keccak hash.Hash // Keccak256 hasher to verify deliveries with
tasks map[common.Hash]*stateTask // Set of tasks currently queued for retrieval tasks map[common.Hash]*stateTask // Set of tasks currently queued for retrieval

View File

@@ -292,20 +292,20 @@ func (f *Fetcher) loop() {
height := f.chainHeight() height := f.chainHeight()
for !f.queue.Empty() { for !f.queue.Empty() {
op := f.queue.PopItem().(*inject) op := f.queue.PopItem().(*inject)
hash := op.block.Hash()
if f.queueChangeHook != nil { if f.queueChangeHook != nil {
f.queueChangeHook(op.block.Hash(), false) f.queueChangeHook(hash, false)
} }
// If too high up the chain or phase, continue later // If too high up the chain or phase, continue later
number := op.block.NumberU64() number := op.block.NumberU64()
if number > height+1 { if number > height+1 {
f.queue.Push(op, -float32(op.block.NumberU64())) f.queue.Push(op, -float32(number))
if f.queueChangeHook != nil { if f.queueChangeHook != nil {
f.queueChangeHook(op.block.Hash(), true) f.queueChangeHook(hash, true)
} }
break break
} }
// Otherwise if fresh and still unknown, try and import // Otherwise if fresh and still unknown, try and import
hash := op.block.Hash()
if number+maxUncleDist < height || f.getBlock(hash) != nil { if number+maxUncleDist < height || f.getBlock(hash) != nil {
f.forgetBlock(hash) f.forgetBlock(hash)
continue continue

View File

@@ -144,7 +144,7 @@ type FilterQuery struct {
// {} or nil matches any topic list // {} or nil matches any topic list
// {{A}} matches topic A in first position // {{A}} matches topic A in first position
// {{}, {B}} matches any topic in first position, B in second position // {{}, {B}} matches any topic in first position, B in second position
// {{A}}, {B}} matches topic A in first position, B in second position // {{A}, {B}} matches topic A in first position, B in second position
// {{A, B}}, {C, D}} matches topic (A OR B) in first position, (C OR D) in second position // {{A, B}}, {C, D}} matches topic (A OR B) in first position, (C OR D) in second position
Topics [][]common.Hash Topics [][]common.Hash
} }

8
p2p/discv5/metrics.go Normal file
View File

@@ -0,0 +1,8 @@
package discv5
import "github.com/ethereum/go-ethereum/metrics"
var (
ingressTrafficMeter = metrics.NewRegisteredMeter("discv5/InboundTraffic", nil)
egressTrafficMeter = metrics.NewRegisteredMeter("discv5/OutboundTraffic", nil)
)

View File

@@ -334,8 +334,10 @@ func (t *udp) sendPacket(toid NodeID, toaddr *net.UDPAddr, ptype byte, req inter
return hash, err return hash, err
} }
log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr)) log.Trace(fmt.Sprintf(">>> %v to %x@%v", nodeEvent(ptype), toid[:8], toaddr))
if _, err = t.conn.WriteToUDP(packet, toaddr); err != nil { if nbytes, err := t.conn.WriteToUDP(packet, toaddr); err != nil {
log.Trace(fmt.Sprint("UDP send failed:", err)) log.Trace(fmt.Sprint("UDP send failed:", err))
} else {
egressTrafficMeter.Mark(int64(nbytes))
} }
//fmt.Println(err) //fmt.Println(err)
return hash, err return hash, err
@@ -374,6 +376,7 @@ func (t *udp) readLoop() {
buf := make([]byte, 1280) buf := make([]byte, 1280)
for { for {
nbytes, from, err := t.conn.ReadFromUDP(buf) nbytes, from, err := t.conn.ReadFromUDP(buf)
ingressTrafficMeter.Mark(int64(nbytes))
if netutil.IsTemporaryError(err) { if netutil.IsTemporaryError(err) {
// Ignore temporary read errors. // Ignore temporary read errors.
log.Debug(fmt.Sprintf("Temporary read error: %v", err)) log.Debug(fmt.Sprintf("Temporary read error: %v", err))

View File

@@ -23,7 +23,7 @@ import (
const ( const (
VersionMajor = 1 // Major version component of the current release VersionMajor = 1 // Major version component of the current release
VersionMinor = 8 // Minor version component of the current release VersionMinor = 8 // Minor version component of the current release
VersionPatch = 9 // Patch version component of the current release VersionPatch = 10 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string VersionMeta = "stable" // Version metadata to append to the version string
) )

View File

@@ -83,7 +83,7 @@ func hexToKeybytes(hex []byte) []byte {
if len(hex)&1 != 0 { if len(hex)&1 != 0 {
panic("can't convert hex key of odd length") panic("can't convert hex key of odd length")
} }
key := make([]byte, (len(hex)+1)/2) key := make([]byte, len(hex)/2)
decodeNibbles(hex, key) decodeNibbles(hex, key)
return key return key
} }

View File

@@ -68,19 +68,19 @@ func newSyncMemBatch() *syncMemBatch {
} }
} }
// TrieSync is the main state trie synchronisation scheduler, which provides yet // Sync is the main state trie synchronisation scheduler, which provides yet
// unknown trie hashes to retrieve, accepts node data associated with said hashes // unknown trie hashes to retrieve, accepts node data associated with said hashes
// and reconstructs the trie step by step until all is done. // and reconstructs the trie step by step until all is done.
type TrieSync struct { type Sync struct {
database DatabaseReader // Persistent database to check for existing entries database DatabaseReader // Persistent database to check for existing entries
membatch *syncMemBatch // Memory buffer to avoid frequest database writes membatch *syncMemBatch // Memory buffer to avoid frequest database writes
requests map[common.Hash]*request // Pending requests pertaining to a key hash requests map[common.Hash]*request // Pending requests pertaining to a key hash
queue *prque.Prque // Priority queue with the pending requests queue *prque.Prque // Priority queue with the pending requests
} }
// NewTrieSync creates a new trie data download scheduler. // NewSync creates a new trie data download scheduler.
func NewTrieSync(root common.Hash, database DatabaseReader, callback LeafCallback) *TrieSync { func NewSync(root common.Hash, database DatabaseReader, callback LeafCallback) *Sync {
ts := &TrieSync{ ts := &Sync{
database: database, database: database,
membatch: newSyncMemBatch(), membatch: newSyncMemBatch(),
requests: make(map[common.Hash]*request), requests: make(map[common.Hash]*request),
@@ -91,7 +91,7 @@ func NewTrieSync(root common.Hash, database DatabaseReader, callback LeafCallbac
} }
// AddSubTrie registers a new trie to the sync code, rooted at the designated parent. // AddSubTrie registers a new trie to the sync code, rooted at the designated parent.
func (s *TrieSync) AddSubTrie(root common.Hash, depth int, parent common.Hash, callback LeafCallback) { func (s *Sync) AddSubTrie(root common.Hash, depth int, parent common.Hash, callback LeafCallback) {
// Short circuit if the trie is empty or already known // Short circuit if the trie is empty or already known
if root == emptyRoot { if root == emptyRoot {
return return
@@ -126,7 +126,7 @@ func (s *TrieSync) AddSubTrie(root common.Hash, depth int, parent common.Hash, c
// interpreted as a trie node, but rather accepted and stored into the database // interpreted as a trie node, but rather accepted and stored into the database
// as is. This method's goal is to support misc state metadata retrievals (e.g. // as is. This method's goal is to support misc state metadata retrievals (e.g.
// contract code). // contract code).
func (s *TrieSync) AddRawEntry(hash common.Hash, depth int, parent common.Hash) { func (s *Sync) AddRawEntry(hash common.Hash, depth int, parent common.Hash) {
// Short circuit if the entry is empty or already known // Short circuit if the entry is empty or already known
if hash == emptyState { if hash == emptyState {
return return
@@ -156,7 +156,7 @@ func (s *TrieSync) AddRawEntry(hash common.Hash, depth int, parent common.Hash)
} }
// Missing retrieves the known missing nodes from the trie for retrieval. // Missing retrieves the known missing nodes from the trie for retrieval.
func (s *TrieSync) Missing(max int) []common.Hash { func (s *Sync) Missing(max int) []common.Hash {
requests := []common.Hash{} requests := []common.Hash{}
for !s.queue.Empty() && (max == 0 || len(requests) < max) { for !s.queue.Empty() && (max == 0 || len(requests) < max) {
requests = append(requests, s.queue.PopItem().(common.Hash)) requests = append(requests, s.queue.PopItem().(common.Hash))
@@ -167,7 +167,7 @@ func (s *TrieSync) Missing(max int) []common.Hash {
// Process injects a batch of retrieved trie nodes data, returning if something // Process injects a batch of retrieved trie nodes data, returning if something
// was committed to the database and also the index of an entry if processing of // was committed to the database and also the index of an entry if processing of
// it failed. // it failed.
func (s *TrieSync) Process(results []SyncResult) (bool, int, error) { func (s *Sync) Process(results []SyncResult) (bool, int, error) {
committed := false committed := false
for i, item := range results { for i, item := range results {
@@ -213,7 +213,7 @@ func (s *TrieSync) Process(results []SyncResult) (bool, int, error) {
// Commit flushes the data stored in the internal membatch out to persistent // Commit flushes the data stored in the internal membatch out to persistent
// storage, returning the number of items written and any occurred error. // storage, returning the number of items written and any occurred error.
func (s *TrieSync) Commit(dbw ethdb.Putter) (int, error) { func (s *Sync) Commit(dbw ethdb.Putter) (int, error) {
// Dump the membatch into a database dbw // Dump the membatch into a database dbw
for i, key := range s.membatch.order { for i, key := range s.membatch.order {
if err := dbw.Put(key[:], s.membatch.batch[key]); err != nil { if err := dbw.Put(key[:], s.membatch.batch[key]); err != nil {
@@ -228,14 +228,14 @@ func (s *TrieSync) Commit(dbw ethdb.Putter) (int, error) {
} }
// Pending returns the number of state entries currently pending for download. // Pending returns the number of state entries currently pending for download.
func (s *TrieSync) Pending() int { func (s *Sync) Pending() int {
return len(s.requests) return len(s.requests)
} }
// schedule inserts a new state retrieval request into the fetch queue. If there // schedule inserts a new state retrieval request into the fetch queue. If there
// is already a pending request for this node, the new request will be discarded // is already a pending request for this node, the new request will be discarded
// and only a parent reference added to the old one. // and only a parent reference added to the old one.
func (s *TrieSync) schedule(req *request) { func (s *Sync) schedule(req *request) {
// If we're already requesting this node, add a new reference and stop // If we're already requesting this node, add a new reference and stop
if old, ok := s.requests[req.hash]; ok { if old, ok := s.requests[req.hash]; ok {
old.parents = append(old.parents, req.parents...) old.parents = append(old.parents, req.parents...)
@@ -248,7 +248,7 @@ func (s *TrieSync) schedule(req *request) {
// children retrieves all the missing children of a state trie entry for future // children retrieves all the missing children of a state trie entry for future
// retrieval scheduling. // retrieval scheduling.
func (s *TrieSync) children(req *request, object node) ([]*request, error) { func (s *Sync) children(req *request, object node) ([]*request, error) {
// Gather all the children of the node, irrelevant whether known or not // Gather all the children of the node, irrelevant whether known or not
type child struct { type child struct {
node node node node
@@ -310,7 +310,7 @@ func (s *TrieSync) children(req *request, object node) ([]*request, error) {
// commit finalizes a retrieval request and stores it into the membatch. If any // commit finalizes a retrieval request and stores it into the membatch. If any
// of the referencing parent requests complete due to this commit, they are also // of the referencing parent requests complete due to this commit, they are also
// committed themselves. // committed themselves.
func (s *TrieSync) commit(req *request) (err error) { func (s *Sync) commit(req *request) (err error) {
// Write the node content to the membatch // Write the node content to the membatch
s.membatch.batch[req.hash] = req.data s.membatch.batch[req.hash] = req.data
s.membatch.order = append(s.membatch.order, req.hash) s.membatch.order = append(s.membatch.order, req.hash)

View File

@@ -87,14 +87,14 @@ func checkTrieConsistency(db *Database, root common.Hash) error {
} }
// Tests that an empty trie is not scheduled for syncing. // Tests that an empty trie is not scheduled for syncing.
func TestEmptyTrieSync(t *testing.T) { func TestEmptySync(t *testing.T) {
dbA := NewDatabase(ethdb.NewMemDatabase()) dbA := NewDatabase(ethdb.NewMemDatabase())
dbB := NewDatabase(ethdb.NewMemDatabase()) dbB := NewDatabase(ethdb.NewMemDatabase())
emptyA, _ := New(common.Hash{}, dbA) emptyA, _ := New(common.Hash{}, dbA)
emptyB, _ := New(emptyRoot, dbB) emptyB, _ := New(emptyRoot, dbB)
for i, trie := range []*Trie{emptyA, emptyB} { for i, trie := range []*Trie{emptyA, emptyB} {
if req := NewTrieSync(trie.Hash(), ethdb.NewMemDatabase(), nil).Missing(1); len(req) != 0 { if req := NewSync(trie.Hash(), ethdb.NewMemDatabase(), nil).Missing(1); len(req) != 0 {
t.Errorf("test %d: content requested for empty trie: %v", i, req) t.Errorf("test %d: content requested for empty trie: %v", i, req)
} }
} }
@@ -102,17 +102,17 @@ func TestEmptyTrieSync(t *testing.T) {
// Tests that given a root hash, a trie can sync iteratively on a single thread, // Tests that given a root hash, a trie can sync iteratively on a single thread,
// requesting retrieval tasks and returning all of them in one go. // requesting retrieval tasks and returning all of them in one go.
func TestIterativeTrieSyncIndividual(t *testing.T) { testIterativeTrieSync(t, 1) } func TestIterativeSyncIndividual(t *testing.T) { testIterativeSync(t, 1) }
func TestIterativeTrieSyncBatched(t *testing.T) { testIterativeTrieSync(t, 100) } func TestIterativeSyncBatched(t *testing.T) { testIterativeSync(t, 100) }
func testIterativeTrieSync(t *testing.T, batch int) { func testIterativeSync(t *testing.T, batch int) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
queue := append([]common.Hash{}, sched.Missing(batch)...) queue := append([]common.Hash{}, sched.Missing(batch)...)
for len(queue) > 0 { for len(queue) > 0 {
@@ -138,14 +138,14 @@ func testIterativeTrieSync(t *testing.T, batch int) {
// Tests that the trie scheduler can correctly reconstruct the state even if only // Tests that the trie scheduler can correctly reconstruct the state even if only
// partial results are returned, and the others sent only later. // partial results are returned, and the others sent only later.
func TestIterativeDelayedTrieSync(t *testing.T) { func TestIterativeDelayedSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
queue := append([]common.Hash{}, sched.Missing(10000)...) queue := append([]common.Hash{}, sched.Missing(10000)...)
for len(queue) > 0 { for len(queue) > 0 {
@@ -173,17 +173,17 @@ func TestIterativeDelayedTrieSync(t *testing.T) {
// Tests that given a root hash, a trie can sync iteratively on a single thread, // Tests that given a root hash, a trie can sync iteratively on a single thread,
// requesting retrieval tasks and returning all of them in one go, however in a // requesting retrieval tasks and returning all of them in one go, however in a
// random order. // random order.
func TestIterativeRandomTrieSyncIndividual(t *testing.T) { testIterativeRandomTrieSync(t, 1) } func TestIterativeRandomSyncIndividual(t *testing.T) { testIterativeRandomSync(t, 1) }
func TestIterativeRandomTrieSyncBatched(t *testing.T) { testIterativeRandomTrieSync(t, 100) } func TestIterativeRandomSyncBatched(t *testing.T) { testIterativeRandomSync(t, 100) }
func testIterativeRandomTrieSync(t *testing.T, batch int) { func testIterativeRandomSync(t *testing.T, batch int) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
queue := make(map[common.Hash]struct{}) queue := make(map[common.Hash]struct{})
for _, hash := range sched.Missing(batch) { for _, hash := range sched.Missing(batch) {
@@ -217,14 +217,14 @@ func testIterativeRandomTrieSync(t *testing.T, batch int) {
// Tests that the trie scheduler can correctly reconstruct the state even if only // Tests that the trie scheduler can correctly reconstruct the state even if only
// partial results are returned (Even those randomly), others sent only later. // partial results are returned (Even those randomly), others sent only later.
func TestIterativeRandomDelayedTrieSync(t *testing.T) { func TestIterativeRandomDelayedSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
queue := make(map[common.Hash]struct{}) queue := make(map[common.Hash]struct{})
for _, hash := range sched.Missing(10000) { for _, hash := range sched.Missing(10000) {
@@ -264,14 +264,14 @@ func TestIterativeRandomDelayedTrieSync(t *testing.T) {
// Tests that a trie sync will not request nodes multiple times, even if they // Tests that a trie sync will not request nodes multiple times, even if they
// have such references. // have such references.
func TestDuplicateAvoidanceTrieSync(t *testing.T) { func TestDuplicateAvoidanceSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, srcData := makeTestTrie() srcDb, srcTrie, srcData := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
queue := append([]common.Hash{}, sched.Missing(0)...) queue := append([]common.Hash{}, sched.Missing(0)...)
requested := make(map[common.Hash]struct{}) requested := make(map[common.Hash]struct{})
@@ -304,14 +304,14 @@ func TestDuplicateAvoidanceTrieSync(t *testing.T) {
// Tests that at any point in time during a sync, only complete sub-tries are in // Tests that at any point in time during a sync, only complete sub-tries are in
// the database. // the database.
func TestIncompleteTrieSync(t *testing.T) { func TestIncompleteSync(t *testing.T) {
// Create a random trie to copy // Create a random trie to copy
srcDb, srcTrie, _ := makeTestTrie() srcDb, srcTrie, _ := makeTestTrie()
// Create a destination trie and sync with the scheduler // Create a destination trie and sync with the scheduler
diskdb := ethdb.NewMemDatabase() diskdb := ethdb.NewMemDatabase()
triedb := NewDatabase(diskdb) triedb := NewDatabase(diskdb)
sched := NewTrieSync(srcTrie.Hash(), diskdb, nil) sched := NewSync(srcTrie.Hash(), diskdb, nil)
added := []common.Hash{} added := []common.Hash{}
queue := append([]common.Hash{}, sched.Missing(1)...) queue := append([]common.Hash{}, sched.Missing(1)...)

View File

@@ -159,9 +159,9 @@ func (sc *Client) DeleteSymmetricKey(ctx context.Context, id string) error {
} }
// Post a message onto the network. // Post a message onto the network.
func (sc *Client) Post(ctx context.Context, message whisper.NewMessage) error { func (sc *Client) Post(ctx context.Context, message whisper.NewMessage) (string, error) {
var ignored bool var hash string
return sc.c.CallContext(ctx, &ignored, "shh_post", message) return hash, sc.c.CallContext(ctx, &hash, "shh_post", message)
} }
// SubscribeMessages subscribes to messages that match the given criteria. This method // SubscribeMessages subscribes to messages that match the given criteria. This method