chainntnfs: don't miss historical events for subscribers with earlier height hints #11247
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 638 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.386
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #11247"
general
weight: 0.35
TechLateef
Fixes #11182.
In this PR, we fix a class of missed historical confirmations and spends in the
TxNotifierwhen several subscriptions for the same txid, script, or outpoint supply different height hints. This is the narrow, minor release subset of #11183; the broader lifetime and hint cache hardening stays there for 0.22.Duplicate registrations share one historical scan. Today, if a later subscriber passes an earlier height hint than the one that scan started from, it just waits on the existing scan, so a confirmation or spend below the first subscriber's hint is never found. The cached height hint makes it worse: it only stores where the next scan should begin, not where the scans behind it started. A hint left by a subscriber whose hint was later than the actual event then hides that event from the next registration. After a restart, a subscriber with an earlier, correct hint can register first and skip straight past its confirmation or spend.
chainrpcclients share these requests with lnd's own subsystems, so a client that registers with a late hint (say, the current tip) can trigger this for lnd.The close confirmation miss
This fixes #11182, the channel close confirmation miss originally described in #11183. After #10331 added a second close transaction confirmation subscriber (waiting for the capacity scaled depth, six confirmations for larger channels), a restart can have the wallet rebroadcaster register its subscription at the current tip before the chain watcher restores its own subscription with the transaction's actual height. If the close transaction was mined below that first hint, the shared scan missed it, and backends without an independent transaction index couldn't recover the confirmation. With this PR, the chain watcher's earlier hint gets a scan of the uncovered prefix, and
TestConfirmationRegistrationOrderreproduces that exact ordering, including a restart before the prefix completes. The spend side had the same gap, and the hint origins below close the restart case where the late subscriber's cached hint would hide the confirmation on its own.Hint origins
In
channeldb, a hint is now stored asHeightHint{Height, Origin}, and a cached hint only applies to a registration whose own hint is at or above the origin. Otherwise the scan starts at the subscriber's hint. The height is encoded first, followed by the origin. A legacy four byte value decodes with an unknown origin and is trusted only for the first subscriber, same as today, so there's no migration, and an older binary reading the new value still recovers the height. The cache interfaces now take a map of hints, so each request keeps its own origin whileupdateHintsstill writes everything in one transaction. We also now query the cache under the notifier's lock, soupdateHintscan't change the hint between the read and the set being created.Prefix scans
Each request set tracks how far down its coverage reaches (the cached origin, its dispatched scans, and tip notifications). A later subscriber whose hint is below that gets a supplemental dispatch of just the uncovered prefix. The set counts its pending scans, so an empty result from one can't advance the shared hint while another is still checking an earlier range. Supplemental dispatches are flagged explicitly, and Neutrino only extends an initial scan's end height to its own tip. The persisted hint needs no change when a prefix is dispatched, since its origin is already above the new subscriber's hint, so a restart before the prefix completes scans it again.
A backend that fails a historical scan never reports it (that's #11234), which leaves the set pending and its hint frozen. That fails safe: the unverified range is scanned again on restart, and results from other scans or at tip are still dispatched.
Testing
On top of targeted tests for both kinds and the hint encoding, we add an asynchronous rapid state machine model,
TestTxNotifierAsyncModelProperty. It queues historical scans and completes, fails, or reports Neutrino progress for them in any order against registrations, blocks, bounded reorgs, and restarts that re-register subscribers in random order, with subscribers drawing their own (possibly late) hints. Its oracle checks that no subscriber gets an event that isn't in the chain, that a subscriber whose hint precedes its event is notified once its scans report, and that the hint cache never lets such a subscriber skip its event after a restart. Reverting the prefix scans for either kind, the pending scan accounting, or hint origins makes it fail within a few thousand runs. The chain notifier interface tests pass on btcd, bitcoind, and Neutrino.The model deliberately leaves out cancellation, re-registration after a set matures, and Neutrino progress inside the reorg window. Those reach a set of lower severity issues on master (stale hints after the final cancellation plus a reorg, leaked request sets, stale scan results credited to a recreated set, Neutrino progress going stale on a reorg) that #11183 addresses, tracked in #11248.