chore(evm) - Delete deprecated store migrations (#1498)

* (fix): Delete deprecated migrations

* Update x/evm/module.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
Vladislav Varadinov 2022-11-25 14:29:47 +01:00 committed by GitHub
parent 9fb4c05647
commit 8866ae0ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 1 additions and 8427 deletions

View File

@ -58,6 +58,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Improvements ### Improvements
* (emv) [#1498](https://github.com/evmos/ethermint/pull/1498) Remove deprecated store migrations
* (ante) [#1455](https://github.com/evmos/ethermint/pull/1455) Refactor `AnteHandler` logic * (ante) [#1455](https://github.com/evmos/ethermint/pull/1455) Refactor `AnteHandler` logic
* (evm) [#1444](https://github.com/evmos/ethermint/pull/1444) Improve performance of `eth_estimateGas` * (evm) [#1444](https://github.com/evmos/ethermint/pull/1444) Improve performance of `eth_estimateGas`
* (ante) [\#1388](https://github.com/evmos/ethermint/pull/1388) Optimize AnteHandler gas consumption * (ante) [\#1388](https://github.com/evmos/ethermint/pull/1388) Optimize AnteHandler gas consumption

View File

@ -1,11 +1,5 @@
package keeper package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v2 "github.com/evmos/ethermint/x/evm/migrations/v2"
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
)
// Migrator is a struct for handling in-place store migrations. // Migrator is a struct for handling in-place store migrations.
type Migrator struct { type Migrator struct {
keeper Keeper keeper Keeper
@ -17,13 +11,3 @@ func NewMigrator(keeper Keeper) Migrator {
keeper: keeper, keeper: keeper,
} }
} }
// Migrate1to2 migrates the store from consensus version v1 to v2
func (m Migrator) Migrate1to2(ctx sdk.Context) error {
return v2.MigrateStore(ctx, &m.keeper.paramSpace)
}
// Migrate2to3 migrates the store from consensus version v2 to v3
func (m Migrator) Migrate2to3(ctx sdk.Context) error {
return v3.MigrateStore(ctx, &m.keeper.paramSpace)
}

View File

@ -1,31 +0,0 @@
package keeper_test
import (
sdk "github.com/cosmos/cosmos-sdk/types"
evmkeeper "github.com/evmos/ethermint/x/evm/keeper"
)
func (suite *KeeperTestSuite) TestMigrations() {
migrator := evmkeeper.NewMigrator(*suite.app.EvmKeeper)
testCases := []struct {
name string
migrateFunc func(ctx sdk.Context) error
}{
{
"Run Migrate1to2",
migrator.Migrate1to2,
},
{
"Run Migrate2to3",
migrator.Migrate2to3,
},
}
for _, tc := range testCases {
suite.Run(tc.name, func() {
err := tc.migrateFunc(suite.ctx)
suite.Require().NoError(err)
})
}
}

View File

@ -1,19 +0,0 @@
package v2
import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/evmos/ethermint/x/evm/types"
)
// MigrateStore sets the default AllowUnprotectedTxs parameter.
func MigrateStore(ctx sdk.Context, paramstore *paramtypes.Subspace) error {
if !paramstore.HasKeyTable() {
ps := paramstore.WithKeyTable(types.ParamKeyTable())
paramstore = &ps
}
// add RejectUnprotected
paramstore.Set(ctx, types.ParamStoreKeyAllowUnprotectedTxs, types.DefaultAllowUnprotectedTxs)
return nil
}

View File

@ -1,47 +0,0 @@
package v2_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/evmos/ethermint/encoding"
"github.com/evmos/ethermint/app"
v2 "github.com/evmos/ethermint/x/evm/migrations/v2"
v2types "github.com/evmos/ethermint/x/evm/migrations/v2/types"
"github.com/evmos/ethermint/x/evm/types"
)
func TestMigrateStore(t *testing.T) {
encCfg := encoding.MakeConfig(app.ModuleBasics)
feemarketKey := sdk.NewKVStoreKey(types.StoreKey)
tFeeMarketKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", types.StoreKey))
ctx := testutil.DefaultContext(feemarketKey, tFeeMarketKey)
paramstore := paramtypes.NewSubspace(
encCfg.Codec, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
).WithKeyTable(v2types.ParamKeyTable())
params := v2types.DefaultParams()
paramstore.SetParamSet(ctx, &params)
require.Panics(t, func() {
var result bool
paramstore.Get(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &result)
})
paramstore = paramtypes.NewSubspace(
encCfg.Codec, encCfg.Amino, feemarketKey, tFeeMarketKey, "evm",
).WithKeyTable(types.ParamKeyTable())
err := v2.MigrateStore(ctx, &paramstore)
require.NoError(t, err)
var result bool
paramstore.Get(ctx, types.ParamStoreKeyAllowUnprotectedTxs, &result)
require.Equal(t, types.DefaultAllowUnprotectedTxs, result)
}

View File

@ -1,167 +0,0 @@
package types
import (
"math/big"
"strings"
sdkmath "cosmossdk.io/math"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/evmos/ethermint/x/evm/types"
)
// EthereumConfig returns an Ethereum ChainConfig for EVM state transitions.
// All the negative or nil values are converted to nil
func (cc ChainConfig) EthereumConfig(chainID *big.Int) *params.ChainConfig {
return &params.ChainConfig{
ChainID: chainID,
HomesteadBlock: getBlockValue(cc.HomesteadBlock),
DAOForkBlock: getBlockValue(cc.DAOForkBlock),
DAOForkSupport: cc.DAOForkSupport,
EIP150Block: getBlockValue(cc.EIP150Block),
EIP150Hash: common.HexToHash(cc.EIP150Hash),
EIP155Block: getBlockValue(cc.EIP155Block),
EIP158Block: getBlockValue(cc.EIP158Block),
ByzantiumBlock: getBlockValue(cc.ByzantiumBlock),
ConstantinopleBlock: getBlockValue(cc.ConstantinopleBlock),
PetersburgBlock: getBlockValue(cc.PetersburgBlock),
IstanbulBlock: getBlockValue(cc.IstanbulBlock),
MuirGlacierBlock: getBlockValue(cc.MuirGlacierBlock),
BerlinBlock: getBlockValue(cc.BerlinBlock),
LondonBlock: getBlockValue(cc.LondonBlock),
ArrowGlacierBlock: getBlockValue(cc.ArrowGlacierBlock),
MergeNetsplitBlock: getBlockValue(cc.MergeForkBlock),
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: nil,
}
}
// DefaultChainConfig returns default evm parameters.
func DefaultChainConfig() ChainConfig {
homesteadBlock := sdk.ZeroInt()
daoForkBlock := sdk.ZeroInt()
eip150Block := sdk.ZeroInt()
eip155Block := sdk.ZeroInt()
eip158Block := sdk.ZeroInt()
byzantiumBlock := sdk.ZeroInt()
constantinopleBlock := sdk.ZeroInt()
petersburgBlock := sdk.ZeroInt()
istanbulBlock := sdk.ZeroInt()
muirGlacierBlock := sdk.ZeroInt()
berlinBlock := sdk.ZeroInt()
londonBlock := sdk.ZeroInt()
arrowGlacierBlock := sdk.ZeroInt()
mergeForkBlock := sdk.ZeroInt()
return ChainConfig{
HomesteadBlock: &homesteadBlock,
DAOForkBlock: &daoForkBlock,
DAOForkSupport: true,
EIP150Block: &eip150Block,
EIP150Hash: common.Hash{}.String(),
EIP155Block: &eip155Block,
EIP158Block: &eip158Block,
ByzantiumBlock: &byzantiumBlock,
ConstantinopleBlock: &constantinopleBlock,
PetersburgBlock: &petersburgBlock,
IstanbulBlock: &istanbulBlock,
MuirGlacierBlock: &muirGlacierBlock,
BerlinBlock: &berlinBlock,
LondonBlock: &londonBlock,
ArrowGlacierBlock: &arrowGlacierBlock,
MergeForkBlock: &mergeForkBlock,
}
}
func getBlockValue(block *sdkmath.Int) *big.Int {
if block == nil || block.IsNegative() {
return nil
}
return block.BigInt()
}
// Validate performs a basic validation of the ChainConfig params. The function will return an error
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return errorsmod.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return errorsmod.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return errorsmod.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return errorsmod.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return errorsmod.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return errorsmod.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return errorsmod.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return errorsmod.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return errorsmod.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return errorsmod.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return errorsmod.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return errorsmod.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return errorsmod.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return errorsmod.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return errorsmod.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
}
func validateBlock(block *sdkmath.Int) error {
// nil value means that the fork has not yet been applied
if block == nil {
return nil
}
if block.IsNegative() {
return errorsmod.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -1,145 +0,0 @@
package types
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/params"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/types"
)
var _ paramtypes.ParamSet = &Params{}
const (
DefaultEVMDenom = types.AttoPhoton
)
// DefaultMinGasMultiplier is 0.5 or 50%
var DefaultMinGasMultiplier = sdk.NewDecWithPrec(50, 2)
// Parameter keys
var (
ParamStoreKeyEVMDenom = []byte("EVMDenom")
ParamStoreKeyEnableCreate = []byte("EnableCreate")
ParamStoreKeyEnableCall = []byte("EnableCall")
ParamStoreKeyExtraEIPs = []byte("EnableExtraEIPs")
ParamStoreKeyChainConfig = []byte("ChainConfig")
// AvailableExtraEIPs define the list of all EIPs that can be enabled by the
// EVM interpreter. These EIPs are applied in order and can override the
// instruction sets from the latest hard fork enabled by the ChainConfig. For
// more info check:
// https://github.com/ethereum/go-ethereum/blob/master/core/vm/interpreter.go#L97
AvailableExtraEIPs = []int64{1344, 1884, 2200, 2929, 3198, 3529}
)
// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
// NewParams creates a new Params instance
func NewParams(evmDenom string, enableCreate, enableCall bool, config ChainConfig, extraEIPs ...int64) Params {
return Params{
EvmDenom: evmDenom,
EnableCreate: enableCreate,
EnableCall: enableCall,
ExtraEIPs: extraEIPs,
ChainConfig: config,
}
}
// DefaultParams returns default evm parameters
// ExtraEIPs is empty to prevent overriding the latest hard fork instruction set
func DefaultParams() Params {
return Params{
EvmDenom: DefaultEVMDenom,
EnableCreate: true,
EnableCall: true,
ChainConfig: DefaultChainConfig(),
ExtraEIPs: nil,
}
}
// ParamSetPairs returns the parameter set pairs.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
paramtypes.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyExtraEIPs, &p.ExtraEIPs, validateEIPs),
paramtypes.NewParamSetPair(ParamStoreKeyChainConfig, &p.ChainConfig, validateChainConfig),
}
}
// Validate performs basic validation on evm parameters.
func (p Params) Validate() error {
if err := sdk.ValidateDenom(p.EvmDenom); err != nil {
return err
}
if err := validateEIPs(p.ExtraEIPs); err != nil {
return err
}
return p.ChainConfig.Validate()
}
// EIPs returns the ExtraEips as a int slice
func (p Params) EIPs() []int {
eips := make([]int, len(p.ExtraEIPs))
for i, eip := range p.ExtraEIPs {
eips[i] = int(eip)
}
return eips
}
func validateEVMDenom(i interface{}) error {
denom, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter EVM denom type: %T", i)
}
return sdk.ValidateDenom(denom)
}
func validateBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateEIPs(i interface{}) error {
eips, ok := i.([]int64)
if !ok {
return fmt.Errorf("invalid EIP slice type: %T", i)
}
for _, eip := range eips {
if !vm.ValidEip(int(eip)) {
return fmt.Errorf("EIP %d is not activateable, valid EIPS are: %s", eip, vm.ActivateableEips())
}
}
return nil
}
func validateChainConfig(i interface{}) error {
cfg, ok := i.(ChainConfig)
if !ok {
return fmt.Errorf("invalid chain config type: %T", i)
}
return cfg.Validate()
}
// IsLondon returns if london hardfork is enabled.
func IsLondon(ethConfig *params.ChainConfig, height int64) bool {
return ethConfig.IsLondon(big.NewInt(height))
}

