ante: move deduct gas to EVM keeper (#584)

This commit is contained in:
Federico Kunze Küllmer 2021-09-22 12:26:29 +02:00 committed by GitHub
parent e65582df71
commit 692fd9548a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 23 deletions

View File

@ -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.
)

View File

@ -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,

View File

@ -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()

View File

@ -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",

View File

@ -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,