Skip to content

Commit

Permalink
core: copy genesis before modifying
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Jan 30, 2025
1 parent 85abb73 commit 5803554
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eth/downloader/testchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5803554

Please sign in to comment.