Skip to content

Commit 0aaf2a9

Browse files
authored
forward blk delay working with maxBlockDelay (#39)
1 parent 73bb494 commit 0aaf2a9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

eth/watcher/watcher.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ func (ws *WatchService) NewWatch(
258258
return nil, fmt.Errorf("watch name not specified")
259259
}
260260

261+
if ws.maxBlockDelta > 0 && ws.maxBlockDelta <= fwdDelay {
262+
return nil, fmt.Errorf("maxBlockDelta %d should larger than fwdDelay %d", ws.maxBlockDelta, fwdDelay)
263+
}
264+
261265
w := &Watch{
262266
name: name,
263267
service: ws,
@@ -431,8 +435,11 @@ func (w *Watch) fetchLogEvents() {
431435
log.Tracef("added %d logs to queue: %s: next from %d", count, w.name, w.fromBlock)
432436
} else {
433437
// we didn't find any event between fromBlock and toBlock, so we can fast forward.
434-
// add additional block delay to mitigate consistency issues from query nodes
435-
fromBlock := toBlock - w.fwdDelay
438+
fromBlock := toBlock
439+
if fromBlock+w.fwdDelay+w.blkDelay >= blkNum {
440+
// add additional block delay to mitigate consistency issues from query nodes
441+
fromBlock = fromBlock - w.fwdDelay
442+
}
436443
if fromBlock > w.fromBlock {
437444
w.fromBlock = fromBlock
438445
}

0 commit comments

Comments
 (0)