Skip to content

feat: log wallet events in the client's run loop#525

Merged
xdustinface merged 1 commit intov0.42-devfrom
feat/log-wallet-events
Mar 13, 2026
Merged

feat: log wallet events in the client's run loop#525
xdustinface merged 1 commit intov0.42-devfrom
feat/log-wallet-events

Conversation

@xdustinface
Copy link
Copy Markdown
Collaborator

@xdustinface xdustinface commented Mar 12, 2026

Handle and log wallet events in the client's run loop. I think it's good to have when investigating issues from logfiles.

Summary by CodeRabbit

  • New Features
    • Added wallet event subscription so clients can receive real-time wallet events (e.g., balance changes, transactions).
    • Sync now listens for and logs wallet events, integrating event-driven updates alongside existing progress and tick updates.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 12e73cff-16d3-43aa-9c68-2138c814344d

📥 Commits

Reviewing files that changed from the base of the PR and between ef3f6c5 and 7742401.

📒 Files selected for processing (4)
  • dash-spv/src/client/sync_coordinator.rs
  • key-wallet-manager/src/test_utils/wallet.rs
  • key-wallet-manager/src/wallet_interface.rs
  • key-wallet-manager/src/wallet_manager/process_block.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • key-wallet-manager/src/wallet_interface.rs
  • dash-spv/src/client/sync_coordinator.rs
  • key-wallet-manager/src/wallet_manager/process_block.rs
  • key-wallet-manager/src/test_utils/wallet.rs

📝 Walkthrough

Walkthrough

Adds a broadcast-based wallet event subscription across the wallet trait, test mocks, and WalletManager, and wires wallet event reception into the client's sync coordinator loop for runtime logging of wallet events.

Changes

Cohort / File(s) Summary
Wallet Interface
key-wallet-manager/src/wallet_interface.rs
Adds fn subscribe_events(&self) -> broadcast::Receiver<WalletEvent>; to WalletInterface for event subscriptions.
WalletManager Implementation
key-wallet-manager/src/wallet_manager/process_block.rs
Implements subscribe_events() for WalletManager<T>, imports WalletEvent/broadcast, and uses the internal sender to emit WalletEvent::BalanceUpdated.
Test Utilities (mocks)
key-wallet-manager/src/test_utils/wallet.rs
Adds a broadcast channel and subscribe_events() to MockWallet and NonMatchingMockWallet; replaces derived Default with explicit constructors that initialize the event sender.
Client sync loop
dash-spv/src/client/sync_coordinator.rs
Subscribes to wallet events in the sync loop and adds a select branch handling wallet_events.recv() to log events or warnings on error.

Sequence Diagram(s)

