diff --git a/.avalanche-golangci.yml b/.avalanche-golangci.yml index cd86981f8b..b63d82f955 100644 --- a/.avalanche-golangci.yml +++ b/.avalanche-golangci.yml @@ -59,7 +59,7 @@ linters: - errorlint # - forbidigo - goconst - # - gocritic + - gocritic - goprintffuncname # - gosec - govet diff --git a/core/blockchain_ext_test.go b/core/blockchain_ext_test.go index 9700614bd4..6d0d52b2e1 100644 --- a/core/blockchain_ext_test.go +++ b/core/blockchain_ext_test.go @@ -6,6 +6,7 @@ package core import ( "fmt" "math/big" + "slices" "testing" "github.com/ava-labs/libevm/common" @@ -1853,7 +1854,7 @@ func ReexecBlocks(t *testing.T, create ReexecTestFunc) { newChain, restartedChain := checkBlockChainState(t, blockchain, gspec, chainDB, checkCreate, checkState) - allTxs := append(foundTxs, missingTxs...) + allTxs := slices.Concat(foundTxs, missingTxs) for _, bc := range []*BlockChain{newChain, restartedChain} { // We should confirm that snapshots were properly initialized if bc.snaps == nil && bc.cacheConfig.SnapshotLimit > 0 { @@ -1985,7 +1986,7 @@ func ReexecMaxBlocks(t *testing.T, create ReexecTestFunc) { } newChain, restartedChain := checkBlockChainState(t, blockchain, gspec, chainDB, checkCreate, checkState) - allTxs := append(foundTxs, missingTxs...) + allTxs := slices.Concat(foundTxs, missingTxs) for _, bc := range []*BlockChain{newChain, restartedChain} { // We should confirm that snapshots were properly initialized if bc.snaps == nil && bc.cacheConfig.SnapshotLimit > 0 { diff --git a/core/extstate/database_test.go b/core/extstate/database_test.go index 07469aff6f..1056c0c9fb 100644 --- a/core/extstate/database_test.go +++ b/core/extstate/database_test.go @@ -209,7 +209,7 @@ func (fs *fuzzState) updateAccount(addrIndex int) { fs.require.NoError(err, "failed to get account %s for update in %s", addr.Hex(), tr.name) fs.require.NotNil(acc, "account %s is nil for update in %s", addr.Hex(), tr.name) acc.Nonce++ - acc.CodeHash = crypto.Keccak256Hash(acc.CodeHash[:]).Bytes() + acc.CodeHash = crypto.Keccak256Hash(acc.CodeHash).Bytes() acc.Balance.Add(acc.Balance, uint256.NewInt(3)) fs.require.NoError(tr.accountTrie.UpdateAccount(addr, acc), "failed to update account %s in %s", addr.Hex(), tr.name) } @@ -286,7 +286,7 @@ func (fs *fuzzState) updateStorage(accountIndex int, storageIndexInput uint64) { storageKeyHash := crypto.Keccak256Hash(storageKey[:]) fs.inputCounter++ updatedValInput := binary.BigEndian.AppendUint64(storageKeyHash[:], fs.inputCounter) - updatedVal := crypto.Keccak256Hash(updatedValInput[:]) + updatedVal := crypto.Keccak256Hash(updatedValInput) for _, tr := range fs.merkleTries { str := fs.openStorageTrie(addr, tr) @@ -324,7 +324,7 @@ func FuzzTree(f *testing.F) { } for _, step := range byteSteps { - step = step % maxStep + step %= maxStep t.Log(stepMap[step]) switch step { case commit: diff --git a/internal/ethapi/api_extra.go b/internal/ethapi/api_extra.go index ef952b4135..924e1a412d 100644 --- a/internal/ethapi/api_extra.go +++ b/internal/ethapi/api_extra.go @@ -125,7 +125,7 @@ func (s *BlockChainAPI) FeeConfig(ctx context.Context, blockNrOrHash *rpc.BlockN } // GetActivePrecompilesAt returns the active precompile configs at the given block timestamp. -// DEPRECATED: Use GetActiveRulesAt instead. +// Deprecated: Use GetActiveRulesAt instead. func (s *BlockChainAPI) GetActivePrecompilesAt(_ context.Context, blockTimestamp *uint64) extras.Precompiles { var timestamp uint64 if blockTimestamp == nil { diff --git a/params/hooks_libevm.go b/params/hooks_libevm.go index a748f03376..c78fd7d53e 100644 --- a/params/hooks_libevm.go +++ b/params/hooks_libevm.go @@ -78,8 +78,7 @@ func (r RulesExtra) ActivePrecompiles(existing []common.Address) []common.Addres } func (r RulesExtra) currentPrecompiles() map[common.Address]vm.PrecompiledContract { - switch { - case r.IsGranite: + if r.IsGranite { return PrecompiledContractsGranite } return nil diff --git a/plugin/evm/customheader/extra.go b/plugin/evm/customheader/extra.go index 843fb0954e..a8572464d1 100644 --- a/plugin/evm/customheader/extra.go +++ b/plugin/evm/customheader/extra.go @@ -50,20 +50,21 @@ func VerifyExtraPrefix( parent *types.Header, header *types.Header, ) error { - switch { - case config.IsSubnetEVM(header.Time): - feeWindow, err := feeWindow(config, parent, header.Time) - if err != nil { - return fmt.Errorf("calculating expected fee window: %w", err) - } - feeWindowBytes := feeWindow.Bytes() - if !bytes.HasPrefix(header.Extra, feeWindowBytes) { - return fmt.Errorf("%w: expected %x as prefix, found %x", - errInvalidExtraPrefix, - feeWindowBytes, - header.Extra, - ) - } + if !config.IsSubnetEVM(header.Time) { + return nil + } + + feeWindow, err := feeWindow(config, parent, header.Time) + if err != nil { + return fmt.Errorf("calculating expected fee window: %w", err) + } + feeWindowBytes := feeWindow.Bytes() + if !bytes.HasPrefix(header.Extra, feeWindowBytes) { + return fmt.Errorf("%w: expected %x as prefix, found %x", + errInvalidExtraPrefix, + feeWindowBytes, + header.Extra, + ) } return nil } diff --git a/plugin/evm/customrawdb/accessors_state_sync_test.go b/plugin/evm/customrawdb/accessors_state_sync_test.go index c9b6f66223..76d38db1c7 100644 --- a/plugin/evm/customrawdb/accessors_state_sync_test.go +++ b/plugin/evm/customrawdb/accessors_state_sync_test.go @@ -4,6 +4,7 @@ package customrawdb import ( + "slices" "testing" "github.com/ava-labs/libevm/common" @@ -19,7 +20,7 @@ func TestClearPrefix(t *testing.T) { require.NoError(WriteSyncSegment(db, common.Hash{1}, common.Hash{})) // add a key that should not be cleared - key := append(syncSegmentsPrefix, []byte("foo")...) + key := slices.Concat(syncSegmentsPrefix, []byte("foo")) require.NoError(db.Put(key, []byte("bar"))) require.NoError(ClearAllSyncSegments(db)) diff --git a/plugin/evm/validators/state/state_test.go b/plugin/evm/validators/state/state_test.go index 1034573575..d66faa20e2 100644 --- a/plugin/evm/validators/state/state_test.go +++ b/plugin/evm/validators/state/state_test.go @@ -95,7 +95,7 @@ func TestState(t *testing.T) { require.ErrorIs(err, ErrImmutableField) // set a different start time should fail - vdr.StartTimestamp = vdr.StartTimestamp + 100 + vdr.StartTimestamp += 100 err = state.UpdateValidator(vdr) require.ErrorIs(err, ErrImmutableField) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 8267557d38..b1cc629ce8 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -1222,7 +1222,7 @@ func (vm *VM) startContinuousProfiler() { return } vm.profiler = profiler.NewContinuous( - filepath.Join(vm.config.ContinuousProfilerDir), + filepath.Clean(vm.config.ContinuousProfilerDir), vm.config.ContinuousProfilerFrequency.Duration, vm.config.ContinuousProfilerMaxFiles, ) diff --git a/plugin/evm/vm_warp_test.go b/plugin/evm/vm_warp_test.go index 042e360138..fe06ab5860 100644 --- a/plugin/evm/vm_warp_test.go +++ b/plugin/evm/vm_warp_test.go @@ -168,7 +168,7 @@ func testSendWarpMessage(t *testing.T, scheme string) { // Verify the message signature after accepting the block. rawSignatureBytes, err := tvm.vm.warpBackend.GetMessageSignature(context.TODO(), unsignedMessage) require.NoError(err) - blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes[:]) + blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes) require.NoError(err) select { @@ -185,7 +185,7 @@ func testSendWarpMessage(t *testing.T, scheme string) { // Verify the blockID will now be signed by the backend and produces a valid signature. rawSignatureBytes, err = tvm.vm.warpBackend.GetBlockSignature(context.TODO(), blk.ID()) require.NoError(err) - blsSignature, err = bls.SignatureFromBytes(rawSignatureBytes[:]) + blsSignature, err = bls.SignatureFromBytes(rawSignatureBytes) require.NoError(err) blockHashPayload, err := payload.NewHash(blk.ID()) diff --git a/precompile/contracts/rewardmanager/module.go b/precompile/contracts/rewardmanager/module.go index 805558edda..88f5ee81af 100644 --- a/precompile/contracts/rewardmanager/module.go +++ b/precompile/contracts/rewardmanager/module.go @@ -55,12 +55,14 @@ func (*configurator) Configure(chainConfig precompileconfig.ChainConfig, cfg pre return fmt.Errorf("expected config type %T, got %T: %v", &Config{}, cfg, cfg) } // configure the RewardManager with the given initial configuration - if config.InitialRewardConfig != nil { + + switch { + case config.InitialRewardConfig != nil: config.InitialRewardConfig.Configure(state) - } else if chainConfig.AllowedFeeRecipients() { + case chainConfig.AllowedFeeRecipients(): // configure the RewardManager according to chainConfig EnableAllowFeeRecipients(state) - } else { + default: // chainConfig does not have any reward address // if chainConfig does not enable fee recipients // default to disabling rewards diff --git a/sync/handlers/leafs_request_test.go b/sync/handlers/leafs_request_test.go index 0bfe48cbae..b69de06b1c 100644 --- a/sync/handlers/leafs_request_test.go +++ b/sync/handlers/leafs_request_test.go @@ -344,8 +344,8 @@ func TestLeafsRequestHandler_OnLeafsRequest(t *testing.T) { "partial mid range": { prepareTestFn: func() (context.Context, message.LeafsRequest) { startKey := largeTrieKeys[1_000] - startKey[31] = startKey[31] + 1 // exclude start key from response - endKey := largeTrieKeys[1_040] // include end key in response + startKey[31]++ // exclude start key from response + endKey := largeTrieKeys[1_040] // include end key in response return context.Background(), message.LeafsRequest{ Root: largeTrieRoot, Start: startKey, diff --git a/triedb/firewood/database.go b/triedb/firewood/database.go index 45fa0d0423..a6d58edc34 100644 --- a/triedb/firewood/database.go +++ b/triedb/firewood/database.go @@ -585,7 +585,5 @@ func arrangeKeyValuePairs(nodes *trienode.MergedNodeSet) ([][]byte, [][]byte) { } // We need to do all storage operations first, so prefix-deletion works for accounts. - keys := append(storageKeys, acctKeys...) - values := append(storageValues, acctValues...) - return keys, values + return append(storageKeys, acctKeys...), append(storageValues, acctValues...) } diff --git a/warp/backend_test.go b/warp/backend_test.go index ea273b53ee..fc824b5e8f 100644 --- a/warp/backend_test.go +++ b/warp/backend_test.go @@ -59,7 +59,7 @@ func TestAddAndGetValidMessage(t *testing.T) { expectedSig, err := warpSigner.Sign(testUnsignedMessage) require.NoError(t, err) - require.Equal(t, expectedSig, signature[:]) + require.Equal(t, expectedSig, signature) } func TestAddAndGetUnknownMessage(t *testing.T) { @@ -100,7 +100,7 @@ func TestGetBlockSignature(t *testing.T) { signature, err := backend.GetBlockSignature(context.TODO(), blkID) require.NoError(err) - require.Equal(expectedSig, signature[:]) + require.Equal(expectedSig, signature) _, err = backend.GetBlockSignature(context.TODO(), ids.GenerateTestID()) require.Error(err) @@ -127,7 +127,7 @@ func TestZeroSizedCache(t *testing.T) { expectedSig, err := warpSigner.Sign(testUnsignedMessage) require.NoError(t, err) - require.Equal(t, expectedSig, signature[:]) + require.Equal(t, expectedSig, signature) } func TestOffChainMessages(t *testing.T) { @@ -155,7 +155,7 @@ func TestOffChainMessages(t *testing.T) { require.NoError(err) expectedSignatureBytes, err := warpSigner.Sign(msg) require.NoError(err) - require.Equal(expectedSignatureBytes, signature[:]) + require.Equal(expectedSignatureBytes, signature) }, }, "unknown message": { diff --git a/warp/service.go b/warp/service.go index 3f63941ff3..19859e4fa7 100644 --- a/warp/service.go +++ b/warp/service.go @@ -55,7 +55,7 @@ func (a *API) GetMessageSignature(ctx context.Context, messageID ids.ID) (hexuti if err != nil { return nil, fmt.Errorf("failed to get signature for message %s with error %w", messageID, err) } - return signature[:], nil + return signature, nil } // GetBlockSignature returns the BLS signature associated with a blockID. @@ -64,7 +64,7 @@ func (a *API) GetBlockSignature(ctx context.Context, blockID ids.ID) (hexutil.By if err != nil { return nil, fmt.Errorf("failed to get signature for block %s with error %w", blockID, err) } - return signature[:], nil + return signature, nil } // GetMessageAggregateSignature fetches the aggregate signature for the requested [messageID] diff --git a/warp/verifier_backend_test.go b/warp/verifier_backend_test.go index 3d72a63a60..9ed620489d 100644 --- a/warp/verifier_backend_test.go +++ b/warp/verifier_backend_test.go @@ -59,7 +59,7 @@ func TestAddressedCallSignatures(t *testing.T) { require.NoError(t, err) backend.AddMessage(msg) - return msg.Bytes(), signature[:] + return msg.Bytes(), signature }, verifyStats: func(t *testing.T, stats *verifierStats) { require.EqualValues(t, 0, stats.messageParseFail.Snapshot().Count()) @@ -68,7 +68,7 @@ func TestAddressedCallSignatures(t *testing.T) { }, "offchain message": { setup: func(_ Backend) (request []byte, expectedResponse []byte) { - return offchainMessage.Bytes(), offchainSignature[:] + return offchainMessage.Bytes(), offchainSignature }, verifyStats: func(t *testing.T, stats *verifierStats) { require.EqualValues(t, 0, stats.messageParseFail.Snapshot().Count()) @@ -189,7 +189,7 @@ func TestBlockSignatures(t *testing.T) { require.NoError(t, err) signature, err := snowCtx.WarpSigner.Sign(unsignedMessage) require.NoError(t, err) - return toMessageBytes(knownBlkID), signature[:] + return toMessageBytes(knownBlkID), signature }, verifyStats: func(t *testing.T, stats *verifierStats) { require.EqualValues(t, 0, stats.blockValidationFail.Snapshot().Count()) @@ -361,6 +361,6 @@ func TestUptimeSignatures(t *testing.T) { require.NoError(t, err) response := &sdk.SignatureResponse{} require.NoError(t, proto.Unmarshal(responseBytes, response)) - require.Equal(t, expectedSignature[:], response.Signature) + require.Equal(t, expectedSignature, response.Signature) } }