Skip to content

Commit b38fa7f

Browse files
committed
rescan: wait till current or end height reached
Let the rescan function wait until the filter headers have either caught up to the back end chain or until they have caught up to the specified rescan end block. This lets the rescan operation take advantage of doing batch filter fetching during rescan making the operation a lot faster since filters can be fetched in batches of 1000 instead of one at a time.
1 parent a5e6452 commit b38fa7f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

rescan.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,36 @@ func (rs *rescanState) rescan() error {
446446
return err
447447
}
448448

449+
// To ensure that we batch as many filter queries as possible, we also
450+
// wait for the header chain to either be current or for it to at least
451+
// have caught up with the specified end block.
452+
log.Debugf("Waiting for the chain source to be current or for the " +
453+
"rescan end height to be reached.")
454+
455+
if err := rs.waitForBlocks(func(hash chainhash.Hash,
456+
height uint32) bool {
457+
458+
// If the header chain is current, then there is no need to
459+
// wait.
460+
if chain.IsCurrent() {
461+
return true
462+
}
463+
464+
// If an end height was specified then we wait until the
465+
// notification corresponding to that block height.
466+
if ro.endBlock.Height > 0 &&
467+
height >= uint32(ro.endBlock.Height) {
468+
469+
return true
470+
}
471+
472+
// If a block hash was specified, check if the notification is
473+
// for that block.
474+
return hash == ro.endBlock.Hash
475+
}); err != nil {
476+
return err
477+
}
478+
449479
log.Debugf("Starting rescan from known block %d (%s)",
450480
rs.curStamp.Height, rs.curStamp.Hash)
451481

0 commit comments

Comments
 (0)