Skip to content

Commit 8ee94a1

Browse files
committed
feat: implement object stores
1 parent f03d2a4 commit 8ee94a1

Some content is hidden

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

42 files changed

+749
-1183
lines changed

ante/evm/01_setup_ctx.go

Lines changed: 5 additions & 17 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,14 @@ 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-
}
18+
type EthSetupContextDecorator struct{}
2219

23-
func NewEthSetUpContextDecorator(evmKeeper anteinterfaces.EVMKeeper) EthSetupContextDecorator {
24-
return EthSetupContextDecorator{
25-
evmKeeper: evmKeeper,
26-
}
20+
func NewEthSetUpContextDecorator() EthSetupContextDecorator {
21+
return EthSetupContextDecorator{}
2722
}
2823

2924
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)
25+
newCtx, err = SetupContextAndResetTransientGas(ctx, tx)
3126
if err != nil {
3227
return ctx, err
3328
}
@@ -37,7 +32,7 @@ func (esc EthSetupContextDecorator) AnteHandle(ctx sdktypes.Context, tx sdktypes
3732
// SetupContextAndResetTransientGas modifies the context to be used in the
3833
// execution of the ante handler associated with an EVM transaction. Previous
3934
// gas consumed is reset in the transient store.
40-
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmKeeper anteinterfaces.EVMKeeper) (sdktypes.Context, error) {
35+
func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx) (sdktypes.Context, error) {
4136
// all transactions must implement GasTx
4237
_, ok := tx.(authante.GasTx)
4338
if !ok {
@@ -50,12 +45,5 @@ func SetupContextAndResetTransientGas(ctx sdktypes.Context, tx sdktypes.Tx, evmK
5045
newCtx := evmante.BuildEvmExecutionCtx(ctx).
5146
WithGasMeter(storetypes.NewInfiniteGasMeter())
5247

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-
6048
return newCtx, nil
6149
}

ante/evm/10_gas_wanted.go

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

ante/evm/11_emit_event.go

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

ante/evm/fee_checker_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ func (m MockFeemarketKeeper) GetBaseFeeEnabled(_ sdk.Context) bool {
3939
return true
4040
}
4141

42-
func (m MockFeemarketKeeper) AddTransientGasWanted(_ sdk.Context, _ uint64) (uint64, error) {
43-
return 0, nil
44-
}
45-
4642
func (m MockFeemarketKeeper) GetParams(_ sdk.Context) (params feemarkettypes.Params) {
4743
return feemarkettypes.DefaultParams()
4844
}

ante/evm/mono_decorator.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
7272
evmDenom := evmtypes.GetEVMCoinDenom()
7373

7474
// 1. setup ctx
75-
ctx, err = SetupContextAndResetTransientGas(ctx, tx, md.evmKeeper)
75+
ctx, err = SetupContextAndResetTransientGas(ctx, tx)
7676
if err != nil {
7777
return ctx, err
7878
}
@@ -255,15 +255,6 @@ func (md MonoDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, ne
255255
return ctx, err
256256
}
257257

258-
// 10. gas wanted
259-
if err := CheckGasWanted(ctx, md.feeMarketKeeper, tx, decUtils.Rules.IsLondon); err != nil {
260-
return ctx, err
261-
}
262-
263-
// 11. emit events
264-
txIdx := uint64(msgIndex) //nolint:gosec // G115
265-
EmitTxHashEvent(ctx, ethMsg, decUtils.BlockTxIndex, txIdx)
266-
267258
if err := CheckTxFee(txFeeInfo, decUtils.TxFee, decUtils.TxGasLimit); err != nil {
268259
return ctx, err
269260
}

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{}
@@ -77,9 +75,6 @@ func (m MockFeeMarketKeeper) GetParams(_ sdk.Context) feemarkettypes.Params {
7775
return feemarkettypes.DefaultParams()
7876
}
7977

80-
func (m MockFeeMarketKeeper) AddTransientGasWanted(_ sdk.Context, _ uint64) (uint64, error) {
81-
return 0, nil
82-
}
8378
func (m MockFeeMarketKeeper) GetBaseFeeEnabled(_ sdk.Context) bool { return true }
8479
func (m MockFeeMarketKeeper) GetBaseFee(_ sdk.Context) math.LegacyDec { return math.LegacyZeroDec() }
8580

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

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

ante/evm/utils.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func NewMonoDecoratorUtils(
7171
BaseFee: baseFee,
7272
MempoolMinGasPrice: mempoolMinGasPrice,
7373
GlobalMinGasPrice: globalMinGasPrice,
74-
BlockTxIndex: ek.GetTxIndexTransient(ctx),
7574
GasWanted: 0,
7675
MinPriority: int64(math.MaxInt64),
7776
// 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
@@ -27,8 +27,6 @@ type EVMKeeper interface {
2727
stateDB vm.StateDB) *vm.EVM
2828
DeductTxCostsFromUserBalance(ctx sdk.Context, fees sdk.Coins, from common.Address) error
2929
SpendableCoin(ctx sdk.Context, addr common.Address) *uint256.Int
30-
ResetTransientGasUsed(ctx sdk.Context)
31-
GetTxIndexTransient(ctx sdk.Context) uint64
3230
GetParams(ctx sdk.Context) evmtypes.Params
3331
// GetBaseFee returns the BaseFee param from the fee market module
3432
// adapted according to the evm denom decimals
@@ -41,7 +39,6 @@ type EVMKeeper interface {
4139
// FeeMarketKeeper exposes the required feemarket keeper interface required for ante handlers
4240
type FeeMarketKeeper interface {
4341
GetParams(ctx sdk.Context) (params feemarkettypes.Params)
44-
AddTransientGasWanted(ctx sdk.Context, gasWanted uint64) (uint64, error)
4542
GetBaseFeeEnabled(ctx sdk.Context) bool
4643
GetBaseFee(ctx sdk.Context) math.LegacyDec
4744
}

evmd/ante/cosmos_handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package ante
33
import (
44
baseevmante "github.com/cosmos/evm/ante"
55
cosmosante "github.com/cosmos/evm/ante/cosmos"
6-
evmante "github.com/cosmos/evm/ante/evm"
76
evmtypes "github.com/cosmos/evm/x/vm/types"
87
ibcante "github.com/cosmos/ibc-go/v10/modules/core/ante"
98

@@ -35,6 +34,5 @@ func newCosmosAnteHandler(options baseevmante.HandlerOptions) sdk.AnteHandler {
3534
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
3635
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
3736
ibcante.NewRedundantRelayDecorator(options.IBCKeeper),
38-
evmante.NewGasWantedDecorator(options.EvmKeeper, options.FeeMarketKeeper),
3937
)
4038
}

evmd/app.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ type EVMD struct {
172172
keys map[string]*storetypes.KVStoreKey
173173
tkeys map[string]*storetypes.TransientStoreKey
174174
memKeys map[string]*storetypes.MemoryStoreKey
175+
okeys map[string]*storetypes.ObjectStoreKey
175176

176177
// keepers
177178
AccountKeeper authkeeper.AccountKeeper
@@ -267,6 +268,8 @@ func NewExampleApp(
267268
bApp.SetVersion(version.Version)
268269
bApp.SetInterfaceRegistry(interfaceRegistry)
269270
bApp.SetTxEncoder(txConfig.TxEncoder())
271+
bApp.SetTxExecutor(DefaultTxExecutor)
272+
bApp.SetDisableBlockGasMeter(true)
270273

271274
// initialize the Cosmos EVM application configuration
272275
if err := evmAppOptions(evmChainID); err != nil {
@@ -284,7 +287,8 @@ func NewExampleApp(
284287
evmtypes.StoreKey, feemarkettypes.StoreKey, erc20types.StoreKey, precisebanktypes.StoreKey,
285288
)
286289

287-
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
290+
tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey)
291+
okeys := storetypes.NewObjectStoreKeys(banktypes.ObjectStoreKey, evmtypes.ObjectStoreKey, feemarkettypes.ObjectStoreKey)
288292

289293
// load state streaming if enabled
290294
if err := bApp.RegisterStreamingServices(appOpts, keys); err != nil {
@@ -305,6 +309,7 @@ func NewExampleApp(
305309
interfaceRegistry: interfaceRegistry,
306310
keys: keys,
307311
tkeys: tkeys,
312+
okeys: okeys,
308313
}
309314

310315
app.ParamsKeeper = initParamsKeeper(appCodec, legacyAmino, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
@@ -332,6 +337,7 @@ func NewExampleApp(
332337

333338
app.BankKeeper = bankkeeper.NewBaseKeeper(
334339
appCodec,
340+
okeys[banktypes.ObjectStoreKey],
335341
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
336342
app.AccountKeeper,
337343
evmdconfig.BlockedAddresses(),
@@ -464,7 +470,7 @@ func NewExampleApp(
464470
app.FeeMarketKeeper = feemarketkeeper.NewKeeper(
465471
appCodec, authtypes.NewModuleAddress(govtypes.ModuleName),
466472
keys[feemarkettypes.StoreKey],
467-
tkeys[feemarkettypes.TransientKey],
473+
okeys[feemarkettypes.ObjectStoreKey],
468474
)
469475

470476
// Set up PreciseBank keeper
@@ -483,7 +489,7 @@ func NewExampleApp(
483489
// NOTE: it's required to set up the EVM keeper before the ERC-20 keeper, because it is used in its instantiation.
484490
app.EVMKeeper = evmkeeper.NewKeeper(
485491
// TODO: check why this is not adjusted to use the runtime module methods like SDK native keepers
486-
appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], keys,
492+
appCodec, keys[evmtypes.StoreKey], okeys[evmtypes.ObjectStoreKey], keys,
487493
authtypes.NewModuleAddress(govtypes.ModuleName),
488494
app.AccountKeeper,
489495
app.PreciseBankKeeper,
@@ -751,6 +757,7 @@ func NewExampleApp(
751757
// initialize stores
752758
app.MountKVStores(keys)
753759
app.MountTransientStores(tkeys)
760+
app.MountObjectStores(okeys)
754761

755762
maxGasWanted := cast.ToUint64(appOpts.Get(srvflags.EVMMaxTxGasWanted))
756763

0 commit comments

Comments
 (0)