Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: get set params are not align in evm #456

Merged
merged 3 commits into from
Apr 5, 2024
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
1 change: 0 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,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,
Expand Down
8 changes: 2 additions & 6 deletions x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -41,15 +40,14 @@ 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
// - 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.
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
14 changes: 3 additions & 11 deletions x/evm/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down
66 changes: 32 additions & 34 deletions x/evm/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,40 +173,38 @@ To support the interface functionality, it imports 4 module Keepers:

```go
type Keeper struct {
// Protobuf codec
cdc codec.BinaryCodec
// 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
transientKey sdk.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
// 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
}
```

Expand Down
1 change: 0 additions & 1 deletion x/evm/statedb/statedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
"",
Expand Down
Loading