Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

blockwatch: Handle both Parity and Geth "unknown block" errors gracefully #285

Merged
merged 1 commit into from
Jul 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Handle both Parity and Geth "unknown block" errors gracefully
  • Loading branch information
fabioberger committed Jul 19, 2019
commit 6d4b9d071e645d514978dd4bbb564a6fbcf26128
16 changes: 14 additions & 2 deletions ethereum/blockwatch/block_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (w *Watcher) buildCanonicalChain(nextHeader *meshdb.MiniHeader, events []*E
// a block header might be returned, but when fetching it's logs, an "unknown block" error is
// returned. This is expected to happen sometimes, and we simply return the events gathered so
// far and pick back up where we left off on the next polling interval.
if err.Error() == "unknown block" {
if isUnknownBlockErr(err) {
log.WithFields(log.Fields{
"nextHeader": nextHeader,
}).Trace("failed to get logs for block")
Expand Down Expand Up @@ -277,7 +277,7 @@ func (w *Watcher) buildCanonicalChain(nextHeader *meshdb.MiniHeader, events []*E
// a block header might be returned, but when fetching it's logs, an "unknown block" error is
// returned. This is expected to happen sometimes, and we simply return the events gathered so
// far and pick back up where we left off on the next polling interval.
if err.Error() == "unknown block" {
if isUnknownBlockErr(err) {
log.WithFields(log.Fields{
"nextHeader": nextHeader,
}).Trace("failed to get logs for block")
Expand Down Expand Up @@ -598,3 +598,15 @@ func (w *Watcher) filterLogsRecurisively(from, to int, allLogs []types.Log) ([]t
allLogs = append(allLogs, logs...)
return allLogs, nil
}

func isUnknownBlockErr(err error) bool {
// Geth error
if err.Error() == "unknown block" {
return true
}
// Parity error
if err.Error() == "One of the blocks specified in filter (fromBlock, toBlock or blockHash) cannot be found" {
return true
}
return false
}