Skip to content

Commit 3b2ab68

Browse files
authored
style: revive lint (#1136)
1 parent 215620b commit 3b2ab68

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+333
-369
lines changed

.avalanche-golangci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ linters:
7373
- perfsprint
7474
# - prealloc
7575
# - predeclared
76-
# - revive
76+
- revive
7777
- spancheck
7878
# - staticcheck
7979
- tagalign
@@ -138,6 +138,9 @@ linters:
138138
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
139139
- name: empty-lines
140140
disabled: false
141+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-import-alias
142+
- name: redundant-import-alias
143+
disabled: false
141144
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
142145
- name: string-format
143146
disabled: false

accounts/abi/bind/bind_extra_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func TestGetSenderNativeAssetCall(t *testing.T) {
6565
auth, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
6666
require.NoError(t, err, "Failed to create transactor")
6767
alloc := types.GenesisAlloc{auth.From: {Balance: big.NewInt(1000000000000000000)}}
68-
atApricotPhase2 := func(nodeConf *node.Config, ethConf *ethconfig.Config) {
68+
atApricotPhase2 := func(_ *node.Config, ethConf *ethconfig.Config) {
6969
chainConfig := *params.TestApricotPhase2Config
7070
chainConfig.ChainID = big.NewInt(1337)
7171
ethConf.Genesis.Config = &chainConfig

cmd/simulator/key/key.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func LoadAll(ctx context.Context, dir string) ([]*Key, error) {
4545

4646
var files []string
4747

48-
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
48+
err := filepath.Walk(dir, func(path string, _ os.FileInfo, _ error) error {
4949
if path == dir {
5050
return nil
5151
}
@@ -59,6 +59,9 @@ func LoadAll(ctx context.Context, dir string) ([]*Key, error) {
5959

6060
ks := make([]*Key, len(files))
6161
for i, file := range files {
62+
if ctx.Err() != nil {
63+
return nil, ctx.Err()
64+
}
6265
k, err := Load(file)
6366
if err != nil {
6467
return nil, fmt.Errorf("could not load key at %s: %w", file, err)

cmd/simulator/load/funder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func DistributeFunds(ctx context.Context, client *ethclient.Client, keys []*key.
109109
if err != nil {
110110
return nil, fmt.Errorf("failed to generate fund distribution sequence from %s of length %d", maxFundsKey.Address, len(needFundsAddrs))
111111
}
112-
worker := NewSingleAddressTxWorker(ctx, client, maxFundsKey.Address)
112+
worker := NewSingleAddressTxWorker(client, maxFundsKey.Address)
113113
txFunderAgent := txs.NewIssueNAgent[*types.Transaction](txSequence, worker, numTxs, m)
114114

115115
if err := txFunderAgent.Execute(ctx); err != nil {

cmd/simulator/load/loader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {
235235

236236
workers := make([]txs.Worker[*types.Transaction], 0, len(clients))
237237
for i, client := range clients {
238-
workers = append(workers, NewSingleAddressTxWorker(ctx, client, ethcrypto.PubkeyToAddress(pks[i].PublicKey)))
238+
workers = append(workers, NewSingleAddressTxWorker(client, ethcrypto.PubkeyToAddress(pks[i].PublicKey)))
239239
}
240240
loader := New(workers, txSequences, config.BatchSize, m)
241241
err = loader.Execute(ctx)

cmd/simulator/load/worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ethereumTxWorker struct {
2626

2727
// NewSingleAddressTxWorker creates and returns a new ethereumTxWorker that confirms transactions by checking the latest
2828
// nonce of [address] and assuming any transaction with a lower nonce was already accepted.
29-
func NewSingleAddressTxWorker(ctx context.Context, client *ethclient.Client, address common.Address) *ethereumTxWorker {
29+
func NewSingleAddressTxWorker(client *ethclient.Client, address common.Address) *ethereumTxWorker {
3030
newHeads := make(chan *types.Header)
3131
tw := &ethereumTxWorker{
3232
client: client,
@@ -39,7 +39,7 @@ func NewSingleAddressTxWorker(ctx context.Context, client *ethclient.Client, add
3939

4040
// NewTxReceiptWorker creates and returns a new ethereumTxWorker that confirms transactions by checking for the
4141
// corresponding transaction receipt.
42-
func NewTxReceiptWorker(ctx context.Context, client *ethclient.Client) *ethereumTxWorker {
42+
func NewTxReceiptWorker(client *ethclient.Client) *ethereumTxWorker {
4343
newHeads := make(chan *types.Header)
4444
tw := &ethereumTxWorker{
4545
client: client,

consensus/dummy/consensus.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ func (eng *DummyEngine) VerifyHeader(chain consensus.ChainHeaderReader, header *
283283
return eng.verifyHeader(chain, header, parent, false)
284284
}
285285

286-
func (*DummyEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
286+
func (*DummyEngine) VerifyUncles(_ consensus.ChainReader, block *types.Block) error {
287287
if len(block.Uncles()) > 0 {
288288
return errUnclesUnsupported
289289
}
290290
return nil
291291
}
292292

293-
func (*DummyEngine) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
293+
func (*DummyEngine) Prepare(_ consensus.ChainHeaderReader, header *types.Header) error {
294294
header.Difficulty = big.NewInt(1)
295295
return nil
296296
}
@@ -475,7 +475,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
475475
), nil
476476
}
477477

478-
func (*DummyEngine) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int {
478+
func (*DummyEngine) CalcDifficulty(_ consensus.ChainHeaderReader, _ uint64, _ *types.Header) *big.Int {
479479
return big.NewInt(1)
480480
}
481481

core/blockchain_ext_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func InsertChainAcceptSingleBlockTest(t *testing.T, create createFunc) {
269269

270270
// This call generates a chain of 3 blocks.
271271
signer := types.HomesteadSigner{}
272-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) {
272+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(_ int, gen *BlockGen) {
273273
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
274274
gen.AddTx(tx)
275275
})
@@ -340,7 +340,7 @@ func InsertLongForkedChainTest(t *testing.T, create createFunc) {
340340

341341
numBlocks := 129
342342
signer := types.HomesteadSigner{}
343-
_, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) {
343+
_, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ int, gen *BlockGen) {
344344
// Generate a transaction to create a unique block
345345
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
346346
gen.AddTx(tx)
@@ -350,7 +350,7 @@ func InsertLongForkedChainTest(t *testing.T, create createFunc) {
350350
}
351351
// Generate the forked chain to be longer than the original chain to check for a regression where
352352
// a longer chain can trigger a reorg.
353-
_, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks+1, 10, func(i int, gen *BlockGen) {
353+
_, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks+1, 10, func(_ int, gen *BlockGen) {
354354
// Generate a transaction with a different amount to ensure [chain2] is different than [chain1].
355355
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), params.TxGas, nil, nil), signer, key1)
356356
gen.AddTx(tx)
@@ -506,15 +506,15 @@ func AcceptNonCanonicalBlockTest(t *testing.T, create createFunc) {
506506

507507
numBlocks := 3
508508
signer := types.HomesteadSigner{}
509-
_, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) {
509+
_, chain1, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ int, gen *BlockGen) {
510510
// Generate a transaction to create a unique block
511511
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
512512
gen.AddTx(tx)
513513
})
514514
if err != nil {
515515
t.Fatal(err)
516516
}
517-
_, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) {
517+
_, chain2, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ int, gen *BlockGen) {
518518
// Generate a transaction with a different amount to create a chain of blocks different from [chain1]
519519
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(5000), params.TxGas, nil, nil), signer, key1)
520520
gen.AddTx(tx)
@@ -615,7 +615,7 @@ func SetPreferenceRewindTest(t *testing.T, create createFunc) {
615615

616616
numBlocks := 3
617617
signer := types.HomesteadSigner{}
618-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) {
618+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ int, gen *BlockGen) {
619619
// Generate a transaction to create a unique block
620620
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
621621
gen.AddTx(tx)
@@ -905,7 +905,7 @@ func EmptyBlocksTest(t *testing.T, create createFunc) {
905905
}
906906
defer blockchain.Stop()
907907

908-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(i int, gen *BlockGen) {})
908+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, 10, func(_ int, _ *BlockGen) {})
909909
if err != nil {
910910
t.Fatal(err)
911911
}
@@ -922,7 +922,7 @@ func EmptyBlocksTest(t *testing.T, create createFunc) {
922922
blockchain.DrainAcceptorQueue()
923923

924924
// Nothing to assert about the state
925-
checkState := func(sdb *state.StateDB) error {
925+
checkState := func(_ *state.StateDB) error {
926926
return nil
927927
}
928928

@@ -1023,7 +1023,7 @@ func ReorgReInsertTest(t *testing.T, create createFunc) {
10231023

10241024
signer := types.HomesteadSigner{}
10251025
numBlocks := 3
1026-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(i int, gen *BlockGen) {
1026+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, numBlocks, 10, func(_ int, gen *BlockGen) {
10271027
// Generate a transaction to create a unique block
10281028
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
10291029
gen.AddTx(tx)
@@ -1427,7 +1427,7 @@ func GenerateChainInvalidBlockFeeTest(t *testing.T, create createFunc) {
14271427

14281428
// This call generates a chain of 3 blocks.
14291429
signer := types.LatestSigner(params.TestChainConfig)
1430-
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
1430+
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
14311431
tx := types.NewTx(&types.DynamicFeeTx{
14321432
ChainID: params.TestChainConfig.ChainID,
14331433
Nonce: gen.TxNonce(addr1),
@@ -1469,7 +1469,7 @@ func InsertChainInvalidBlockFeeTest(t *testing.T, create createFunc) {
14691469
// This call generates a chain of 3 blocks.
14701470
signer := types.LatestSigner(params.TestChainConfig)
14711471
eng := dummy.NewFakerWithMode(TestCallbacks, dummy.Mode{ModeSkipBlockFee: true, ModeSkipCoinbase: true})
1472-
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
1472+
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
14731473
tx := types.NewTx(&types.DynamicFeeTx{
14741474
ChainID: params.TestChainConfig.ChainID,
14751475
Nonce: gen.TxNonce(addr1),
@@ -1516,7 +1516,7 @@ func InsertChainValidBlockFeeTest(t *testing.T, create createFunc) {
15161516
signer := types.LatestSigner(params.TestChainConfig)
15171517
tip := big.NewInt(50000 * params.GWei)
15181518
transfer := big.NewInt(10000)
1519-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
1519+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
15201520
feeCap := new(big.Int).Add(gen.BaseFee(), tip)
15211521
tx := types.NewTx(&types.DynamicFeeTx{
15221522
ChainID: params.TestChainConfig.ChainID,
@@ -1598,7 +1598,7 @@ func ReexecBlocksTest(t *testing.T, create ReexecTestFunc) {
15981598

15991599
// This call generates a chain of 10 blocks.
16001600
signer := types.HomesteadSigner{}
1601-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 10, 10, func(i int, gen *BlockGen) {
1601+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 10, 10, func(_ int, gen *BlockGen) {
16021602
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
16031603
gen.AddTx(tx)
16041604
})
@@ -1732,7 +1732,7 @@ func ReexecMaxBlocksTest(t *testing.T, create ReexecTestFunc) {
17321732
numAcceptedBlocks := 2*newCommitInterval - 1
17331733

17341734
signer := types.HomesteadSigner{}
1735-
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, genNumBlocks, 10, func(i int, gen *BlockGen) {
1735+
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, genNumBlocks, 10, func(_ int, gen *BlockGen) {
17361736
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
17371737
gen.AddTx(tx)
17381738
})

core/extstate/firewood_database.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (db *firewoodAccessorDb) OpenTrie(root common.Hash) (state.Trie, error) {
2929
}
3030

3131
// OpenStorageTrie opens a wrapped version of the account trie.
32-
func (db *firewoodAccessorDb) OpenStorageTrie(stateRoot common.Hash, address common.Address, root common.Hash, self state.Trie) (state.Trie, error) {
32+
func (*firewoodAccessorDb) OpenStorageTrie(_ common.Hash, _ common.Address, root common.Hash, self state.Trie) (state.Trie, error) {
3333
accountTrie, ok := self.(*firewood.AccountTrie)
3434
if !ok {
3535
return nil, fmt.Errorf("Invalid account trie type: %T", self)
@@ -39,7 +39,7 @@ func (db *firewoodAccessorDb) OpenStorageTrie(stateRoot common.Hash, address com
3939

4040
// CopyTrie returns a deep copy of the given trie.
4141
// It can be altered by the caller.
42-
func (db *firewoodAccessorDb) CopyTrie(t state.Trie) state.Trie {
42+
func (*firewoodAccessorDb) CopyTrie(t state.Trie) state.Trie {
4343
switch t := t.(type) {
4444
case *firewood.AccountTrie:
4545
return t.Copy()

core/fifo_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (f *BufferFIFOCache[K, V]) remove(key K) error {
6565

6666
type NoOpFIFOCache[K comparable, V any] struct{}
6767

68-
func (f *NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
69-
func (f *NoOpFIFOCache[K, V]) Get(_ K) (V, bool) {
68+
func (*NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
69+
func (*NoOpFIFOCache[K, V]) Get(_ K) (V, bool) {
7070
return *new(V), false
7171
}

0 commit comments

Comments
 (0)