View File

@ -1,25 +0,0 @@
package v3
import (
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/evmos/ethermint/x/evm/types"
)
// MigrateStore sets the default for GrayGlacierBlock and MergeNetsplitBlock in ChainConfig parameter.
func MigrateStore(ctx sdk.Context, paramstore *paramtypes.Subspace) error {
if !paramstore.HasKeyTable() {
ps := paramstore.WithKeyTable(types.ParamKeyTable())
paramstore = &ps
}
prevConfig := &types.ChainConfig{}
paramstore.GetIfExists(ctx, types.ParamStoreKeyChainConfig, prevConfig)
defaultConfig := types.DefaultChainConfig()
prevConfig.GrayGlacierBlock = defaultConfig.GrayGlacierBlock
prevConfig.MergeNetsplitBlock = defaultConfig.MergeNetsplitBlock
paramstore.Set(ctx, types.ParamStoreKeyChainConfig, prevConfig)
return nil
}

View File

@ -1,58 +0,0 @@
package v3_test
import (
"fmt"
"testing"
v3 "github.com/evmos/ethermint/x/evm/migrations/v3"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/testutil"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/evmos/ethermint/encoding"
"github.com/evmos/ethermint/app"
v3types "github.com/evmos/ethermint/x/evm/migrations/v3/types"
"github.com/evmos/ethermint/x/evm/types"
)
func TestMigrateStore(t *testing.T) {
encCfg := encoding.MakeConfig(app.ModuleBasics)
evmKey := sdk.NewKVStoreKey(types.StoreKey)
tEvmKey := sdk.NewTransientStoreKey(fmt.Sprintf("%s_test", types.StoreKey))
ctx := testutil.DefaultContext(evmKey, tEvmKey)
paramstore := paramtypes.NewSubspace(
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
).WithKeyTable(v3types.ParamKeyTable())
params := v3types.DefaultParams()
paramstore.SetParamSet(ctx, &params)
require.Panics(t, func() {
var preMigrationConfig types.ChainConfig
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
})
var preMigrationConfig v3types.ChainConfig
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
require.NotNil(t, preMigrationConfig.MergeForkBlock)
paramstore = paramtypes.NewSubspace(
encCfg.Codec, encCfg.Amino, evmKey, tEvmKey, "evm",
).WithKeyTable(types.ParamKeyTable())
err := v3.MigrateStore(ctx, &paramstore)
require.NoError(t, err)
updatedDefaultConfig := types.DefaultChainConfig()
var postMigrationConfig types.ChainConfig
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &postMigrationConfig)
require.Equal(t, postMigrationConfig.GrayGlacierBlock, updatedDefaultConfig.GrayGlacierBlock)
require.Equal(t, postMigrationConfig.MergeNetsplitBlock, updatedDefaultConfig.MergeNetsplitBlock)
require.Panics(t, func() {
var preMigrationConfig v3types.ChainConfig
paramstore.Get(ctx, types.ParamStoreKeyChainConfig, &preMigrationConfig)
})
}

