From 935e7144fbdbc55d929ef013599a09637d96a336 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Wed, 24 Mar 2021 15:56:56 +0200 Subject: [PATCH] neutrinonotify: persist rescan progress. Adding persistency to neutrino re-scan progress. In case the re-scan failed in the middle or the node was restarted before the re-scan has been completed this fix will start from the last point instead of the beginning. On long re-scan , such as old channels on mobile devices this is crucial. --- chainntnfs/neutrinonotify/neutrino.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index 567fa520..8842d4ce 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -778,6 +778,18 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, neutrino.EndBlock(&headerfs.BlockStamp{ Height: int32(ntfn.HistoricalDispatch.EndHeight), }), + neutrino.ProgressHandler(func(processedHeight uint32) { + // We persist the rescan progress to achieve incremental + // behavior across restarts, otherwise long rescans may + // start from the beginning with every restart. + err := n.spendHintCache.CommitSpendHint( + processedHeight, + ntfn.HistoricalDispatch.SpendRequest) + if err != nil { + chainntnfs.Log.Errorf("Failed to update rescan "+ + "progress: %v", err) + } + }), neutrino.QuitChan(n.quit), ) if err != nil && !strings.Contains(err.Error(), "not found") {