diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index b3d365f525..143166574b 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -754,7 +754,7 @@ func authTwitter(url string, tokenV1, tokenV2 string) (string, string, string, c func authTwitterWithTokenV1(tweetID string, token string) (string, string, string, common.Address, error) { // Query the tweet details from Twitter url := fmt.Sprintf("https://api.twitter.com/1.1/statuses/show.json?id=%s", tweetID) - req, err := http.NewRequest(http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) if err != nil { return "", "", "", common.Address{}, err } @@ -791,7 +791,7 @@ func authTwitterWithTokenV1(tweetID string, token string) (string, string, strin func authTwitterWithTokenV2(tweetID string, token string) (string, string, string, common.Address, error) { // Query the tweet details from Twitter url := fmt.Sprintf("https://api.twitter.com/2/tweets/%s?expansions=author_id&user.fields=profile_image_url", tweetID) - req, err := http.NewRequest(http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) if err != nil { return "", "", "", common.Address{}, err } diff --git a/core/genesis.go b/core/genesis.go index 073f5ecf2e..91962c92a5 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -417,6 +417,7 @@ func LoadCliqueConfig(db ethdb.Database, genesis *Genesis) (*params.CliqueConfig // There is no stored chain config and no new config provided, // In this case the default chain config(mainnet) will be used, // namely ethash is the specified consensus engine, return nil. + //nolint:nilnil return nil, nil } diff --git a/core/state/state_object.go b/core/state/state_object.go index 95fe6f52fa..9e38af3e51 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -357,6 +357,7 @@ func (s *stateObject) commitTrie(db Database) (*trie.NodeSet, error) { } // If nothing changed, don't bother with committing anything if tr == nil { + //nolint:nilnil return nil, nil } // Track the amount of time wasted on committing the storage trie diff --git a/core/state/statedb.go b/core/state/statedb.go index fe910e889a..eee5e621da 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -692,6 +692,7 @@ func (s *StateDB) Database() Database { func (s *StateDB) StorageTrie(addr common.Address) (Trie, error) { stateObject := s.getStateObject(addr) if stateObject == nil { + //nolint:nilnil return nil, nil } cpy := stateObject.deepCopy(s) diff --git a/eth/filters/filter_system_test.go b/eth/filters/filter_system_test.go index c8fdc8006c..6e8a149490 100644 --- a/eth/filters/filter_system_test.go +++ b/eth/filters/filter_system_test.go @@ -81,6 +81,7 @@ func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumbe hash = rawdb.ReadHeadBlockHash(b.db) number := rawdb.ReadHeaderNumber(b.db, hash) if number == nil { + //nolint:nilnil return nil, nil } num = *number @@ -88,6 +89,7 @@ func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumbe hash = rawdb.ReadFinalizedBlockHash(b.db) number := rawdb.ReadHeaderNumber(b.db, hash) if number == nil { + //nolint:nilnil return nil, nil } num = *number @@ -103,6 +105,7 @@ func (b *testBackend) HeaderByNumber(ctx context.Context, blockNr rpc.BlockNumbe func (b *testBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { number := rawdb.ReadHeaderNumber(b.db, hash) if number == nil { + //nolint:nilnil return nil, nil } return rawdb.ReadHeader(b.db, hash, *number), nil diff --git a/eth/protocols/snap/sync.go b/eth/protocols/snap/sync.go index 8268f066c1..466a48e36b 100644 --- a/eth/protocols/snap/sync.go +++ b/eth/protocols/snap/sync.go @@ -29,7 +29,6 @@ import ( "sync/atomic" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/math" "github.com/ethereum/go-ethereum/core/rawdb" @@ -2901,6 +2900,7 @@ func (s *Syncer) onHealState(paths [][]byte, value []byte) error { if len(paths) == 1 { var account types.StateAccount if err := rlp.DecodeBytes(value, &account); err != nil { + //nolint:nilerr return nil // Returning the error here would drop the remote peer } blob := snapshot.SlimAccountRLP(account.Nonce, account.Balance, account.Root, account.CodeHash) diff --git a/ethdb/remotedb/remotedb.go b/ethdb/remotedb/remotedb.go index 9ce657d780..7a89897685 100644 --- a/ethdb/remotedb/remotedb.go +++ b/ethdb/remotedb/remotedb.go @@ -34,6 +34,7 @@ type Database struct { func (db *Database) Has(key []byte) (bool, error) { if _, err := db.Get(key); err != nil { + //nolint:nilerr return false, nil } return true, nil @@ -50,6 +51,7 @@ func (db *Database) Get(key []byte) ([]byte, error) { func (db *Database) HasAncient(kind string, number uint64) (bool, error) { if _, err := db.Ancient(kind, number); err != nil { + //nolint:nilerr return false, nil } return true, nil diff --git a/graphql/graphql.go b/graphql/graphql.go index 3421d98467..1dce7b7111 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -470,6 +470,7 @@ func (t *Transaction) Logs(ctx context.Context) (*[]*Log, error) { } // Pending tx if block == nil { + //nolint:nilnil return nil, nil } h, err := block.Hash(ctx) diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index fe2e500f4d..ae8fa97f72 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -272,25 +272,32 @@ func (b *backendMock) RPCTxFeeCap() float64 { return 0 } func (b *backendMock) UnprotectedAllowed() bool { return false } func (b *backendMock) SetHead(number uint64) {} func (b *backendMock) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) HeaderByHash(ctx context.Context, hash common.Hash) (*types.Header, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) HeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Header, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) CurrentBlock() *types.Header { return nil } func (b *backendMock) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) BlockByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*types.Block, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) GetBody(ctx context.Context, hash common.Hash, number rpc.BlockNumber) (*types.Body, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) { @@ -299,11 +306,16 @@ func (b *backendMock) StateAndHeaderByNumber(ctx context.Context, number rpc.Blo func (b *backendMock) StateAndHeaderByNumberOrHash(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (*state.StateDB, *types.Header, error) { return nil, nil, nil } -func (b *backendMock) PendingBlockAndReceipts() (*types.Block, types.Receipts) { return nil, nil } +func (b *backendMock) PendingBlockAndReceipts() (*types.Block, types.Receipts) { + //nolint:nilnil + return nil, nil +} func (b *backendMock) GetReceipts(ctx context.Context, hash common.Hash) (types.Receipts, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) GetLogs(ctx context.Context, blockHash common.Hash, number uint64) ([][]*types.Log, error) { + //nolint:nilnil return nil, nil } func (b *backendMock) GetTd(ctx context.Context, hash common.Hash) *big.Int { return nil } diff --git a/metrics/librato/client.go b/metrics/librato/client.go index f1b9e1e916..9d926c8534 100644 --- a/metrics/librato/client.go +++ b/metrics/librato/client.go @@ -2,6 +2,7 @@ package librato import ( "bytes" + "context" "encoding/json" "fmt" "io" @@ -80,7 +81,7 @@ func (c *LibratoClient) PostMetrics(batch Batch) (err error) { return } - if req, err = http.NewRequest(http.MethodPost, MetricsPostUrl, bytes.NewBuffer(js)); err != nil { + if req, err = http.NewRequestWithContext(context.Background(), http.MethodPost, MetricsPostUrl, bytes.NewBuffer(js)); err != nil { return } diff --git a/node/rpcstack_test.go b/node/rpcstack_test.go index 672fd9fb95..22ca4b7ee8 100644 --- a/node/rpcstack_test.go +++ b/node/rpcstack_test.go @@ -18,6 +18,7 @@ package node import ( "bytes" + "context" "fmt" "io" "net/http" @@ -167,7 +168,7 @@ func TestWebsocketOrigins(t *testing.T) { // TestIsWebsocket tests if an incoming websocket upgrade request is handled properly. func TestIsWebsocket(t *testing.T) { - r, _ := http.NewRequest(http.MethodGet, "/", nil) + r, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, "/", nil) assert.False(t, isWebsocket(r)) r.Header.Set("upgrade", "websocket") @@ -296,7 +297,7 @@ func baseRpcRequest(t *testing.T, url, bodyStr string, extraHeaders ...string) * // Create the request. body := bytes.NewReader([]byte(bodyStr)) - req, err := http.NewRequest(http.MethodPost, url, body) + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, body) if err != nil { t.Fatal("could not create http request:", err) } @@ -530,7 +531,14 @@ func TestGzipHandler(t *testing.T) { srv := httptest.NewServer(newGzipHandler(test.handler)) defer srv.Close() - resp, err := http.Get(srv.URL) + cli := &http.Client{ + Timeout: 10 * time.Second, + } + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, srv.URL, nil) + if err != nil { + log.Crit("Can't build request", "url", srv.URL, "err", err) + } + resp, err := cli.Do(req) if err != nil { t.Fatal(err) } diff --git a/p2p/nat/natupnp.go b/p2p/nat/natupnp.go index a8de00e978..213885d4eb 100644 --- a/p2p/nat/natupnp.go +++ b/p2p/nat/natupnp.go @@ -79,6 +79,7 @@ func (n *upnp) ExternalIP() (addr net.IP, err error) { func (n *upnp) AddMapping(protocol string, extport, intport int, desc string, lifetime time.Duration) error { ip, err := n.internalAddress() if err != nil { + //nolint:nilerr return nil // TODO: Shouldn't we return the error? } protocol = strings.ToUpper(protocol) diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 1d812514de..8a138dd93d 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -427,8 +427,15 @@ func execP2PNode() { } // Send status to the host. + cli := &http.Client{ + Timeout: 10 * time.Second, + } statusJSON, _ := json.Marshal(status) - resp, err := http.Post(statusURL, "application/json", bytes.NewReader(statusJSON)) + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, statusURL, bytes.NewReader(statusJSON)) + if err != nil { + log.Crit("Can't build request", "url", statusURL, "err", err) + } + resp, err := cli.Do(req) if err != nil { log.Crit("Can't post startup info", "url", statusURL, "err", err) } diff --git a/p2p/simulations/http.go b/p2p/simulations/http.go index 7a4f70e9b0..9b3ab3535d 100644 --- a/p2p/simulations/http.go +++ b/p2p/simulations/http.go @@ -102,7 +102,7 @@ type SubscribeOpts struct { // nodes and connections and filtering message events func (c *Client) SubscribeNetwork(events chan *Event, opts SubscribeOpts) (event.Subscription, error) { url := fmt.Sprintf("%s/events?current=%t&filter=%s", c.URL, opts.Current, opts.Filter) - req, err := http.NewRequest(http.MethodGet, url, nil) + req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, url, nil) if err != nil { return nil, err } diff --git a/p2p/simulations/mocker_test.go b/p2p/simulations/mocker_test.go index 0112ee5cfd..eea2f96d71 100644 --- a/p2p/simulations/mocker_test.go +++ b/p2p/simulations/mocker_test.go @@ -19,7 +19,9 @@ package simulations import ( + "context" "encoding/json" + "github.com/ethereum/go-ethereum/log" "net/http" "net/url" "strconv" @@ -152,7 +154,15 @@ func TestMocker(t *testing.T) { } //reset the network - resp, err = http.Post(s.URL+"/reset", "", nil) + cli := &http.Client{ + Timeout: 10 * time.Second, + } + resetUrl := s.URL + "/reset" + req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, resetUrl, nil) + if err != nil { + log.Crit("Can't build request", "url", resetUrl, "err", err) + } + resp, err = cli.Do(req) if err != nil { t.Fatalf("Could not reset network: %s", err) } diff --git a/tests/state_test_util.go b/tests/state_test_util.go index 3e84b99a71..d99940e2eb 100644 --- a/tests/state_test_util.go +++ b/tests/state_test_util.go @@ -193,6 +193,7 @@ func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bo if err != nil { // Here, an error exists but it was expected. // We do not check the post state or logs. + //nolint:nilerr return snaps, statedb, nil } post := t.json.Post[subtest.Fork][subtest.Index]