all: fix linter errors

This commit is contained in:
Tomasz Zdybał 2019-09-16 10:50:26 +02:00
parent 52f18c83ab
commit 63a4ff7a8d
No known key found for this signature in database
GPG key ID: F157D3BD6E2EED66
19 changed files with 91 additions and 83 deletions

View file

@ -287,9 +287,6 @@ func (c *BoundContract) FilterLogs(opts *FilterOpts, name string, query ...[]int
return nil return nil
}), nil }), nil
if err != nil {
return nil, nil, err
}
return logs, sub, nil return logs, sub, nil
} }

View file

@ -744,21 +744,21 @@ func testExternalUI(api *core.SignerAPI) {
api.UI.ShowInfo("Please approve the next request for signing a clique header") api.UI.ShowInfo("Please approve the next request for signing a clique header")
time.Sleep(delay) time.Sleep(delay)
cliqueHeader := types.Header{ cliqueHeader := types.Header{
common.HexToHash("0000H45H"), ParentHash: common.HexToHash("0000H45H"),
common.HexToHash("0000H45H"), UncleHash: common.HexToHash("0000H45H"),
common.HexToAddress("0000H45H"), Coinbase: common.HexToAddress("0000H45H"),
common.HexToHash("0000H00H"), Root: common.HexToHash("0000H00H"),
common.HexToHash("0000H45H"), TxHash: common.HexToHash("0000H45H"),
common.HexToHash("0000H45H"), ReceiptHash: common.HexToHash("0000H45H"),
types.Bloom{}, Bloom: types.Bloom{},
big.NewInt(1337), Difficulty: big.NewInt(1337),
big.NewInt(1337), Number: big.NewInt(1337),
1338, GasLimit: 1338,
1338, GasUsed: 1338,
1338, Time: 1338,
[]byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"), Extra: []byte("Extra data Extra data Extra data Extra data Extra data Extra data Extra data Extra data"),
common.HexToHash("0x0000H45H"), MixDigest: common.HexToHash("0x0000H45H"),
types.BlockNonce{}, Nonce: types.BlockNonce{},
} }
cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader) cliqueRlp, err := rlp.EncodeToBytes(cliqueHeader)
if err != nil { 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" + "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`" "the user with the contents of the `message`"
sighash, msg := accounts.TextAndHash([]byte("hello world")) 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{ add("SignDataRequest", desc, &core.SignDataRequest{
Address: common.NewMixedcaseAddress(a), Address: common.NewMixedcaseAddress(a),
@ -953,8 +953,8 @@ func GenDoc(ctx *cli.Context) {
add("SignTxRequest", desc, &core.SignTxRequest{ add("SignTxRequest", desc, &core.SignTxRequest{
Meta: meta, Meta: meta,
Callinfo: []core.ValidationInfo{ Callinfo: []core.ValidationInfo{
{"Warning", "Something looks odd, show this message as a warning"}, {Typ: "Warning", Message: "Something looks odd, show this message as a warning"},
{"Info", "User should see this aswell"}, {Typ: "Info", Message: "User should see this aswell"},
}, },
Transaction: core.SendTxArgs{ Transaction: core.SendTxArgs{
Data: &data, Data: &data,
@ -1020,16 +1020,16 @@ func GenDoc(ctx *cli.Context) {
&core.ListRequest{ &core.ListRequest{
Meta: meta, Meta: meta,
Accounts: []accounts.Account{ Accounts: []accounts.Account{
{a, accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/a"}}, {Address: a, URL: accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/a"}},
{b, accounts.URL{Scheme: "keystore", Path: "/path/to/keyfile/b"}}}, {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. "+ 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", "Note: the UI is free to respond with any address the caller, regardless of whether it exists or not",
&core.ListResponse{ &core.ListResponse{
Accounts: []accounts.Account{ Accounts: []accounts.Account{
{common.HexToAddress("0xcowbeef000000cowbeef00000000000000000c0w"), accounts.URL{Path: ".. ignored .."}}, {Address: common.HexToAddress("0xcowbeef000000cowbeef00000000000000000c0w"), URL: accounts.URL{Path: ".. ignored .."}},
{common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff"), accounts.URL{}}, {Address: common.HexToAddress("0xffffffffffffffffffffffffffffffffffffffff"), URL: accounts.URL{}},
}}) }})
} }

View file

@ -351,7 +351,7 @@ func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash commo
headers []*types.Header headers []*types.Header
snap *Snapshot snap *Snapshot
) )
for snap == nil { for /*snap == nil*/ {
// If an in-memory snapshot was found, use that // If an in-memory snapshot was found, use that
if s, ok := c.recents.Get(hash); ok { if s, ok := c.recents.Get(hash); ok {
snap = s.(*Snapshot) snap = s.(*Snapshot)

View file

@ -42,7 +42,7 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie" "github.com/ethereum/go-ethereum/trie"
"github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
) )
var ( var (

View file

@ -204,10 +204,8 @@ func TestFreezerRepairDanglingHeadLarge(t *testing.T) {
f.Append(uint64(x), data) f.Append(uint64(x), data)
} }
// The last item should be there // The last item should be there
if _, err = f.Retrieve(f.items - 1); err == nil { if _, err = f.Retrieve(f.items - 1); err != nil {
if err != nil { t.Fatal(err)
t.Fatal(err)
}
} }
f.Close() f.Close()
} }

View file

@ -36,7 +36,7 @@ func BenchmarkCutOriginal(b *testing.B) {
func BenchmarkCutsetterFn(b *testing.B) { func BenchmarkCutsetterFn(b *testing.B) {
value := common.HexToHash("0x01") value := common.HexToHash("0x01")
cutSetFn := func(r rune) bool { cutSetFn := func(r rune) bool {
return int32(r) == int32(0) return r == 0
} }
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
bytes.TrimLeftFunc(value[:], cutSetFn) bytes.TrimLeftFunc(value[:], cutSetFn)

View file

@ -360,65 +360,69 @@ func BenchmarkOpSdiv(b *testing.B) {
opBenchmark(b, opSdiv, x, y) opBenchmark(b, opSdiv, x, y)
} }
const (
ABCDEF = "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff"
)
func BenchmarkOpMod(b *testing.B) { func BenchmarkOpMod(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opMod, x, y) opBenchmark(b, opMod, x, y)
} }
func BenchmarkOpSmod(b *testing.B) { func BenchmarkOpSmod(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opSmod, x, y) opBenchmark(b, opSmod, x, y)
} }
func BenchmarkOpExp(b *testing.B) { func BenchmarkOpExp(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opExp, x, y) opBenchmark(b, opExp, x, y)
} }
func BenchmarkOpSignExtend(b *testing.B) { func BenchmarkOpSignExtend(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opSignExtend, x, y) opBenchmark(b, opSignExtend, x, y)
} }
func BenchmarkOpLt(b *testing.B) { func BenchmarkOpLt(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opLt, x, y) opBenchmark(b, opLt, x, y)
} }
func BenchmarkOpGt(b *testing.B) { func BenchmarkOpGt(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opGt, x, y) opBenchmark(b, opGt, x, y)
} }
func BenchmarkOpSlt(b *testing.B) { func BenchmarkOpSlt(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opSlt, x, y) opBenchmark(b, opSlt, x, y)
} }
func BenchmarkOpSgt(b *testing.B) { func BenchmarkOpSgt(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opSgt, x, y) opBenchmark(b, opSgt, x, y)
} }
func BenchmarkOpEq(b *testing.B) { func BenchmarkOpEq(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opEq, x, y) opBenchmark(b, opEq, x, y)
} }
@ -428,45 +432,45 @@ func BenchmarkOpEq2(b *testing.B) {
opBenchmark(b, opEq, x, y) opBenchmark(b, opEq, x, y)
} }
func BenchmarkOpAnd(b *testing.B) { func BenchmarkOpAnd(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opAnd, x, y) opBenchmark(b, opAnd, x, y)
} }
func BenchmarkOpOr(b *testing.B) { func BenchmarkOpOr(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opOr, x, y) opBenchmark(b, opOr, x, y)
} }
func BenchmarkOpXor(b *testing.B) { func BenchmarkOpXor(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opXor, x, y) opBenchmark(b, opXor, x, y)
} }
func BenchmarkOpByte(b *testing.B) { func BenchmarkOpByte(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
opBenchmark(b, opByte, x, y) opBenchmark(b, opByte, x, y)
} }
func BenchmarkOpAddmod(b *testing.B) { func BenchmarkOpAddmod(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" z := ABCDEF
opBenchmark(b, opAddmod, x, y, z) opBenchmark(b, opAddmod, x, y, z)
} }
func BenchmarkOpMulmod(b *testing.B) { func BenchmarkOpMulmod(b *testing.B) {
x := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" x := ABCDEF
y := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" y := ABCDEF
z := "ABCDEF090807060504030201ffffffffffffffffffffffffffffffffffffffff" z := ABCDEF
opBenchmark(b, opMulmod, x, y, z) opBenchmark(b, opMulmod, x, y, z)
} }

View file

@ -7,7 +7,7 @@
// Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve. // Package bn256 implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve.
package bn256 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 // 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. // output of an operation, but cannot be used as an input.

View file

@ -236,9 +236,7 @@ func (pm *ProtocolManager) removePeer(id string) {
log.Error("Peer removal failed", "peer", id, "err", err) log.Error("Peer removal failed", "peer", id, "err", err)
} }
// Hard disconnect at the networking layer // 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) { func (pm *ProtocolManager) Start(maxPeers int) {

View file

@ -326,7 +326,8 @@ func testRequest(ctx context.Context, t *testing.T, client *rpc.Client) bool {
var res string var res string
var addr common.Address var addr common.Address
rand.Read(addr[:]) 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") err := client.CallContext(c, &res, "eth_getBalance", addr, "latest")
if err != nil { if err != nil {
t.Log("request error:", err) t.Log("request error:", err)

View file

@ -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 { func tfCodeAccess(db ethdb.Database, bhash common.Hash, num uint64) light.OdrRequest {
number := rawdb.ReadHeaderNumber(db, bhash) number := rawdb.ReadHeaderNumber(db, bhash)
if number != nil { if number == nil {
return nil return nil
} }
header := rawdb.ReadHeader(db, bhash, *number) header := rawdb.ReadHeader(db, bhash, *number)

View file

@ -795,9 +795,7 @@ func (t *UDPv4) handlePacket(from *net.UDPAddr, buf []byte) error {
return err return err
} }
fromID := fromKey.id() 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) t.log.Trace("<< "+packet.name(), "id", fromID, "addr", from, "err", err)
if err == nil { if err == nil {
packet.handle(t, from, fromID, hash) packet.handle(t, from, fromID, hash)

View file

@ -26,7 +26,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/log" "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 // An implementation of nat.Interface can map local ports to ports

View file

@ -22,7 +22,7 @@ import (
"strings" "strings"
"time" "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 // natPMPClient adapts the NAT-PMP protocol implementation so it conforms to

View file

@ -424,7 +424,8 @@ func (t *expectEvents) nodeEvent(id string, up bool) *Event {
Config: &adapters.NodeConfig{ Config: &adapters.NodeConfig{
ID: enode.HexID(id), ID: enode.HexID(id),
}, },
up: up, up: up,
upMu: new(sync.RWMutex),
} }
return &Event{ return &Event{
Type: EventTypeNode, Type: EventTypeNode,

View file

@ -118,6 +118,7 @@ func (net *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error)
node := &Node{ node := &Node{
Node: adapterNode, Node: adapterNode,
Config: conf, Config: conf,
upMu: new(sync.RWMutex),
} }
log.Trace("Node created", "id", conf.ID) log.Trace("Node created", "id", conf.ID)
net.nodeMap[conf.ID] = len(net.Nodes) net.nodeMap[conf.ID] = len(net.Nodes)
@ -631,9 +632,19 @@ type Node struct {
// up tracks whether or not the node is running // up tracks whether or not the node is running
up bool 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 { func (n *Node) Up() bool {
n.upMu.RLock() n.upMu.RLock()
defer n.upMu.RUnlock() defer n.upMu.RUnlock()
@ -695,6 +706,7 @@ func (n *Node) UnmarshalJSON(raw []byte) error {
return err return err
} }
n.upMu = new(sync.RWMutex)
n.SetUp(node.Up) n.SetUp(node.Up)
n.Config = node.Config n.Config = node.Config
return nil return nil

View file

@ -544,7 +544,9 @@ func expectErrorMessageToContain(t *testing.T, got error, want string) {
func expectNodeEquality(t *testing.T, got Node, want Node) { func expectNodeEquality(t *testing.T, got Node, want Node) {
t.Helper() 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) t.Errorf("Node.UnmarshalJSON() = %v, want %v", got, want)
} }
} }

View file

@ -358,7 +358,7 @@ func TestJsonFiles(t *testing.T) {
continue continue
} }
var typedData core.TypedData var typedData core.TypedData
err = json.Unmarshal([]byte(data), &typedData) err = json.Unmarshal(data, &typedData)
if err != nil { if err != nil {
t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err) t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err)
continue continue
@ -390,7 +390,7 @@ func TestFuzzerFiles(t *testing.T) {
continue continue
} }
var typedData core.TypedData var typedData core.TypedData
err = json.Unmarshal([]byte(data), &typedData) err = json.Unmarshal(data, &typedData)
if err != nil { if err != nil {
t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err) t.Errorf("Test %d, file %v, json unmarshalling failed: %v", i, fInfo.Name(), err)
continue continue

View file

@ -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, // kdf should run no less than 0.1 seconds on an average computer,
// because it's an once in a session experience // because it's an once in a session experience
derived := pbkdf2.Key([]byte(password), nil, 65356, aesKeyLength, sha256.New) derived := pbkdf2.Key([]byte(password), nil, 65356, aesKeyLength, sha256.New)
if err != nil {
return "", err
}
whisper.keyMu.Lock() whisper.keyMu.Lock()
defer whisper.keyMu.Unlock() defer whisper.keyMu.Unlock()