diff --git a/accounts/abi/bind/base.go b/accounts/abi/bind/base.go index f74a0af211..c26d754ca4 100644 --- a/accounts/abi/bind/base.go +++ b/accounts/abi/bind/base.go @@ -287,9 +287,6 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int return nil }), nil - if err != nil { - return nil, nil, err - } return logs, sub, nil } diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 88d9eaaa5d..85a1add8ff 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -744,21 +744,21 @@ func testExternalUI(api *core.SignerAPI) { api.UI.ShowInfo("Please approve the next request for signing a clique header") time.Sleep(delay) cliqueHeader := types.Header{ - common.HexToHash("0000H45H"), - common.HexToHash("0000H45H"), - common.HexToAddress("0000H45H"), - common.HexToHash("0000H00H"), - common.HexToHash("0000H45H"), - common.HexToHash("0000H45H"), - types.Bloom{}, - big.NewInt(1337), - big.NewInt(1337), - 1338, - 1338, - 1338, - []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), - common.HexToHash("0x0000H45H"), - types.BlockNonce{}, + ParentHash: common.HexToHash("0000H45H"), + UncleHash: common.HexToHash("0000H45H"), + Coinbase: common.HexToAddress("0000H45H"), + Root: common.HexToHash("0000H00H"), + TxHash: common.HexToHash("0000H45H"), + ReceiptHash: common.HexToHash("0000H45H"), + Bloom: types.Bloom{}, + Difficulty: big.NewInt(1337), + Number: big.NewInt(1337), + GasLimit: 1338, + GasUsed: 1338, + Time: 1338, + Extra: []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), + MixDigest: common.HexToHash("0x0000H45H"), + Nonce: types.BlockNonce{}, } cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader) if err != nil { @@ -922,7 +922,7 @@ func GenDoc(ctx *cli.Context) { "of the work in canonicalizing and making sense of the data, and it's up to the UI to present" + "the user with the contents of the `message`" sighash, msg := accounts.TextAndHash([]byte("hello world")) - messages := []*core.NameValueType{{"message", msg, accounts.MimetypeTextPlain}} + messages := []*core.NameValueType{{Name: "message", Value: msg, Typ: accounts.MimetypeTextPlain}} add("SignDataRequest", desc, &core.SignDataRequest{ Address: common.NewMixedcaseAddress(a), @@ -953,8 +953,8 @@ func GenDoc(ctx *cli.Context) { add("SignTxRequest", desc, &core.SignTxRequest{ Meta: meta, Callinfo: []core.ValidationInfo{ - {"Warning", "Something looks odd, show this message as a warning"}, - {"Info", "User should see this aswell"}, + {Typ: "Warning", Message: "Something looks odd, show this message as a warning"}, + {Typ: "Info", Message: "User should see this aswell"}, }, Transaction: core.SendTxArgs{ Data: &data, @@ -1020,16 +1020,16 @@ func GenDoc(ctx *cli.Context) { &core.ListRequest{ Meta: meta, Accounts: []accounts.Account{ - {a, accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/a"}}, - {b, accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/b"}}}, + {Address: a, URL: accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/a"}}, + {Address: b, URL: accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/b"}}}, }) add("ListResponse", "Response to list request. The response contains a list of all addresses to show to the caller. "+ "Note: the UI is free to respond with any address the caller, regardless of whether it exists or not", &core.ListResponse{ Accounts: []accounts.Account{ - {common.HexToAddress("0xcowbeef000000cowbeef00000000000000000c0w"), accounts.URL{Path: ".. ignored .."}}, - {common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff"), accounts.URL{}}, + {Address: common.HexToAddress("0xcowbeef000000cowbeef00000000000000000c0w"), URL: accounts.URL{Path: ".. ignored .."}}, + {Address: common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff"), URL: accounts.URL{}}, }}) } diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 02b6da35b2..990bd87f77 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -351,7 +351,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo headers []*types.Header snap *Snapshot ) - for snap == nil { + for /*snap == nil*/ { // If an in-memory snapshot was found, use that if s, ok := c.recents.Get(hash); ok { snap = s.(*Snapshot) diff --git a/core/blockchain.go b/core/blockchain.go index 833de3bc7e..cbaf36818f 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -42,7 +42,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" ) var ( diff --git a/core/rawdb/freezer_table_test.go b/core/rawdb/freezer_table_test.go index 7de1081517..44215565eb 100644 --- a/core/rawdb/freezer_table_test.go +++ b/core/rawdb/freezer_table_test.go @@ -204,10 +204,8 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) { f.Append(uint64(x), data) } // The last item should be there - if _, err = f.Retrieve(f.items - 1); err == nil { - if err != nil { - t.Fatal(err) - } + if _, err = f.Retrieve(f.items - 1); err != nil { + t.Fatal(err) } f.Close() } diff --git a/core/state/state_object_test.go b/core/state/state_object_test.go index e86d3b9943..c66d910e95 100644 --- a/core/state/state_object_test.go +++ b/core/state/state_object_test.go @@ -36,7 +36,7 @@ func BenchmarkCutOriginal(b *testing.B) { func BenchmarkCutsetterFn(b *testing.B) { value := common.HexToHash("0x01") cutSetFn := func(r rune) bool { - return int32(r) == int32(0) + return r == 0 } for i := 0; i < b.N; i++ { bytes.TrimLeftFunc(value[:], cutSetFn) diff --git a/core/vm/instructions_test.go b/core/vm/instructions_test.go index 50d0a9ddae..8938f15879 100644 --- a/core/vm/instructions_test.go +++ b/core/vm/instructions_test.go @@ -360,65 +360,69 @@ func BenchmarkOpSdiv(b *testing.B) { opBenchmark(b, opSdiv, x, y) } +const ( + ABCDEF = "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" +) + func BenchmarkOpMod(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opMod, x, y) } func BenchmarkOpSmod(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opSmod, x, y) } func BenchmarkOpExp(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opExp, x, y) } func BenchmarkOpSignExtend(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opSignExtend, x, y) } func BenchmarkOpLt(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opLt, x, y) } func BenchmarkOpGt(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opGt, x, y) } func BenchmarkOpSlt(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opSlt, x, y) } func BenchmarkOpSgt(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opSgt, x, y) } func BenchmarkOpEq(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opEq, x, y) } @@ -428,45 +432,45 @@ func BenchmarkOpEq2(b *testing.B) { opBenchmark(b, opEq, x, y) } func BenchmarkOpAnd(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opAnd, x, y) } func BenchmarkOpOr(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opOr, x, y) } func BenchmarkOpXor(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opXor, x, y) } func BenchmarkOpByte(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF opBenchmark(b, opByte, x, y) } func BenchmarkOpAddmod(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF + z := ABCDEF opBenchmark(b, opAddmod, x, y, z) } func BenchmarkOpMulmod(b *testing.B) { - x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" - z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" + x := ABCDEF + y := ABCDEF + z := ABCDEF opBenchmark(b, opMulmod, x, y, z) } diff --git a/crypto/bn256/bn256_fast.go b/crypto/bn256/bn256_fast.go index 5c081493b0..aab969eddc 100644 --- a/crypto/bn256/bn256_fast.go +++ b/crypto/bn256/bn256_fast.go @@ -7,7 +7,7 @@ // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. package bn256 -import "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" +import bn256 "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare" // G1 is an abstract cyclic group. The zero value is suitable for use as the // output of an operation, but cannot be used as an input. diff --git a/eth/handler.go b/eth/handler.go index 4ce2d1c82f..ca1273554f 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -236,9 +236,7 @@ func (pm *ProtocolManager) removePeer(id string) { log.Error("Peer removal failed", "peer", id, "err", err) } // Hard disconnect at the networking layer - if peer != nil { - peer.Peer.Disconnect(p2p.DiscUselessPeer) - } + peer.Peer.Disconnect(p2p.DiscUselessPeer) } func (pm *ProtocolManager) Start(maxPeers int) { diff --git a/les/api_test.go b/les/api_test.go index 660af8eeec..ed2f8b17ec 100644 --- a/les/api_test.go +++ b/les/api_test.go @@ -326,7 +326,8 @@ func testRequest(ctx context.Context, t *testing.T, client *rpc.Client) bool { var res string var addr common.Address rand.Read(addr[:]) - c, _ := context.WithTimeout(ctx, time.Second*12) + c, cf := context.WithTimeout(ctx, time.Second*12) + defer cf() err := client.CallContext(c, &res, "eth_getBalance", addr, "latest") if err != nil { t.Log("request error:", err) diff --git a/les/request_test.go b/les/request_test.go index 69b57ca317..bea0ad0e0c 100644 --- a/les/request_test.go +++ b/les/request_test.go @@ -65,7 +65,7 @@ func TestCodeAccessLes3(t *testing.T) { testAccess(t, 3, tfCodeAccess) } func tfCodeAccess(db ethdb.Database, bhash common.Hash, num uint64) light.OdrRequest { number := rawdb.ReadHeaderNumber(db, bhash) - if number != nil { + if number == nil { return nil } header := rawdb.ReadHeader(db, bhash, *number) diff --git a/p2p/discover/v4_udp.go b/p2p/discover/v4_udp.go index a8f7101b05..fcbef20251 100644 --- a/p2p/discover/v4_udp.go +++ b/p2p/discover/v4_udp.go @@ -795,9 +795,7 @@ func (t *UDPv4) handlePacket(from *net.UDPAddr, buf []byte) error { return err } fromID := fromKey.id() - if err == nil { - err = packet.preverify(t, from, fromID, fromKey) - } + err = packet.preverify(t, from, fromID, fromKey) t.log.Trace("<< "+packet.name(), "id", fromID, "addr", from, "err", err) if err == nil { packet.handle(t, from, fromID, hash) diff --git a/p2p/nat/nat.go b/p2p/nat/nat.go index 8fad921c48..504b7b074a 100644 --- a/p2p/nat/nat.go +++ b/p2p/nat/nat.go @@ -26,7 +26,7 @@ import ( "time" "github.com/ethereum/go-ethereum/log" - "github.com/jackpal/go-nat-pmp" + natpmp "github.com/jackpal/go-nat-pmp" ) // An implementation of nat.Interface can map local ports to ports diff --git a/p2p/nat/natpmp.go b/p2p/nat/natpmp.go index 8ba9714728..7f85543f8e 100644 --- a/p2p/nat/natpmp.go +++ b/p2p/nat/natpmp.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "github.com/jackpal/go-nat-pmp" + natpmp "github.com/jackpal/go-nat-pmp" ) // natPMPClient adapts the NAT-PMP protocol implementation so it conforms to diff --git a/p2p/simulations/http_test.go b/p2p/simulations/http_test.go index 84f6ce2a51..ed571f74e0 100644 --- a/p2p/simulations/http_test.go +++ b/p2p/simulations/http_test.go @@ -424,7 +424,8 @@ func (t *expectEvents) nodeEvent(id string, up bool) *Event { Config: &adapters.NodeConfig{ ID: enode.HexID(id), }, - up: up, + up: up, + upMu: new(sync.RWMutex), } return &Event{ Type: EventTypeNode, diff --git a/p2p/simulations/network.go b/p2p/simulations/network.go index f03c953e89..ed335ec1cc 100644 --- a/p2p/simulations/network.go +++ b/p2p/simulations/network.go @@ -118,6 +118,7 @@ func (net *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error) node := &Node{ Node: adapterNode, Config: conf, + upMu: new(sync.RWMutex), } log.Trace("Node created", "id", conf.ID) net.nodeMap[conf.ID] = len(net.Nodes) @@ -631,9 +632,19 @@ type Node struct { // up tracks whether or not the node is running up bool - upMu sync.RWMutex + upMu *sync.RWMutex } +/* +func (n *Node) Clone() *Node { + return &Node{ + Node: n.Node, + Config: n.Config, + up: n.up, + } +} +*/ + func (n *Node) Up() bool { n.upMu.RLock() defer n.upMu.RUnlock() @@ -695,6 +706,7 @@ func (n *Node) UnmarshalJSON(raw []byte) error { return err } + n.upMu = new(sync.RWMutex) n.SetUp(node.Up) n.Config = node.Config return nil diff --git a/p2p/simulations/network_test.go b/p2p/simulations/network_test.go index 01cd1000de..8ece48967a 100644 --- a/p2p/simulations/network_test.go +++ b/p2p/simulations/network_test.go @@ -544,7 +544,9 @@ func expectErrorMessageToContain(t *testing.T, got error, want string) { func expectNodeEquality(t *testing.T, got Node, want Node) { t.Helper() - if !reflect.DeepEqual(got, want) { + if got.up != want.up || + !reflect.DeepEqual(got.Node, want.Node) || + !reflect.DeepEqual(got.Config, want.Config) { t.Errorf("Node.UnmarshalJSON() = %v, want %v", got, want) } } diff --git a/signer/core/signed_data_test.go b/signer/core/signed_data_test.go index 6b0da45530..e5f4780890 100644 --- a/signer/core/signed_data_test.go +++ b/signer/core/signed_data_test.go @@ -358,7 +358,7 @@ func TestJsonFiles(t *testing.T) { continue } var typedData core.TypedData - err = json.Unmarshal([]byte(data), &typedData) + err = json.Unmarshal(data, &typedData) if err != nil { t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err) continue @@ -390,7 +390,7 @@ func TestFuzzerFiles(t *testing.T) { continue } var typedData core.TypedData - err = json.Unmarshal([]byte(data), &typedData) + err = json.Unmarshal(data, &typedData) if err != nil { t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err) continue diff --git a/whisper/whisperv6/whisper.go b/whisper/whisperv6/whisper.go index eb713f84ee..9a868daa63 100644 --- a/whisper/whisperv6/whisper.go +++ b/whisper/whisperv6/whisper.go @@ -527,9 +527,6 @@ func (whisper *Whisper) AddSymKeyFromPassword(password string) (string, error) { // kdf should run no less than 0.1 seconds on an average computer, // because it's an once in a session experience derived := pbkdf2.Key([]byte(password), nil, 65356, aesKeyLength, sha256.New) - if err != nil { - return "", err - } whisper.keyMu.Lock() defer whisper.keyMu.Unlock()