chainntnfs: populate spendsByHeight during historical dispatch

This commit fixes a buggy scenario where:
- a spend of the desired outpoint occurs
- RegisterSpend is called, not immediately notifying
- caller performs a historical dispatch, calling UpdateSpendDetails
- caller is notified on the Spend channel
- re-org occurs
- caller is not notified of the re-org
We fix this by correctly populating the spendsByHeight map when
dispatchSpendDetails is called. This mirrors the confirmation case.
This commit is contained in:
eugene committed 2021-09-01 16:45:13 -04:00
1 parent d263a01a2d
commit 2fbee31c6e
2 files changed
+105

No files matched your search

+13
View File
@@ -1325,6 +1325,19 @@ func (n *TxNotifier) dispatchSpendDetails(ntfn *SpendNtfn, details *SpendDetail)
return ErrTxNotifierExiting
}
spendHeight := uint32(details.SpendingHeight)
// We also add to spendsByHeight to notify on chain reorgs.
reorgSafeHeight := spendHeight + n.reorgSafetyLimit
if reorgSafeHeight > n.currentHeight {
txSet, exists := n.spendsByHeight[spendHeight]
if !exists {
txSet = make(map[SpendRequest]struct{})
n.spendsByHeight[spendHeight] = txSet
}
txSet[ntfn.SpendRequest] = struct{}{}
}
return nil
}