Skip to content
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

### FEATURES

- [\#589](https://github.com/cosmos/evm/pull/589) Remove parallelization blockers via migration from transient to object store, refactoring of gas, indexing, and bloom utilities.
- [\#768](https://github.com/cosmos/evm/pull/768) Added ICS-02 Client Router precompile

### BUG FIXES
Expand Down Expand Up @@ -110,7 +111,6 @@
- [\#577](https://github.com/cosmos/evm/pull/577) Changed the way to create a stateful precompile based on the cmn.Precompile, change `NewPrecompile` to not return error.
- [\#661](https://github.com/cosmos/evm/pull/661) Removes evmAppOptions from the repository and moves initialization to genesis. Chains must now have a display and denom metadata set for the defined EVM denom in the bank module's metadata.


## v0.4.1

### DEPENDENCIES
Expand Down
1 change: 0 additions & 1 deletion ante/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandl
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
)
}
22 changes: 3 additions & 19 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,10 @@ 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
}

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

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 +28,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 +41,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
}
85 changes: 0 additions & 85 deletions ante/evm/10_gas_wanted.go

This file was deleted.

43 changes: 2 additions & 41 deletions ante/evm/11_emit_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,23 @@ package evm
import (
"strconv"

anteinterfaces "github.com/cosmos/evm/ante/interfaces"
evmtypes "github.com/cosmos/evm/x/vm/types"

errorsmod "cosmossdk.io/errors"

sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
)

// EthEmitEventDecorator emit events in ante handler in case of tx execution failed (out of block gas limit).
type EthEmitEventDecorator struct {
evmKeeper anteinterfaces.EVMKeeper
}

// NewEthEmitEventDecorator creates a new EthEmitEventDecorator
func NewEthEmitEventDecorator(evmKeeper anteinterfaces.EVMKeeper) EthEmitEventDecorator {
return EthEmitEventDecorator{evmKeeper}
}

// AnteHandle emits some basic events for the eth messages
func (eeed EthEmitEventDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// After eth tx passed ante handler, the fee is deducted and nonce increased, it shouldn't be ignored by json-rpc,
// we need to emit some basic events at the very end of ante handler to be indexed by CometBFT.
blockTxIndex := eeed.evmKeeper.GetTxIndexTransient(ctx)

msgs := tx.GetMsgs()
if msgs == nil {
return ctx, errorsmod.Wrap(errortypes.ErrUnknownRequest, "invalid transaction. Transaction without messages")
}

for i, msg := range msgs {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
if !ok {
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

txIdx := uint64(i) //nolint:gosec // G115 // won't exceed uint64
EmitTxHashEvent(ctx, msgEthTx, blockTxIndex, txIdx)
}

return next(ctx, tx, simulate)
}

// EmitTxHashEvent emits the Ethereum tx
//
// FIXME: This is Technical debt. Ideally the sdk.Tx hash should be the Ethereum
// tx hash (msg.Hash) instead of using events for indexing Eth txs.
// TxIndex should be included in the header vote extension as part of ABCI++
func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex, msgIndex uint64) {
func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex uint64) {
// emit ethereum tx hash as an event so that it can be indexed by CometBFT for query purposes
// it's emitted in ante handler, so we can query failed transaction (out of block gas limit).
ctx.EventManager().EmitEvent(
sdk.NewEvent(
evmtypes.EventTypeEthereumTx,
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.Hash().String()),
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex+msgIndex, 10)), // #nosec G115
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex, 10)), // #nosec G115
),
)
}
12 changes: 3 additions & 9 deletions ante/evm/mono_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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 @@ -265,14 +265,8 @@ 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, md.feemarketParams); err != nil {
return ctx, err
}

