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
2 changes: 1 addition & 1 deletion core/blockchain_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ func EmptyBlocksTest(t *testing.T, create createFunc) {
blockchain.DrainAcceptorQueue()

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

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,12 +29,12 @@ func (db *firewoodAccessorDb) OpenTrie(root common.Hash) (state.Trie, error) {
}

// OpenStorageTrie opens a wrapped version of the account trie.
func (*firewoodAccessorDb) OpenStorageTrie(_ common.Hash, _ common.Address, root common.Hash, self state.Trie) (state.Trie, error) {
func (*firewoodAccessorDb) OpenStorageTrie(_ common.Hash, _ common.Address, accountRoot 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)
}
return firewood.NewStorageTrie(accountTrie, root)
return firewood.NewStorageTrie(accountTrie, accountRoot)
}

// CopyTrie returns a deep copy of the given trie.
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 (*NoOpFIFOCache[K, V]) Put(_ K, _ V) {}
func (*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
}
2 changes: 1 addition & 1 deletion core/state_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (*MockTrieDB) Size() (common.StorageSize, common.StorageSize, common.Storag
return 0, 0, 0
}

func (*MockTrieDB) Cap(_ 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()
return internalAPI.GetBadBlocks(ctx)
}

// AccountRangeMaxResults is the maximum number of results to be returned per call
Expand Down
8 changes: 7 additions & 1 deletion internal/ethapi/api_extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ 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"
)

Expand All @@ -23,6 +24,11 @@ type DetailedExecutionResult struct {
ReturnData hexutil.Bytes `json:"returnData"` // Data from evm(function result or data supplied with revert opcode)
}

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

