Skip to content

SubscribeWalletEvents streams a wallet's withdrawal events over gRPC - #668

Merged
Jossec101 merged 3 commits into
wallet-events/fix-withdrawal-statefrom
wallet-events/subscribe
Nov 12, 2026
Merged

Jossec101 merged 3 commits into
wallet-events/fix-withdrawal-statefrom
wallet-events/subscribe

Conversation

@Jossec101

@Jossec101 Jossec101 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Stack: 2/4 · based on #667 · next #669

What

  • New bidirectional RPC SubscribeWalletEvents(stream WalletEventsClientMessage) returns (stream WalletEvent)
    • first client message: subscribe { wallet_id, event_types }
    • server sends WALLET_EVENT_SUBSCRIBED, then one event per withdrawal change: created, signature added, signing, broadcast, confirmed, bumped, cancelled, rejected, failed, replacement reverted, other status change
    • WithdrawalEvent payload: status + previous status, tx id, reference id, reason, amount, destinations, signatures collected/required, fee rate, RBF links (bumping_request_id, replaced_by_request_id, is_rbf_cancellation)
  • WalletEventHub (singleton): in-process fan-out per wallet, bounded buffer per subscriber
  • WithdrawalEventPublisher: the withdrawal repositories publish after each successful save
    • Update always calls the publisher; the publisher reads the stored status/TxId before the write and publishes the diff, only when someone subscribes to that wallet
    • signature approvals publish from WalletWithdrawalRequestPsbtRepository
  • GRPCAuthInterceptor now authenticates server/client/duplex streaming calls too; the call keeps only the token's id and name (AuthenticatedApiToken, same record and key as Audit gRPC-created requests, wallet transfers and user roles #666), via GRPCAuthInterceptor.GetApiToken(context)
  • Kestrel HTTP/2 keepalive pings (30s/20s) so idle streams survive proxies
  • GetStatus moved to WithdrawalEventMapper.ToProtoStatus (shared with the existing status RPCs)

Why

  • API clients could only poll GetWithdrawalsRequestStatus* to follow withdrawals
  • Without the interceptor change, any streaming RPC would have run unauthenticated (the interceptor only covered unary calls)

Caveats

  • Live only: nothing is stored or replayed; clients reconcile with GetWithdrawalsRequestStatus after WALLET_EVENT_SUBSCRIBED
  • In-process: events reach streams connected to the same NodeGuard instance (Quartz is non-clustered today)
  • A subscriber that falls 1024 events behind is dropped with RESOURCE_EXHAUSTED; shutdown ends calls with UNAVAILABLE
  • confirmations is not streamed; the event type says when a withdrawal confirmed

Tested

  • Unit: hub, event mapping (every transition), publisher (InMemory), repository diffing, PSBT approval event, RPC (subscribe first, NotFound, Spark refused, filter, cancellation, shutdown), streaming auth
  • E2E added (WalletEventsE2ETests): hot withdrawal created → signing → broadcast → confirmed with nothing going backwards, RBF bump links, no token → Unauthenticated, unknown wallet → NotFound
  • Full unit suite green locally; E2E not run yet (needs the run-e2e-tests label or a local stack run)

… gRPC

- New bidirectional RPC: the first client message subscribes to a wallet; the server answers
  WALLET_EVENT_SUBSCRIBED, then one WalletEvent per withdrawal change (created, signature added, signing,
  broadcast, confirmed, bumped, cancelled, rejected, failed, replacement reverted), with RBF links.
- In-process WalletEventHub (live only, bounded per subscriber; a slow subscriber is dropped with
  RESOURCE_EXHAUSTED, shutdown ends calls with UNAVAILABLE).
- The withdrawal repositories publish after each successful save, diffing status/TxId against the stored
  row only when someone subscribes to the wallet.
- GRPCAuthInterceptor now authenticates streaming calls too (previously unary only) and exposes the token.
- Kestrel HTTP/2 keepalive pings so idle streams survive proxies.
@Jossec101
Jossec101 added this pull request to stack #671 November 11, 2026 14:36
@Jossec101 Jossec101 changed the title feat: SubscribeWalletEvents streams a wallet's withdrawal events over gRPC SubscribeWalletEvents streams a wallet's withdrawal events over gRPC Nov 11, 2026
@Jossec101
Jossec101 marked this pull request as ready for review November 11, 2026 15:52
Comment thread src/Rpc/GRPCAuthInterceptor.cs Resolved
…quest's state before an update

- WalletWithdrawalRequestRepository.Update no longer checks for subscribers: it always calls
  ReadBeforeUpdate before the write and PublishUpdated after a successful one.
- The publisher reads the stored status/TxId only when someone subscribes to the wallet and the request
  was saved; it returns null on a failed read and never throws.
- IsWatched is now private to the publisher.
- GRPCAuthInterceptor stores an AuthenticatedApiToken(Id, Name) instead of the APIToken row, so the token
  value never travels down the call.
- Same record, file and key as #666 (HttpContext.Items "NodeGuard.ApiToken"; UserState is HttpContext.Items
  under ASP.NET Core), so AuditService identifies the token on streaming calls once #666 merges.
- GetApiToken keeps its name and now returns AuthenticatedApiToken.
@Jossec101
Jossec101 merged commit ea2a5ca into main Nov 12, 2026
6 checks passed
@Jossec101
Jossec101 deleted the wallet-events/subscribe branch November 12, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants