more linter fixes

This commit is contained in:
Igor Mandrigin 2021-03-18 11:44:22 +01:00
parent f1f849e691
commit 36297dd057
16 changed files with 27 additions and 33 deletions

View File

@ -26,7 +26,7 @@ import (
)
// largeNumber returns a very large big.Int.
func largeNumber(megabytes int) *uint256.Int {
func largeNumber(megabytes int) *uint256.Int { //nolint:unparam
buf := make([]byte, megabytes*1024*1024)
//nolint:errcheck
rand.Read(buf)
@ -36,7 +36,7 @@ func largeNumber(megabytes int) *uint256.Int {
}
// largeBuffer returns a very large buffer.
func largeBuffer(megabytes int) []byte {
func largeBuffer(megabytes int) []byte { //nolint:unparam
buf := make([]byte, megabytes*1024*1024)
//nolint:errcheck
rand.Read(buf)
@ -44,7 +44,7 @@ func largeBuffer(megabytes int) []byte {
}
// largeString returns a very large string.
func largeString(megabytes int) string {
func largeString(megabytes int) string { //nolint:unparam
buf := make([]byte, megabytes*1024*1024)
//nolint:errcheck
rand.Read(buf)

View File

@ -24,7 +24,7 @@ import (
"golang.org/x/sys/unix"
)
func getFreeDiskSpace(path string) (uint64, error) {
func getFreeDiskSpace(path string) (uint64, error) { //nolint:deadcode
var stat unix.Statfs_t
if err := unix.Statfs(path, &stat); err != nil {
return 0, fmt.Errorf("failed to call Statfs: %v", err)

View File

@ -446,8 +446,8 @@ func TestAddress_Format(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.out != tt.want {
t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want)
if tt.out != tt.want { //nolint:scopelint
t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want) //nolint:scopelint
}
})
}
@ -531,8 +531,8 @@ func TestHash_Format(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.out != tt.want {
t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want)
if tt.out != tt.want { //nolint:scopelint
t.Errorf("%s does not render as expected:\n got %s\nwant %s", tt.name, tt.out, tt.want) //nolint:scopelint
}
})
}

View File

@ -787,7 +787,7 @@ func ReadAllBadBlocks(db ethdb.Database) []*types.Block {
if err := rlp.DecodeBytes(blob, &badBlocks); err != nil {
return nil
}
var blocks []*types.Block
var blocks []*types.Block //nolint:prealloc
for _, bad := range badBlocks {
blocks = append(blocks, types.NewBlockWithHeader(bad.Header).WithBody(bad.Body.Transactions, bad.Body.Uncles))
}

View File

@ -75,7 +75,7 @@ func (p *statePrefetcher) Prefetch(block *types.Block, ibs *state.IntraBlockStat
// precacheTransaction attempts to apply a transaction to the given state database
// and uses the input parameters for its environment. The goal is not to execute
// the transaction successfully, rather to warm up touched data slots.
func precacheTransaction(msg types.Message, config *params.ChainConfig, gaspool *GasPool, ibs vm.IntraBlockState, header *types.Header, evm *vm.EVM) error {
func precacheTransaction(msg types.Message, config *params.ChainConfig, gaspool *GasPool, ibs vm.IntraBlockState, header *types.Header, evm *vm.EVM) error { //nolint:unparam
// Update the evm with the new transaction context.
evm.Reset(NewEVMTxContext(msg), ibs)
// Add addresses to access list if applicable

View File

@ -130,7 +130,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
Time: parent.Time() + 10,
UncleHash: types.EmptyUncleHash,
}
var receipts []*types.Receipt
var receipts []*types.Receipt //nolint:prealloc
// The post-state result doesn't need to be correct (this is a bad block), but we do need something there
// Preferably something unique. So let's use a combo of blocknum + txhash

View File

@ -998,9 +998,10 @@ func testShiftedHeaderAttack(t *testing.T, protocol uint, mode SyncMode) {
// for various failure scenarios. Afterwards a full sync is attempted to make
// sure no state was corrupted.
// no fast sync for TurboGeth
//func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
//func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
//func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) }
/*
func TestInvalidHeaderRollback63Fast(t *testing.T) { testInvalidHeaderRollback(t, 63, FastSync) }
func TestInvalidHeaderRollback64Fast(t *testing.T) { testInvalidHeaderRollback(t, 64, FastSync) }
func TestInvalidHeaderRollback65Fast(t *testing.T) { testInvalidHeaderRollback(t, 65, FastSync) }
func testInvalidHeaderRollback(t *testing.T, protocol uint, mode SyncMode) {
t.Skip("deadlock")
@ -1087,6 +1088,7 @@ func testInvalidHeaderRollback(t *testing.T, protocol uint, mode SyncMode) {
}
tester.terminate()
}
*/
// Tests that a peer advertising a high TD doesn't get to stall the downloader
// afterwards by not sending any useful hashes.

View File

@ -115,9 +115,9 @@ func dummyPeer(id string) *peerConnection {
}
func TestBasics(t *testing.T) {
emptyChain := getEmptyChain() //nolint:govet
numOfBlocks := len(emptyChain.blocks)
numOfReceipts := len(emptyChain.blocks) / 2
emptyCh := getEmptyChain()
numOfBlocks := len(emptyCh.blocks)
numOfReceipts := len(emptyCh.blocks) / 2
q := newQueue(10, 10)
if !q.Idle() {

View File

@ -131,7 +131,7 @@ type handler struct {
}
// newHandler returns a handler for all Ethereum chain management protocol.
func newHandler(config *handlerConfig) (*handler, error) {
func newHandler(config *handlerConfig) (*handler, error) { //nolint:unparam
// Create the protocol manager with the base fields
if config.EventMux == nil {
config.EventMux = new(event.TypeMux) // Nicety initialization for tests

View File

@ -196,7 +196,7 @@ func (h *ethHandler) handleBlockAnnounces(peer *eth.Peer, hashes []common.Hash,
// handleBlockBroadcast is invoked from a peer's message handler when it transmits a
// block broadcast for the local node to process.
func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block, td *big.Int) error {
func (h *ethHandler) handleBlockBroadcast(peer *eth.Peer, block *types.Block, td *big.Int) error { //nolint:unparam
// Schedule the block for import
if err := h.blockFetcher.Enqueue(peer.ID(), block); err != nil {
log.Error("blockFetcher.Enqueue", "error", err)

View File

@ -37,10 +37,6 @@ var (
// errPeerNotRegistered is returned if a peer is attempted to be removed from
// a peer set, but no peer with the given id exists.
errPeerNotRegistered = errors.New("peer not registered")
// errSnapWithoutEth is returned if a peer attempts to connect only on the
// snap protocol without advertizing the eth main protocol.
errSnapWithoutEth = errors.New("peer connected on snap without compatible eth support")
)
// peerSet represents the collection of active peers currently participating in

View File

@ -46,10 +46,6 @@ const (
// nowadays, the practical limit will always be softResponseLimit.
maxBodiesServe = 1024
// maxNodeDataServe is the maximum number of state trie nodes to serve. This
// number is there to limit the number of disk lookups.
maxNodeDataServe = 1024
// maxReceiptsServe is the maximum number of block receipts to serve. This
// number is mostly there to limit the number of disk lookups. With block
// containing 200+ transactions nowadays, the practical limit will always

View File

@ -154,7 +154,7 @@ func handleGetBlockBodies66(backend Backend, msg Decoder, peer *Peer) error {
return peer.ReplyBlockBodiesRLP(query.RequestId, response)
}
func answerGetBlockBodiesQuery(backend Backend, query GetBlockBodiesPacket, peer *Peer) []rlp.RawValue {
func answerGetBlockBodiesQuery(backend Backend, query GetBlockBodiesPacket, peer *Peer) []rlp.RawValue { //nolint:unparam
// Gather blocks until the fetch or network limits is reached
var (
bytes int
@ -217,7 +217,7 @@ func handleGetReceipts66(backend Backend, msg Decoder, peer *Peer) error {
return peer.ReplyReceiptsRLP(query.RequestId, response)
}
func answerGetReceiptsQuery(backend Backend, query GetReceiptsPacket, peer *Peer) []rlp.RawValue {
func answerGetReceiptsQuery(backend Backend, query GetReceiptsPacket, peer *Peer) []rlp.RawValue { //nolint:unparam
// Gather state data until the fetch or network limits is reached
var (
bytes int
@ -395,7 +395,7 @@ func handleGetPooledTransactions66(backend Backend, msg Decoder, peer *Peer) err
return peer.ReplyPooledTransactionsRLP(query.RequestId, hashes, txs)
}
func answerGetPooledTransactions(backend Backend, query GetPooledTransactionsPacket, peer *Peer) ([]common.Hash, []rlp.RawValue) {
func answerGetPooledTransactions(backend Backend, query GetPooledTransactionsPacket, peer *Peer) ([]common.Hash, []rlp.RawValue) { //nolint:unparam
// Gather transactions until the fetch or network limits is reached
var (
bytes int

View File

@ -57,7 +57,7 @@ const (
)
// max is a helper function which returns the larger of the two given integers.
func max(a, b int) int {
func max(a, b int) int { //nolint:unparam
if a > b {
return a
}

View File

@ -182,7 +182,7 @@ func newChainSyncer(handler *handler) *chainSyncer {
// handlePeerEvent notifies the syncer about a change in the peer set.
// This is called for new peers and every time a peer announces a new
// chain head.
func (cs *chainSyncer) handlePeerEvent(peer *eth.Peer) bool {
func (cs *chainSyncer) handlePeerEvent(peer *eth.Peer) bool { //nolint:unparam
select {
case cs.peerEventCh <- struct{}{}:
return true

View File

@ -357,7 +357,7 @@ func (api *SignerAPI) derivationLoop(events chan accounts.WalletEvent) {
// Derive first N accounts, hardcoded for now
for i := 0; i < limit; i++ {
path := next()
if acc, err := event.Wallet.Derive(path, true); err != nil {
if acc, err := event.Wallet.Derive(path, true); err != nil { //nolint:scopelint
log.Warn("Account derivation failed", "error", err)
} else {
log.Info("Derived account", "address", acc.Address, "path", path)