Skip to content
Draft
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
3 changes: 2 additions & 1 deletion ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
evmtypes "github.com/cosmos/evm/x/vm/types"
ibckeeper "github.com/cosmos/ibc-go/v10/modules/core/keeper"

errorsmod "cosmossdk.io/errors"
Expand All @@ -20,7 +21,7 @@ import (
type HandlerOptions struct {
Cdc codec.BinaryCodec
AccountKeeper anteinterfaces.AccountKeeper
BankKeeper anteinterfaces.BankKeeper
BankKeeper evmtypes.BankKeeper
IBCKeeper *ibckeeper.Keeper
FeeMarketKeeper anteinterfaces.FeeMarketKeeper
EvmKeeper anteinterfaces.EVMKeeper
Expand Down
22 changes: 5 additions & 17 deletions ante/evm/01_setup_ctx.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package evm

import (
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
evmante "github.com/cosmos/evm/x/vm/ante"

errorsmod "cosmossdk.io/errors"
Expand All @@ -16,18 +15,14 @@ var _ sdktypes.AnteDecorator = &EthSetupContextDecorator{}

// EthSetupContextDecorator is adapted from SetUpContextDecorator from cosmos-sdk, it ignores gas consumption
// by setting the gas meter to infinite
type EthSetupContextDecorator struct {
evmKeeper anteinterfaces.EVMKeeper
}
type EthSetupContextDecorator struct{}

func NewEthSetUpContextDecorator(evmKeeper anteinterfaces.EVMKeeper) EthSetupContextDecorator {
return EthSetupContextDecorator{
evmKeeper: evmKeeper,
}
func NewEthSetUpContextDecorator() EthSetupContextDecorator {
return EthSetupContextDecorator{}
}

func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes.Tx, simulate bool, next sdktypes.AnteHandler) (newCtx sdktypes.Context, err error) {
newCtx, err = SetupContextAndResetTransientGas(ctx, tx, esc.evmKeeper)
newCtx, err = SetupContextAndResetTransientGas(ctx, tx)
if err != nil {
return ctx, err
}
Expand All @@ -37,7 +32,7 @@ func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes
// SetupContextAndResetTransientGas modifies the context to be used in the
// execution of the ante handler associated with an EVM transaction. Previous
// gas consumed is reset in the transient store.
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmKeeper anteinterfaces.EVMKeeper) (sdktypes.Context, error) {
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx) (sdktypes.Context, error) {
// all transactions must implement GasTx
_, ok := tx.(authante.GasTx)
if !ok {
Expand All @@ -50,12 +45,5 @@ func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmK
newCtx := evmante.BuildEvmExecutionCtx(ctx).
WithGasMeter(storetypes.NewInfiniteGasMeter())

// Reset transient gas used to prepare the execution of current cosmos tx.
// Transient gas-used is necessary to sum the gas-used of cosmos tx, when it contains multiple eth msgs.
//
// TODO: add more context here to explain why gas used is reset. Not clear
// from docstring.
evmKeeper.ResetTransientGasUsed(ctx)

return newCtx, nil
}
82 changes: 0 additions & 82 deletions ante/evm/10_gas_wanted.go

This file was deleted.

64 changes: 0 additions & 64 deletions ante/evm/11_emit_event.go

This file was deleted.

11 changes: 8 additions & 3 deletions ante/evm/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ func FeeChecker(

// checkTxFeeWithValidatorMinGasPrices implements the default fee logic, where the minimum price per
// unit of gas is fixed and set by each validator, and the tx priority is computed from the gas price.
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.FeeTx) (sdk.Coins, int64, error) {
feeCoins := tx.GetFee()
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return nil, 0, errorsmod.Wrap(errortypes.ErrTxDecode, "Tx must be a FeeTx")
}

feeCoins := feeTx.GetFee()
minGasPrices := ctx.MinGasPrices()
gas := int64(tx.GetGas()) //#nosec G115 -- checked for int overflow on ValidateBasic()
gas := int64(feeTx.GetGas()) //#nosec G115 -- checked for int overflow on ValidateBasic()

// Ensure that the provided fees meet a minimum threshold for the validator,
// if this is a CheckTx. This is only for local mempool purposes, and thus
Expand Down
4 changes: 0 additions & 4 deletions ante/evm/fee_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func (m MockFeemarketKeeper) GetBaseFeeEnabled(_ sdk.Context) bool {
return true
}

func (m MockFeemarketKeeper) AddTransientGasWanted(_ sdk.Context, _ uint64) (uint64, error) {
return 0, nil
}

func (m MockFeemarketKeeper) GetParams(_ sdk.Context) (params feemarkettypes.Params) {
return feemarkettypes.DefaultParams()
}
Expand Down
23 changes: 6 additions & 17 deletions ante/evm/mono_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
evmDenom := evmtypes.GetEVMCoinDenom()

// 1. setup ctx
ctx, err = SetupContextAndResetTransientGas(ctx, tx, md.evmKeeper)
ctx, err = SetupContextAndResetTransientGas(ctx, tx)
if err != nil {
return ctx, err
}
Expand Down Expand Up @@ -217,13 +217,11 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
return ctx, err
}

gasWanted := UpdateCumulativeGasWanted(
ctx,
gas,
md.maxGasWanted,
decUtils.GasWanted,
)
decUtils.GasWanted = gasWanted
if md.maxGasWanted != 0 {
decUtils.GasWanted += min(gas, md.maxGasWanted)
} else {
decUtils.GasWanted += gas
}

minPriority := GetMsgPriority(
ethTx,
Expand Down Expand Up @@ -255,15 +253,6 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
return ctx, err
}

// 10. gas wanted
if err := CheckGasWanted(ctx, md.feeMarketKeeper, tx, decUtils.Rules.IsLondon); err != nil {
return ctx, err
}

// 11. emit events
txIdx := uint64(msgIndex) //nolint:gosec // G115
EmitTxHashEvent(ctx, ethMsg, decUtils.BlockTxIndex, txIdx)

if err := CheckTxFee(txFeeInfo, decUtils.TxFee, decUtils.TxGasLimit); err != nil {
return ctx, err
}
Expand Down
11 changes: 6 additions & 5 deletions ante/evm/mono_decorator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,11 @@ func (k *ExtendedEVMKeeper) SpendableCoin(ctx sdk.Context, addr common.Address)
return uint256.NewInt(0)
}

func (k *ExtendedEVMKeeper) ResetTransientGasUsed(_ sdk.Context) {}
func (k *ExtendedEVMKeeper) GetParams(_ sdk.Context) evmsdktypes.Params {
return evmsdktypes.DefaultParams()
}
func (k *ExtendedEVMKeeper) GetBaseFee(_ sdk.Context) *big.Int { return big.NewInt(0) }
func (k *ExtendedEVMKeeper) GetMinGasPrice(_ sdk.Context) math.LegacyDec { return math.LegacyZeroDec() }
func (k *ExtendedEVMKeeper) GetTxIndexTransient(_ sdk.Context) uint64 { return 0 }

// only methods called by EVMMonoDecorator
type MockFeeMarketKeeper struct{}
Expand All @@ -77,9 +75,6 @@ func (m MockFeeMarketKeeper) GetParams(_ sdk.Context) feemarkettypes.Params {
return feemarkettypes.DefaultParams()
}

func (m MockFeeMarketKeeper) AddTransientGasWanted(_ sdk.Context, _ uint64) (uint64, error) {
return 0, nil
}
func (m MockFeeMarketKeeper) GetBaseFeeEnabled(_ sdk.Context) bool { return true }
func (m MockFeeMarketKeeper) GetBaseFee(_ sdk.Context) math.LegacyDec { return math.LegacyZeroDec() }

Expand Down Expand Up @@ -202,6 +197,12 @@ func TestMonoDecorator(t *testing.T) {
monoDec := evm.NewEVMMonoDecorator(accountKeeper, MockFeeMarketKeeper{}, keeper, 0)
ctx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
ctx = ctx.WithBlockGasMeter(storetypes.NewGasMeter(1e19))
blockParams := tmproto.BlockParams{
MaxBytes: 200000,
MaxGas: 81500000, // default limit
}
consParams := tmproto.ConsensusParams{Block: &blockParams}
ctx = ctx.WithConsensusParams(consParams)

msgs := tc.buildMsgs(privKey)
tx, err := utiltx.PrepareEthTx(cfg.TxConfig, nil, toMsgSlice(msgs)...)
Expand Down
Loading
Loading