View File

@ -1,166 +0,0 @@
package types
import (
"math/big"
"strings"
sdkmath "cosmossdk.io/math"
"github.com/evmos/ethermint/x/evm/types"
errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)
// EthereumConfig returns an Ethereum ChainConfig for EVM state transitions.
// All the negative or nil values are converted to nil
func (cc ChainConfig) EthereumConfig(chainID *big.Int) *params.ChainConfig {
return &params.ChainConfig{
ChainID: chainID,
HomesteadBlock: getBlockValue(cc.HomesteadBlock),
DAOForkBlock: getBlockValue(cc.DAOForkBlock),
DAOForkSupport: cc.DAOForkSupport,
EIP150Block: getBlockValue(cc.EIP150Block),
EIP150Hash: common.HexToHash(cc.EIP150Hash),
EIP155Block: getBlockValue(cc.EIP155Block),
EIP158Block: getBlockValue(cc.EIP158Block),
ByzantiumBlock: getBlockValue(cc.ByzantiumBlock),
ConstantinopleBlock: getBlockValue(cc.ConstantinopleBlock),
PetersburgBlock: getBlockValue(cc.PetersburgBlock),
IstanbulBlock: getBlockValue(cc.IstanbulBlock),
MuirGlacierBlock: getBlockValue(cc.MuirGlacierBlock),
BerlinBlock: getBlockValue(cc.BerlinBlock),
LondonBlock: getBlockValue(cc.LondonBlock),
ArrowGlacierBlock: getBlockValue(cc.ArrowGlacierBlock),
TerminalTotalDifficulty: nil,
Ethash: nil,
Clique: nil,
}
}
// DefaultChainConfig returns default evm parameters.
func DefaultChainConfig() ChainConfig {
homesteadBlock := sdk.ZeroInt()
daoForkBlock := sdk.ZeroInt()
eip150Block := sdk.ZeroInt()
eip155Block := sdk.ZeroInt()
eip158Block := sdk.ZeroInt()
byzantiumBlock := sdk.ZeroInt()
constantinopleBlock := sdk.ZeroInt()
petersburgBlock := sdk.ZeroInt()
istanbulBlock := sdk.ZeroInt()
muirGlacierBlock := sdk.ZeroInt()
berlinBlock := sdk.ZeroInt()
londonBlock := sdk.ZeroInt()
arrowGlacierBlock := sdk.ZeroInt()
mergeForkBlock := sdk.ZeroInt()
return ChainConfig{
HomesteadBlock: &homesteadBlock,
DAOForkBlock: &daoForkBlock,
DAOForkSupport: true,
EIP150Block: &eip150Block,
EIP150Hash: common.Hash{}.String(),
EIP155Block: &eip155Block,
EIP158Block: &eip158Block,
ByzantiumBlock: &byzantiumBlock,
ConstantinopleBlock: &constantinopleBlock,
PetersburgBlock: &petersburgBlock,
IstanbulBlock: &istanbulBlock,
MuirGlacierBlock: &muirGlacierBlock,
BerlinBlock: &berlinBlock,
LondonBlock: &londonBlock,
ArrowGlacierBlock: &arrowGlacierBlock,
MergeForkBlock: &mergeForkBlock,
}
}
func getBlockValue(block *sdkmath.Int) *big.Int {
if block == nil || block.IsNegative() {
return nil
}
return block.BigInt()
}
// Validate performs a basic validation of the ChainConfig params. The function will return an error
// if any of the block values is uninitialized (i.e nil) or if the EIP150Hash is an invalid hash.
func (cc ChainConfig) Validate() error {
if err := validateBlock(cc.HomesteadBlock); err != nil {
return errorsmod.Wrap(err, "homesteadBlock")
}
if err := validateBlock(cc.DAOForkBlock); err != nil {
return errorsmod.Wrap(err, "daoForkBlock")
}
if err := validateBlock(cc.EIP150Block); err != nil {
return errorsmod.Wrap(err, "eip150Block")
}
if err := validateHash(cc.EIP150Hash); err != nil {
return err
}
if err := validateBlock(cc.EIP155Block); err != nil {
return errorsmod.Wrap(err, "eip155Block")
}
if err := validateBlock(cc.EIP158Block); err != nil {
return errorsmod.Wrap(err, "eip158Block")
}
if err := validateBlock(cc.ByzantiumBlock); err != nil {
return errorsmod.Wrap(err, "byzantiumBlock")
}
if err := validateBlock(cc.ConstantinopleBlock); err != nil {
return errorsmod.Wrap(err, "constantinopleBlock")
}
if err := validateBlock(cc.PetersburgBlock); err != nil {
return errorsmod.Wrap(err, "petersburgBlock")
}
if err := validateBlock(cc.IstanbulBlock); err != nil {
return errorsmod.Wrap(err, "istanbulBlock")
}
if err := validateBlock(cc.MuirGlacierBlock); err != nil {
return errorsmod.Wrap(err, "muirGlacierBlock")
}
if err := validateBlock(cc.BerlinBlock); err != nil {
return errorsmod.Wrap(err, "berlinBlock")
}
if err := validateBlock(cc.LondonBlock); err != nil {
return errorsmod.Wrap(err, "londonBlock")
}
if err := validateBlock(cc.ArrowGlacierBlock); err != nil {
return errorsmod.Wrap(err, "arrowGlacierBlock")
}
if err := validateBlock(cc.MergeForkBlock); err != nil {
return errorsmod.Wrap(err, "mergeForkBlock")
}
// NOTE: chain ID is not needed to check config order
if err := cc.EthereumConfig(nil).CheckConfigForkOrder(); err != nil {
return errorsmod.Wrap(err, "invalid config fork order")
}
return nil
}
func validateHash(hex string) error {
if hex != "" && strings.TrimSpace(hex) == "" {
return errorsmod.Wrap(types.ErrInvalidChainConfig, "hash cannot be blank")
}
return nil
}
func validateBlock(block *sdkmath.Int) error {
// nil value means that the fork has not yet been applied
if block == nil {
return nil
}
if block.IsNegative() {
return errorsmod.Wrapf(
types.ErrInvalidChainConfig, "block value cannot be negative: %s", block,
)
}
return nil
}

