core: gracefully wrap Seek error if failed to retrieve header hases

This commit is contained in:
Anna Shaleva 2022-02-25 13:44:14 +03:00 committed by AnnaShaleva
parent 8d6aa1782d
commit 9adcefc2ef

View file

@ -5,6 +5,7 @@ import (
"context" "context"
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt"
iocore "io" iocore "io"
"github.com/nspcc-dev/neo-go/pkg/core/block" "github.com/nspcc-dev/neo-go/pkg/core/block"
@ -513,18 +514,20 @@ func (dao *Simple) GetStateSyncCurrentBlockHeight() (uint32, error) {
func (dao *Simple) GetHeaderHashes() ([]util.Uint256, error) { func (dao *Simple) GetHeaderHashes() ([]util.Uint256, error) {
var hashes = make([]util.Uint256, 0) var hashes = make([]util.Uint256, 0)
var seekErr error
dao.Store.Seek(storage.SeekRange{ dao.Store.Seek(storage.SeekRange{
Prefix: dao.mkKeyPrefix(storage.IXHeaderHashList), Prefix: dao.mkKeyPrefix(storage.IXHeaderHashList),
}, func(k, v []byte) bool { }, func(k, v []byte) bool {
newHashes, err := read2000Uint256Hashes(v) newHashes, err := read2000Uint256Hashes(v)
if err != nil { if err != nil {
panic(err) seekErr = fmt.Errorf("failed to read batch of 2000 header hashes: %w", err)
return false
} }
hashes = append(hashes, newHashes...) hashes = append(hashes, newHashes...)
return true return true
}) })
return hashes, nil return hashes, seekErr
} }
// GetTransaction returns Transaction and its height by the given hash // GetTransaction returns Transaction and its height by the given hash