Skip to content

Commit 8ec4a06

Browse files
authored
core: sanity-check fork configuration in genesis (#31171)
This is to prevent a crash on startup with a custom genesis configuration. With this change in place, upgrading a chain created by geth v1.14.x and below will now print an error instead of crashing: Fatal: Failed to register the Ethereum service: invalid chain configuration: missing entry for fork "cancun" in blobSchedule Arguably this is not great, and it should just auto-upgrade the config. We'll address this in a follow-up PR for geth v1.15.2
1 parent 24ed0b5 commit 8ec4a06

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

core/genesis.go

+5
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
364364
}
365365
newCfg := genesis.chainConfigOrDefault(ghash, storedCfg)
366366

367+
// Sanity-check the new configuration.
368+
if err := newCfg.CheckConfigForkOrder(); err != nil {
369+
return nil, common.Hash{}, nil, err
370+
}
371+
367372
// TODO(rjl493456442) better to define the comparator of chain config
368373
// and short circuit if the chain config is not changed.
369374
compatErr := storedCfg.CheckCompatible(newCfg, head.Number.Uint64(), head.Time)

params/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -735,13 +735,13 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
735735
} {
736736
if cur.config != nil {
737737
if err := cur.config.validate(); err != nil {
738-
return fmt.Errorf("invalid blob configuration for fork %s: %v", cur.name, err)
738+
return fmt.Errorf("invalid chain configuration in blobSchedule for fork %q: %v", cur.name, err)
739739
}
740740
}
741741
if cur.timestamp != nil {
742742
// If the fork is configured, a blob schedule must be defined for it.
743743
if cur.config == nil {
744-
return fmt.Errorf("unsupported fork configuration: missing blob configuration entry for %v in schedule", cur.name)
744+
return fmt.Errorf("invalid chain configuration: missing entry for fork %q in blobSchedule", cur.name)
745745
}
746746
}
747747
}

0 commit comments

Comments
 (0)