Skip to content

Commit a5c4a7c

Browse files
authored
Merge pull request #9921 from yyforyongyu/fix-notification
Use spent height as the rescan start height in `RegisterSpendNtfn`
2 parents 207df8d + adf2719 commit a5c4a7c

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

chainntnfs/bitcoindnotify/bitcoind.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,16 @@ func (b *BitcoindNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
833833
return nil, err
834834
}
835835

836-
if uint32(blockHeight) > ntfn.HistoricalDispatch.StartHeight {
837-
ntfn.HistoricalDispatch.StartHeight = uint32(blockHeight)
836+
spentHeight := uint32(blockHeight)
837+
chainntnfs.Log.Debugf("Outpoint(%v) has spent at height %v",
838+
outpoint, spentHeight)
839+
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 {
845+
ntfn.HistoricalDispatch.StartHeight = spentHeight
838846
}
839847
}
840848

chainntnfs/btcdnotify/btcd.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,15 +933,25 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
933933
"block %v: %v", blockHash, err)
934934
}
935935

936-
if uint32(blockHeader.Height) > ntfn.HistoricalDispatch.StartHeight {
936+
spentHeight := uint32(blockHeader.Height)
937+
chainntnfs.Log.Debugf("Outpoint(%v) has spent at height %v",
938+
outpoint, spentHeight)
939+
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 {
937945
startHash, err = b.chainConn.GetBlockHash(
938-
int64(blockHeader.Height),
946+
int64(spentHeight),
939947
)
940948
if err != nil {
941949
return nil, fmt.Errorf("unable to get block "+
942950
"hash for height %d: %v",
943951
blockHeader.Height, err)
944952
}
953+
954+
ntfn.HistoricalDispatch.StartHeight = spentHeight
945955
}
946956
}
947957

docs/release-notes/release-notes-0.19.2.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
- [Use](https://github.com/lightningnetwork/lnd/pull/9889) `BigSizeT` instead of
2424
`uint16` for the htlc index that's used in the revocation log.
2525

26+
- [Fixed](https://github.com/lightningnetwork/lnd/pull/9921) a case where the
27+
spending notification of an output may be missed if wrong height hint is used.
28+
2629
# New Features
2730

2831
## Functional Enhancements

0 commit comments

Comments
 (0)