diff --git a/app/app.go b/app/app.go index 10511f33..ec29bfbf 100644 --- a/app/app.go +++ b/app/app.go @@ -350,7 +350,7 @@ func NewEthermintApp( app.EvmKeeper = evmkeeper.NewKeeper( appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], app.GetSubspace(evmtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, - tracer, + tracer, ethermint.ProtoAccountWithAddress, ) // Create IBC Keeper diff --git a/types/account.go b/types/account.go index 08c51279..650ca2f3 100644 --- a/types/account.go +++ b/types/account.go @@ -4,6 +4,7 @@ import ( "bytes" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" @@ -52,6 +53,14 @@ func ProtoAccount() authtypes.AccountI { } } +// ProtoAccountWithAddress is a drop-in replacement for accountKeeper.NewAccountWithAddress(), but requires the caller to +// call accountKeeper.SetAccount() after calling this function +func ProtoAccountWithAddress(addr sdk.AccAddress) authtypes.AccountI { + acc := ProtoAccount() + acc.SetAddress(addr) + return acc +} + // GetBaseAccount returns base account. func (acc EthAccount) GetBaseAccount() *authtypes.BaseAccount { return acc.BaseAccount diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index a57d369c..2cf9d4cf 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -3,18 +3,21 @@ package keeper import ( "math/big" - "github.com/cosmos/cosmos-sdk/codec" - "github.com/cosmos/cosmos-sdk/store/prefix" - sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/params" + "github.com/tendermint/tendermint/libs/log" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + ethermint "github.com/evmos/ethermint/types" "github.com/evmos/ethermint/x/evm/statedb" "github.com/evmos/ethermint/x/evm/types" @@ -53,6 +56,11 @@ type Keeper struct { // EVM Hooks for tx post-processing hooks types.EvmHooks + + // Creates a basic account used in account initialization + // see x/auth/keeper/keeper.go for a similar example + // ethermint.ProtoAccountWithAddress is recommended here unless another account type is needed + AccountProtoFn func(sdk.AccAddress) authtypes.AccountI } // NewKeeper generates new evm module keeper @@ -60,8 +68,7 @@ func NewKeeper( cdc codec.BinaryCodec, storeKey, transientKey sdk.StoreKey, paramSpace paramtypes.Subspace, ak types.AccountKeeper, bankKeeper types.BankKeeper, sk types.StakingKeeper, - fmk types.FeeMarketKeeper, - tracer string, + fmk types.FeeMarketKeeper, tracer string, accountProtoFn func(sdk.AccAddress) authtypes.AccountI, ) *Keeper { // ensure evm module account is set if addr := ak.GetModuleAddress(types.ModuleName); addr == nil { @@ -84,6 +91,7 @@ func NewKeeper( storeKey: storeKey, transientKey: transientKey, tracer: tracer, + AccountProtoFn: accountProtoFn, } } diff --git a/x/evm/keeper/statedb.go b/x/evm/keeper/statedb.go index 32efb194..b3212e4d 100644 --- a/x/evm/keeper/statedb.go +++ b/x/evm/keeper/statedb.go @@ -106,7 +106,8 @@ func (k *Keeper) SetAccount(ctx sdk.Context, addr common.Address, account stated cosmosAddr := sdk.AccAddress(addr.Bytes()) acct := k.accountKeeper.GetAccount(ctx, cosmosAddr) if acct == nil { - acct = k.accountKeeper.NewAccountWithAddress(ctx, cosmosAddr) + acct = k.AccountProtoFn(cosmosAddr) + acct = k.accountKeeper.NewAccount(ctx, acct) } if err := acct.SetSequence(account.Nonce); err != nil { diff --git a/x/evm/types/interfaces.go b/x/evm/types/interfaces.go index f5e16f7f..9fefa462 100644 --- a/x/evm/types/interfaces.go +++ b/x/evm/types/interfaces.go @@ -15,6 +15,7 @@ import ( // AccountKeeper defines the expected account keeper interface type AccountKeeper interface { NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI + NewAccount(ctx sdk.Context, account authtypes.AccountI) authtypes.AccountI GetModuleAddress(moduleName string) sdk.AccAddress GetAllAccounts(ctx sdk.Context) (accounts []authtypes.AccountI) IterateAccounts(ctx sdk.Context, cb func(account authtypes.AccountI) bool)