Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

ante: move deduct gas to EVM keeper #584

Merged
merged 1 commit into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
Expand Down
17 changes: 7 additions & 10 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions app/ante/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
9 changes: 3 additions & 6 deletions x/evm/keeper/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 1 addition & 3 deletions x/evm/keeper/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down