Skip to content

Commit 79bcc14

Browse files
feat!: Block STM (#589)
x/vm Keeper TransientGas used has been refactored to write gas used per transaction to an object store key which is unique based on the txn index. This avoid each transaction reading/writing the same key/value. It is reset during EndBlock via deletion of all transient gas values. Block bloom has been refactored to write each transactions' log bloom to a separate key in object storage. An EndBlocker has been added to accumulate all of these into a final bloom, and Reset is called to delete all of the keys. x/feemarket Keeper TransientBlockGasWanted was fully removed. BlockGasWanted was added to the SDK's context and is now updated in baseapp during FinalizeBlock. The base fee calculation of the feemarket module has been updated to use the context's gas wanted for base fee calculation. Antehandlers As mentioned above, we no longer use gas wanted via the antehandlers so that has been removed. The event emission has been changed to use the context's tx index instead of transient storage.
1 parent f6d50b4 commit 79bcc14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+667
-749
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### FEATURES
1212

13+
- [\#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.
1314
- [\#768](https://github.com/cosmos/evm/pull/768) Added ICS-02 Client Router precompile
1415

1516
### BUG FIXES
@@ -110,7 +111,6 @@
110111
- [\#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.
111112
- [\#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.
112113

113-
114114
## v0.4.1
115115

116116
### DEPENDENCIES

ante/cosmos.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ func newCosmosAnteHandler(ctx sdk.Context, options HandlerOptions) sdk.AnteHandl
4040
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
4141
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
4242
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
43-
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper, &feemarketParams),
4443
)
4544
}

ante/evm/01_setup_ctx.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package evm
22

33
import (
4-
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
54
evmante "github.com/cosmos/evm/x/vm/ante"
65

76
errorsmod "cosmossdk.io/errors"
@@ -16,18 +15,10 @@ var _ sdktypes.AnteDecorator = &EthSetupContextDecorator{}
1615

1716
// EthSetupContextDecorator is adapted from SetUpContextDecorator from cosmos-sdk, it ignores gas consumption
1817
// by setting the gas meter to infinite
19-
type EthSetupContextDecorator struct {
20-
evmKeeper anteinterfaces.EVMKeeper
21-
}
22-
23-
func NewEthSetUpContextDecorator(evmKeeper anteinterfaces.EVMKeeper) EthSetupContextDecorator {
24-
return EthSetupContextDecorator{
25-
evmKeeper: evmKeeper,
26-
}
27-
}
18+
type EthSetupContextDecorator struct{}
2819

2920
func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes.Tx, simulate bool, next sdktypes.AnteHandler) (newCtx sdktypes.Context, err error) {
30-
newCtx, err = SetupContextAndResetTransientGas(ctx, tx, esc.evmKeeper)
21+
newCtx, err = SetupContextAndResetTransientGas(ctx, tx)
3122
if err != nil {
3223
return ctx, err
3324
}
@@ -37,7 +28,7 @@ func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes
3728
// SetupContextAndResetTransientGas modifies the context to be used in the
3829
// execution of the ante handler associated with an EVM transaction. Previous
3930
// gas consumed is reset in the transient store.
40-
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmKeeper anteinterfaces.EVMKeeper) (sdktypes.Context, error) {
31+
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx) (sdktypes.Context, error) {
4132
// all transactions must implement GasTx
4233
_, ok := tx.(authante.GasTx)
4334
if !ok {
@@ -50,12 +41,5 @@ func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmK
5041
newCtx := evmante.BuildEvmExecutionCtx(ctx).
5142
WithGasMeter(storetypes.NewInfiniteGasMeter())
5243

53-
// Reset transient gas used to prepare the execution of current cosmos tx.
54-
// Transient gas-used is necessary to sum the gas-used of cosmos tx, when it contains multiple eth msgs.
55-
//
56-
// TODO: add more context here to explain why gas used is reset. Not clear
57-
// from docstring.
58-
evmKeeper.ResetTransientGasUsed(ctx)
59-
6044
return newCtx, nil
6145
}

ante/evm/10_gas_wanted.go

Lines changed: 0 additions & 85 deletions
This file was deleted.

ante/evm/11_emit_event.go

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,62 +3,23 @@ package evm
33
import (
44
"strconv"
55

6-
anteinterfaces "github.com/cosmos/evm/ante/interfaces"
76
evmtypes "github.com/cosmos/evm/x/vm/types"
87

9-
errorsmod "cosmossdk.io/errors"
10-
118
sdk "github.com/cosmos/cosmos-sdk/types"
12-
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
139
)
1410

15-
// EthEmitEventDecorator emit events in ante handler in case of tx execution failed (out of block gas limit).
16-
type EthEmitEventDecorator struct {
17-
evmKeeper anteinterfaces.EVMKeeper
18-
}
19-
20-
// NewEthEmitEventDecorator creates a new EthEmitEventDecorator
21-
func NewEthEmitEventDecorator(evmKeeper anteinterfaces.EVMKeeper) EthEmitEventDecorator {
22-
return EthEmitEventDecorator{evmKeeper}
23-
}
24-
25-
// AnteHandle emits some basic events for the eth messages
26-
func (eeed EthEmitEventDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
27-
// After eth tx passed ante handler, the fee is deducted and nonce increased, it shouldn't be ignored by json-rpc,
28-
// we need to emit some basic events at the very end of ante handler to be indexed by CometBFT.
29-
blockTxIndex := eeed.evmKeeper.GetTxIndexTransient(ctx)
30-
31-
msgs := tx.GetMsgs()
32-
if msgs == nil {
33-
return ctx, errorsmod.Wrap(errortypes.ErrUnknownRequest, "invalid transaction. Transaction without messages")
34-
}
35-
36-
for i, msg := range msgs {
37-
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
38-
if !ok {
39-
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
40-
}
41-
42-
txIdx := uint64(i) //nolint:gosec // G115 // won't exceed uint64
43-
EmitTxHashEvent(ctx, msgEthTx, blockTxIndex, txIdx)
44-
}
45-
46-
return next(ctx, tx, simulate)
47-
}
48-
4911
// EmitTxHashEvent emits the Ethereum tx
5012
//
5113
// FIXME: This is Technical debt. Ideally the sdk.Tx hash should be the Ethereum
5214
// tx hash (msg.Hash) instead of using events for indexing Eth txs.
53-
// TxIndex should be included in the header vote extension as part of ABCI++
54-
func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex, msgIndex uint64) {
15+
func EmitTxHashEvent(ctx sdk.Context, msg *evmtypes.MsgEthereumTx, blockTxIndex uint64) {
5516
// emit ethereum tx hash as an event so that it can be indexed by CometBFT for query purposes
5617
// it's emitted in ante handler, so we can query failed transaction (out of block gas limit).
5718
ctx.EventManager().EmitEvent(
5819
sdk.NewEvent(
5920
evmtypes.EventTypeEthereumTx,
6021
sdk.NewAttribute(evmtypes.AttributeKeyEthereumTxHash, msg.Hash().String()),
61-
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex+msgIndex, 10)), // #nosec G115
22+
sdk.NewAttribute(evmtypes.AttributeKeyTxIndex, strconv.FormatUint(blockTxIndex, 10)), // #nosec G115
6223
),
6324
)
6425
}

ante/evm/mono_decorator.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
7979
evmDenom := evmtypes.GetEVMCoinDenom()
8080

8181
// 1. setup ctx
82-
ctx, err = SetupContextAndResetTransientGas(ctx, tx, md.evmKeeper)
82+
ctx, err = SetupContextAndResetTransientGas(ctx, tx)
8383
if err != nil {
8484
return ctx, err
8585
}
@@ -265,14 +265,8 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
265265
return ctx, err
266266
}
267267

