chainntnfs: add a pkscript notifier stream#10807
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request implements a robust, stream-based interface for monitoring Bitcoin script activity. By moving away from single-target notifications to a script-based subscription model, it enables more efficient and flexible chain monitoring. The changes include backend support for bitcoind, btcd, and neutrino, along with a comprehensive gRPC API for external clients to leverage these new capabilities. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new PkScriptNotifier interface and implementation, allowing clients to watch for confirmation and spend events on specific output scripts. The changes include support for historical scans, resource limiting, and a new bidirectional gRPC stream in chainrpc. The reviewer suggested refactoring the duplicated historical dispatch logic across the bitcoind, btcd, and neutrino backends into a shared helper and noted that an error in completeHistoricalPkScriptDispatchLocked should be explicitly handled.
🔴 PR Severity: CRITICAL
🟠 High (9 files — base severity)
🟡 Medium (5 files)
🟢 Low (2 files — excluded from count)
⬛ Excluded from counting (test/auto-generated files)
AnalysisBase severity: HIGH — The PR touches Bumped to CRITICAL — The PR has approximately 4,938 lines changed in non-test, non-auto-generated files, well exceeding the 500-line threshold that triggers a one-level severity bump. The core of this PR introduces a new To override, add a |
Add a TxNotifier-backed stream for watching pkScripts with confirmation, spend, partial confirmation, historical scan, and reorg notifications.
Support pkScript streams in bitcoind, btcd, and neutrino, including historical scan dispatch and neutrino compact-filter updates.
Expose RegisterPkScriptNtfn with register/add/remove mutations, acknowledgements, historical scan events, and pkScript notification conversion.
Add shared notifier tests and RPC integration scenarios for historical scans, removals, confirmation modes, multi-stream watching, validation, and reorg handling.
Show how to register a pkScript notification stream, defer cancellation, add scripts with all notifier options, and handle stream events.
Mention the new RegisterPkScriptNtfn stream and supporting documentation in the 0.22.0 release notes.
4d9a081 to
65fd383
Compare
This PR adds a pkScript notifier stream for clients that need to watch confirmed on-chain activity for output
scripts without knowing the funding transaction or outpoint ahead of time.
The feature is exposed in two layers:
chainntnfs.PkScriptNotifierfor in-process notifier users.chainrpc.RegisterPkScriptNtfnas a bidirectional chain notifier RPC.Behavior
A client opens one long-lived stream, sends an initial
registerrequest, then dynamically mutates thewatched script set with
addandremoverequests.For each watched pkScript, clients can choose to receive:
The notifier tracks future chain activity only. An
addacknowledgment means the scripts were accepted forfuture blocks; it does not perform historical backfill. Clients that need historical discovery should scan
their own history first, then add scripts that must remain watched for future confirmations, spends, and
reorgs.
Reorg invalidations are delivered on the same response stream by setting
disconnected=trueon thenotification being invalidated.
Resource Bounds
The notifier enforces limits for:
A client that stops reading responses can have its registration canceled once its bounded queue is exhausted.
Backend Support
The pkScript notifier is wired through the
bitcoind,btcd, andneutrinochain notifier backends.For
neutrino, watched scripts must be convertible into compact filter watch addresses. Unsupported scriptsare rejected.
Documentation
This PR adds
docs/pkscriptnotifier.md, covering RPC semantics, future-only watching, reorg handling,resource bounds, examples, and backend support.
Tests
Covered by unit tests, RPC tests, and integration tests for: