core: copy genesis before modifying

This commit is contained in:
Marius van der Wijden 2025-01-30 16:14:14 +01:00
parent 85abb73a7e
commit 5803554aae
2 changed files with 16 additions and 2 deletions

View file

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

View file

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