From 8ec4a06b3f0686a3c181c5f88c899390ee80fb60 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 13 Feb 2025 13:05:05 +0100 Subject: [PATCH] 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 --- core/genesis.go | 5 +++++ params/config.go | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 8546f4e37e..4dd6c9ed24 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -364,6 +364,11 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g } newCfg := genesis.chainConfigOrDefault(ghash, storedCfg) + // Sanity-check the new configuration. + if err := newCfg.CheckConfigForkOrder(); err != nil { + return nil, common.Hash{}, nil, err + } + // TODO(rjl493456442) better to define the comparator of chain config // and short circuit if the chain config is not changed. compatErr := storedCfg.CheckCompatible(newCfg, head.Number.Uint64(), head.Time) diff --git a/params/config.go b/params/config.go index cb12098bc9..5a2e10a943 100644 --- a/params/config.go +++ b/params/config.go @@ -735,13 +735,13 @@ func (c *ChainConfig) CheckConfigForkOrder() error { } { if cur.config != nil { if err := cur.config.validate(); err != nil { - return fmt.Errorf("invalid blob configuration for fork %s: %v", cur.name, err) + return fmt.Errorf("invalid chain configuration in blobSchedule for fork %q: %v", cur.name, err) } } if cur.timestamp != nil { // If the fork is configured, a blob schedule must be defined for it. if cur.config == nil { - return fmt.Errorf("unsupported fork configuration: missing blob configuration entry for %v in schedule", cur.name) + return fmt.Errorf("invalid chain configuration: missing entry for fork %q in blobSchedule", cur.name) } } }