From 924d1336f18fa1057bd86aeb25a5578842c246de Mon Sep 17 00:00:00 2001 From: Diego Nava Date: Thu, 21 Sep 2023 16:38:05 +0200 Subject: [PATCH] use the updated state in case there is one --- core/genesis.go | 4 ++-- core/preimages.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/genesis.go b/core/genesis.go index 8f6d0777e..721aab331 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -254,9 +254,9 @@ func (g *Genesis) ToBlock(db ethdb.Database) *types.Block { statedb.SetState(addr, key, value) } //statedb.AddPreimage(crypto.Keccak256Hash((addr[:])), addr.Bytes()[:]) - rawdb.WritePreimages( + _ = rawdb.WritePreimages( statedb.Database().DiskDB(), map[ethCommon.Hash][]byte{ - crypto.Keccak256Hash((addr.Bytes())): addr.Bytes(), + crypto.Keccak256Hash(addr.Bytes()): addr.Bytes(), }, ) } diff --git a/core/preimages.go b/core/preimages.go index e0f1eacfd..663a50296 100644 --- a/core/preimages.go +++ b/core/preimages.go @@ -233,7 +233,12 @@ func GeneratePreimages(chain BlockChain, start, end uint64) error { if err != nil { return fmt.Errorf("error executing block #%d: %s", i, err) } - startingState = endingState + stateAt, err := chain.StateAt(block.Root()) + if err == nil && stateAt != nil { + startingState = stateAt + } else { + startingState = endingState + } } // force any pre-images in memory so far to go to disk, if they haven't already fmt.Println("committing images")