From de71195bcbc02697e6fe9707baac9bcd8278531d Mon Sep 17 00:00:00 2001 From: eugene Date: Fri, 16 Jul 2021 15:47:51 -0400 Subject: [PATCH] chainntnfs/neutrinonotify: update EndHeight after filter update After the error is received on the filter update errChan, update the EndHeight if we're performing a historical scan. If a block was mined after the call to RegisterConf/RegisterSpend but before the filter was updated, then the block would not have the filter applied. This means that a block containing the desired conf/spend parameters would be undetected. Fix this by ensuring the historical scan also includes this height, as it would previously not be included. --- chainntnfs/neutrinonotify/neutrino.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index 6e82b0b9..ace62f3b 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -777,6 +777,14 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint, return ntfn.Event, nil } + // Grab the current best height as the height may have been updated + // while we were draining the chainUpdates queue. + n.bestBlockMtx.RLock() + currentHeight := uint32(n.bestBlock.Height) + n.bestBlockMtx.RUnlock() + + ntfn.HistoricalDispatch.EndHeight = currentHeight + // With the filter updated, we'll dispatch our historical rescan to // ensure we detect the spend if it happened in the past. n.wg.Add(1) @@ -929,6 +937,14 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, return ntfn.Event, nil } + // Grab the current best height as the height may have been updated + // while we were draining the chainUpdates queue. + n.bestBlockMtx.RLock() + currentHeight := uint32(n.bestBlock.Height) + n.bestBlockMtx.RUnlock() + + ntfn.HistoricalDispatch.EndHeight = currentHeight + // Finally, with the filter updated, we can dispatch the historical // rescan to ensure we can detect if the event happened in the past. select {