File diff suppressed because it is too large Load Diff

View File

@ -1,150 +0,0 @@
package types
import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/params"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/evmos/ethermint/types"
)
var _ paramtypes.ParamSet = &Params{}
var (
// DefaultEVMDenom defines the default EVM denomination on Ethermint
DefaultEVMDenom = types.AttoPhoton
// DefaultMinGasMultiplier is 0.5 or 50%
DefaultMinGasMultiplier = sdk.NewDecWithPrec(50, 2)
// DefaultAllowUnprotectedTxs rejects all unprotected txs (i.e false)
DefaultAllowUnprotectedTxs = false
)
// Parameter keys
var (
ParamStoreKeyEVMDenom = []byte("EVMDenom")
ParamStoreKeyEnableCreate = []byte("EnableCreate")
ParamStoreKeyEnableCall = []byte("EnableCall")
ParamStoreKeyExtraEIPs = []byte("EnableExtraEIPs")
ParamStoreKeyChainConfig = []byte("ChainConfig")
ParamStoreKeyAllowUnprotectedTxs = []byte("AllowUnprotectedTxs")
// AvailableExtraEIPs define the list of all EIPs that can be enabled by the
// EVM interpreter. These EIPs are applied in order and can override the
// instruction sets from the latest hard fork enabled by the ChainConfig. For
// more info check:
// https://github.com/ethereum/go-ethereum/blob/master/core/vm/interpreter.go#L97
AvailableExtraEIPs = []int64{1344, 1884, 2200, 2929, 3198, 3529}
)
// ParamKeyTable returns the parameter key table.
func ParamKeyTable() paramtypes.KeyTable {
return paramtypes.NewKeyTable().RegisterParamSet(&Params{})
}
// NewParams creates a new Params instance
func NewParams(evmDenom string, enableCreate, enableCall bool, config ChainConfig, extraEIPs ...int64) Params {
return Params{
EvmDenom: evmDenom,
EnableCreate: enableCreate,
EnableCall: enableCall,
ExtraEIPs: extraEIPs,
ChainConfig: config,
}
}
// DefaultParams returns default evm parameters
// ExtraEIPs is empty to prevent overriding the latest hard fork instruction set
func DefaultParams() Params {
return Params{
EvmDenom: DefaultEVMDenom,
EnableCreate: true,
EnableCall: true,
ChainConfig: DefaultChainConfig(),
ExtraEIPs: nil,
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
}
}
// ParamSetPairs returns the parameter set pairs.
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{
paramtypes.NewParamSetPair(ParamStoreKeyEVMDenom, &p.EvmDenom, validateEVMDenom),
paramtypes.NewParamSetPair(ParamStoreKeyEnableCreate, &p.EnableCreate, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyEnableCall, &p.EnableCall, validateBool),
paramtypes.NewParamSetPair(ParamStoreKeyExtraEIPs, &p.ExtraEIPs, validateEIPs),
paramtypes.NewParamSetPair(ParamStoreKeyChainConfig, &p.ChainConfig, validateChainConfig),
paramtypes.NewParamSetPair(ParamStoreKeyAllowUnprotectedTxs, &p.AllowUnprotectedTxs, validateBool),
}
}
// Validate performs basic validation on evm parameters.
func (p Params) Validate() error {
if err := sdk.ValidateDenom(p.EvmDenom); err != nil {
return err
}
if err := validateEIPs(p.ExtraEIPs); err != nil {
return err
}
return p.ChainConfig.Validate()
}
// EIPs returns the ExtraEips as a int slice
func (p Params) EIPs() []int {
eips := make([]int, len(p.ExtraEIPs))
for i, eip := range p.ExtraEIPs {
eips[i] = int(eip)
}
return eips
}
func validateEVMDenom(i interface{}) error {
denom, ok := i.(string)
if !ok {
return fmt.Errorf("invalid parameter EVM denom type: %T", i)
}
return sdk.ValidateDenom(denom)
}
func validateBool(i interface{}) error {
_, ok := i.(bool)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
return nil
}
func validateEIPs(i interface{}) error {
eips, ok := i.([]int64)
if !ok {
return fmt.Errorf("invalid EIP slice type: %T", i)
}
for _, eip := range eips {
if !vm.ValidEip(int(eip)) {
return fmt.Errorf("EIP %d is not activateable, valid EIPS are: %s", eip, vm.ActivateableEips())
}
}
return nil
}
func validateChainConfig(i interface{}) error {
cfg, ok := i.(ChainConfig)
if !ok {
return fmt.Errorf("invalid chain config type: %T", i)
}
return cfg.Validate()
}
// IsLondon returns if london hardfork is enabled.
func IsLondon(ethConfig *params.ChainConfig, height int64) bool {
return ethConfig.IsLondon(big.NewInt(height))
}

View File

@ -122,16 +122,6 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
func (am AppModule) RegisterServices(cfg module.Configurator) { func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), am.keeper) types.RegisterMsgServer(cfg.MsgServer(), am.keeper)
types.RegisterQueryServer(cfg.QueryServer(), am.keeper) types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
m := keeper.NewMigrator(*am.keeper)
err := cfg.RegisterMigration(types.ModuleName, 1, m.Migrate1to2)
if err != nil {
panic(err)
}
err = cfg.RegisterMigration(types.ModuleName, 2, m.Migrate2to3)
if err != nil {
panic(err)
}
} }
// Route returns the message routing key for the evm module. // Route returns the message routing key for the evm module.