Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .avalanche-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ linters:
- perfsprint
# - prealloc
# - predeclared
# - revive
- revive
- spancheck
# - staticcheck
- tagalign
Expand Down Expand Up @@ -138,6 +138,9 @@ linters:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
- name: empty-lines
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redundant-import-alias
- name: redundant-import-alias
disabled: false
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
- name: string-format
disabled: false
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestGetSenderNativeAssetCall(t *testing.T) {
auth, err := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
require.NoError(t, err, "Failed to create transactor")
alloc := types.GenesisAlloc{auth.From: {Balance: big.NewInt(1000000000000000000)}}
atApricotPhase2 := func(nodeConf *node.Config, ethConf *ethconfig.Config) {
atApricotPhase2 := func(_ *node.Config, ethConf *ethconfig.Config) {
chainConfig := *params.TestApricotPhase2Config
chainConfig.ChainID = big.NewInt(1337)
ethConf.Genesis.Config = &chainConfig
Expand Down
5 changes: 4 additions & 1 deletion cmd/simulator/key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func LoadAll(ctx context.Context, dir string) ([]*Key, error) {

var files []string

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

ks := make([]*Key, len(files))
for i, file := range files {
if ctx.Err() != nil {
return nil, ctx.Err()
}
k, err := Load(file)
if err != nil {
return nil, fmt.Errorf("could not load key at %s: %w", file, err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/simulator/load/funder.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func DistributeFunds(ctx context.Context, client *ethclient.Client, keys []*key.
if err != nil {
return nil, fmt.Errorf("failed to generate fund distribution sequence from %s of length %d", maxFundsKey.Address, len(needFundsAddrs))
}
worker := NewSingleAddressTxWorker(ctx, client, maxFundsKey.Address)
worker := NewSingleAddressTxWorker(client, maxFundsKey.Address)
txFunderAgent := txs.NewIssueNAgent[*types.Transaction](txSequence, worker, numTxs, m)

if err := txFunderAgent.Execute(ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/simulator/load/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func ExecuteLoader(ctx context.Context, config config.Config) error {

workers := make([]txs.Worker[*types.Transaction], 0, len(clients))
for i, client := range clients {
workers = append(workers, NewSingleAddressTxWorker(ctx, client, ethcrypto.PubkeyToAddress(pks[i].PublicKey)))
workers = append(workers, NewSingleAddressTxWorker(client, ethcrypto.PubkeyToAddress(pks[i].PublicKey)))
}
loader := New(workers, txSequences, config.BatchSize, m)
err = loader.Execute(ctx)
Expand Down
4 changes: 2 additions & 2 deletions cmd/simulator/load/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type ethereumTxWorker struct {

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

// NewTxReceiptWorker creates and returns a new ethereumTxWorker that confirms transactions by checking for the
// corresponding transaction receipt.
func NewTxReceiptWorker(ctx context.Context, client *ethclient.Client) *ethereumTxWorker {
func NewTxReceiptWorker(client *ethclient.Client) *ethereumTxWorker {
newHeads := make(chan *types.Header)
tw := &ethereumTxWorker{
client: client,
Expand Down
6 changes: 3 additions & 3 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,14 @@ func (eng *DummyEngine) VerifyHeader(chain consensus.ChainHeaderReader, header *
return eng.verifyHeader(chain, header, parent, false)
}

func (*DummyEngine) VerifyUncles(chain consensus.ChainReader, block *types.Block) error {
func (*DummyEngine) VerifyUncles(_ consensus.ChainReader, block *types.Block) error {
if len(block.Uncles()) > 0 {
return errUnclesUnsupported
}
return nil
}

func (*DummyEngine) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error {
func (*DummyEngine) Prepare(_ consensus.ChainHeaderReader, header *types.Header) error {
header.Difficulty = big.NewInt(1)
return nil
}
Expand Down Expand Up @@ -475,7 +475,7 @@ func (eng *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, h
), nil
}

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

Expand Down
28 changes: 14 additions & 14 deletions core/blockchain_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func InsertChainAcceptSingleBlockTest(t *testing.T, create createFunc) {

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

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

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

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

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

// Nothing to assert about the state
checkState := func(sdb *state.StateDB) error {
checkState := func(_ *state.StateDB) error {
return nil
}

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

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

// This call generates a chain of 3 blocks.
signer := types.LatestSigner(params.TestChainConfig)
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
_, _, _, err = GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Nonce: gen.TxNonce(addr1),
Expand Down Expand Up @@ -1469,7 +1469,7 @@ func InsertChainInvalidBlockFeeTest(t *testing.T, create createFunc) {
// This call generates a chain of 3 blocks.
signer := types.LatestSigner(params.TestChainConfig)
eng := dummy.NewFakerWithMode(TestCallbacks, dummy.Mode{ModeSkipBlockFee: true, ModeSkipCoinbase: true})
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
_, chain, _, err := GenerateChainWithGenesis(gspec, eng, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Nonce: gen.TxNonce(addr1),
Expand Down Expand Up @@ -1516,7 +1516,7 @@ func InsertChainValidBlockFeeTest(t *testing.T, create createFunc) {
signer := types.LatestSigner(params.TestChainConfig)
tip := big.NewInt(50000 * params.GWei)
transfer := big.NewInt(10000)
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(i int, gen *BlockGen) {
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, 3, ap4.TargetBlockRate-1, func(_ int, gen *BlockGen) {
feeCap := new(big.Int).Add(gen.BaseFee(), tip)
tx := types.NewTx(&types.DynamicFeeTx{
ChainID: params.TestChainConfig.ChainID,
Expand Down Expand Up @@ -1598,7 +1598,7 @@ func ReexecBlocksTest(t *testing.T, create ReexecTestFunc) {

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

signer := types.HomesteadSigner{}
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, genNumBlocks, 10, func(i int, gen *BlockGen) {
_, chain, _, err := GenerateChainWithGenesis(gspec, blockchain.engine, genNumBlocks, 10, func(_ int, gen *BlockGen) {
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(addr1), addr2, big.NewInt(10000), params.TxGas, nil, nil), signer, key1)
gen.AddTx(tx)
})
Expand Down
4 changes: 2 additions & 2 deletions core/extstate/firewood_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (db *firewoodAccessorDb) OpenTrie(root common.Hash) (state.Trie, error) {
}

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

// CopyTrie returns a deep copy of the given trie.
// It can be altered by the caller.
func (db *firewoodAccessorDb) CopyTrie(t state.Trie) state.Trie {
func (*firewoodAccessorDb) CopyTrie(t state.Trie) state.Trie {
switch t := t.(type) {
case *firewood.AccountTrie:
return t.Copy()
Expand Down
4 changes: 2 additions & 2 deletions core/fifo_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (f *BufferFIFOCache[K, V]) remove(key K) error {

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

func (f *NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
func (f *NoOpFIFOCache[K, V]) Get(_ K) (V, bool) {
func (*NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
func (*NoOpFIFOCache[K, V]) Get(_ K) (V, bool) {
return *new(V), false
}
6 changes: 3 additions & 3 deletions core/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ func (t *MockTrieDB) Dereference(root common.Hash) error {
return nil
}

func (t *MockTrieDB) Commit(root common.Hash, report bool) error {
func (t *MockTrieDB) Commit(root common.Hash, _ bool) error {
t.LastCommit = root
return nil
}

func (t *MockTrieDB) Size() (common.StorageSize, common.StorageSize, common.StorageSize) {
func (*MockTrieDB) Size() (common.StorageSize, common.StorageSize, common.StorageSize) {
return 0, 0, 0
}

func (t *MockTrieDB) Cap(limit common.StorageSize) error {
func (*MockTrieDB) Cap(_ common.StorageSize) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion eth/api_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (api *DebugAPI) Preimage(ctx context.Context, hash common.Hash) (hexutil.By
// and returns them as a JSON list of block hashes.
func (api *DebugAPI) GetBadBlocks(ctx context.Context) ([]*ethapi.BadBlockArgs, error) {
internalAPI := ethapi.NewBlockChainAPI(api.eth.APIBackend)
return internalAPI.GetBadBlocks(ctx)
return internalAPI.GetBadBlocks()
}

// AccountRangeMaxResults is the maximum number of results to be returned per call
Expand Down
8 changes: 1 addition & 7 deletions internal/ethapi/api_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@ import (
"github.com/ava-labs/libevm/rlp"

"github.com/ava-labs/coreth/core"
"github.com/ava-labs/coreth/params"
"github.com/ava-labs/coreth/rpc"
)

// GetChainConfig returns the chain config.
func (api *BlockChainAPI) GetChainConfig(ctx context.Context) *params.ChainConfig {
return api.b.ChainConfig()
}

type DetailedExecutionResult struct {
UsedGas uint64 `json:"gas"` // Total used gas but include the refunded gas
ErrCode int `json:"errCode"` // EVM error code
Expand Down Expand Up @@ -69,7 +63,7 @@ type BadBlockArgs struct {

// GetBadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
// and returns them as a JSON list of block hashes.
func (s *BlockChainAPI) GetBadBlocks(ctx context.Context) ([]*BadBlockArgs, error) {
func (s *BlockChainAPI) GetBadBlocks() ([]*BadBlockArgs, error) {
var (
badBlocks, reasons = s.b.BadBlocks()
results = make([]*BadBlockArgs, 0, len(badBlocks))
Expand Down
4 changes: 2 additions & 2 deletions nativeasset/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func UnpackNativeAssetBalanceInput(input []byte) (common.Address, common.Hash, e
}

// Run implements StatefulPrecompiledContract
func (b *NativeAssetBalance) Run(accessibleState contract.AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) {
func (b *NativeAssetBalance) Run(accessibleState contract.AccessibleState, _ common.Address, _ common.Address, input []byte, suppliedGas uint64, _ bool) (ret []byte, remainingGas uint64, err error) {
// input: encodePacked(address 20 bytes, assetID 32 bytes)
if suppliedGas < b.GasCost {
return nil, 0, vm.ErrOutOfGas
Expand Down Expand Up @@ -166,6 +166,6 @@ func (c *NativeAssetCall) run(env vm.PrecompileEnvironment, stateDB contract.Sta

type DeprecatedContract struct{}

func (*DeprecatedContract) Run(accessibleState contract.AccessibleState, caller common.Address, addr common.Address, input []byte, suppliedGas uint64, readOnly bool) (ret []byte, remainingGas uint64, err error) {
func (*DeprecatedContract) Run(_ contract.AccessibleState, _ common.Address, _ common.Address, _ []byte, suppliedGas uint64, _ bool) (ret []byte, remainingGas uint64, err error) {
return nil, suppliedGas, vm.ErrExecutionReverted
}
Loading
Loading