// CallDetailed performs the same call as Call, but returns the full context
func (s *BlockChainAPI) CallDetailed(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride) (*DetailedExecutionResult, error) {
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, nil, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
Expand Down Expand Up @@ -63,7 +69,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() ([]*BadBlockArgs, error) {
func (s *BlockChainAPI) GetBadBlocks(context.Context) ([]*BadBlockArgs, error) {
var (
badBlocks, reasons = s.b.BadBlocks()
results = make([]*BadBlockArgs, 0, len(badBlocks))
Expand Down
69 changes: 69 additions & 0 deletions internal/ethapi/api_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,87 @@
package ethapi

import (
"context"
"errors"
"math/big"
"testing"

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/common/hexutil"
"github.com/ava-labs/libevm/core/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

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

ethparams "github.com/ava-labs/libevm/params"
)

func TestBlockchainAPI_GetChainConfig(t *testing.T) {
t.Parallel()

ctrl := gomock.NewController(t)
defer ctrl.Finish()

wantConfig := &params.ChainConfig{
ChainID: big.NewInt(43114),
}
backend := NewMockBackend(ctrl)
backend.EXPECT().ChainConfig().Return(wantConfig)

api := NewBlockChainAPI(backend)

gotConfig := api.GetChainConfig(context.Background())
assert.Equal(t, wantConfig, gotConfig)
}

// Copy one test case from TestCall
func TestBlockchainAPI_CallDetailed(t *testing.T) {
t.Parallel()
// Initialize test accounts
var (
accounts = newAccounts(2)
genesis = &core.Genesis{
Config: params.TestChainConfig,
Alloc: types.GenesisAlloc{
accounts[0].addr: {Balance: big.NewInt(params.Ether)},
accounts[1].addr: {Balance: big.NewInt(params.Ether)},
},
}
genBlocks = 10
signer = types.HomesteadSigner{}
blockNumber = rpc.LatestBlockNumber
)
api := NewBlockChainAPI(newTestBackend(t, genBlocks, genesis, dummy.NewCoinbaseFaker(), func(i int, b *core.BlockGen) {
// Transfer from account[0] to account[1]
// value: 1000 wei
// fee: 0 wei
tx, _ := types.SignTx(types.NewTx(&types.LegacyTx{Nonce: uint64(i), To: &accounts[1].addr, Value: big.NewInt(1000), Gas: ethparams.TxGas, GasPrice: b.BaseFee(), Data: nil}), signer, accounts[0].key)
b.AddTx(tx)
}))

result, err := api.CallDetailed(
context.Background(),
TransactionArgs{
From: &accounts[0].addr,
To: &accounts[1].addr,
Value: (*hexutil.Big)(big.NewInt(1000)),
},
rpc.BlockNumberOrHash{BlockNumber: &blockNumber},
nil,
)
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, 0, result.ErrCode)
require.Nil(t, result.ReturnData)
require.Equal(t, ethparams.TxGas, result.UsedGas)
require.Empty(t, result.Err)
}

func TestBlockChainAPI_stateQueryBlockNumberAllowed(t *testing.T) {
t.Parallel()

Expand Down
14 changes: 7 additions & 7 deletions network/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ func TestRequestAnyRequestsRoutingAndResponse(t *testing.T) {
func TestAppRequestOnCtxCancellation(t *testing.T) {
codecManager := buildCodec(t, HelloRequest{}, HelloResponse{})
sender := testAppSender{
sendAppRequestFn: func(_ context.Context, _ set.Set[ids.NodeID], _ uint32, _ []byte) error {
sendAppRequestFn: func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
return nil
},
sendAppResponseFn: func(_ ids.NodeID, _ uint32, _ []byte) error {
sendAppResponseFn: func(ids.NodeID, uint32, []byte) error {
return nil
},
}
Expand Down Expand Up @@ -263,7 +263,7 @@ func TestAppRequestOnShutdown(t *testing.T) {
called bool
)
sender := testAppSender{
sendAppRequestFn: func(_ context.Context, _ set.Set[ids.NodeID], _ uint32, _ []byte) error {
sendAppRequestFn: func(context.Context, set.Set[ids.NodeID], uint32, []byte) error {
wg.Add(1)
go func() {
called = true
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestSyncedAppRequestAnyOnCtxCancellation(t *testing.T) {
}
return nil
},
sendAppResponseFn: func(_ ids.NodeID, _ uint32, _ []byte) error {
sendAppResponseFn: func(ids.NodeID, uint32, []byte) error {
return nil
},
}
Expand Down Expand Up @@ -639,7 +639,7 @@ func (t testAppSender) SendAppGossip(_ context.Context, config common.SendConfig
return t.sendAppGossipFn(config, message)
}

func (testAppSender) SendAppError(_ context.Context, _ ids.NodeID, _ uint32, _ int32, _ string) error {
func (testAppSender) SendAppError(context.Context, ids.NodeID, uint32, int32, string) error {
panic("not implemented")
}

Expand Down Expand Up @@ -751,12 +751,12 @@ type testSDKHandler struct {
appRequested bool
}

func (*testSDKHandler) AppGossip(_ context.Context, _ ids.NodeID, _ []byte) {
func (*testSDKHandler) AppGossip(context.Context, ids.NodeID, []byte) {
// TODO implement me
panic("implement me")
}

func (t *testSDKHandler) AppRequest(_ context.Context, _ ids.NodeID, _ time.Time, _ []byte) ([]byte, *common.AppError) {
func (t *testSDKHandler) AppRequest(context.Context, ids.NodeID, time.Time, []byte) ([]byte, *common.AppError) {
t.appRequested = true
return nil, nil
}
4 changes: 3 additions & 1 deletion params/config_libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ var payloads ethparams.ExtraPayloads[*extras.ChainConfig, RulesExtra]
// constructRulesExtra acts as an adjunct to the [params.ChainConfig.Rules]
// method. Its primary purpose is to construct the extra payload for the
// [params.Rules] but it MAY also modify the [params.Rules].
func constructRulesExtra(_ *ethparams.ChainConfig, _ *ethparams.Rules, cEx *extras.ChainConfig, _ *big.Int, _ bool, timestamp uint64) RulesExtra {
//
//nolint:revive // General-purpose types lose the meaning of args if unused ones are removed
func constructRulesExtra(c *ethparams.ChainConfig, r *ethparams.Rules, cEx *extras.ChainConfig, blockNum *big.Int, isMerge bool, timestamp uint64) RulesExtra {
var rules RulesExtra
if cEx == nil {
return rules
Expand Down
3 changes: 2 additions & 1 deletion params/extras/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ type ChainConfig struct {
UpgradeConfig `json:"-"` // Config specified in upgradeBytes (avalanche network upgrades or enable/disabling precompiles). Not serialized.
}

func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, _ *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
//nolint:revive // General-purpose types lose the meaning of args if unused ones are removed
func (c *ChainConfig) CheckConfigCompatible(newcfg_ *ethparams.ChainConfig, headNumber *big.Int, headTimestamp uint64) *ethparams.ConfigCompatError {
if c == nil {
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions plugin/evm/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewAdminService(vm *VM, performanceDir string) *Admin {
}

// StartCPUProfiler starts a cpu profile writing to the specified file
func (p *Admin) StartCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
func (p *Admin) StartCPUProfiler(*http.Request, *struct{}, *api.EmptyReply) error {
log.Info("Admin: StartCPUProfiler called")

p.vm.ctx.Lock.Lock()
Expand All @@ -38,7 +38,7 @@ func (p *Admin) StartCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply
}

// StopCPUProfiler stops the cpu profile
func (p *Admin) StopCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
func (p *Admin) StopCPUProfiler(*http.Request, *struct{}, *api.EmptyReply) error {
log.Info("Admin: StopCPUProfiler called")

p.vm.ctx.Lock.Lock()
Expand All @@ -48,7 +48,7 @@ func (p *Admin) StopCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply)
}

// MemoryProfile runs a memory profile writing to the specified file
func (p *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
func (p *Admin) MemoryProfile(*http.Request, *struct{}, *api.EmptyReply) error {
log.Info("Admin: MemoryProfile called")

p.vm.ctx.Lock.Lock()
Expand All @@ -58,7 +58,7 @@ func (p *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) e
}

// LockProfile runs a mutex profile writing to the specified file
func (p *Admin) LockProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
func (p *Admin) LockProfile(*http.Request, *struct{}, *api.EmptyReply) error {
log.Info("Admin: LockProfile called")

p.vm.ctx.Lock.Lock()
Expand Down
10 changes: 5 additions & 5 deletions plugin/evm/atomic/atomictest/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ type TestUnsignedTx struct {
}

// GasUsed implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) GasUsed(_ bool) (uint64, error) { return t.GasUsedV, nil }
func (t *TestUnsignedTx) GasUsed(bool) (uint64, error) { return t.GasUsedV, nil }

// Verify implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) Verify(_ *snow.Context, _ extras.Rules) error { return t.VerifyV }
func (t *TestUnsignedTx) Verify(*snow.Context, extras.Rules) error { return t.VerifyV }

// AtomicOps implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) AtomicOps() (ids.ID, *avalancheatomic.Requests, error) {
Expand All @@ -73,7 +73,7 @@ func (*TestUnsignedTx) Initialize(_, _ []byte) {}
func (t *TestUnsignedTx) ID() ids.ID { return t.IDV }

// Burned implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) Burned(_ ids.ID) (uint64, error) { return t.BurnedV, nil }
func (t *TestUnsignedTx) Burned(ids.ID) (uint64, error) { return t.BurnedV, nil }

// Bytes implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) Bytes() []byte { return t.UnsignedBytesV }
Expand All @@ -85,12 +85,12 @@ func (t *TestUnsignedTx) SignedBytes() []byte { return t.SignedBytesV }
func (t *TestUnsignedTx) InputUTXOs() set.Set[ids.ID] { return t.InputUTXOsV }

// Visit implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) Visit(_ atomic.Visitor) error {
func (t *TestUnsignedTx) Visit(atomic.Visitor) error {
return t.VisitV
}

// EVMStateTransfer implements the UnsignedAtomicTx interface
func (t *TestUnsignedTx) EVMStateTransfer(_ *snow.Context, _ atomic.StateDB) error {
func (t *TestUnsignedTx) EVMStateTransfer(*snow.Context, atomic.StateDB) error {
return t.EVMStateTransferV
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/evm/atomic/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ var _ gossip.Marshaller[*Tx] = (*TxMarshaller)(nil)

type TxMarshaller struct{}

func (_ *TxMarshaller) MarshalGossip(tx *Tx) ([]byte, error) {
func (*TxMarshaller) MarshalGossip(tx *Tx) ([]byte, error) {
return tx.SignedBytes(), nil
}

func (_ *TxMarshaller) UnmarshalGossip(bytes []byte) (*Tx, error) {
func (*TxMarshaller) UnmarshalGossip(bytes []byte) (*Tx, error) {
return ExtractAtomicTx(bytes, Codec)
}
2 changes: 1 addition & 1 deletion plugin/evm/atomic/sync/leaf_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (

type uninitializedHandler struct{}

func (*uninitializedHandler) OnLeafsRequest(_ context.Context, _ ids.NodeID, _ uint32, _ message.LeafsRequest) ([]byte, error) {
func (*uninitializedHandler) OnLeafsRequest(context.Context, ids.NodeID, uint32, message.LeafsRequest) ([]byte, error) {
return nil, errUninitialized
}

Expand Down
6 changes: 3 additions & 3 deletions plugin/evm/customrawdb/database_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (s *stubDatabase) NewIterator(_, _ []byte) ethdb.Iterator {
}

// AncientSize is used in [InspectDatabase] to determine the ancient sizes.
func (*stubDatabase) AncientSize(_ string) (uint64, error) {
func (*stubDatabase) AncientSize(string) (uint64, error) {
return 0, nil
}

Expand All @@ -94,11 +94,11 @@ func (s *stubDatabase) Put(key, value []byte) error {
return nil
}

func (*stubDatabase) Get(_ []byte) ([]byte, error) {
func (*stubDatabase) Get([]byte) ([]byte, error) {
return nil, nil
}

func (*stubDatabase) ReadAncients(_ func(ethdb.AncientReaderOp) error) error {
func (*stubDatabase) ReadAncients(func(ethdb.AncientReaderOp) error) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/evm/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "context"
// Health returns nil if this chain is healthy.
// Also returns details, which should be one of:
// string, []byte, map[string]string
func (*VM) HealthCheck(_ context.Context) (interface{}, error) {
func (*VM) HealthCheck(context.Context) (interface{}, error) {
// TODO perform actual health check
return nil, nil
}
6 changes: 3 additions & 3 deletions plugin/evm/message/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ type ResponseHandler interface {

type NoopRequestHandler struct{}

func (NoopRequestHandler) HandleLeafsRequest(_ context.Context, _ ids.NodeID, _ uint32, _ LeafsRequest) ([]byte, error) {
func (NoopRequestHandler) HandleLeafsRequest(context.Context, ids.NodeID, uint32, LeafsRequest) ([]byte, error) {
return nil, nil
}

func (NoopRequestHandler) HandleBlockRequest(_ context.Context, _ ids.NodeID, _ uint32, _ BlockRequest) ([]byte, error) {
func (NoopRequestHandler) HandleBlockRequest(context.Context, ids.NodeID, uint32, BlockRequest) ([]byte, error) {
return nil, nil
}

func (NoopRequestHandler) HandleCodeRequest(_ context.Context, _ ids.NodeID, _ uint32, _ CodeRequest) ([]byte, error) {
func (NoopRequestHandler) HandleCodeRequest(context.Context, ids.NodeID, uint32, CodeRequest) ([]byte, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ func (vm *VM) GetBlockIDAtHeight(_ context.Context, height uint64) (ids.ID, erro
return ids.ID(hash), nil
}

func (*VM) Version(_ context.Context) (string, error) {
func (*VM) Version(context.Context) (string, error) {
return Version, nil
}

Expand Down
Loading
Loading