Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .avalanche-golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ linters:
- errorlint
# - forbidigo
- goconst
# - gocritic
- gocritic
- goprintffuncname
# - gosec
- govet
Expand Down
5 changes: 3 additions & 2 deletions core/blockchain_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package core
import (
"fmt"
"math/big"
"slices"
"testing"

"github.com/ava-labs/libevm/common"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions core/extstate/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions plugin/evm/customheader/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ func VerifyExtraPrefix(
parent *types.Header,
header *types.Header,
) error {
switch {
case config.IsSubnetEVM(header.Time):
if config.IsSubnetEVM(header.Time) {
feeWindow, err := feeWindow(config, parent, header.Time)
if err != nil {
return fmt.Errorf("calculating expected fee window: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion plugin/evm/customrawdb/accessors_state_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package customrawdb

import (
"slices"
"testing"

"github.com/ava-labs/libevm/common"
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/validators/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,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,
)
Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/vm_warp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
Expand Down
8 changes: 5 additions & 3 deletions precompile/contracts/rewardmanager/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sync/handlers/leafs_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,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,
Expand Down
4 changes: 1 addition & 3 deletions triedb/firewood/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
}
8 changes: 4 additions & 4 deletions warp/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions warp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Expand Down
8 changes: 4 additions & 4 deletions warp/verifier_backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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)
}
}