Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit f07b14f

Browse files
GAtom22fedekunzeVvaradinovMalteHerrmann
authored
refactor(params): store all params under one key in evm module (#1617)
* refactor(params): store all params under one key in evm module * refactor(params): add changelog entry * refactor(params): update based on review comments. Remove params getter functions * refactor(params): refactor params store key * refactor(params): remove unnecessary store keys * refactor(params): add paramSetPairs for backwards compatibility * Update CHANGELOG.md * refactor(params): add license to params_legacy file * Apply suggestions from code review * fix(evm): handle RC1 params during migration (#1624) * fix(evm): handle RC1 params during migration * migration * fix: test case updated for RC1 * v5 migration * tests * tests pt2 * comment * execute make proto-all Co-authored-by: Vladislav Varadinov <[email protected]> Co-authored-by: MalteHerrmann <[email protected]> * Apply suggestions from code review * rm dup vars Co-authored-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: Vladislav Varadinov <[email protected]> Co-authored-by: MalteHerrmann <[email protected]>
1 parent 9305788 commit f07b14f

29 files changed

+1302
-1373
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
4141
### Bug Fixes
4242

4343
* (rpc) [#1613](https://github.com/evmos/ethermint/pull/1613) Change the default json-rpc listen address to localhost.
44+
* (upgrade) [#1617](https://github.com/evmos/ethermint/pull/1617) Refactor `evm` module's parameters to store them under a single store key
4445
* (rpc) [#1611](https://github.com/evmos/ethermint/pull/1611) Add missing next fee in fee history, fix wrong oldestBlock and align earliest input as ethereum.
4546

4647
### Improvements

app/ante/eth.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
149149
return next(newCtx, tx, simulate)
150150
}
151151

152-
chainCfg := egcd.evmKeeper.GetChainConfig(ctx)
152+
evmParams := egcd.evmKeeper.GetParams(ctx)
153+
chainCfg := evmParams.GetChainConfig()
153154
ethCfg := chainCfg.EthereumConfig(egcd.evmKeeper.ChainID())
154155

155156
blockHeight := big.NewInt(ctx.BlockHeight())
@@ -183,7 +184,7 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
183184
gasWanted += txData.GetGas()
184185
}
185186

186-
evmDenom := egcd.evmKeeper.GetEVMDenom(ctx)
187+
evmDenom := evmParams.GetEvmDenom()
187188

188189
fees, err := keeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, ctx.IsCheckTx())
189190
if err != nil {

app/ante/fee_market.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ func NewGasWantedDecorator(
4242
}
4343

4444
func (gwd GasWantedDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
45-
chainCfg := gwd.evmKeeper.GetChainConfig(ctx)
45+
evmParams := gwd.evmKeeper.GetParams(ctx)
46+
chainCfg := evmParams.GetChainConfig()
4647
ethCfg := chainCfg.EthereumConfig(gwd.evmKeeper.ChainID())
4748

4849
blockHeight := big.NewInt(ctx.BlockHeight())

app/ante/fees.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
8888
if minGasPrice.IsZero() || simulate {
8989
return next(ctx, tx, simulate)
9090
}
91-
92-
evmDenom := mpd.evmKeeper.GetEVMDenom(ctx)
91+
evmParams := mpd.evmKeeper.GetParams(ctx)
92+
evmDenom := evmParams.GetEvmDenom()
9393
minGasPrices := sdk.DecCoins{
9494
{
9595
Denom: evmDenom,
@@ -133,7 +133,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
133133
return next(ctx, tx, simulate)
134134
}
135135

136-
chainCfg := empd.evmKeeper.GetChainConfig(ctx)
136+
evmParams := empd.evmKeeper.GetParams(ctx)
137+
chainCfg := evmParams.GetChainConfig()
137138
ethCfg := chainCfg.EthereumConfig(empd.evmKeeper.ChainID())
138139
baseFee := empd.evmKeeper.GetBaseFee(ctx, ethCfg)
139140

@@ -191,7 +192,8 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
191192
if !ctx.IsCheckTx() || simulate {
192193
return next(ctx, tx, simulate)
193194
}
194-
chainCfg := mfd.evmKeeper.GetChainConfig(ctx)
195+
evmParams := mfd.evmKeeper.GetParams(ctx)
196+
chainCfg := evmParams.GetChainConfig()
195197
ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID())
196198

197199
baseFee := mfd.evmKeeper.GetBaseFee(ctx, ethCfg)
@@ -200,7 +202,7 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
200202
return next(ctx, tx, simulate)
201203
}
202204

203-
evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)
205+
evmDenom := evmParams.GetEvmDenom()
204206
minGasPrice := ctx.MinGasPrices().AmountOf(evmDenom)
205207

206208
for _, msg := range tx.GetMsgs() {

app/ante/interfaces.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ type EVMKeeper interface {
4949
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
5050
ResetTransientGasUsed(ctx sdk.Context)
5151
GetTxIndexTransient(ctx sdk.Context) uint64
52-
GetChainConfig(ctx sdk.Context) evmtypes.ChainConfig
53-
GetAllowUnprotectedTxs(ctx sdk.Context) bool
54-
GetEVMDenom(ctx sdk.Context) string
55-
GetEnableCall(ctx sdk.Context) bool
56-
GetEnableCreate(ctx sdk.Context) bool
52+
GetParams(ctx sdk.Context) evmtypes.Params
5753
}
5854

5955
type protoTxProvider interface {

app/ante/setup.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,14 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
152152
txFee := sdk.Coins{}
153153
txGasLimit := uint64(0)
154154

155-
chainCfg := vbd.evmKeeper.GetChainConfig(ctx)
155+
evmParams := vbd.evmKeeper.GetParams(ctx)
156+
chainCfg := evmParams.GetChainConfig()
156157
chainID := vbd.evmKeeper.ChainID()
157158
ethCfg := chainCfg.EthereumConfig(chainID)
158159
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
159-
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
160-
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
161-
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
160+
enableCreate := evmParams.GetEnableCreate()
161+
enableCall := evmParams.GetEnableCall()
162+
evmDenom := evmParams.GetEvmDenom()
162163

163164
for _, msg := range protoTx.GetMsgs() {
164165
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)

app/ante/sigverify.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ func NewEthSigVerificationDecorator(ek EVMKeeper) EthSigVerificationDecorator {
4444
// won't see the error message.
4545
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
4646
chainID := esvd.evmKeeper.ChainID()
47-
chainCfg := esvd.evmKeeper.GetChainConfig(ctx)
47+
evmParams := esvd.evmKeeper.GetParams(ctx)
48+
chainCfg := evmParams.GetChainConfig()
4849
ethCfg := chainCfg.EthereumConfig(chainID)
4950
blockNum := big.NewInt(ctx.BlockHeight())
5051
signer := ethtypes.MakeSigner(ethCfg, blockNum)
@@ -55,7 +56,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
5556
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
5657
}
5758

58-
allowUnprotectedTxs := esvd.evmKeeper.GetAllowUnprotectedTxs(ctx)
59+
allowUnprotectedTxs := evmParams.GetAllowUnprotectedTxs()
5960
ethTx := msgEthTx.AsTransaction()
6061
if !allowUnprotectedTxs && !ethTx.Protected() {
6162
return ctx, errorsmod.Wrapf(

app/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
863863
paramsKeeper.Subspace(ibctransfertypes.ModuleName)
864864
paramsKeeper.Subspace(ibchost.ModuleName)
865865
// ethermint subspaces
866-
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable())
866+
paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint: staticcheck
867867
paramsKeeper.Subspace(feemarkettypes.ModuleName).WithKeyTable(feemarkettypes.ParamKeyTable())
868868
return paramsKeeper
869869
}

proto/ethermint/evm/v1/evm.proto

+1-11
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,14 @@ message Params {
1515
// enable_call toggles state transitions that use the vm.Call function
1616
bool enable_call = 3 [(gogoproto.moretags) = "yaml:\"enable_call\""];
1717
// extra_eips defines the additional EIPs for the vm.Config
18-
ExtraEIPs extra_eips = 4 [
19-
(gogoproto.customname) = "ExtraEIPs",
20-
(gogoproto.moretags) = "yaml:\"extra_eips\"",
21-
(gogoproto.nullable) = false
22-
];
18+
repeated int64 extra_eips = 4 [(gogoproto.customname) = "ExtraEIPs", (gogoproto.moretags) = "yaml:\"extra_eips\""];
2319
// chain_config defines the EVM chain configuration parameters
2420
ChainConfig chain_config = 5 [(gogoproto.moretags) = "yaml:\"chain_config\"", (gogoproto.nullable) = false];
2521
// allow_unprotected_txs defines if replay-protected (i.e non EIP155
2622
// signed) transactions can be executed on the state machine.
2723
bool allow_unprotected_txs = 6;
2824
}
2925

30-
// ExtraEIPs represents extra EIPs for the vm.Config
31-
message ExtraEIPs {
32-
// eips defines the additional EIPs for the vm.Config
33-
repeated int64 eips = 1 [(gogoproto.customname) = "EIPs", (gogoproto.moretags) = "yaml:\"eips\""];
34-
}
35-
3626
// ChainConfig defines the Ethereum ChainConfig parameters using *sdk.Int values
3727
// instead of *big.Int.
3828
message ChainConfig {

x/evm/handler_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ func (suite *EvmTestSuite) TestERC20TransferReverted() {
597597

598598
before := k.GetBalance(suite.ctx, suite.from)
599599

600-
ethCfg := suite.app.EvmKeeper.GetChainConfig(suite.ctx).EthereumConfig(nil)
600+
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
601+
ethCfg := evmParams.GetChainConfig().EthereumConfig(nil)
601602
baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg)
602603

603604
txData, err := types.UnpackTxData(tx.Data)

x/evm/keeper/keeper.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ func (k *Keeper) GetNonce(ctx sdk.Context, addr common.Address) uint64 {
321321
// GetBalance load account's balance of gas token
322322
func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int {
323323
cosmosAddr := sdk.AccAddress(addr.Bytes())
324-
evmDenom := k.GetEVMDenom(ctx)
324+
evmParams := k.GetParams(ctx)
325+
evmDenom := evmParams.GetEvmDenom()
325326
// if node is pruned, params is empty. Return invalid value
326327
if evmDenom == "" {
327328
return big.NewInt(-1)

x/evm/keeper/migrations.go

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package keeper
1818
import (
1919
sdk "github.com/cosmos/cosmos-sdk/types"
2020
v4 "github.com/evmos/ethermint/x/evm/migrations/v4"
21+
v5 "github.com/evmos/ethermint/x/evm/migrations/v5"
2122
"github.com/evmos/ethermint/x/evm/types"
2223
)
2324

@@ -39,3 +40,8 @@ func NewMigrator(keeper Keeper, legacySubspace types.Subspace) Migrator {
3940
func (m Migrator) Migrate3to4(ctx sdk.Context) error {
4041
return v4.MigrateStore(ctx, m.keeper.storeKey, m.legacySubspace, m.keeper.cdc)
4142
}
43+
44+
// Migrate4to5 migrates the store from consensus version 4 to 5
45+
func (m Migrator) Migrate4to5(ctx sdk.Context) error {
46+
return v5.MigrateStore(ctx, m.keeper.storeKey, m.keeper.cdc)
47+
}

x/evm/keeper/params.go

+13-128
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import (
2222

2323
// GetParams returns the total set of evm parameters.
2424
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
25-
evmDenom := k.GetEVMDenom(ctx)
26-
allowUnprotectedTx := k.GetAllowUnprotectedTxs(ctx)
27-
enableCreate := k.GetEnableCreate(ctx)
28-
enableCall := k.GetEnableCall(ctx)
29-
chainCfg := k.GetChainConfig(ctx)
30-
extraEIPs := k.GetExtraEIPs(ctx)
31-
32-
return types.NewParams(evmDenom, allowUnprotectedTx, enableCreate, enableCall, chainCfg, extraEIPs)
25+
store := ctx.KVStore(k.storeKey)
26+
bz := store.Get(types.KeyPrefixParams)
27+
if len(bz) == 0 {
28+
return k.GetLegacyParams(ctx)
29+
}
30+
k.cdc.MustUnmarshal(bz, &params)
31+
return
3332
}
3433

3534
// SetParams sets the EVM params each in their individual key for better get performance
@@ -38,13 +37,13 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error {
3837
return err
3938
}
4039

41-
k.setExtraEIPs(ctx, params.ExtraEIPs)
42-
k.setChainConfig(ctx, params.ChainConfig)
43-
k.setEvmDenom(ctx, params.EvmDenom)
44-
k.setEnableCall(ctx, params.EnableCall)
45-
k.setEnableCreate(ctx, params.EnableCreate)
46-
k.setAllowUnprotectedTxs(ctx, params.AllowUnprotectedTxs)
40+
store := ctx.KVStore(k.storeKey)
41+
bz, err := k.cdc.Marshal(&params)
42+
if err != nil {
43+
return err
44+
}
4745

46+
store.Set(types.KeyPrefixParams, bz)
4847
return nil
4948
}
5049

@@ -54,117 +53,3 @@ func (k Keeper) GetLegacyParams(ctx sdk.Context) types.Params {
5453
k.ss.GetParamSetIfExists(ctx, &params)
5554
return params
5655
}
57-
58-
// GetExtraEIPs returns the extra EIPs enabled on the chain.
59-
func (k Keeper) GetExtraEIPs(ctx sdk.Context) types.ExtraEIPs {
60-
var extraEIPs types.ExtraEIPs
61-
store := ctx.KVStore(k.storeKey)
62-
bz := store.Get(types.ParamStoreKeyExtraEIPs)
63-
if len(bz) == 0 {
64-
return k.GetLegacyParams(ctx).ExtraEIPs
65-
}
66-
k.cdc.MustUnmarshal(bz, &extraEIPs)
67-
return extraEIPs
68-
}
69-
70-
// GetChainConfig returns the chain configuration parameter.
71-
func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig {
72-
var chainCfg types.ChainConfig
73-
store := ctx.KVStore(k.storeKey)
74-
bz := store.Get(types.ParamStoreKeyChainConfig)
75-
if len(bz) == 0 {
76-
return k.GetLegacyParams(ctx).ChainConfig
77-
}
78-
k.cdc.MustUnmarshal(bz, &chainCfg)
79-
return chainCfg
80-
}
81-
82-
// GetEVMDenom returns the EVM denom.
83-
func (k Keeper) GetEVMDenom(ctx sdk.Context) string {
84-
store := ctx.KVStore(k.storeKey)
85-
bz := store.Get(types.ParamStoreKeyEVMDenom)
86-
if len(bz) == 0 {
87-
return k.GetLegacyParams(ctx).EvmDenom
88-
}
89-
return string(bz)
90-
}
91-
92-
// GetEnableCall returns true if the EVM Call operation is enabled.
93-
func (k Keeper) GetEnableCall(ctx sdk.Context) bool {
94-
store := ctx.KVStore(k.storeKey)
95-
exist := store.Has(types.ParamStoreKeyEnableCall)
96-
if !exist {
97-
exist = k.GetLegacyParams(ctx).EnableCall
98-
}
99-
return exist
100-
}
101-
102-
// GetEnableCreate returns true if the EVM Create contract operation is enabled.
103-
func (k Keeper) GetEnableCreate(ctx sdk.Context) bool {
104-
store := ctx.KVStore(k.storeKey)
105-
exist := store.Has(types.ParamStoreKeyEnableCreate)
106-
if !exist {
107-
exist = k.GetLegacyParams(ctx).EnableCreate
108-
}
109-
return exist
110-
}
111-
112-
// GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain.
113-
func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool {
114-
store := ctx.KVStore(k.storeKey)
115-
exist := store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
116-
if !exist {
117-
exist = k.GetLegacyParams(ctx).AllowUnprotectedTxs
118-
}
119-
return exist
120-
}
121-
122-
// setChainConfig sets the ChainConfig in the store
123-
func (k Keeper) setChainConfig(ctx sdk.Context, chainCfg types.ChainConfig) {
124-
store := ctx.KVStore(k.storeKey)
125-
chainCfgBz := k.cdc.MustMarshal(&chainCfg)
126-
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)
127-
}
128-
129-
// setExtraEIPs sets the ExtraEIPs in the store
130-
func (k Keeper) setExtraEIPs(ctx sdk.Context, extraEIPs types.ExtraEIPs) {
131-
extraEIPsBz := k.cdc.MustMarshal(&extraEIPs)
132-
store := ctx.KVStore(k.storeKey)
133-
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
134-
}
135-
136-
// setEvmDenom sets the EVMDenom param in the store
137-
func (k Keeper) setEvmDenom(ctx sdk.Context, evmDenom string) {
138-
store := ctx.KVStore(k.storeKey)
139-
store.Set(types.ParamStoreKeyEVMDenom, []byte(evmDenom))
140-
}
141-
142-
// setAllowUnprotectedTxs sets the AllowUnprotectedTxs param in the store
143-
func (k Keeper) setAllowUnprotectedTxs(ctx sdk.Context, enable bool) {
144-
store := ctx.KVStore(k.storeKey)
145-
if enable {
146-
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
147-
return
148-
}
149-
store.Delete(types.ParamStoreKeyAllowUnprotectedTxs)
150-
}
151-
152-
// setEnableCreate sets the EnableCreate param in the store
153-
func (k Keeper) setEnableCreate(ctx sdk.Context, enable bool) {
154-
store := ctx.KVStore(k.storeKey)
155-
if enable {
156-
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
157-
return
158-
}
159-
store.Delete(types.ParamStoreKeyEnableCreate)
160-
}
161-
162-
// setEnableCall sets the EnableCall param in the store
163-
func (k Keeper) setEnableCall(ctx sdk.Context, enable bool) {
164-
store := ctx.KVStore(k.storeKey)
165-
if enable {
166-
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
167-
return
168-
}
169-
store.Delete(types.ParamStoreKeyEnableCall)
170-
}

0 commit comments

Comments
 (0)