diff --git a/app/ante/ante.go b/app/ante/ante.go index bb051744..ff887892 100644 --- a/app/ante/ante.go +++ b/app/ante/ante.go @@ -62,7 +62,7 @@ func NewAnteHandler( NewEthSigVerificationDecorator(evmKeeper), NewEthAccountVerificationDecorator(ak, bankKeeper, evmKeeper), NewEthNonceVerificationDecorator(ak), - NewEthGasConsumeDecorator(ak, bankKeeper, evmKeeper), + NewEthGasConsumeDecorator(evmKeeper), NewCanTransferDecorator(evmKeeper), NewEthIncrementSenderSequenceDecorator(ak), // innermost AnteDecorator. ) diff --git a/app/ante/eth.go b/app/ante/eth.go index ce429a13..8a3e5748 100644 --- a/app/ante/eth.go +++ b/app/ante/eth.go @@ -30,6 +30,9 @@ type EVMKeeper interface { ResetRefundTransient(ctx sdk.Context) NewEVM(msg core.Message, config *params.ChainConfig, params evmtypes.Params, coinbase common.Address, tracer vm.Tracer) *vm.EVM GetCodeHash(addr common.Address) common.Hash + DeductTxCostsFromUserBalance( + ctx sdk.Context, msgEthTx evmtypes.MsgEthereumTx, txData evmtypes.TxData, denom string, homestead, istanbul bool, + ) (sdk.Coins, error) } // EthSigVerificationDecorator validates an ethereum signatures @@ -227,17 +230,13 @@ func (nvd EthNonceVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, // EthGasConsumeDecorator validates enough intrinsic gas for the transaction and // gas consumption. type EthGasConsumeDecorator struct { - ak evmtypes.AccountKeeper - bankKeeper evmtypes.BankKeeper - evmKeeper EVMKeeper + evmKeeper EVMKeeper } // NewEthGasConsumeDecorator creates a new EthGasConsumeDecorator -func NewEthGasConsumeDecorator(ak evmtypes.AccountKeeper, bankKeeper evmtypes.BankKeeper, ek EVMKeeper) EthGasConsumeDecorator { +func NewEthGasConsumeDecorator(evmKeeper EVMKeeper) EthGasConsumeDecorator { return EthGasConsumeDecorator{ - ak: ak, - bankKeeper: bankKeeper, - evmKeeper: ek, + evmKeeper: evmKeeper, } } @@ -284,10 +283,8 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula return ctx, stacktrace.Propagate(err, "failed to unpack tx data") } - fees, err := evmkeeper.DeductTxCostsFromUserBalance( + fees, err := egcd.evmKeeper.DeductTxCostsFromUserBalance( ctx, - egcd.bankKeeper, - egcd.ak, *msgEthTx, txData, evmDenom, diff --git a/app/ante/eth_test.go b/app/ante/eth_test.go index 34ae1655..a7c2c4cd 100644 --- a/app/ante/eth_test.go +++ b/app/ante/eth_test.go @@ -195,9 +195,7 @@ func (suite AnteTestSuite) TestEthNonceVerificationDecorator() { } func (suite AnteTestSuite) TestEthGasConsumeDecorator() { - dec := ante.NewEthGasConsumeDecorator( - suite.app.AccountKeeper, suite.app.BankKeeper, suite.app.EvmKeeper, - ) + dec := ante.NewEthGasConsumeDecorator(suite.app.EvmKeeper) addr := tests.GenerateAddress() diff --git a/x/evm/keeper/utils.go b/x/evm/keeper/utils.go index 6dc69cbf..2c9ef9bd 100644 --- a/x/evm/keeper/utils.go +++ b/x/evm/keeper/utils.go @@ -12,12 +12,9 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" ) -// AccountKeeper defines an expected keeper interface for the auth module's AccountKeeper // DeductTxCostsFromUserBalance it calculates the tx costs and deducts the fees -func DeductTxCostsFromUserBalance( +func (k Keeper) DeductTxCostsFromUserBalance( ctx sdk.Context, - bankKeeper evmtypes.BankKeeper, - accountKeeper evmtypes.AccountKeeper, msgEthTx evmtypes.MsgEthereumTx, txData evmtypes.TxData, denom string, @@ -27,7 +24,7 @@ func DeductTxCostsFromUserBalance( isContractCreation := txData.GetTo() == nil // fetch sender account from signature - signerAcc, err := authante.GetSignerAcc(ctx, accountKeeper, msgEthTx.GetFrom()) + signerAcc, err := authante.GetSignerAcc(ctx, k.accountKeeper, msgEthTx.GetFrom()) if err != nil { return nil, stacktrace.Propagate(err, "account not found for sender %s", msgEthTx.From) } @@ -62,7 +59,7 @@ func DeductTxCostsFromUserBalance( fees := sdk.Coins{sdk.NewCoin(denom, sdk.NewIntFromBigInt(feeAmt))} // deduct the full gas cost from the user balance - if err := authante.DeductFees(bankKeeper, ctx, signerAcc, fees); err != nil { + if err := authante.DeductFees(k.bankKeeper, ctx, signerAcc, fees); err != nil { return nil, stacktrace.Propagate( err, "failed to deduct full gas cost %s from the user %s balance", diff --git a/x/evm/keeper/utils_test.go b/x/evm/keeper/utils_test.go index a1c765ba..d8cc4b5d 100644 --- a/x/evm/keeper/utils_test.go +++ b/x/evm/keeper/utils_test.go @@ -235,10 +235,8 @@ func (suite *KeeperTestSuite) TestDeductTxCostsFromUserBalance() { txData, _ := evmtypes.UnpackTxData(tx.Data) - fees, err := evmkeeper.DeductTxCostsFromUserBalance( + fees, err := suite.app.EvmKeeper.DeductTxCostsFromUserBalance( suite.app.EvmKeeper.Ctx(), - suite.app.BankKeeper, - suite.app.AccountKeeper, *tx, txData, evmtypes.DefaultEVMDenom,