Skip to content

Commit 6f0e847

Browse files
committed
fix(core): use attached extras with avalanchego customrawdb in genesis
1 parent 198db42 commit 6f0e847

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

core/genesis.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,14 @@ func SetupGenesisBlock(
182182
return newcfg, common.Hash{}, err
183183
}
184184

185-
// Avoid mutating shared extras attached to newcfg (tests may reuse global configs).
186-
extra := *params.GetExtra(newcfg)
187-
188-
storedcfg := customrawdb.ReadChainConfig(db, stored, &extra)
185+
// Use the attached extras pointer to ensure upgrade bytes round-trip correctly.
186+
extra := params.GetExtra(newcfg)
187+
storedcfg := customrawdb.ReadChainConfig(db, stored, extra)
189188
// If there is no previously stored chain config, write the chain config to disk.
190189
if storedcfg == nil {
191190
// Note: this can happen since we did not previously write the genesis block and chain config in the same batch.
192191
log.Warn("Found genesis block without chain config")
193-
customrawdb.WriteChainConfig(db, stored, newcfg, extra)
192+
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
194193
return newcfg, stored, nil
195194
}
196195

@@ -229,7 +228,7 @@ func SetupGenesisBlock(
229228
}
230229
// Required to write the chain config to disk to ensure both the chain config and upgrade bytes are persisted to disk.
231230
// Note: this intentionally removes an extra check from upstream.
232-
customrawdb.WriteChainConfig(db, stored, newcfg, extra)
231+
customrawdb.WriteChainConfig(db, stored, newcfg, *extra)
233232
return newcfg, stored, nil
234233
}
235234

@@ -406,9 +405,8 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *triedb.Database) (*types.Blo
406405
rawdb.WriteHeadBlockHash(batch, block.Hash())
407406
rawdb.WriteHeadHeaderHash(batch, block.Hash())
408407

409-
// Avoid mutating shared extras attached to config
410-
extraCommit := *params.GetExtra(config)
411-
customrawdb.WriteChainConfig(batch, block.Hash(), config, extraCommit)
408+
extra := params.GetExtra(config)
409+
customrawdb.WriteChainConfig(batch, block.Hash(), config, *extra)
412410
if err := batch.Write(); err != nil {
413411
return nil, fmt.Errorf("failed to write genesis block: %w", err)
414412
}

0 commit comments

Comments
 (0)