From 5803554aae02c2d0f6e96384f941a199e0620fae Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Thu, 30 Jan 2025 16:14:14 +0100 Subject: [PATCH] core: copy genesis before modifying --- core/genesis.go | 16 +++++++++++++++- eth/downloader/testchain_test.go | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index b579e33c77..03c89d4534 100644 --- a/core/genesis.go +++ b/core/genesis.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 diff --git a/eth/downloader/testchain_test.go b/eth/downloader/testchain_test.go index 1bf895c0ee..8fa2e83413 100644 --- a/eth/downloader/testchain_test.go +++ b/eth/downloader/testchain_test.go @@ -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() {