From 9d01ed67f96ee27caaeb7f7cd33219915fcb1e59 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 24 Jul 2023 20:27:05 +0300 Subject: [PATCH 1/5] move genesis verify to vm --- core/genesis.go | 32 +++++++++++++++++--------------- plugin/evm/vm.go | 4 ++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 65b9aa8aad..e345953c69 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -183,21 +183,6 @@ func SetupGenesisBlock( if genesis.Config == nil { return nil, common.Hash{}, errGenesisNoConfig } - // Make sure genesis gas limit is consistent in SubnetEVM fork - if genesis.Config.IsSubnetEVM(genesis.Timestamp) { - gasLimitConfig := genesis.Config.FeeConfig.GasLimit.Uint64() - if gasLimitConfig != genesis.GasLimit { - return nil, common.Hash{}, fmt.Errorf( - "gas limit in fee config (%d) does not match gas limit in header (%d)", - gasLimitConfig, - genesis.GasLimit, - ) - } - // Verify config - if err := genesis.Config.Verify(); err != nil { - return nil, common.Hash{}, err - } - } // Just commit the new block if there is no stored genesis block. stored := rawdb.ReadCanonicalHash(db, 0) @@ -396,6 +381,23 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block { return block } +func (g *Genesis) Verify() error { + // Make sure genesis gas limit is consistent in SubnetEVM fork + gasLimitConfig := g.Config.FeeConfig.GasLimit.Uint64() + if gasLimitConfig != g.GasLimit { + return fmt.Errorf( + "gas limit in fee config (%d) does not match gas limit in header (%d)", + gasLimitConfig, + g.GasLimit, + ) + } + // Verify config + if err := g.Config.Verify(); err != nil { + return err + } + return nil +} + // GenesisBlockForTesting creates and writes a block in which addr has the given wei balance. func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big.Int) *types.Block { g := Genesis{ diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index b55907f594..f5afc1f13f 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -314,6 +314,10 @@ func (vm *VM) Initialize( g.Config.FeeConfig = params.DefaultFeeConfig } + if err := g.Verify(); err != nil { + return fmt.Errorf("failed to verify genesis: %w", err) + } + vm.ethConfig = ethconfig.NewDefaultConfig() vm.ethConfig.Genesis = g // NetworkID here is different than Avalanche's NetworkID. From 4f2265bc73e3fb4ed04ce8af528cacfe606a8be9 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 24 Jul 2023 20:28:53 +0300 Subject: [PATCH 2/5] fix comment --- core/genesis.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/genesis.go b/core/genesis.go index e345953c69..db52a157d7 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -382,7 +382,7 @@ func (g *Genesis) MustCommit(db ethdb.Database) *types.Block { } func (g *Genesis) Verify() error { - // Make sure genesis gas limit is consistent in SubnetEVM fork + // Make sure genesis gas limit is consistent gasLimitConfig := g.Config.FeeConfig.GasLimit.Uint64() if gasLimitConfig != g.GasLimit { return fmt.Errorf( From 62721ab5d3d7e0716fe574e69be54d070946a546 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 24 Jul 2023 22:04:24 +0300 Subject: [PATCH 3/5] set a correct default from genesis --- plugin/evm/vm.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index f5afc1f13f..28acc7088e 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -312,6 +312,7 @@ func (vm *VM) Initialize( if g.Config.FeeConfig == commontype.EmptyFeeConfig { log.Info("No fee config given in genesis, setting default fee config", "DefaultFeeConfig", params.DefaultFeeConfig) g.Config.FeeConfig = params.DefaultFeeConfig + g.Config.FeeConfig.GasLimit = new(big.Int).SetUint64(g.GasLimit) } if err := g.Verify(); err != nil { From 74f81db03c9b0dd4741c6369f9b6ce3b3a9adb22 Mon Sep 17 00:00:00 2001 From: Ceyhun Onur Date: Mon, 24 Jul 2023 22:33:25 +0300 Subject: [PATCH 4/5] fix log --- plugin/evm/vm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index 28acc7088e..a66b5a8ed6 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -310,9 +310,9 @@ func (vm *VM) Initialize( vm.syntacticBlockValidator = NewBlockValidator() if g.Config.FeeConfig == commontype.EmptyFeeConfig { - log.Info("No fee config given in genesis, setting default fee config", "DefaultFeeConfig", params.DefaultFeeConfig) g.Config.FeeConfig = params.DefaultFeeConfig g.Config.FeeConfig.GasLimit = new(big.Int).SetUint64(g.GasLimit) + log.Info("No fee config given in genesis, setting default fee config", "DefaultConfig", g.Config.FeeConfig) } if err := g.Verify(); err != nil { From db90a22c5fbd93dbd02c542b883a4a16bb3cbbfa Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 24 Jul 2023 15:54:31 -0700 Subject: [PATCH 5/5] revert change to vm.go --- plugin/evm/vm.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go index a66b5a8ed6..f5afc1f13f 100644 --- a/plugin/evm/vm.go +++ b/plugin/evm/vm.go @@ -310,9 +310,8 @@ func (vm *VM) Initialize( vm.syntacticBlockValidator = NewBlockValidator() if g.Config.FeeConfig == commontype.EmptyFeeConfig { + log.Info("No fee config given in genesis, setting default fee config", "DefaultFeeConfig", params.DefaultFeeConfig) g.Config.FeeConfig = params.DefaultFeeConfig - g.Config.FeeConfig.GasLimit = new(big.Int).SetUint64(g.GasLimit) - log.Info("No fee config given in genesis, setting default fee config", "DefaultConfig", g.Config.FeeConfig) } if err := g.Verify(); err != nil {