From a1847881a7856a8e37afa4105533de4e8385c6ea Mon Sep 17 00:00:00 2001 From: drklee3 Date: Mon, 8 Jan 2024 15:46:41 -0800 Subject: [PATCH] Update statedb usage in app --- app/ante/eth.go | 5 +++-- app/ante/eth_test.go | 8 ++++---- app/ante/interfaces.go | 2 +- app/ante/sigs_test.go | 4 ++-- app/ante/utils_test.go | 5 +++-- app/app.go | 3 ++- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/ante/eth.go b/app/ante/eth.go index 2402167be7..90a1c45e54 100644 --- a/app/ante/eth.go +++ b/app/ante/eth.go @@ -28,6 +28,7 @@ import ( ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm/keeper" "github.com/evmos/ethermint/x/evm/statedb" + "github.com/evmos/ethermint/x/evm/types" evmtypes "github.com/evmos/ethermint/x/evm/types" "github.com/ethereum/go-ethereum/common" @@ -88,7 +89,7 @@ func (avd EthAccountVerificationDecorator) AnteHandle( if acct == nil { acc := avd.ak.NewAccountWithAddress(ctx, from) avd.ak.SetAccount(ctx, acc) - acct = statedb.NewEmptyAccount() + acct = types.NewEmptyAccount() } else if acct.IsContract() { return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType, "the sender is not EOA: address %s, codeHash <%s>", fromAddr, acct.CodeHash) @@ -302,7 +303,7 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate BaseFee: baseFee, } - stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))) + stateDB := statedb.New(ctx, ctd.evmKeeper, types.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))) evm := ctd.evmKeeper.NewEVM(ctx, coreMsg, cfg, evmtypes.NewNoOpTracer(), stateDB) // check that caller has enough balance to cover asset transfer for **topmost** call diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index 0fb9ea8b20..b5dd9dd7f1 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -10,8 +10,8 @@ import ( "github.com/evmos/ethermint/server/config" "github.com/evmos/ethermint/tests" ethermint "github.com/evmos/ethermint/types" - "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/evmos/ethermint/x/evm/vm" ethtypes "github.com/ethereum/go-ethereum/core/types" ) @@ -26,7 +26,7 @@ func (suite AnteTestSuite) TestNewEthAccountVerificationDecorator() { tx := evmtypes.NewTxContract(suite.app.EvmKeeper.ChainID(), 1, big.NewInt(10), 1000, big.NewInt(1), nil, nil, nil, nil) tx.From = addr.Hex() - var vmdb *statedb.StateDB + var vmdb vm.StateDB testCases := []struct { name string @@ -192,7 +192,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() { dynamicFeeTx.From = addr.Hex() dynamicFeeTxPriority := int64(1) - var vmdb *statedb.StateDB + var vmdb vm.StateDB testCases := []struct { name string @@ -352,7 +352,7 @@ func (suite AnteTestSuite) TestCanTransferDecorator() { err := tx.Sign(suite.ethSigner, tests.NewSigner(privKey)) suite.Require().NoError(err) - var vmdb *statedb.StateDB + var vmdb vm.StateDB testCases := []struct { name string diff --git a/app/ante/interfaces.go b/app/ante/interfaces.go index e48e0a50a4..c2bb63cd62 100644 --- a/app/ante/interfaces.go +++ b/app/ante/interfaces.go @@ -41,7 +41,7 @@ type DynamicFeeEVMKeeper interface { // EVMKeeper defines the expected keeper interface used on the Eth AnteHandler type EVMKeeper interface { - statedb.Keeper + evm.StateDBKeeper DynamicFeeEVMKeeper NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) evm.EVM diff --git a/app/ante/sigs_test.go b/app/ante/sigs_test.go index 0c7b0539c8..be87ab15f3 100644 --- a/app/ante/sigs_test.go +++ b/app/ante/sigs_test.go @@ -4,7 +4,7 @@ import ( "math/big" "github.com/evmos/ethermint/tests" - "github.com/evmos/ethermint/x/evm/statedb" + "github.com/evmos/ethermint/x/evm/types" evmtypes "github.com/evmos/ethermint/x/evm/types" ) @@ -15,7 +15,7 @@ func (suite AnteTestSuite) TestSignatures() { addr, privKey := tests.NewAddrKey() to := tests.GenerateAddress() - acc := statedb.NewEmptyAccount() + acc := types.NewEmptyAccount() acc.Nonce = 1 acc.Balance = big.NewInt(10000000000) diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index c92961c391..e87c82e839 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -53,6 +53,7 @@ import ( "github.com/evmos/ethermint/tests" "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/evmos/ethermint/x/evm/vm" feemarkettypes "github.com/evmos/ethermint/x/feemarket/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -73,8 +74,8 @@ type AnteTestSuite struct { const TestGasLimit uint64 = 100000 -func (suite *AnteTestSuite) StateDB() *statedb.StateDB { - return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()))) +func (suite *AnteTestSuite) StateDB() vm.StateDB { + return statedb.New(suite.ctx, suite.app.EvmKeeper, evmtypes.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes()))) } func (suite *AnteTestSuite) SetupTest() { diff --git a/app/app.go b/app/app.go index e828c0e11f..65aaaf42cb 100644 --- a/app/app.go +++ b/app/app.go @@ -123,6 +123,7 @@ import ( ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" + "github.com/evmos/ethermint/x/evm/statedb" evmtypes "github.com/evmos/ethermint/x/evm/types" legacyevmtypes "github.com/evmos/ethermint/x/evm/types/legacy" "github.com/evmos/ethermint/x/evm/vm/geth" @@ -422,7 +423,7 @@ func NewEthermintApp( appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, - nil, geth.NewEVM, tracer, evmSs, + nil, geth.NewEVM, statedb.New, tracer, evmSs, ) // Create IBC Keeper