268-
// 10. gas wanted
269-
if err := CheckGasWanted(ctx, md.feeMarketKeeper, tx, decUtils.Rules.IsLondon, md.feemarketParams); err != nil {
270-
return ctx, err
271-
}
272-
273-
// 11. emit events
274-
txIdx := uint64(msgIndex) //nolint:gosec // G115
275-
EmitTxHashEvent(ctx, ethMsg, decUtils.BlockTxIndex, txIdx)
268+
// Emit event unconditionally - ctx.TxIndex() will be valid during block execution
269+
EmitTxHashEvent(ctx, ethMsg, uint64(ctx.TxIndex())) // #nosec G115 -- no overlfow here
276270

277271
if err := CheckTxFee(txFeeInfo, decUtils.TxFee, decUtils.TxGasLimit); err != nil {
278272
return ctx, err

ante/evm/mono_decorator_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ func (k *ExtendedEVMKeeper) SpendableCoin(ctx sdk.Context, addr common.Address)
6262
return uint256.NewInt(0)
6363
}
6464

65-
func (k *ExtendedEVMKeeper) ResetTransientGasUsed(_ sdk.Context) {}
6665
func (k *ExtendedEVMKeeper) GetParams(_ sdk.Context) evmsdktypes.Params {
6766
return evmsdktypes.DefaultParams()
6867
}
6968
func (k *ExtendedEVMKeeper) GetBaseFee(_ sdk.Context) *big.Int { return big.NewInt(0) }
7069
func (k *ExtendedEVMKeeper) GetMinGasPrice(_ sdk.Context) math.LegacyDec { return math.LegacyZeroDec() }
71-
func (k *ExtendedEVMKeeper) GetTxIndexTransient(_ sdk.Context) uint64 { return 0 }
7270

