@@ -182,17 +182,26 @@ func SetupGenesisBlock(
182182 return newcfg , common.Hash {}, err
183183 }
184184
185- // Read stored config into a local extras copy to avoid mutating shared extras concurrently.
186- extraCopy := * params .GetExtra (newcfg )
187- storedcfg := customrawdb .ReadChainConfig (db , stored , & extraCopy )
185+ // Read stored config. We'll persist the new config (including upgrade bytes)
186+ // prior to compatibility checks to ensure on-disk state is up to date.
187+ extra := params .GetExtra (newcfg )
188+ storedcfg := customrawdb .ReadChainConfig (db , stored , extra )
188189 // If there is no previously stored chain config, write the chain config to disk.
189190 if storedcfg == nil {
190191 // Note: this can happen since we did not previously write the genesis block and chain config in the same batch.
191192 log .Warn ("Found genesis block without chain config" )
192- customrawdb .WriteChainConfig (db , stored , newcfg , * params . GetExtra ( newcfg ) )
193+ customrawdb .WriteChainConfig (db , stored , newcfg , * extra )
193194 return newcfg , stored , nil
194195 }
195196
197+ // Persist the new chain config (and upgrade bytes) to disk now to avoid
198+ // spurious compatibility failures due to missing upgrade bytes on older databases.
199+ customrawdb .WriteChainConfig (db , stored , newcfg , * extra )
200+
201+ // Re-read stored config into a fresh extras copy for a clean comparison.
202+ storedExtra := * params .GetExtra (newcfg )
203+ storedcfg = customrawdb .ReadChainConfig (db , stored , & storedExtra )
204+
196205 // Notes on the following line:
197206 // - this is needed in coreth to handle the case where existing nodes do not
198207 // have the Berlin or London forks initialized by block number on disk.
@@ -226,9 +235,8 @@ func SetupGenesisBlock(
226235 return newcfg , stored , compatErr
227236 }
228237 }
229- // Required to write the chain config to disk to ensure both the chain config and upgrade bytes are persisted to disk.
230- // Note: this intentionally removes an extra check from upstream.
231- customrawdb .WriteChainConfig (db , stored , newcfg , * params .GetExtra (newcfg ))
238+ // Chain config has already been written above.
239+ // Write is idempotent but not required here.
232240 return newcfg , stored , nil
233241}
234242
0 commit comments