Skip to content

Commit 6d2d126

Browse files
authored
core: fix accessor mismatch for genesis state (#26747)
1 parent 90d2551 commit 6d2d126

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

core/genesis.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (ga *GenesisAlloc) deriveHash() (common.Hash, error) {
138138
// flush is very similar with deriveHash, but the main difference is
139139
// all the generated states will be persisted into the given database.
140140
// Also, the genesis state specification will be flushed as well.
141-
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database) error {
141+
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhash common.Hash) error {
142142
statedb, err := state.New(common.Hash{}, state.NewDatabaseWithNodeDB(db, triedb), nil)
143143
if err != nil {
144144
return err
@@ -166,15 +166,15 @@ func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database) error {
166166
if err != nil {
167167
return err
168168
}
169-
rawdb.WriteGenesisStateSpec(db, root, blob)
169+
rawdb.WriteGenesisStateSpec(db, blockhash, blob)
170170
return nil
171171
}
172172

173173
// CommitGenesisState loads the stored genesis state with the given block
174174
// hash and commits it into the provided trie database.
175-
func CommitGenesisState(db ethdb.Database, triedb *trie.Database, hash common.Hash) error {
175+
func CommitGenesisState(db ethdb.Database, triedb *trie.Database, blockhash common.Hash) error {
176176
var alloc GenesisAlloc
177-
blob := rawdb.ReadGenesisStateSpec(db, hash)
177+
blob := rawdb.ReadGenesisStateSpec(db, blockhash)
178178
if len(blob) != 0 {
179179
if err := alloc.UnmarshalJSON(blob); err != nil {
180180
return err
@@ -186,7 +186,7 @@ func CommitGenesisState(db ethdb.Database, triedb *trie.Database, hash common.Ha
186186
// - supported networks(mainnet, testnets), recover with defined allocations
187187
// - private network, can't recover
188188
var genesis *Genesis
189-
switch hash {
189+
switch blockhash {
190190
case params.MainnetGenesisHash:
191191
genesis = DefaultGenesisBlock()
192192
case params.RinkebyGenesisHash:
@@ -202,7 +202,7 @@ func CommitGenesisState(db ethdb.Database, triedb *trie.Database, hash common.Ha
202202
return errors.New("not found")
203203
}
204204
}
205-
return alloc.flush(db, triedb)
205+
return alloc.flush(db, triedb, blockhash)
206206
}
207207

208208
// GenesisAccount is an account in the state of the genesis block.
@@ -493,7 +493,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database) (*types.Block
493493
// All the checks has passed, flush the states derived from the genesis
494494
// specification as well as the specification itself into the provided
495495
// database.
496-
if err := g.Alloc.flush(db, triedb); err != nil {
496+
if err := g.Alloc.flush(db, triedb, block.Hash()); err != nil {
497497
return nil, err
498498
}
499499
rawdb.WriteTd(db, block.Hash(), block.NumberU64(), block.Difficulty())

core/rawdb/accessors_metadata.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ func WriteChainConfig(db ethdb.KeyValueWriter, hash common.Hash, cfg *params.Cha
8282
}
8383

8484
// ReadGenesisStateSpec retrieves the genesis state specification based on the
85-
// given genesis hash.
86-
func ReadGenesisStateSpec(db ethdb.KeyValueReader, hash common.Hash) []byte {
87-
data, _ := db.Get(genesisStateSpecKey(hash))
85+
// given genesis (block-)hash.
86+
func ReadGenesisStateSpec(db ethdb.KeyValueReader, blockhash common.Hash) []byte {
87+
data, _ := db.Get(genesisStateSpecKey(blockhash))
8888
return data
8989
}
9090

9191
// WriteGenesisStateSpec writes the genesis state specification into the disk.
92-
func WriteGenesisStateSpec(db ethdb.KeyValueWriter, hash common.Hash, data []byte) {
93-
if err := db.Put(genesisStateSpecKey(hash), data); err != nil {
92+
func WriteGenesisStateSpec(db ethdb.KeyValueWriter, blockhash common.Hash, data []byte) {
93+
if err := db.Put(genesisStateSpecKey(blockhash), data); err != nil {
9494
log.Crit("Failed to store genesis state", "err", err)
9595
}
9696
}

0 commit comments

Comments
 (0)