fix preimage import bugs (#4529)

* fix preimage import bugs
* fix typo
pull/4535/head
Diego Nava 1 year ago committed by GitHub
parent 88e033af4f
commit b143085c2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      core/preimages.go

@ -17,6 +17,7 @@ import (
"github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/core/types"
"github.com/harmony-one/harmony/internal/utils" "github.com/harmony-one/harmony/internal/utils"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/syndtr/goleveldb/leveldb"
) )
// ImportPreimages is public so `main.go` can call it directly` // ImportPreimages is public so `main.go` can call it directly`
@ -42,8 +43,10 @@ func ImportPreimages(chain BlockChain, path string) error {
// set this value in database, and prometheus, if needed // set this value in database, and prometheus, if needed
prev, err := rawdb.ReadPreimageImportBlock(dbReader) prev, err := rawdb.ReadPreimageImportBlock(dbReader)
if err != nil { if err != nil {
if !errors.Is(err, leveldb.ErrNotFound) {
return fmt.Errorf("no prior value found, overwriting: %s", err) return fmt.Errorf("no prior value found, overwriting: %s", err)
} }
}
if blockNumber > prev { if blockNumber > prev {
if rawdb.WritePreimageImportBlock(dbReader, blockNumber) != nil { if rawdb.WritePreimageImportBlock(dbReader, blockNumber) != nil {
return fmt.Errorf("error saving last import block: %s", err) return fmt.Errorf("error saving last import block: %s", err)
@ -230,7 +233,7 @@ func GeneratePreimages(chain BlockChain, start, end uint64) error {
if stateAt != nil { if stateAt != nil {
if root, err := endingState.Commit(false); err != 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() { } 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()) 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 // force any pre-images in memory so far to go to disk, if they haven't already
fmt.Println("committing images") fmt.Println("committing images")
if endingState != nil {
if _, err := endingState.Commit(false); err != nil { if _, err := endingState.Commit(false); err != nil {
return fmt.Errorf("unabe to commit state for block: %w", err) return fmt.Errorf("unable to commit state for block: %w", err)
}
} }
if err := chain.CommitPreimages(); err != nil { if err := chain.CommitPreimages(); err != nil {
return fmt.Errorf("error committing preimages %s", err) return fmt.Errorf("error committing preimages %s", err)
} }

Loading…
Cancel
Save