Repository navigation
chainntnfs/btcdnotify: scan the chain for historical spends - #11583
eynhaender wants to merge 3 commits into
Conversation
RegisterSpendNtfn issued the btcd rescan command, which rpcclient marks as deprecated, to find a spend below the current height. Dispatch the historical spend request to the notification dispatcher instead, which scans the blocks of the requested range from the end height down to the start height and matches each transaction against the request, as the bitcoind notifier does. The outpoint case keeps its existing shortcuts: an unspent output completes the request at once, and a spent output starts the scan at the height of its funding block. The dispatcher now always updates the spend details once the scan finishes, including when no spend was found. Previously an output script request whose rescan found no spend left the request pending, so its spend hint was never committed and the historical dispatch was repeated from the original height hint on every restart. This also allows btcd-compatible servers that do not implement the deprecated rescan command, such as libbitcoin-server, to serve as a chain backend.
|
Appreciate the effort you put into the chainntnfs/btcdnotify code here, @eynhaender. As laid out in our guidelines for new contributors, PRs from first-time contributors are not prioritized for review. Rather than leave this open indefinitely, we are going to close it for now. If you're confident this fixes a real problem in the chainntnfs/btcdnotify code, the better route is a detailed issue: how to reproduce it, the lnd version and backend you were running, and why the current behavior is wrong. Maintainers can then decide whether a fix is warranted and may take it over or ask you to resubmit. If you'd like to contribute going forward, reviewing open PRs and helping triage issues is the path we recommend. It's a stronger signal of understanding than a first patch, and it makes it a lot easier for us to prioritize your PRs later. An issue describing the btcd |
Description
RegisterSpendNtfnof the btcd notifier used the deprecated btcdrescancommand (RescanAsync) for historical spends. The historical spend dispatch now runs in the notification dispatcher, as the bitcoind notifier does: it scans the blocks of the range from the end height down (getblockhash,getblock) and matches each transaction withSpendRequest.MatchesTx. The outpoint shortcuts are kept: an unspent output completes the request at once,and a spent output starts the scan at its funding height.
The dispatch now always updates the spend details, also when no spend was found. Before, an output script request without a spend stayed pending, so its spend hint was never committed and the scan repeated from the original height
hint on every restart, also with btcd.
This lets btcd-compatible servers without
rescan, such as libbitcoin-server, serve as a chain backend. There, every historical spend dispatch failed and the spend was never notified. lnd no longer usesrescan.Related: btcsuite/btcwallet#1515 removes the wallet's use of
rescan. The two changes are independent.Verification
TestHistoricalSpendDetails: unspent, spent and out-of-range requests, by outpoint and by script.TestHistoricalSpendDispatchUnspent: the spend hint of an unspent output script is committed. Fails on master against btcd, passes with this change.chainntnfsinterface tests (btcd): 30/30, same as master.make itest backend=btcd(384 cases): identical to master, 545 passed, 9 skipped. 812 historical spend scans completed, 99 found a spend, none failed.