7371
// only methods called by EVMMonoDecorator
7472
type MockFeeMarketKeeper struct{}
@@ -79,9 +77,6 @@ func (m MockFeeMarketKeeper) GetParams(ctx sdk.Context) feemarkettypes.Params {
7977
return param
8078
}
8179

82-
func (m MockFeeMarketKeeper) AddTransientGasWanted(_ sdk.Context, _ uint64) (uint64, error) {
83-
return 0, nil
84-
}
8580
func (m MockFeeMarketKeeper) GetBaseFeeEnabled(_ sdk.Context) bool { return true }
8681
func (m MockFeeMarketKeeper) GetBaseFee(_ sdk.Context) math.LegacyDec { return math.LegacyZeroDec() }
8782

@@ -222,6 +217,12 @@ func TestMonoDecorator(t *testing.T) {
222217
monoDec := evm.NewEVMMonoDecorator(accountKeeper, feeMarketKeeper, keeper, 0, &params, &feemarketParams)
223218
ctx := sdk.NewContext(nil, tmproto.Header{}, false, log.NewNopLogger())
224219
ctx = ctx.WithBlockGasMeter(storetypes.NewGasMeter(1e19))
220+
blockParams := tmproto.BlockParams{
221+
MaxBytes: 200000,
222+
MaxGas: 81500000, // default limit
223+
}
224+
consParams := tmproto.ConsensusParams{Block: &blockParams}
225+
ctx = ctx.WithConsensusParams(consParams)
225226

226227
msgs := tc.buildMsgs(privKey)
227228
tx, err := utiltx.PrepareEthTx(cfg.TxConfig, nil, toMsgSlice(msgs)...)

ante/evm/nonce_limit_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (m *mockAccountKeeper) GetAccount(ctx context.Context, addr sdk.AccAddress)
3434
}
3535
func (m *mockAccountKeeper) SetAccount(ctx context.Context, account sdk.AccountI) { m.last = account }
3636
func (m *mockAccountKeeper) RemoveAccount(ctx context.Context, account sdk.AccountI) {}
37-
func (m *mockAccountKeeper) GetParams(ctx context.Context) (params authtypes.Params) { return }
37+
func (m *mockAccountKeeper) GetParams(ctx context.Context) (params authtypes.Params) { return params }
3838
func (m *mockAccountKeeper) GetSequence(ctx context.Context, addr sdk.AccAddress) (uint64, error) {
3939
if m.last == nil {
4040
return 0, nil

ante/evm/utils.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type DecoratorUtils struct {
2626
BaseFee *big.Int
2727
MempoolMinGasPrice sdkmath.LegacyDec
2828
GlobalMinGasPrice sdkmath.LegacyDec
29-
BlockTxIndex uint64
3029
TxGasLimit uint64
3130
GasWanted uint64
3231
MinPriority int64
@@ -73,7 +72,6 @@ func NewMonoDecoratorUtils(
7372
BaseFee: baseFee,
7473
MempoolMinGasPrice: mempoolMinGasPrice,
7574
GlobalMinGasPrice: globalMinGasPrice,
76-
BlockTxIndex: ek.GetTxIndexTransient(ctx),
7775
GasWanted: 0,
7876
MinPriority: int64(math.MaxInt64),
7977
// TxGasLimit and TxFee are set to zero because they are updated

ante/interfaces/evm.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ type EVMKeeper interface {
2323
stateDB vm.StateDB) *vm.EVM
2424
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
2525
SpendableCoin(ctx sdk.Context, addr common.Address) *uint256.Int
26-
ResetTransientGasUsed(ctx sdk.Context)
27-
GetTxIndexTransient(ctx sdk.Context) uint64
2826
GetParams(ctx sdk.Context) evmtypes.Params
2927
}
3028

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

3734
type ProtoTxProvider interface {

0 commit comments

Comments
 (0)