Skip to content

tbc: add filtered transaction notifications#986

Open
marcopeereboom wants to merge 2 commits intomainfrom
marco_txnotify
Open

tbc: add filtered transaction notifications#986
marcopeereboom wants to merge 2 commits intomainfrom
marco_txnotify

Conversation

@marcopeereboom
Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added area: tbc This is a change to TBC (Tiny Bitcoin) changelog: required This pull request must update the CHANGELOG.md file or explicitly be marked with changelog: skip labels Apr 23, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 23, 2026

Codecov Report

❌ Patch coverage is 87.44395% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
service/tbc/rpc.go 89.83% 9 Missing and 3 partials ⚠️
service/tbc/tbc.go 58.62% 11 Missing and 1 partial ⚠️
internal/testutil/mock/tbc.go 0.00% 4 Missing ⚠️

📢 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.
@github-actions github-actions Bot added area: docs This is a change to documentation changelog: done This pull request includes an appropriate update to CHANGELOG.md. and removed changelog: required This pull request must update the CHANGELOG.md file or explicitly be marked with changelog: skip labels Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs This is a change to documentation area: tbc This is a change to TBC (Tiny Bitcoin) changelog: done This pull request includes an appropriate update to CHANGELOG.md.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant