Skip to content

Commit

Permalink
Manually revert statedb type migration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Feb 9, 2024
1 parent 9988fb9 commit f505a41
Show file tree
Hide file tree
Showing 30 changed files with 249 additions and 300 deletions.
4 changes: 2 additions & 2 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (avd EthAccountVerificationDecorator) AnteHandle(
if acct == nil {
acc := avd.ak.NewAccountWithAddress(ctx, from)
avd.ak.SetAccount(ctx, acc)
acct = evmtypes.NewEmptyAccount()
acct = statedb.NewEmptyAccount()
} else if acct.IsContract() {
return ctx, errorsmod.Wrapf(errortypes.ErrInvalidType,
"the sender is not EOA: address %s, codeHash <%s>", fromAddr, acct.CodeHash)
Expand Down Expand Up @@ -302,7 +302,7 @@ func (ctd CanTransferDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
BaseFee: baseFee,
}

stateDB := statedb.New(ctx, ctd.evmKeeper, evmtypes.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
stateDB := statedb.New(ctx, ctd.evmKeeper, statedb.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
Expand Down
8 changes: 4 additions & 4 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 vm.StateDB
var vmdb *statedb.StateDB

testCases := []struct {
name string
Expand Down Expand Up @@ -192,7 +192,7 @@ func (suite AnteTestSuite) TestEthGasConsumeDecorator() {
dynamicFeeTx.From = addr.Hex()
dynamicFeeTxPriority := int64(1)

var vmdb vm.StateDB
var vmdb *statedb.StateDB

testCases := []struct {
name string
Expand Down Expand Up @@ -352,7 +352,7 @@ func (suite AnteTestSuite) TestCanTransferDecorator() {
err := tx.Sign(suite.ethSigner, tests.NewSigner(privKey))
suite.Require().NoError(err)

var vmdb vm.StateDB
var vmdb *statedb.StateDB

testCases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type DynamicFeeEVMKeeper interface {

// EVMKeeper defines the expected keeper interface used on the Eth AnteHandler
type EVMKeeper interface {
evm.StateDBKeeper
statedb.Keeper
DynamicFeeEVMKeeper

NewEVM(ctx sdk.Context, msg core.Message, cfg *statedb.EVMConfig, tracer vm.EVMLogger, stateDB vm.StateDB) evm.EVM
Expand Down
4 changes: 2 additions & 2 deletions app/ante/sigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"math/big"

"github.com/evmos/ethermint/tests"
"github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"
)

Expand All @@ -15,7 +15,7 @@ func (suite AnteTestSuite) TestSignatures() {
addr, privKey := tests.NewAddrKey()
to := tests.GenerateAddress()

acc := types.NewEmptyAccount()
acc := statedb.NewEmptyAccount()
acc.Nonce = 1
acc.Balance = big.NewInt(10000000000)

Expand Down
5 changes: 2 additions & 3 deletions app/ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ 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"
Expand All @@ -74,8 +73,8 @@ type AnteTestSuite struct {

const TestGasLimit uint64 = 100000

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) StateDB() *statedb.StateDB {
return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes())))
}

func (suite *AnteTestSuite) SetupTest() {
Expand Down
3 changes: 1 addition & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ 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"
Expand Down Expand Up @@ -423,7 +422,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, statedb.New, tracer, evmSs,
nil, geth.NewEVM, tracer, evmSs,
)

// Create IBC Keeper
Expand Down
6 changes: 2 additions & 4 deletions tests/importer/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (

evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/statedb"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/evm/vm"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
Expand Down Expand Up @@ -142,7 +140,7 @@ func (suite *ImporterTestSuite) TestImportBlocks() {
})
ctx := suite.app.NewContext(false, tmheader)
ctx = ctx.WithBlockHeight(tmheader.Height)
vmdb := statedb.New(ctx, suite.app.EvmKeeper, evmtypes.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))
vmdb := statedb.New(ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes())))

if chainConfig.DAOForkSupport && chainConfig.DAOForkBlock != nil && chainConfig.DAOForkBlock.Cmp(block.Number()) == 0 {
applyDAOHardFork(vmdb)
Expand Down Expand Up @@ -228,7 +226,7 @@ func applyDAOHardFork(vmdb ethvm.StateDB) {
// Ref: https://github.com/ethereum/go-ethereum/blob/52f2461774bcb8cdd310f86b4bc501df5b783852/core/state_processor.go#L88
func applyTransaction(
ctx sdk.Context, config *ethparams.ChainConfig, bc ethcore.ChainContext, author *common.Address,
gp *ethcore.GasPool, evmKeeper *evmkeeper.Keeper, vmdb vm.StateDB, header *ethtypes.Header,
gp *ethcore.GasPool, evmKeeper *evmkeeper.Keeper, vmdb *statedb.StateDB, header *ethtypes.Header,
tx *ethtypes.Transaction, usedGas *uint64, cfg ethvm.Config,
) (*ethtypes.Receipt, uint64, error) {
msg, err := tx.AsMessage(ethtypes.MakeSigner(config, header.Number), sdk.ZeroInt().BigInt())
Expand Down
4 changes: 2 additions & 2 deletions x/evm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/evmos/ethermint/crypto/ethsecp256k1"
etherminttypes "github.com/evmos/ethermint/types"
"github.com/evmos/ethermint/x/evm"
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"
"github.com/evmos/ethermint/x/evm/vm"
)

func (suite *EvmTestSuite) TestInitGenesis() {
Expand All @@ -19,7 +19,7 @@ func (suite *EvmTestSuite) TestInitGenesis() {

address := common.HexToAddress(privkey.PubKey().Address().String())

var vmdb vm.StateDB
var vmdb *statedb.StateDB

testCases := []struct {
name string
Expand Down
5 changes: 2 additions & 3 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/evmos/ethermint/x/evm/keeper"
"github.com/evmos/ethermint/x/evm/vm"

sdkmath "cosmossdk.io/math"
"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -182,8 +181,8 @@ func (suite *EvmTestSuite) SignTx(tx *types.MsgEthereumTx) {
suite.Require().NoError(err)
}

func (suite *EvmTestSuite) StateDB() vm.StateDB {
return statedb.New(suite.ctx, suite.app.EvmKeeper, types.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes())))
func (suite *EvmTestSuite) StateDB() *statedb.StateDB {
return statedb.New(suite.ctx, suite.app.EvmKeeper, statedb.NewEmptyTxConfig(common.BytesToHash(suite.ctx.HeaderHash().Bytes())))
}

func TestEvmTestSuite(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions x/evm/keeper/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (k *Keeper) EVMConfig(ctx sdk.Context, proposerAddress sdk.ConsAddress, cha
}

// TxConfig loads `TxConfig` from current transient storage
func (k *Keeper) TxConfig(ctx sdk.Context, txHash common.Hash) types.TxConfig {
return types.NewTxConfig(
func (k *Keeper) TxConfig(ctx sdk.Context, txHash common.Hash) statedb.TxConfig {
return statedb.NewTxConfig(
common.BytesToHash(ctx.HeaderHash()), // BlockHash
txHash, // TxHash
uint(k.GetTxIndexTransient(ctx)), // TxIndex
Expand Down
10 changes: 5 additions & 5 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms
return nil, status.Error(codes.InvalidArgument, err.Error())
}

txConfig := types.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash()))

// pass false to not commit StateDB
res, err := k.ApplyMessageWithConfig(ctx, msg, nil, false, cfg, txConfig)
Expand Down Expand Up @@ -324,7 +324,7 @@ func (k Keeper) EstimateGas(c context.Context, req *types.EthCallRequest) (*type
nonce := k.GetNonce(ctx, args.GetFrom())
args.Nonce = (*hexutil.Uint64)(&nonce)

txConfig := types.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))

// convert the tx args to an ethereum message
msg, err := args.ToMessage(req.GasCap, cfg.BaseFee)
Expand Down Expand Up @@ -423,7 +423,7 @@ func (k Keeper) TraceTx(c context.Context, req *types.QueryTraceTxRequest) (*typ
}
signer := ethtypes.MakeSigner(cfg.ChainConfig, big.NewInt(ctx.BlockHeight()))

txConfig := types.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
for i, tx := range req.Predecessors {
ethTx := tx.AsTransaction()
msg, err := ethTx.AsMessage(signer, cfg.BaseFee)
Expand Down Expand Up @@ -503,7 +503,7 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
txsLength := len(req.Txs)
results := make([]*types.TxTraceResult, 0, txsLength)

txConfig := types.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
txConfig := statedb.NewEmptyTxConfig(common.BytesToHash(ctx.HeaderHash().Bytes()))
for i, tx := range req.Txs {
result := types.TxTraceResult{}
ethTx := tx.AsTransaction()
Expand Down Expand Up @@ -533,7 +533,7 @@ func (k Keeper) TraceBlock(c context.Context, req *types.QueryTraceBlockRequest)
func (k *Keeper) traceTx(
ctx sdk.Context,
cfg *statedb.EVMConfig,
txConfig types.TxConfig,
txConfig statedb.TxConfig,
signer ethtypes.Signer,
tx *ethtypes.Transaction,
traceConfig *types.TraceConfig,
Expand Down
21 changes: 10 additions & 11 deletions x/evm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
ethlogger "github.com/ethereum/go-ethereum/eth/tracers/logger"
ethparams "github.com/ethereum/go-ethereum/params"
Expand Down Expand Up @@ -238,12 +237,12 @@ func (suite *KeeperTestSuite) TestQueryStorage() {

testCases := []struct {
msg string
malleate func(vm.StateDB)
malleate func(*statedb.StateDB)
expPass bool
}{
{
"invalid address",
func(vm.StateDB) {
func(*statedb.StateDB) {
req = &types.QueryStorageRequest{
Address: invalidAddress,
}
Expand All @@ -252,7 +251,7 @@ func (suite *KeeperTestSuite) TestQueryStorage() {
},
{
"success",
func(vmdb vm.StateDB) {
func(vmdb *statedb.StateDB) {
key := common.BytesToHash([]byte("key"))
value := common.BytesToHash([]byte("value"))
expValue = value.String()
Expand Down Expand Up @@ -297,12 +296,12 @@ func (suite *KeeperTestSuite) TestQueryCode() {

testCases := []struct {
msg string
malleate func(vm.StateDB)
malleate func(*statedb.StateDB)
expPass bool
}{
{
"invalid address",
func(vm.StateDB) {
func(*statedb.StateDB) {
req = &types.QueryCodeRequest{
Address: invalidAddress,
}
Expand All @@ -313,7 +312,7 @@ func (suite *KeeperTestSuite) TestQueryCode() {
},
{
"success",
func(vmdb vm.StateDB) {
func(vmdb *statedb.StateDB) {
expCode = []byte("code")
vmdb.SetCode(suite.Address, expCode)

Expand Down Expand Up @@ -356,17 +355,17 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {

testCases := []struct {
msg string
malleate func(vm.StateDB)
malleate func(*statedb.StateDB)
}{
{
"empty logs",
func(vm.StateDB) {
func(*statedb.StateDB) {
expLogs = nil
},
},
{
"success",
func(vmdb vm.StateDB) {
func(vmdb *statedb.StateDB) {
expLogs = []*types.Log{
{
Address: suite.Address.String(),
Expand All @@ -392,7 +391,7 @@ func (suite *KeeperTestSuite) TestQueryTxLogs() {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

vmdb := statedb.New(suite.Ctx, suite.App.EvmKeeper, types.NewTxConfig(common.BytesToHash(suite.Ctx.HeaderHash().Bytes()), txHash, txIndex, logIndex))
vmdb := statedb.New(suite.Ctx, suite.App.EvmKeeper, statedb.NewTxConfig(common.BytesToHash(suite.Ctx.HeaderHash().Bytes()), txHash, txIndex, logIndex))
tc.malleate(vmdb)
suite.Require().NoError(vmdb.Commit())

Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (suite *KeeperTestSuite) TestEvmHooks() {
k := suite.App.EvmKeeper
ctx := suite.Ctx
txHash := common.BigToHash(big.NewInt(1))
vmdb := statedb.New(ctx, k, types.NewTxConfig(
vmdb := statedb.New(ctx, k, statedb.NewTxConfig(
common.BytesToHash(ctx.HeaderHash().Bytes()),
txHash,
0,
Expand Down
Loading

0 comments on commit f505a41

Please sign in to comment.