From b143085c2d34c99114c13b0c70b816eb451b0fad Mon Sep 17 00:00:00 2001 From: Diego Nava <8563843+diego1q2w@users.noreply.github.com> Date: Thu, 12 Oct 2023 15:51:29 +0200 Subject: [PATCH] fix preimage import bugs (#4529) * fix preimage import bugs * fix typo --- core/preimages.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/preimages.go b/core/preimages.go index 8605271a7..5034cc0e9 100644 --- a/core/preimages.go +++ b/core/preimages.go @@ -17,6 +17,7 @@ import ( "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/internal/utils" "github.com/pkg/errors" + "github.com/syndtr/goleveldb/leveldb" ) // ImportPreimages is public so `main.go` can call it directly` @@ -42,7 +43,9 @@ func ImportPreimages(chain BlockChain, path string) error { // set this value in database, and prometheus, if needed prev, err := rawdb.ReadPreimageImportBlock(dbReader) if err != nil { - return fmt.Errorf("no prior value found, overwriting: %s", err) + if !errors.Is(err, leveldb.ErrNotFound) { + return fmt.Errorf("no prior value found, overwriting: %s", err) + } } if blockNumber > prev { if rawdb.WritePreimageImportBlock(dbReader, blockNumber) != nil { @@ -230,7 +233,7 @@ func GeneratePreimages(chain BlockChain, start, end uint64) error { if stateAt != nil { if root, err := endingState.Commit(false); err != nil { - return fmt.Errorf("unabe to commit state for block '%d': %w", i, err) + return fmt.Errorf("unable to commit state for block '%d': %w", i, err) } else if root.Hex() != block.Root().Hex() { return fmt.Errorf("block root hashes different after commit commitRoot='%s' blockRoot='%s'", root.Hex(), block.Root().Hex()) } @@ -245,10 +248,11 @@ func GeneratePreimages(chain BlockChain, start, end uint64) error { } // force any pre-images in memory so far to go to disk, if they haven't already fmt.Println("committing images") - if _, err := endingState.Commit(false); err != nil { - return fmt.Errorf("unabe to commit state for block: %w", err) + if endingState != nil { + if _, err := endingState.Commit(false); err != nil { + return fmt.Errorf("unable to commit state for block: %w", err) + } } - if err := chain.CommitPreimages(); err != nil { return fmt.Errorf("error committing preimages %s", err) }