Skip to content

Commit

Permalink
forward blk delay working with maxBlockDelay (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhou authored Sep 23, 2021
1 parent 73bb494 commit 0aaf2a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions eth/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ func (ws *WatchService) NewWatch(
return nil, fmt.Errorf("watch name not specified")
}

if ws.maxBlockDelta > 0 && ws.maxBlockDelta <= fwdDelay {
return nil, fmt.Errorf("maxBlockDelta %d should larger than fwdDelay %d", ws.maxBlockDelta, fwdDelay)
}

w := &Watch{
name: name,
service: ws,
Expand Down Expand Up @@ -431,8 +435,11 @@ func (w *Watch) fetchLogEvents() {
log.Tracef("added %d logs to queue: %s: next from %d", count, w.name, w.fromBlock)
} else {
// we didn't find any event between fromBlock and toBlock, so we can fast forward.
// add additional block delay to mitigate consistency issues from query nodes
fromBlock := toBlock - w.fwdDelay
fromBlock := toBlock
if fromBlock+w.fwdDelay+w.blkDelay >= blkNum {
// add additional block delay to mitigate consistency issues from query nodes
fromBlock = fromBlock - w.fwdDelay
}
if fromBlock > w.fromBlock {
w.fromBlock = fromBlock
}
Expand Down

0 comments on commit 0aaf2a9

Please sign in to comment.