// 11. emit events
txIdx := uint64(msgIndex) //nolint:gosec // G115
EmitTxHashEvent(ctx, ethMsg, decUtils.BlockTxIndex, txIdx)
// Emit event unconditionally - ctx.TxIndex() will be valid during block execution
EmitTxHashEvent(ctx, ethMsg, uint64(ctx.TxIndex())) // #nosec G115 -- no overlfow here

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 @@ -79,9 +77,6 @@ func (m MockFeeMarketKeeper) GetParams(ctx sdk.Context) feemarkettypes.Params {
return param
}

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 @@ -222,6 +217,12 @@ func TestMonoDecorator(t *testing.T) {
monoDec := evm.NewEVMMonoDecorator(accountKeeper, feeMarketKeeper, keeper, 0, &params, &feemarketParams)
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
2 changes: 1 addition & 1 deletion ante/evm/nonce_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (m *mockAccountKeeper) GetAccount(ctx context.Context, addr sdk.AccAddress)
}
func (m *mockAccountKeeper) SetAccount(ctx context.Context, account sdk.AccountI) { m.last = account }
func (m *mockAccountKeeper) RemoveAccount(ctx context.Context, account sdk.AccountI) {}
func (m *mockAccountKeeper) GetParams(ctx context.Context) (params authtypes.Params) { return }
func (m *mockAccountKeeper) GetParams(ctx context.Context) (params authtypes.Params) { return params }
func (m *mockAccountKeeper) GetSequence(ctx context.Context, addr sdk.AccAddress) (uint64, error) {
if m.last == nil {
return 0, nil
Expand Down
2 changes: 0 additions & 2 deletions ante/evm/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ type DecoratorUtils struct {
BaseFee *big.Int
MempoolMinGasPrice sdkmath.LegacyDec
GlobalMinGasPrice sdkmath.LegacyDec
BlockTxIndex uint64
TxGasLimit uint64
GasWanted uint64
MinPriority int64
Expand Down Expand Up @@ -73,7 +72,6 @@ func NewMonoDecoratorUtils(
BaseFee: baseFee,
MempoolMinGasPrice: mempoolMinGasPrice,
GlobalMinGasPrice: globalMinGasPrice,
BlockTxIndex: ek.GetTxIndexTransient(ctx),
GasWanted: 0,
MinPriority: int64(math.MaxInt64),
// TxGasLimit and TxFee are set to zero because they are updated
Expand Down
3 changes: 0 additions & 3 deletions ante/interfaces/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ type EVMKeeper interface {
stateDB vm.StateDB) *vm.EVM
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
SpendableCoin(ctx sdk.Context, addr common.Address) *uint256.Int
ResetTransientGasUsed(ctx sdk.Context)
GetTxIndexTransient(ctx sdk.Context) uint64
GetParams(ctx sdk.Context) evmtypes.Params
}

// FeeMarketKeeper exposes the required feemarket keeper interface required for ante handlers
type FeeMarketKeeper interface {
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
}

type ProtoTxProvider interface {
Expand Down
7 changes: 0 additions & 7 deletions ante/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ import (
// set, it returns the max gas from the application consensus params.
// NOTE: see https://github.com/cosmos/cosmos-sdk/issues/9514 for full reference
func BlockGasLimit(ctx sdk.Context) uint64 {
blockGasMeter := ctx.BlockGasMeter()

// Get the limit from the gas meter only if its not null and not an InfiniteGasMeter
if blockGasMeter != nil && blockGasMeter.Limit() != 0 {
return blockGasMeter.Limit()
}

// Otherwise get from the consensus parameters
cp := ctx.ConsensusParams()
if cp.Block == nil {
Expand Down
2 changes: 1 addition & 1 deletion ante/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func generatePubKeysAndSignatures(n int, msg []byte, _ bool) (pubkeys []cryptoty
pubkeys[i] = privkey.PubKey()
signatures[i], _ = privkey.Sign(msg)
}
return
return pubkeys, signatures
}

func expectedGasCostByKeys(pubkeys []cryptotypes.PubKey) uint64 {
Expand Down
Loading
Loading