tbc: add filtered transaction notifications#986
Open
marcopeereboom wants to merge 2 commits intomainfrom
Open
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add per-listener ScriptHash watch filters to the notification system. Clients subscribe via TxWatch with script hashes and receive tx_mempool (0-conf) and tx_confirmed (block inclusion) push notifications over the websocket session. Add NtfnTypeTxMempool and NtfnTypeTxConfirmed constants. Add Metadata field to Notification (omitempty, backward compat). Add Watch, Unwatch, accepts on Listener for ScriptHash filtering. Watch returns error if set would exceed maxWatchScripts (1024). Add NotificationTxMempool and NotificationTxConfirmed constructors. Emit tx_mempool in handleTx and TxBroadcast after mempool insert. Emit tx_confirmed in block processing after insertBlock. Add TxWatch, TxUnwatch, TxNotification to tbcapi command set. Add per-session listener with push goroutine in rpc.go. Extract parseScriptHashes helper for input validation. Use ws.requestContext for listener lifetime, not handler timeout.
17 unit tests covering positive, negative, and edge cases. Positive: mempool delivery, confirmed delivery, block and blockheader passthrough with active filter, no-filter receives all, multiple script hashes, multiple listeners with disjoint watch sets, watch-unwatch-rewatch lifecycle. Negative: unwatched drop for both tx types, never-watched unwatch no-op, duplicate watch idempotent, empty watch list initializes filter, corrupt metadata rejected, parsing edge cases, watch set limit exceeded. 2 fuzz tests: ScriptHash hex parsing and accepts with arbitrary notification types and metadata. 8 integration tests: server-to-websocket Watch then Notify then push delivery, filter drop through websocket, unwatch through websocket with delivery verification, unwatch before watch, bad script hash length on watch and unwatch, watch set limit exceeded through websocket with batched fill. 2 direct unit tests: notifyTxOutputs no-listeners early return, notifyTxOutputs context cancellation error path. 1 e2e test: external package Watch and Unwatch API round-trip. Handle CmdTxWatch and CmdTxUnwatch in mock TBC server.
f7dbad7 to
a844d58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add per-listener ScriptHash watch filters to the tbcd notification system. Clients connect via websocket, call TxWatch with a list of script hashes (addresses), and receive push notifications when matching transactions hit the mempool or are confirmed in a block.
This is the notification layer instead of polling UTXOsByAddress.