Skip to content

Commit 881e044

Browse files
committed
chainntnfs: use spent height as height hint if found
Previously when deciding whether a UTXO is spent or not, we accept a height hint as the starting block to look for the spending tx in the rescan process. When it's already found spent before the rescan starts, we will update the height hint to be the spent height, only if the latter is greater. This means if the user-specified hint is greater than the actual spending height, this UTXO will never be found as spent. We now fix it by always using the spent height as the hint.
1 parent 6fb81b2 commit 881e044

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

chainntnfs/bitcoindnotify/bitcoind.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,11 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
837837
chainntnfs.Log.Debugf("Outpoint(%v) has spent at height %v",
838838
outpoint, spentHeight)
839839

840-
if spentHeight > ntfn.HistoricalDispatch.StartHeight {
840+
// Since the tx has already been spent at spentHeight, the
841+
// heightHint specified by the caller is no longer relevant. We
842+
// now update the starting height to be the spent height to make
843+
// sure we won't miss it in the rescan.
844+
if spentHeight != ntfn.HistoricalDispatch.StartHeight {
841845
ntfn.HistoricalDispatch.StartHeight = spentHeight
842846
}
843847
}

chainntnfs/btcdnotify/btcd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,11 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
937937
chainntnfs.Log.Debugf("Outpoint(%v) has spent at height %v",
938938
outpoint, spentHeight)
939939

940-
if spentHeight > ntfn.HistoricalDispatch.StartHeight {
940+
// Since the tx has already been spent at spentHeight, the
941+
// heightHint specified by the caller is no longer relevant. We
942+
// now update the starting height to be the spent height to make
943+
// sure we won't miss it in the rescan.
944+
if spentHeight != ntfn.HistoricalDispatch.StartHeight {
941945
startHash, err = b.chainConn.GetBlockHash(
942946
int64(spentHeight),
943947
)

0 commit comments

Comments
 (0)