diff --git a/.avalanche-golangci.yml b/.avalanche-golangci.yml index dd05206be2..dbe379846c 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 b3c6ed5195..7c0383e170 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" @@ -1694,7 +1695,7 @@ func ReexecBlocksTest(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 { @@ -1826,7 +1827,7 @@ func ReexecMaxBlocksTest(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 36c4f2402e..a11d32d28d 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/params/config_extra.go b/params/config_extra.go index 1d908e20b6..c68097808e 100644 --- a/params/config_extra.go +++ b/params/config_extra.go @@ -50,13 +50,14 @@ func SetEthUpgrades(c *ChainConfig) error { extra := GetExtra(c) // Because Fuji and Mainnet have already accepted the Berlin and London // blocks, it is assumed that they are scheduled for activation. - if c.ChainID != nil && AvalancheFujiChainID.Cmp(c.ChainID) == 0 { + switch { + case c.ChainID != nil && AvalancheFujiChainID.Cmp(c.ChainID) == 0: c.BerlinBlock = big.NewInt(184985) // https://testnet.snowtrace.io/block/184985?chainid=43113, AP2 activation block c.LondonBlock = big.NewInt(805078) // https://testnet.snowtrace.io/block/805078?chainid=43113, AP3 activation block - } else if c.ChainID != nil && AvalancheMainnetChainID.Cmp(c.ChainID) == 0 { + case c.ChainID != nil && AvalancheMainnetChainID.Cmp(c.ChainID) == 0: c.BerlinBlock = big.NewInt(1640340) // https://snowtrace.io/block/1640340?chainid=43114, AP2 activation block c.LondonBlock = big.NewInt(3308552) // https://snowtrace.io/block/3308552?chainid=43114, AP3 activation block - } else { + default: // In testing or local networks, we only support enabling Berlin and // London at the initially active time. This corresponds to an intended // block number of 0. diff --git a/plugin/evm/atomic/vm/block_extension.go b/plugin/evm/atomic/vm/block_extension.go index c73addf99a..349946b67b 100644 --- a/plugin/evm/atomic/vm/block_extension.go +++ b/plugin/evm/atomic/vm/block_extension.go @@ -119,13 +119,11 @@ func (be *blockExtension) SyntacticVerify(rules extras.Rules) error { if headerExtra.ExtDataHash != hash { return fmt.Errorf("extra data hash mismatch: have %x, want %x", headerExtra.ExtDataHash, hash) } - } else { - if headerExtra.ExtDataHash != (common.Hash{}) { - return fmt.Errorf( - "expected ExtDataHash to be empty but got %x", - headerExtra.ExtDataHash, - ) - } + } else if headerExtra.ExtDataHash != (common.Hash{}) { + return fmt.Errorf( + "expected ExtDataHash to be empty but got %x", + headerExtra.ExtDataHash, + ) } // Block must not be empty diff --git a/plugin/evm/atomic/vm/import_tx_test.go b/plugin/evm/atomic/vm/import_tx_test.go index e335ca0ebb..095f0ef5a9 100644 --- a/plugin/evm/atomic/vm/import_tx_test.go +++ b/plugin/evm/atomic/vm/import_tx_test.go @@ -1327,8 +1327,7 @@ func executeTxTest(t *testing.T, test atomicTxTest) { var baseFee *big.Int // If ApricotPhase3 is active, use the initial base fee for the atomic transaction - switch { - case rules.IsApricotPhase3: + if rules.IsApricotPhase3 { baseFee = vmtest.InitialBaseFee } diff --git a/plugin/evm/atomic/vm/tx_test.go b/plugin/evm/atomic/vm/tx_test.go index 180fa3bd06..7b99a3f32d 100644 --- a/plugin/evm/atomic/vm/tx_test.go +++ b/plugin/evm/atomic/vm/tx_test.go @@ -49,10 +49,8 @@ func TestCalculateDynamicFee(t *testing.T) { if cost != test.expectedValue { t.Fatalf("Expected value: %d, found: %d", test.expectedValue, cost) } - } else { - if err != test.expectedErr { - t.Fatalf("Expected error: %s, found error: %s", test.expectedErr, err) - } + } else if err != test.expectedErr { + t.Fatalf("Expected error: %s, found error: %s", test.expectedErr, err) } } } diff --git a/plugin/evm/customrawdb/accessors_state_sync_test.go b/plugin/evm/customrawdb/accessors_state_sync_test.go index 7c2174eb0e..6a57572e4f 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" @@ -18,7 +19,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/vm.go b/plugin/evm/vm.go index 34a41bc5db..6b07c32aa5 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -1131,7 +1131,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 28b36cb927..5c78558ed9 100644 --- a/plugin/evm/vm_warp_test.go +++ b/plugin/evm/vm_warp_test.go @@ -152,7 +152,7 @@ func testSendWarpMessage(t *testing.T, scheme string) { // Verify the message signature after accepting the block. rawSignatureBytes, err := vm.warpBackend.GetMessageSignature(context.TODO(), unsignedMessage) require.NoError(err) - blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes[:]) + blsSignature, err := bls.SignatureFromBytes(rawSignatureBytes) require.NoError(err) select { @@ -169,7 +169,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 = 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/sync/handlers/leafs_request_test.go b/sync/handlers/leafs_request_test.go index 4631eb3fcc..2853252de4 100644 --- a/sync/handlers/leafs_request_test.go +++ b/sync/handlers/leafs_request_test.go @@ -358,8 +358,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 bd049dd8a8..dc6bf7f035 100644 --- a/triedb/firewood/database.go +++ b/triedb/firewood/database.go @@ -584,7 +584,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 43eb3a0ca3..fce6b5111b 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 1c0ef635de..19885b9632 100644 --- a/warp/service.go +++ b/warp/service.go @@ -58,7 +58,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. @@ -67,7 +67,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 54033eed1e..73cf9947a3 100644 --- a/warp/verifier_backend_test.go +++ b/warp/verifier_backend_test.go @@ -54,7 +54,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()) @@ -63,7 +63,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()) @@ -175,7 +175,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())