diff --git a/accounts/abi/reflect.go b/accounts/abi/reflect.go index 11248e073..35e5556d2 100644 --- a/accounts/abi/reflect.go +++ b/accounts/abi/reflect.go @@ -123,15 +123,8 @@ func set(dst, src reflect.Value) error { func setSlice(dst, src reflect.Value) error { slice := reflect.MakeSlice(dst.Type(), src.Len(), src.Len()) for i := 0; i < src.Len(); i++ { - if src.Index(i).Kind() == reflect.Struct { - if err := set(slice.Index(i), src.Index(i)); err != nil { - return err - } - } else { - // e.g. [][32]uint8 to []common.Hash - if err := set(slice.Index(i), src.Index(i)); err != nil { - return err - } + if err := set(slice.Index(i), src.Index(i)); err != nil { + return err } } if dst.CanSet() { diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index 7407ed0a4..88a9c5e62 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -419,7 +419,7 @@ func dispatchOutput(ctx *cli.Context, baseDir string, result *ExecutionResult, a return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err)) } os.Stdout.Write(b) - os.Stdout.Write([]byte("\n")) + os.Stdout.WriteString("\n") } if len(stdErrObject) > 0 { b, err := json.MarshalIndent(stdErrObject, "", " ") @@ -427,7 +427,7 @@ func dispatchOutput(ctx *cli.Context, baseDir string, result *ExecutionResult, a return NewError(ErrorJson, fmt.Errorf("failed marshalling output: %v", err)) } os.Stderr.Write(b) - os.Stderr.Write([]byte("\n")) + os.Stderr.WriteString("\n") } return nil } diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index bb5375384..2d9d7a1e9 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -741,7 +741,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c return "", "", "", common.Address{}, errors.New("No Ethereum address found to fund") } var avatar string - if parts = regexp.MustCompile("src=\"([^\"]+twimg.com/profile_images[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 { + if parts = regexp.MustCompile(`src="([^"]+twimg\.com/profile_images[^"]+)"`).FindStringSubmatch(string(body)); len(parts) == 2 { avatar = parts[1] } return username + "@twitter", username, avatar, address, nil @@ -867,7 +867,7 @@ func authFacebook(url string) (string, string, common.Address, error) { return "", "", common.Address{}, errors.New("No Ethereum address found to fund") } var avatar string - if parts = regexp.MustCompile("src=\"([^\"]+fbcdn.net[^\"]+)\"").FindStringSubmatch(string(body)); len(parts) == 2 { + if parts = regexp.MustCompile(`src="([^"]+fbcdn\.net[^"]+)"`).FindStringSubmatch(string(body)); len(parts) == 2 { avatar = parts[1] } return username + "@facebook", avatar, address, nil diff --git a/core/bloombits/generator_test.go b/core/bloombits/generator_test.go index 88e3ed6b0..883948d12 100644 --- a/core/bloombits/generator_test.go +++ b/core/bloombits/generator_test.go @@ -70,7 +70,7 @@ func BenchmarkGenerator(b *testing.B) { if err != nil { b.Fatalf("failed to create bloombit generator: %v", err) } - for j, bloom := range input { + for j, bloom := range &input { if err := gen.AddBloom(uint(j), bloom); err != nil { b.Fatalf("bloom %d: failed to add: %v", i, err) } @@ -89,7 +89,7 @@ func BenchmarkGenerator(b *testing.B) { if err != nil { b.Fatalf("failed to create bloombit generator: %v", err) } - for j, bloom := range input { + for j, bloom := range &input { if err := gen.AddBloom(uint(j), bloom); err != nil { b.Fatalf("bloom %d: failed to add: %v", i, err) } diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index d88965c15..66f013409 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -385,7 +385,7 @@ func testGetNodeData(t *testing.T, protocol uint) { acc2Addr := crypto.PubkeyToAddress(acc2Key.PublicKey) signer := types.HomesteadSigner{} - // Create a chain generator with some simple transactions (blatantly stolen from @fjl/chain_markets_test) + // Create a chain generator with some simple transactions (blatantly stolen from @fjl/chain_makers_test) generator := func(i int, block *core.BlockGen) { switch i { case 0: @@ -420,9 +420,8 @@ func testGetNodeData(t *testing.T, protocol uint) { peer, _ := newTestPeer("peer", protocol, backend) defer peer.close() - // Fetch for now the entire chain db + // Collect all state tree hashes. var hashes []common.Hash - it := backend.db.NewIterator(nil, nil) for it.Next() { if key := it.Key(); len(key) == common.HashLength { @@ -431,6 +430,7 @@ func testGetNodeData(t *testing.T, protocol uint) { } it.Release() + // Request all hashes. p2p.Send(peer.app, GetNodeDataMsg, GetNodeDataPacket66{ RequestId: 123, GetNodeDataPacket: hashes, @@ -442,38 +442,40 @@ func testGetNodeData(t *testing.T, protocol uint) { if msg.Code != NodeDataMsg { t.Fatalf("response packet code mismatch: have %x, want %x", msg.Code, NodeDataMsg) } - var ( - data [][]byte - res NodeDataPacket66 - ) + var res NodeDataPacket66 if err := msg.Decode(&res); err != nil { t.Fatalf("failed to decode response node data: %v", err) } - data = res.NodeDataPacket - // Verify that all hashes correspond to the requested data, and reconstruct a state tree + + // Verify that all hashes correspond to the requested data. + data := res.NodeDataPacket for i, want := range hashes { if hash := crypto.Keccak256Hash(data[i]); hash != want { t.Errorf("data hash mismatch: have %x, want %x", hash, want) } } - statedb := rawdb.NewMemoryDatabase() + + // Reconstruct state tree from the received data. + reconstructDB := rawdb.NewMemoryDatabase() for i := 0; i < len(data); i++ { - statedb.Put(hashes[i].Bytes(), data[i]) + rawdb.WriteTrieNode(reconstructDB, hashes[i], data[i]) } + + // Sanity check whether all state matches. accounts := []common.Address{testAddr, acc1Addr, acc2Addr} for i := uint64(0); i <= backend.chain.CurrentBlock().NumberU64(); i++ { - trie, _ := state.New(backend.chain.GetBlockByNumber(i).Root(), state.NewDatabase(statedb), nil) - + root := backend.chain.GetBlockByNumber(i).Root() + reconstructed, _ := state.New(root, state.NewDatabase(reconstructDB), nil) for j, acc := range accounts { - state, _ := backend.chain.State() + state, _ := backend.chain.StateAt(root) bw := state.GetBalance(acc) - bh := trie.GetBalance(acc) + bh := reconstructed.GetBalance(acc) - if (bw != nil && bh == nil) || (bw == nil && bh != nil) { - t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw) + if (bw == nil) != (bh == nil) { + t.Errorf("block %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw) } - if bw != nil && bh != nil && bw.Cmp(bw) != 0 { - t.Errorf("test %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw) + if bw != nil && bh != nil && bw.Cmp(bh) != 0 { + t.Errorf("block %d, account %d: balance mismatch: have %v, want %v", i, j, bh, bw) } } } diff --git a/node/api.go b/node/api.go index be20b89d9..a685ecd6b 100644 --- a/node/api.go +++ b/node/api.go @@ -218,7 +218,7 @@ func (api *privateAdminAPI) StartHTTP(host *string, port *int, cors *string, api } // StartRPC starts the HTTP RPC API server. -// This method is deprecated. Use StartHTTP instead. +// Deprecated: use StartHTTP instead. func (api *privateAdminAPI) StartRPC(host *string, port *int, cors *string, apis *string, vhosts *string) (bool, error) { log.Warn("Deprecation warning", "method", "admin.StartRPC", "use-instead", "admin.StartHTTP") return api.StartHTTP(host, port, cors, apis, vhosts) @@ -231,7 +231,7 @@ func (api *privateAdminAPI) StopHTTP() (bool, error) { } // StopRPC shuts down the HTTP server. -// This method is deprecated. Use StopHTTP instead. +// Deprecated: use StopHTTP instead. func (api *privateAdminAPI) StopRPC() (bool, error) { log.Warn("Deprecation warning", "method", "admin.StopRPC", "use-instead", "admin.StopHTTP") return api.StopHTTP() diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index 6c2fd5f8f..daa84313d 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -29,6 +29,7 @@ import ( "strconv" "strings" "unicode" + "unicode/utf8" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/common" @@ -100,7 +101,8 @@ func (t *Type) isReferenceType() bool { return false } // Reference types must have a leading uppercase character - return unicode.IsUpper([]rune(t.Type)[0]) + r, _ := utf8.DecodeRuneInString(t.Type) + return unicode.IsUpper(r) } type Types map[string][]Type diff --git a/signer/core/validation.go b/signer/core/validation.go index af858862e..7639dbf64 100644 --- a/signer/core/validation.go +++ b/signer/core/validation.go @@ -21,7 +21,7 @@ import ( "regexp" ) -var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ ]+$") +var printable7BitAscii = regexp.MustCompile("^[A-Za-z0-9!\"#$%&'()*+,\\-./:;<=>?@[\\]^_`{|}~ ]+$") // ValidatePasswordFormat returns an error if the password is too short, or consists of characters // outside the range of the printable 7bit ascii set