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

refactor(params): store all params under one key in evm module #1617

Merged
merged 19 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fde18d9
refactor(params): store all params under one key in evm module
GAtom22 Jan 19, 2023
c606869
refactor(params): add changelog entry
GAtom22 Jan 19, 2023
0a491ef
refactor(params): update based on review comments. Remove params gett…
GAtom22 Jan 20, 2023
83eecc0
Merge branch 'main' into GAtom22/evm-params
GAtom22 Jan 20, 2023
1f1ce8f
refactor(params): refactor params store key
GAtom22 Jan 20, 2023
af9d799
Merge branch 'GAtom22/evm-params' of https://github.com/evmos/ethermi…
GAtom22 Jan 20, 2023
fff184c
refactor(params): remove unnecessary store keys
GAtom22 Jan 20, 2023
ed7efb7
Merge branch 'main' into GAtom22/evm-params
GAtom22 Jan 20, 2023
e419274
refactor(params): add paramSetPairs for backwards compatibility
GAtom22 Jan 20, 2023
9530e19
Merge branch 'GAtom22/evm-params' of https://github.com/evmos/ethermi…
GAtom22 Jan 20, 2023
f2e899f
Update CHANGELOG.md
fedekunze Jan 21, 2023
7d75104
refactor(params): add license to params_legacy file
GAtom22 Jan 22, 2023
3d276ec
Merge branch 'GAtom22/evm-params' of https://github.com/evmos/ethermi…
GAtom22 Jan 22, 2023
110cd8e
Merge branch 'main' into GAtom22/evm-params
GAtom22 Jan 22, 2023
2c50d32
Apply suggestions from code review
fedekunze Jan 22, 2023
085f84f
fix(evm): handle RC1 params during migration (#1624)
fedekunze Jan 23, 2023
46418fe
Merge branch 'main' into GAtom22/evm-params
fedekunze Jan 23, 2023
d23fcee
Apply suggestions from code review
fedekunze Jan 23, 2023
35261e2
rm dup vars
fedekunze Jan 23, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (rpc) [#1613](https://github.com/evmos/ethermint/pull/1613) Change the default json-rpc listen address to localhost.
* (upgrade) [#1617](https://github.com/evmos/ethermint/pull/1617) Refactor `evm` module's parameters to store them under a single store key
* (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.


fedekunze marked this conversation as resolved.
Show resolved Hide resolved
## [v0.21.0-rc1] - 2022-1-13

### State Machine Breaking
Expand Down
5 changes: 3 additions & 2 deletions app/ante/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (egcd EthGasConsumeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simula
return next(newCtx, tx, simulate)
}

chainCfg := egcd.evmKeeper.GetChainConfig(ctx)
evmParams := egcd.evmKeeper.GetParams(ctx)
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(egcd.evmKeeper.ChainID())

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

evmDenom := egcd.evmKeeper.GetEVMDenom(ctx)
evmDenom := evmParams.GetEvmDenom()

fees, err := keeper.VerifyFee(txData, evmDenom, baseFee, homestead, istanbul, ctx.IsCheckTx())
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion app/ante/fee_market.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func NewGasWantedDecorator(
}

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

blockHeight := big.NewInt(ctx.BlockHeight())
Expand Down
12 changes: 7 additions & 5 deletions app/ante/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (mpd MinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
if minGasPrice.IsZero() || simulate {
return next(ctx, tx, simulate)
}

evmDenom := mpd.evmKeeper.GetEVMDenom(ctx)
evmParams := mpd.evmKeeper.GetParams(ctx)
evmDenom := evmParams.GetEvmDenom()
minGasPrices := sdk.DecCoins{
{
Denom: evmDenom,
Expand Down Expand Up @@ -133,7 +133,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
return next(ctx, tx, simulate)
}

chainCfg := empd.evmKeeper.GetChainConfig(ctx)
evmParams := empd.evmKeeper.GetParams(ctx)
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(empd.evmKeeper.ChainID())
baseFee := empd.evmKeeper.GetBaseFee(ctx, ethCfg)

Expand Down Expand Up @@ -191,7 +192,8 @@ func (mfd EthMempoolFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulat
if !ctx.IsCheckTx() || simulate {
return next(ctx, tx, simulate)
}
chainCfg := mfd.evmKeeper.GetChainConfig(ctx)
evmParams := mfd.evmKeeper.GetParams(ctx)
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(mfd.evmKeeper.ChainID())

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

evmDenom := mfd.evmKeeper.GetEVMDenom(ctx)
evmDenom := evmParams.GetEvmDenom()
minGasPrice := ctx.MinGasPrices().AmountOf(evmDenom)

for _, msg := range tx.GetMsgs() {
Expand Down
6 changes: 1 addition & 5 deletions app/ante/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ type EVMKeeper interface {
GetBalance(ctx sdk.Context, addr common.Address) *big.Int
ResetTransientGasUsed(ctx sdk.Context)
GetTxIndexTransient(ctx sdk.Context) uint64
GetChainConfig(ctx sdk.Context) evmtypes.ChainConfig
GetAllowUnprotectedTxs(ctx sdk.Context) bool
GetEVMDenom(ctx sdk.Context) string
GetEnableCall(ctx sdk.Context) bool
GetEnableCreate(ctx sdk.Context) bool
GetParams(ctx sdk.Context) evmtypes.Params
}

type protoTxProvider interface {
Expand Down
9 changes: 5 additions & 4 deletions app/ante/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ func (vbd EthValidateBasicDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simu
txFee := sdk.Coins{}
txGasLimit := uint64(0)

chainCfg := vbd.evmKeeper.GetChainConfig(ctx)
evmParams := vbd.evmKeeper.GetParams(ctx)
chainCfg := evmParams.GetChainConfig()
chainID := vbd.evmKeeper.ChainID()
ethCfg := chainCfg.EthereumConfig(chainID)
baseFee := vbd.evmKeeper.GetBaseFee(ctx, ethCfg)
enableCreate := vbd.evmKeeper.GetEnableCreate(ctx)
enableCall := vbd.evmKeeper.GetEnableCall(ctx)
evmDenom := vbd.evmKeeper.GetEVMDenom(ctx)
enableCreate := evmParams.GetEnableCreate()
enableCall := evmParams.GetEnableCall()
evmDenom := evmParams.GetEvmDenom()

for _, msg := range protoTx.GetMsgs() {
msgEthTx, ok := msg.(*evmtypes.MsgEthereumTx)
Expand Down
5 changes: 3 additions & 2 deletions app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ func NewEthSigVerificationDecorator(ek EVMKeeper) EthSigVerificationDecorator {
// won't see the error message.
func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
chainID := esvd.evmKeeper.ChainID()
chainCfg := esvd.evmKeeper.GetChainConfig(ctx)
evmParams := esvd.evmKeeper.GetParams(ctx)
chainCfg := evmParams.GetChainConfig()
ethCfg := chainCfg.EthereumConfig(chainID)
blockNum := big.NewInt(ctx.BlockHeight())
signer := ethtypes.MakeSigner(ethCfg, blockNum)
Expand All @@ -55,7 +56,7 @@ func (esvd EthSigVerificationDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, s
return ctx, errorsmod.Wrapf(errortypes.ErrUnknownRequest, "invalid message type %T, expected %T", msg, (*evmtypes.MsgEthereumTx)(nil))
}

allowUnprotectedTxs := esvd.evmKeeper.GetAllowUnprotectedTxs(ctx)
allowUnprotectedTxs := evmParams.GetAllowUnprotectedTxs()
ethTx := msgEthTx.AsTransaction()
if !allowUnprotectedTxs && !ethTx.Protected() {
return ctx, errorsmod.Wrapf(
Expand Down
3 changes: 2 additions & 1 deletion x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ func (suite *EvmTestSuite) TestERC20TransferReverted() {

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

ethCfg := suite.app.EvmKeeper.GetChainConfig(suite.ctx).EthereumConfig(nil)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := evmParams.GetChainConfig().EthereumConfig(nil)
baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg)

txData, err := types.UnpackTxData(tx.Data)
Expand Down
3 changes: 2 additions & 1 deletion x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ func (k *Keeper) GetNonce(ctx sdk.Context, addr common.Address) uint64 {
// GetBalance load account's balance of gas token
func (k *Keeper) GetBalance(ctx sdk.Context, addr common.Address) *big.Int {
cosmosAddr := sdk.AccAddress(addr.Bytes())
evmDenom := k.GetEVMDenom(ctx)
evmParams := k.GetParams(ctx)
evmDenom := evmParams.GetEvmDenom()
// if node is pruned, params is empty. Return invalid value
if evmDenom == "" {
return big.NewInt(-1)
Expand Down
142 changes: 14 additions & 128 deletions x/evm/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (

// GetParams returns the total set of evm parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
evmDenom := k.GetEVMDenom(ctx)
allowUnprotectedTx := k.GetAllowUnprotectedTxs(ctx)
enableCreate := k.GetEnableCreate(ctx)
enableCall := k.GetEnableCall(ctx)
chainCfg := k.GetChainConfig(ctx)
extraEIPs := k.GetExtraEIPs(ctx)

return types.NewParams(evmDenom, allowUnprotectedTx, enableCreate, enableCall, chainCfg, extraEIPs)
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyPrefixParams)
if len(bz) == 0 {
params = k.GetLegacyParams(ctx)
return
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
}
k.cdc.MustUnmarshal(bz, &params)
return
}

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

k.setExtraEIPs(ctx, params.ExtraEIPs)
k.setChainConfig(ctx, params.ChainConfig)
k.setEvmDenom(ctx, params.EvmDenom)
k.setEnableCall(ctx, params.EnableCall)
k.setEnableCreate(ctx, params.EnableCreate)
k.setAllowUnprotectedTxs(ctx, params.AllowUnprotectedTxs)
store := ctx.KVStore(k.storeKey)
bz, err := k.cdc.Marshal(&params)
if err != nil {
return err
}

store.Set(types.KeyPrefixParams, bz)
return nil
}

Expand All @@ -54,117 +54,3 @@ func (k Keeper) GetLegacyParams(ctx sdk.Context) types.Params {
k.ss.GetParamSetIfExists(ctx, &params)
return params
}

// GetExtraEIPs returns the extra EIPs enabled on the chain.
func (k Keeper) GetExtraEIPs(ctx sdk.Context) types.ExtraEIPs {
var extraEIPs types.ExtraEIPs
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyExtraEIPs)
if len(bz) == 0 {
return k.GetLegacyParams(ctx).ExtraEIPs
}
k.cdc.MustUnmarshal(bz, &extraEIPs)
return extraEIPs
}

// GetChainConfig returns the chain configuration parameter.
func (k Keeper) GetChainConfig(ctx sdk.Context) types.ChainConfig {
var chainCfg types.ChainConfig
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyChainConfig)
if len(bz) == 0 {
return k.GetLegacyParams(ctx).ChainConfig
}
k.cdc.MustUnmarshal(bz, &chainCfg)
return chainCfg
}

// GetEVMDenom returns the EVM denom.
func (k Keeper) GetEVMDenom(ctx sdk.Context) string {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.ParamStoreKeyEVMDenom)
if len(bz) == 0 {
return k.GetLegacyParams(ctx).EvmDenom
}
return string(bz)
}

// GetEnableCall returns true if the EVM Call operation is enabled.
func (k Keeper) GetEnableCall(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
exist := store.Has(types.ParamStoreKeyEnableCall)
if !exist {
exist = k.GetLegacyParams(ctx).EnableCall
}
return exist
}

// GetEnableCreate returns true if the EVM Create contract operation is enabled.
func (k Keeper) GetEnableCreate(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
exist := store.Has(types.ParamStoreKeyEnableCreate)
if !exist {
exist = k.GetLegacyParams(ctx).EnableCreate
}
return exist
}

// GetAllowUnprotectedTxs returns true if unprotected txs (i.e non-replay protected as per EIP-155) are supported by the chain.
func (k Keeper) GetAllowUnprotectedTxs(ctx sdk.Context) bool {
store := ctx.KVStore(k.storeKey)
exist := store.Has(types.ParamStoreKeyAllowUnprotectedTxs)
if !exist {
exist = k.GetLegacyParams(ctx).AllowUnprotectedTxs
}
return exist
}

// setChainConfig sets the ChainConfig in the store
func (k Keeper) setChainConfig(ctx sdk.Context, chainCfg types.ChainConfig) {
store := ctx.KVStore(k.storeKey)
chainCfgBz := k.cdc.MustMarshal(&chainCfg)
store.Set(types.ParamStoreKeyChainConfig, chainCfgBz)
}

// setExtraEIPs sets the ExtraEIPs in the store
func (k Keeper) setExtraEIPs(ctx sdk.Context, extraEIPs types.ExtraEIPs) {
extraEIPsBz := k.cdc.MustMarshal(&extraEIPs)
store := ctx.KVStore(k.storeKey)
store.Set(types.ParamStoreKeyExtraEIPs, extraEIPsBz)
}

// setEvmDenom sets the EVMDenom param in the store
func (k Keeper) setEvmDenom(ctx sdk.Context, evmDenom string) {
store := ctx.KVStore(k.storeKey)
store.Set(types.ParamStoreKeyEVMDenom, []byte(evmDenom))
}

// setAllowUnprotectedTxs sets the AllowUnprotectedTxs param in the store
func (k Keeper) setAllowUnprotectedTxs(ctx sdk.Context, enable bool) {
store := ctx.KVStore(k.storeKey)
if enable {
store.Set(types.ParamStoreKeyAllowUnprotectedTxs, []byte{0x01})
return
}
store.Delete(types.ParamStoreKeyAllowUnprotectedTxs)
}

// setEnableCreate sets the EnableCreate param in the store
func (k Keeper) setEnableCreate(ctx sdk.Context, enable bool) {
store := ctx.KVStore(k.storeKey)
if enable {
store.Set(types.ParamStoreKeyEnableCreate, []byte{0x01})
return
}
store.Delete(types.ParamStoreKeyEnableCreate)
}

// setEnableCall sets the EnableCall param in the store
func (k Keeper) setEnableCall(ctx sdk.Context, enable bool) {
store := ctx.KVStore(k.storeKey)
if enable {
store.Set(types.ParamStoreKeyEnableCall, []byte{0x01})
return
}
store.Delete(types.ParamStoreKeyEnableCall)
}
15 changes: 10 additions & 5 deletions x/evm/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (suite *KeeperTestSuite) TestParams() {
return params.EvmDenom
},
func() interface{} {
return suite.app.EvmKeeper.GetEVMDenom(suite.ctx)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEvmDenom()
},
true,
},
Expand All @@ -45,7 +46,8 @@ func (suite *KeeperTestSuite) TestParams() {
return params.EnableCreate
},
func() interface{} {
return suite.app.EvmKeeper.GetEnableCreate(suite.ctx)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEnableCreate()
},
true,
},
Expand All @@ -57,7 +59,8 @@ func (suite *KeeperTestSuite) TestParams() {
return params.EnableCall
},
func() interface{} {
return suite.app.EvmKeeper.GetEnableCall(suite.ctx)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetEnableCall()
},
true,
},
Expand All @@ -69,7 +72,8 @@ func (suite *KeeperTestSuite) TestParams() {
return params.AllowUnprotectedTxs
},
func() interface{} {
return suite.app.EvmKeeper.GetAllowUnprotectedTxs(suite.ctx)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetAllowUnprotectedTxs()
},
true,
},
Expand All @@ -81,7 +85,8 @@ func (suite *KeeperTestSuite) TestParams() {
return params.ChainConfig
},
func() interface{} {
return suite.app.EvmKeeper.GetChainConfig(suite.ctx)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
return evmParams.GetChainConfig()
},
true,
},
Expand Down
3 changes: 2 additions & 1 deletion x/evm/keeper/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ func (suite *KeeperTestSuite) TestVerifyFeeAndDeductTxCostsFromUserBalance() {

txData, _ := evmtypes.UnpackTxData(tx.Data)

ethCfg := suite.app.EvmKeeper.GetChainConfig(suite.ctx).EthereumConfig(nil)
evmParams := suite.app.EvmKeeper.GetParams(suite.ctx)
ethCfg := evmParams.GetChainConfig().EthereumConfig(nil)
baseFee := suite.app.EvmKeeper.GetBaseFee(suite.ctx, ethCfg)
priority := evmtypes.GetTxPriority(txData, baseFee)

Expand Down
Loading