From 60a1d73e0838e2f0b9a93d9fd8e4580b8d4478e2 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Sun, 14 Oct 2018 17:52:09 -0700 Subject: [PATCH] chainntnfs/txnotifier: commit height hint after rescan is complete In this commit, we'll now commit the current height of the TxNotifier as the height hint for an outpoint/transaction after a rescan has been completed and has determined that the outpoint is unspent/transaction is unconfirmed. We do this to prevent another potentially long rescan if the daemon is restarted before a new block comes in (which is when the hints will be updated again). --- chainntnfs/txnotifier.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index 50a243b13..e2a682eae 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -447,6 +447,20 @@ func (n *TxNotifier) UpdateConfDetails(txid chainhash.Hash, if details == nil { Log.Debugf("Conf details for txid=%v not found during "+ "historical dispatch, waiting to dispatch at tip", txid) + + // We'll commit the current height as the confirm hint to + // prevent another potentially long rescan if we restart before + // a new block comes in. + err := n.confirmHintCache.CommitConfirmHint( + n.currentHeight, txid, + ) + if err != nil { + // The error is not fatal as this is an optimistic + // optimization, so we'll avoid returning an error. + Log.Debugf("Unable to update confirm hint to %d for "+ + "%v: %v", n.currentHeight, txid, err) + } + return nil } @@ -792,6 +806,17 @@ func (n *TxNotifier) updateSpendDetails(op wire.OutPoint, // If the historical rescan was not able to find a spending transaction // for this outpoint, then we can track the spend at tip. if details == nil { + // We'll commit the current height as the spend hint to prevent + // another potentially long rescan if we restart before a new + // block comes in. + err := n.spendHintCache.CommitSpendHint(n.currentHeight, op) + if err != nil { + // The error is not fatal as this is an optimistic + // optimization, so we'll avoid returning an error. + Log.Debugf("Unable to update spend hint to %d for %v: %v", + n.currentHeight, op, err) + } + return nil }