@@ -75,6 +75,19 @@ type Genesis struct {
75
75
BlobGasUsed * uint64 `json:"blobGasUsed"` // EIP-4844
76
76
}
77
77
78
+ // copy copies the genesis.
79
+ func (g * Genesis ) copy () * Genesis {
80
+ if g != nil {
81
+ cpy := * g
82
+ if g .Config != nil {
83
+ conf := * g .Config
84
+ cpy .Config = & conf
85
+ }
86
+ return & cpy
87
+ }
88
+ return nil
89
+ }
90
+
78
91
func ReadGenesis (db ethdb.Database ) (* Genesis , error ) {
79
92
var genesis Genesis
80
93
stored := rawdb .ReadCanonicalHash (db , 0 )
@@ -248,21 +261,17 @@ type ChainOverrides struct {
248
261
}
249
262
250
263
// apply applies the chain overrides on the supplied chain config.
251
- func (o * ChainOverrides ) apply (cfg * params.ChainConfig ) ( * params. ChainConfig , error ) {
264
+ func (o * ChainOverrides ) apply (cfg * params.ChainConfig ) error {
252
265
if o == nil || cfg == nil {
253
- return cfg , nil
266
+ return nil
254
267
}
255
- cpy := * cfg
256
268
if o .OverrideCancun != nil {
257
- cpy .CancunTime = o .OverrideCancun
269
+ cfg .CancunTime = o .OverrideCancun
258
270
}
259
271
if o .OverrideVerkle != nil {
260
- cpy .VerkleTime = o .OverrideVerkle
272
+ cfg .VerkleTime = o .OverrideVerkle
261
273
}
262
- if err := cpy .CheckConfigForkOrder (); err != nil {
263
- return nil , err
264
- }
265
- return & cpy , nil
274
+ return cfg .CheckConfigForkOrder ()
266
275
}
267
276
268
277
// SetupGenesisBlock writes or updates the genesis block in db.
@@ -281,6 +290,8 @@ func SetupGenesisBlock(db ethdb.Database, triedb *triedb.Database, genesis *Gene
281
290
}
282
291
283
292
func SetupGenesisBlockWithOverride (db ethdb.Database , triedb * triedb.Database , genesis * Genesis , overrides * ChainOverrides ) (* params.ChainConfig , common.Hash , * params.ConfigCompatError , error ) {
293
+ // Copy the genesis, so we can operate on a copy.
294
+ genesis = genesis .copy ()
284
295
// Sanitize the supplied genesis, ensuring it has the associated chain
285
296
// config attached.
286
297
if genesis != nil && genesis .Config == nil {
@@ -295,17 +306,15 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
295
306
} else {
296
307
log .Info ("Writing custom genesis block" )
297
308
}
298
- chainCfg , err := overrides .apply (genesis .Config )
299
- if err != nil {
309
+ if err := overrides .apply (genesis .Config ); err != nil {
300
310
return nil , common.Hash {}, nil , err
301
311
}
302
- genesis .Config = chainCfg
303
312
304
313
block , err := genesis .Commit (db , triedb )
305
314
if err != nil {
306
315
return nil , common.Hash {}, nil , err
307
316
}
308
- return chainCfg , block .Hash (), nil , nil
317
+ return genesis . Config , block .Hash (), nil , nil
309
318
}
310
319
// Commit the genesis if the genesis block exists in the ancient database
311
320
// but the key-value database is empty without initializing the genesis
@@ -322,11 +331,9 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
322
331
} else {
323
332
log .Info ("Writing custom genesis block" )
324
333
}
325
- chainCfg , err := overrides .apply (genesis .Config )
326
- if err != nil {
334
+ if err := overrides .apply (genesis .Config ); err != nil {
327
335
return nil , common.Hash {}, nil , err
328
336
}
329
- genesis .Config = chainCfg
330
337
331
338
if hash := genesis .ToBlock ().Hash (); hash != ghash {
332
339
return nil , common.Hash {}, nil , & GenesisMismatchError {ghash , hash }
@@ -335,17 +342,15 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, g
335
342
if err != nil {
336
343
return nil , common.Hash {}, nil , err
337
344
}
338
- return chainCfg , block .Hash (), nil , nil
345
+ return genesis . Config , block .Hash (), nil , nil
339
346
}
340
347
// The genesis block has already been committed previously. Verify that the
341
348
// provided genesis with chain overrides matches the existing one, and update
342
349
// the stored chain config if necessary.
343
350
if genesis != nil {
344
- chainCfg , err := overrides .apply (genesis .Config )
345
- if err != nil {
351
+ if err := overrides .apply (genesis .Config ); err != nil {
346
352
return nil , common.Hash {}, nil , err
347
353
}
348
- genesis .Config = chainCfg
349
354
350
355
if hash := genesis .ToBlock ().Hash (); hash != ghash {
351
356
return nil , common.Hash {}, nil , & GenesisMismatchError {ghash , hash }
0 commit comments