Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 17 additions & 15 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
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{
Expand Down
4 changes: 4 additions & 0 deletions plugin/evm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down