From a2e2df461f37d1c126dbb76e7be120cda65e9f43 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 23 Aug 2023 12:00:55 -0400 Subject: [PATCH] Reverted changes to `geth init` --- core/genesis.go | 24 ++---------------------- core/rawdb/accessors_metadata.go | 6 ------ 2 files changed, 2 insertions(+), 28 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 49a86c625d..481795166d 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -167,21 +167,11 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhas return err } } - - if err := writeGenesisStateSpec(db, blockhash, *ga); err != nil { - return err - } - - return nil -} - -// writeGenesisStateSpec marshals the genesis state specification and persist to database. -func writeGenesisStateSpec(db ethdb.Database, blockhash common.Hash, alloc GenesisAlloc) error { - blob, err := json.Marshal(alloc) + // Marshal the genesis state specification and persist. + blob, err := json.Marshal(ga) if err != nil { return err } - rawdb.WriteGenesisStateSpec(db, blockhash, blob) return nil } @@ -405,19 +395,10 @@ func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, gen if compatErr != nil && ((head.Number.Uint64() != 0 && compatErr.RewindToBlock != 0) || (head.Time != 0 && compatErr.RewindToTime != 0)) { return newcfg, stored, compatErr } - // Don't overwrite if the old is identical to the new if newData, _ := json.Marshal(newcfg); !bytes.Equal(storedData, newData) { rawdb.WriteChainConfig(db, stored, newcfg) } - - // We only write genesis alloc if the `genesis` is non-nil, which happen on blockchain boot and custom network. - if genesis != nil && !rawdb.HasGenesisStateSpec(db, stored) { - if err := writeGenesisStateSpec(db, stored, genesis.Alloc); err != nil { - return newcfg, stored, fmt.Errorf("write genesis state spec: %w", err) - } - } - return newcfg, stored, nil } @@ -549,7 +530,6 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database, bcLogger Bloc if err := g.Alloc.flush(db, triedb, block.Hash(), bcLogger); err != nil { return nil, err } - rawdb.WriteTd(db, block.Hash(), block.NumberU64(), block.Difficulty()) rawdb.WriteBlock(db, block) rawdb.WriteReceipts(db, block.Hash(), block.NumberU64(), nil) diff --git a/core/rawdb/accessors_metadata.go b/core/rawdb/accessors_metadata.go index bc88f75b14..2ff29d1add 100644 --- a/core/rawdb/accessors_metadata.go +++ b/core/rawdb/accessors_metadata.go @@ -81,12 +81,6 @@ func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, cfg *params.Cha } } -// HasGenesisStateSpec determines if the genesis state specification based on the -// given genesis (block-)hash exists in the database -func HasGenesisStateSpec(db ethdb.KeyValueReader, blockhash common.Hash) bool { - return len(ReadGenesisStateSpec(db, blockhash)) > 0 -} - // ReadGenesisStateSpec retrieves the genesis state specification based on the // given genesis (block-)hash. func ReadGenesisStateSpec(db ethdb.KeyValueReader, blockhash common.Hash) []byte {