sequenceDiagram
    participant Client as DashSpvClient
    participant Wallet as WalletManager
    participant Channel as BroadcastChannel
    rect rgba(200,220,255,0.5)
    Client->>Wallet: subscribe_events()
    Wallet->>Channel: return Receiver
    end
    rect rgba(200,255,200,0.5)
    Wallet->>Channel: broadcast WalletEvent (e.g., BalanceUpdated)
    Channel-->>Client: deliver WalletEvent
    Client->>Client: log WalletEvent
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I sent a ping through channels bright,
Events danced softly in the night,
Wallets chirped, receivers sprang,
Logs recorded every twang,
Hopping on, I celebrate the light! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding wallet event logging to the client's run loop, which matches the primary objective of handling and logging wallet events.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/log-wallet-events
📝 Coding Plan for PR comments
  • Generate coding plan

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dash-spv/src/client/sync_coordinator.rs`:
- Around line 56-59: The wallet_events.recv() arm currently swallows
RecvError::Lagged and RecvError::Closed; replace the single pattern with a full
match on wallet_events.recv() so you log and handle all cases: on Ok(event) call
tracing::info!("Wallet event: {}", event.description()) and return None as
before; on Err(broadcast::RecvError::Lagged) emit a tracing::warn (include the
lag count if available or at least the error) and return None; on
Err(broadcast::RecvError::Closed) emit tracing::error indicating the
wallet_events channel closed and return None (or take any existing shutdown
behavior). Reference wallet_events.recv(), event.description(), and
RecvError::Lagged/RecvError::Closed in your changes.

In `@key-wallet-manager/src/wallet_interface.rs`:
- Around line 95-96: The new subscription API is unconditionally declared and
uses tokio::sync::broadcast which is std-only while WalletManager::event_sender
is behind #[cfg(feature = "std")]; fix by gating the broadcast import and the
WalletInterface::subscribe_events method with #[cfg(feature = "std")] and ensure
the implementation that calls self.event_sender.subscribe() (the impl block in
wallet_manager/process_block.rs) is also behind #[cfg(feature = "std")] or moved
into a std-only extension trait; reference WalletInterface::subscribe_events,
WalletManager::event_sender, the tokio::sync::broadcast import, and the impl
block in process_block.rs when applying the guards.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9239fb3c-8f14-45e4-87ca-811161922eb2

📥 Commits

Reviewing files that changed from the base of the PR and between d9d55ef and ef3f6c5.

📒 Files selected for processing (4)
  • dash-spv/src/client/sync_coordinator.rs
  • key-wallet-manager/src/test_utils/wallet.rs
  • key-wallet-manager/src/wallet_interface.rs
  • key-wallet-manager/src/wallet_manager/process_block.rs

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 53.84615% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.92%. Comparing base (d9d55ef) to head (7742401).
⚠️ Report is 2 commits behind head on v0.42-dev.

Files with missing lines Patch % Lines
dash-spv/src/client/sync_coordinator.rs 66.66% 3 Missing ⚠️
...wallet-manager/src/wallet_manager/process_block.rs 25.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #525      +/-   ##
=============================================
- Coverage      66.92%   66.92%   -0.01%     
=============================================
  Files            313      313              
  Lines          64729    64741      +12     
=============================================
+ Hits           43322    43329       +7     
- Misses         21407    21412       +5     
Flag Coverage Δ *Carryforward flag
core 75.02% <ø> (ø)
dash-network 75.00% <ø> (ø) Carriedforward from d9d55ef
dash-network-ffi 34.76% <ø> (ø) Carriedforward from d9d55ef
dash-spv 68.26% <ø> (ø) Carriedforward from d9d55ef
dash-spv-ffi 34.76% <ø> (ø) Carriedforward from d9d55ef
dashcore 75.00% <ø> (ø) Carriedforward from d9d55ef
dashcore-private 75.00% <ø> (ø) Carriedforward from d9d55ef
dashcore-rpc 19.92% <ø> (ø) Carriedforward from d9d55ef
dashcore-rpc-json 19.92% <ø> (ø) Carriedforward from d9d55ef
dashcore_hashes 75.00% <ø> (ø) Carriedforward from d9d55ef
ffi 36.38% <ø> (-0.02%) ⬇️
key-wallet 65.64% <ø> (-0.01%) ⬇️ Carriedforward from d9d55ef
key-wallet-ffi 34.76% <ø> (ø) Carriedforward from d9d55ef
key-wallet-manager 65.64% <ø> (-0.01%) ⬇️ Carriedforward from d9d55ef
rpc 19.92% <ø> (ø)
spv 81.18% <66.66%> (+0.09%) ⬆️
wallet 65.67% <25.00%> (-0.02%) ⬇️

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
key-wallet-manager/src/wallet_interface.rs 0.00% <ø> (ø)
dash-spv/src/client/sync_coordinator.rs 72.72% <66.66%> (-1.56%) ⬇️
...wallet-manager/src/wallet_manager/process_block.rs 56.89% <25.00%> (-3.11%) ⬇️

... and 18 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Handle and log wallet events in the client's run loop. I think it's good to have when investigating issues from logfiles.
@xdustinface xdustinface force-pushed the feat/log-wallet-events branch from ef3f6c5 to 7742401 Compare March 12, 2026 15:57
@xdustinface xdustinface requested a review from ZocoLini March 13, 2026 01:54
@xdustinface xdustinface merged commit 63cb86d into v0.42-dev Mar 13, 2026
84 of 85 checks passed
@xdustinface xdustinface deleted the feat/log-wallet-events branch March 13, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants