core: copy genesis before modifying

pull/31097/head
Marius van der Wijden 1 week ago
parent 85abb73a7e
commit 5803554aae
  1. 16
      core/genesis.go
  2. 2
      eth/downloader/testchain_test.go

@ -280,9 +280,10 @@ func SetupGenesisBlock(db ethdb.Database, triedb *triedb.Database, genesis *Gene
return SetupGenesisBlockWithOverride(db, triedb, genesis, nil)
}
func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, genesis *Genesis, overrides *ChainOverrides) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, origGenesis *Genesis, overrides *ChainOverrides) (*params.ChainConfig, common.Hash, *params.ConfigCompatError, error) {
// Sanitize the supplied genesis, ensuring it has the associated chain
// config attached.
genesis := origGenesis.Copy()
if genesis != nil && genesis.Config == nil {
return nil, common.Hash{}, nil, errGenesisNoConfig
}
@ -550,6 +551,19 @@ func (g *Genesis) MustCommit(db ethdb.Database, triedb *triedb.Database) *types.
return block
}
// Copy copies the genesis.
func (g *Genesis) Copy() *Genesis {
if g != nil {
cpy := *g
if g.Config != nil {
conf := *g.Config
cpy.Config = &conf
}
return &cpy
}
return nil
}
// EnableVerkleAtGenesis indicates whether the verkle fork should be activated
// at genesis. This is a temporary solution only for verkle devnet testing, where
// verkle fork is activated at genesis, and the configured activation date has

@ -210,7 +210,7 @@ func newTestBlockchain(blocks []*types.Block) *core.BlockChain {
testBlockchains[head] = new(testBlockchain)
}
tbc := testBlockchains[head]
defer testBlockchainsLock.Unlock()
testBlockchainsLock.Unlock()
// Ensure that the database is generated
tbc.gen.Do(func() {

Loading…
Cancel
Save