evm: move ChainConfig to Params (#266)

* evm: move ChainConfig to Params

* fixes

* fix test
This commit is contained in:
Federico Kunze Küllmer
2021-07-14 05:13:55 -04:00
committed by GitHub
parent 74b7eaf431
commit e09bf23bd0
26 changed files with 1185 additions and 1884 deletions
+4 -19
View File
@@ -298,19 +298,6 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q
}, nil
}
// ChainConfig implements the Query/ChainConfig gRPC method
func (k Keeper) ChainConfig(c context.Context, _ *types.QueryChainConfigRequest) (*types.QueryChainConfigResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
cfg, found := k.GetChainConfig(ctx)
if !found {
return nil, status.Error(codes.NotFound, types.ErrChainConfigNotFound.Error())
}
return &types.QueryChainConfigResponse{
Config: cfg,
}, nil
}
// StaticCall implements Query/StaticCall gRPCP method
func (k Keeper) StaticCall(c context.Context, req *types.QueryStaticCallRequest) (*types.QueryStaticCallResponse, error) {
if req == nil {
@@ -389,12 +376,10 @@ func (k Keeper) EthCall(c context.Context, req *types.EthCallRequest) (*types.Ms
msg := args.ToMessage(uint64(ethermint.DefaultRPCGasLimit))
cfg, found := k.GetChainConfig(ctx)
if !found {
return nil, status.Error(codes.Internal, types.ErrChainConfigNotFound.Error())
}
ethCfg := cfg.EthereumConfig(k.eip155ChainID)
evm := k.NewEVM(msg, ethCfg)
params := k.GetParams(ctx)
ethCfg := params.ChainConfig.EthereumConfig(k.eip155ChainID)
evm := k.NewEVM(msg, ethCfg, params)
res, err := k.ApplyMessage(evm, msg, ethCfg)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
-9
View File
@@ -608,15 +608,6 @@ func (suite *KeeperTestSuite) TestQueryParams() {
suite.Require().Equal(expParams, res.Params)
}
func (suite *KeeperTestSuite) TestQueryChainConfig() {
ctx := sdk.WrapSDKContext(suite.ctx)
expChainConfig := types.DefaultChainConfig()
res, err := suite.queryClient.ChainConfig(ctx, &types.QueryChainConfigRequest{})
suite.Require().NoError(err)
suite.Require().Equal(expChainConfig, res.Config)
}
func (suite *KeeperTestSuite) TestQueryValidatorAccount() {
var (
req *types.QueryValidatorAccountRequest
-12
View File
@@ -83,15 +83,3 @@ func (suite *KeeperTestSuite) SetupTest() {
func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(KeeperTestSuite))
}
func (suite *KeeperTestSuite) TestChainConfig() {
config, found := suite.app.EvmKeeper.GetChainConfig(suite.ctx)
suite.Require().True(found)
suite.Require().Equal(types.DefaultChainConfig(), config)
config.EIP150Block = sdk.NewInt(100)
suite.app.EvmKeeper.SetChainConfig(suite.ctx, config)
newConfig, found := suite.app.EvmKeeper.GetChainConfig(suite.ctx)
suite.Require().True(found)
suite.Require().Equal(config, newConfig)
}
-20
View File
@@ -16,23 +16,3 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}
// GetChainConfig gets block height from block consensus hash
func (k Keeper) GetChainConfig(ctx sdk.Context) (types.ChainConfig, bool) {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyPrefixChainConfig)
if len(bz) == 0 {
return types.ChainConfig{}, false
}
var config types.ChainConfig
k.cdc.MustUnmarshal(bz, &config)
return config, true
}
// SetChainConfig sets the mapping from block consensus hash to block height
func (k Keeper) SetChainConfig(ctx sdk.Context, config types.ChainConfig) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&config)
store.Set(types.KeyPrefixChainConfig, bz)
}
+6 -11
View File
@@ -25,7 +25,7 @@ import (
)
// NewEVM generates an ethereum VM from the provided Message fields and the ChainConfig.
func (k *Keeper) NewEVM(msg core.Message, config *params.ChainConfig) *vm.EVM {
func (k *Keeper) NewEVM(msg core.Message, config *params.ChainConfig, params types.Params) *vm.EVM {
blockCtx := vm.BlockContext{
CanTransfer: core.CanTransfer,
Transfer: core.Transfer,
@@ -38,16 +38,14 @@ func (k *Keeper) NewEVM(msg core.Message, config *params.ChainConfig) *vm.EVM {
}
txCtx := core.NewEVMTxContext(msg)
vmConfig := k.VMConfig()
vmConfig := k.VMConfig(params)
return vm.NewEVM(blockCtx, txCtx, k, config, vmConfig)
}
// VMConfig creates an EVM configuration from the module parameters and the debug setting.
// The config generated uses the default JumpTable from the EVM.
func (k Keeper) VMConfig() vm.Config {
params := k.GetParams(k.ctx)
func (k Keeper) VMConfig(params types.Params) vm.Config {
return vm.Config{
Debug: k.debug,
Tracer: vm.NewJSONLogger(&vm.LogConfig{Debug: k.debug}, os.Stderr), // TODO: consider using the Struct Logger too
@@ -112,11 +110,8 @@ func (k Keeper) GetHashFn() vm.GetHashFunc {
func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumTxResponse, error) {
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), types.MetricKeyTransitionDB)
cfg, found := k.GetChainConfig(k.ctx)
if !found {
return nil, stacktrace.Propagate(types.ErrChainConfigNotFound, "configuration not found")
}
ethCfg := cfg.EthereumConfig(k.eip155ChainID)
params := k.GetParams(k.ctx)
ethCfg := params.ChainConfig.EthereumConfig(k.eip155ChainID)
// get the latest signer according to the chain rules from the config
signer := ethtypes.MakeSigner(ethCfg, big.NewInt(k.ctx.BlockHeight()))
@@ -132,7 +127,7 @@ func (k *Keeper) ApplyTransaction(tx *ethtypes.Transaction) (*types.MsgEthereumT
cacheCtx, commit := k.ctx.CacheContext()
k.ctx = cacheCtx
evm := k.NewEVM(msg, ethCfg)
evm := k.NewEVM(msg, ethCfg, params)
k.SetTxHashTransient(tx.Hash())
k.IncreaseTxIndexTransient()