From 9f4a9d950e5ad60c5f3c23121d0f9dfd4ee1c417 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 5 May 2023 14:57:07 +0200 Subject: [PATCH] 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. --- rescan.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/rescan.go b/rescan.go index ebf32f07..d04a4a80 100644 --- a/rescan.go +++ b/rescan.go @@ -446,6 +446,36 @@ func (rs *rescanState) rescan() error { return err } + // To ensure that we batch as many filter queries as possible, we also + // wait for the header chain to either be current or for it to at least + // have caught up with the specified end block. + log.Debugf("Waiting for the chain source to be current or for the " + + "rescan end height to be reached.") + + if err := rs.waitForBlocks(func(hash chainhash.Hash, + height uint32) bool { + + // If the header chain is current, then there is no need to + // wait. + if chain.IsCurrent() { + return true + } + + // If an end height was specified then we wait until the + // notification corresponding to that block height. + if ro.endBlock.Height > 0 && + height >= uint32(ro.endBlock.Height) { + + return true + } + + // If a block hash was specified, check if the notification is + // for that block. + return hash == ro.endBlock.Hash + }); err != nil { + return err + } + log.Debugf("Starting rescan from known block %d (%s)", rs.curStamp.Height, rs.curStamp.Hash)