From 642fd0bc53eeb1da3ac6e36a17eff4d8e65dcf0e Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 5 Apr 2024 12:12:06 +0800 Subject: [PATCH 1/3] Problem: get set params are not align in feemarket --- app/app.go | 1 + x/evm/spec/02_state.md | 3 ++- x/feemarket/keeper/keeper.go | 14 +++++++++----- x/feemarket/keeper/params.go | 12 +++++++++--- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/app/app.go b/app/app.go index e078157472..50dad2063e 100644 --- a/app/app.go +++ b/app/app.go @@ -495,6 +495,7 @@ func NewEthermintApp( feeMarketSs := app.GetSubspace(feemarkettypes.ModuleName) app.FeeMarketKeeper = feemarketkeeper.NewKeeper( appCodec, + runtime.NewKVStoreService(keys[feemarkettypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName), keys[feemarkettypes.StoreKey], okeys[feemarkettypes.ObjectStoreKey], ) diff --git a/x/evm/spec/02_state.md b/x/evm/spec/02_state.md index 024f238f75..f7961e2e5d 100644 --- a/x/evm/spec/02_state.md +++ b/x/evm/spec/02_state.md @@ -175,6 +175,7 @@ To support the interface functionality, it imports 4 module Keepers: type Keeper struct { // Protobuf codec cdc codec.BinaryCodec + storeService corestoretypes.KVStoreService // Store key required for the EVM Prefix KVStore. It is required by: // - storing account's Storage State // - storing account's Code @@ -183,7 +184,7 @@ type Keeper struct { storeKey sdk.StoreKey // key to access the transient store, which is reset on every block during Commit - transientKey sdk.StoreKey + objectKey storetypes.StoreKey // module specific parameter space that can be configured through governance paramSpace paramtypes.Subspace diff --git a/x/feemarket/keeper/keeper.go b/x/feemarket/keeper/keeper.go index ecda4dd22d..8c0d2bce72 100644 --- a/x/feemarket/keeper/keeper.go +++ b/x/feemarket/keeper/keeper.go @@ -18,6 +18,7 @@ package keeper import ( "math/big" + corestoretypes "cosmossdk.io/core/store" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -32,7 +33,8 @@ var KeyPrefixBaseFeeV1 = []byte{2} // Keeper grants access to the Fee Market module state. type Keeper struct { // Protobuf codec - cdc codec.BinaryCodec + cdc codec.BinaryCodec + storeService corestoretypes.KVStoreService // Store key required for the Fee Market Prefix KVStore. storeKey, objectKey storetypes.StoreKey // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. @@ -42,6 +44,7 @@ type Keeper struct { // NewKeeper generates new fee market module keeper func NewKeeper( cdc codec.BinaryCodec, + storeService corestoretypes.KVStoreService, authority sdk.AccAddress, storeKey, objectKey storetypes.StoreKey, ) Keeper { @@ -51,10 +54,11 @@ func NewKeeper( } return Keeper{ - cdc: cdc, - storeKey: storeKey, - objectKey: objectKey, - authority: authority, + cdc: cdc, + storeService: storeService, + storeKey: storeKey, + objectKey: objectKey, + authority: authority, } } diff --git a/x/feemarket/keeper/params.go b/x/feemarket/keeper/params.go index 01c9381f66..fe4b1d76d6 100644 --- a/x/feemarket/keeper/params.go +++ b/x/feemarket/keeper/params.go @@ -30,8 +30,12 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { objStore := ctx.ObjectStore(k.objectKey) v := objStore.Get(types.KeyPrefixObjectParams) if v == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ParamsKey) + if err != nil { + panic(err) + } params = new(types.Params) - bz := ctx.KVStore(k.storeKey).Get(types.ParamsKey) if bz != nil { k.cdc.MustUnmarshal(bz, params) } @@ -47,9 +51,11 @@ func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { if err := p.Validate(); err != nil { return err } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&p) - store.Set(types.ParamsKey, bz) + if err := store.Set(types.ParamsKey, bz); err != nil { + return err + } // set to cache as well, decode again to be compatible with the previous behavior var params types.Params From 00f231276d059e97ee32815ced03ad07d03c1bd8 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 5 Apr 2024 12:12:26 +0800 Subject: [PATCH 2/3] align doc --- x/evm/keeper/keeper.go | 2 +- x/evm/spec/02_state.md | 68 ++++++++++++++++++++---------------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 60d46d4c71..569fec826a 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -49,7 +49,7 @@ type Keeper struct { // - storing module parameters storeKey storetypes.StoreKey - // key to access the transient store, which is reset on every block during Commit + // key to access the object store, which is reset on every block during Commit objectKey storetypes.StoreKey // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. diff --git a/x/evm/spec/02_state.md b/x/evm/spec/02_state.md index f7961e2e5d..cba2923513 100644 --- a/x/evm/spec/02_state.md +++ b/x/evm/spec/02_state.md @@ -173,41 +173,39 @@ To support the interface functionality, it imports 4 module Keepers: ```go type Keeper struct { - // Protobuf codec - cdc codec.BinaryCodec - storeService corestoretypes.KVStoreService - // Store key required for the EVM Prefix KVStore. It is required by: - // - storing account's Storage State - // - storing account's Code - // - storing Bloom filters by block height. Needed for the Web3 API. - // For the full list, check the module specification - storeKey sdk.StoreKey - - // key to access the transient store, which is reset on every block during Commit - objectKey storetypes.StoreKey - - // module specific parameter space that can be configured through governance - paramSpace paramtypes.Subspace - // access to account state - accountKeeper types.AccountKeeper - // update balance and accounting operations with coins - bankKeeper types.BankKeeper - // access historical headers for EVM state transition execution - stakingKeeper types.StakingKeeper - // fetch EIP1559 base fee and parameters - feeMarketKeeper types.FeeMarketKeeper - - // chain ID number obtained from the context's chain id - eip155ChainID *big.Int - - // Tracer used to collect execution traces from the EVM transaction execution - tracer string - // trace EVM state transition execution. This value is obtained from the `--trace` flag. - // For more info check https://geth.ethereum.org/docs/dapp/tracing - debug bool - - // EVM Hooks for tx post-processing - hooks types.EvmHooks + // Protobuf codec + cdc codec.Codec + storeService corestoretypes.KVStoreService + // Store key required for the EVM Prefix KVStore. It is required by: + // - storing account's Storage State + // - storing account's Code + // - storing module parameters + storeKey storetypes.StoreKey + + // key to access the object store, which is reset on every block during Commit + objectKey storetypes.StoreKey + + // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. + authority sdk.AccAddress + // access to account state + accountKeeper types.AccountKeeper + // update balance and accounting operations with coins + bankKeeper types.BankKeeper + // access historical headers for EVM state transition execution + stakingKeeper types.StakingKeeper + // fetch EIP1559 base fee and parameters + feeMarketKeeper types.FeeMarketKeeper + + // chain ID number obtained from the context's chain id + eip155ChainID *big.Int + + // Tracer used to collect execution traces from the EVM transaction execution + tracer string + + // EVM Hooks for tx post-processing + hooks types.EvmHooks + + customContractFns []CustomContractFn } ``` From 588c374104c539cb38557caebcc360239af1212a Mon Sep 17 00:00:00 2001 From: mmsqe Date: Fri, 5 Apr 2024 13:19:37 +0800 Subject: [PATCH 3/3] Apply suggestions from code review --- app/app.go | 2 -- x/evm/keeper/keeper.go | 6 +----- x/evm/keeper/params.go | 14 +++----------- x/evm/spec/02_state.md | 1 - x/evm/statedb/statedb_test.go | 1 - x/feemarket/keeper/keeper.go | 14 +++++--------- x/feemarket/keeper/params.go | 12 +++--------- 7 files changed, 12 insertions(+), 38 deletions(-) diff --git a/app/app.go b/app/app.go index 50dad2063e..872310ec48 100644 --- a/app/app.go +++ b/app/app.go @@ -495,7 +495,6 @@ func NewEthermintApp( feeMarketSs := app.GetSubspace(feemarkettypes.ModuleName) app.FeeMarketKeeper = feemarketkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[feemarkettypes.StoreKey]), authtypes.NewModuleAddress(govtypes.ModuleName), keys[feemarkettypes.StoreKey], okeys[feemarkettypes.ObjectStoreKey], ) @@ -504,7 +503,6 @@ func NewEthermintApp( evmSs := app.GetSubspace(evmtypes.ModuleName) app.EvmKeeper = evmkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[evmtypes.StoreKey]), keys[evmtypes.StoreKey], okeys[evmtypes.ObjectStoreKey], authtypes.NewModuleAddress(govtypes.ModuleName), app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.FeeMarketKeeper, tracer, diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 569fec826a..2e4bc9b924 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -18,7 +18,6 @@ package keeper import ( "math/big" - corestoretypes "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" @@ -41,8 +40,7 @@ type CustomContractFn func(sdk.Context, params.Rules) vm.PrecompiledContract // Keeper grants access to the EVM module state and implements the go-ethereum StateDB interface. type Keeper struct { // Protobuf codec - cdc codec.Codec - storeService corestoretypes.KVStoreService + cdc codec.Codec // Store key required for the EVM Prefix KVStore. It is required by: // - storing account's Storage State // - storing account's Code @@ -78,7 +76,6 @@ type Keeper struct { // NewKeeper generates new evm module keeper func NewKeeper( cdc codec.Codec, - storeService corestoretypes.KVStoreService, storeKey, objectKey storetypes.StoreKey, authority sdk.AccAddress, ak types.AccountKeeper, @@ -101,7 +98,6 @@ func NewKeeper( // NOTE: we pass in the parameter space to the CommitStateDB in order to use custom denominations for the EVM operations return &Keeper{ cdc: cdc, - storeService: storeService, authority: authority, accountKeeper: ak, bankKeeper: bankKeeper, diff --git a/x/evm/keeper/params.go b/x/evm/keeper/params.go index eff1a9c5bf..17d3908a16 100644 --- a/x/evm/keeper/params.go +++ b/x/evm/keeper/params.go @@ -26,21 +26,15 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { objStore := ctx.ObjectStore(k.objectKey) v := objStore.Get(types.KeyPrefixObjectParams) if v == nil { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.KeyPrefixParams) - if err != nil { - panic(err) - } params = new(types.Params) + bz := ctx.KVStore(k.storeKey).Get(types.KeyPrefixParams) if bz != nil { k.cdc.MustUnmarshal(bz, params) } - objStore.Set(types.KeyPrefixObjectParams, params) } else { params = v.(*types.Params) } - return *params } @@ -49,11 +43,9 @@ func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { if err := p.Validate(); err != nil { return err } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&p) - if err := store.Set(types.KeyPrefixParams, bz); err != nil { - return err - } + store.Set(types.KeyPrefixParams, bz) // set to cache as well, decode again to be compatible with the previous behavior var params types.Params diff --git a/x/evm/spec/02_state.md b/x/evm/spec/02_state.md index cba2923513..00e723d7a3 100644 --- a/x/evm/spec/02_state.md +++ b/x/evm/spec/02_state.md @@ -175,7 +175,6 @@ To support the interface functionality, it imports 4 module Keepers: type Keeper struct { // Protobuf codec cdc codec.Codec - storeService corestoretypes.KVStoreService // Store key required for the EVM Prefix KVStore. It is required by: // - storing account's Storage State // - storing account's Code diff --git a/x/evm/statedb/statedb_test.go b/x/evm/statedb/statedb_test.go index 0b384afce0..462578a7a6 100644 --- a/x/evm/statedb/statedb_test.go +++ b/x/evm/statedb/statedb_test.go @@ -820,7 +820,6 @@ func newTestKeeper(t *testing.T, cms storetypes.MultiStore) (sdk.Context, *evmke ) evmKeeper := evmkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(testStoreKeys[evmtypes.StoreKey]), testStoreKeys[evmtypes.StoreKey], testObjKeys[evmtypes.ObjectStoreKey], authtypes.NewModuleAddress(govtypes.ModuleName), accountKeeper, bankKeeper, nil, nil, "", diff --git a/x/feemarket/keeper/keeper.go b/x/feemarket/keeper/keeper.go index 8c0d2bce72..ecda4dd22d 100644 --- a/x/feemarket/keeper/keeper.go +++ b/x/feemarket/keeper/keeper.go @@ -18,7 +18,6 @@ package keeper import ( "math/big" - corestoretypes "cosmossdk.io/core/store" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" @@ -33,8 +32,7 @@ var KeyPrefixBaseFeeV1 = []byte{2} // Keeper grants access to the Fee Market module state. type Keeper struct { // Protobuf codec - cdc codec.BinaryCodec - storeService corestoretypes.KVStoreService + cdc codec.BinaryCodec // Store key required for the Fee Market Prefix KVStore. storeKey, objectKey storetypes.StoreKey // the address capable of executing a MsgUpdateParams message. Typically, this should be the x/gov module account. @@ -44,7 +42,6 @@ type Keeper struct { // NewKeeper generates new fee market module keeper func NewKeeper( cdc codec.BinaryCodec, - storeService corestoretypes.KVStoreService, authority sdk.AccAddress, storeKey, objectKey storetypes.StoreKey, ) Keeper { @@ -54,11 +51,10 @@ func NewKeeper( } return Keeper{ - cdc: cdc, - storeService: storeService, - storeKey: storeKey, - objectKey: objectKey, - authority: authority, + cdc: cdc, + storeKey: storeKey, + objectKey: objectKey, + authority: authority, } } diff --git a/x/feemarket/keeper/params.go b/x/feemarket/keeper/params.go index fe4b1d76d6..01c9381f66 100644 --- a/x/feemarket/keeper/params.go +++ b/x/feemarket/keeper/params.go @@ -30,12 +30,8 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { objStore := ctx.ObjectStore(k.objectKey) v := objStore.Get(types.KeyPrefixObjectParams) if v == nil { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ParamsKey) - if err != nil { - panic(err) - } params = new(types.Params) + bz := ctx.KVStore(k.storeKey).Get(types.ParamsKey) if bz != nil { k.cdc.MustUnmarshal(bz, params) } @@ -51,11 +47,9 @@ func (k Keeper) SetParams(ctx sdk.Context, p types.Params) error { if err := p.Validate(); err != nil { return err } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&p) - if err := store.Set(types.ParamsKey, bz); err != nil { - return err - } + store.Set(types.ParamsKey, bz) // set to cache as well, decode again to be compatible with the previous behavior var params types.Params