Skip to content

refactor(dash-spv): inline event logging into monitor tasks#757

Merged
xdustinface merged 1 commit into
v0.42-devfrom
refactor/inline-event-logging
May 12, 2026
Merged

refactor(dash-spv): inline event logging into monitor tasks#757
xdustinface merged 1 commit into
v0.42-devfrom
refactor/inline-event-logging

Conversation

@xdustinface

@xdustinface xdustinface commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Drop LoggingEventHandler and the auto-prepend in DashSpvClient::new. Instead, have spawn_broadcast_monitor log every received event via tracing::info!("{}: {}", name, event) before consumer handlers run, and have spawn_progress_monitor log progress directly alongside its on_progress dispatch. Add Display impls on SyncEvent, NetworkEvent, and WalletEvent that delegate to their existing description() so the helper can format generically with an E: Display bound.

Summary by CodeRabbit

  • Improvements
    • Built-in event logging integrated directly into monitoring services for sync, network, and wallet activities, improving consistency and performance.
    • Event display formatting standardized across all event types for more uniform logging output.
    • Monitor labels enhanced for improved clarity in system diagnostics.

Review Change Stack

Drop `LoggingEventHandler` and the auto-prepend in `DashSpvClient::new`. Instead, have `spawn_broadcast_monitor` log every received event via `tracing::info!("{}: {}", name, event)` before consumer handlers run, and have `spawn_progress_monitor` log progress directly alongside its `on_progress` dispatch. Add `Display` impls on `SyncEvent`, `NetworkEvent`, and `WalletEvent` that delegate to their existing `description()` so the helper can format generically with an `E: Display` bound.
@coderabbitai

coderabbitai Bot commented May 11, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR refactors event logging in the Dash SPV client by implementing Display for SyncEvent, NetworkEvent, and WalletEvent, then integrating tracing::info! calls directly into broadcast and progress monitor dispatch loops. The standalone LoggingEventHandler is removed, and client initialization no longer injects it. Monitor name labels are standardized. Tests are updated accordingly.

Changes

Event Logging Architecture Refactoring

Layer / File(s) Summary
Display Trait Implementations
dash-spv/src/network/event.rs, dash-spv/src/sync/events.rs, key-wallet-manager/src/events.rs
NetworkEvent, SyncEvent, and WalletEvent each implement std::fmt::Display by delegating to their existing description() method, enabling direct string formatting for logging.
Monitor Dispatch Refactoring
dash-spv/src/client/event_handler.rs
spawn_broadcast_monitor generic constraint now requires E: Display. Logging via tracing::info! is integrated directly into broadcast event dispatch before handlers run. spawn_progress_monitor similarly logs initial and updated SyncProgress values before invoking on_progress handlers. LoggingEventHandler struct and its implementation are removed; logging responsibility shifts entirely into the monitor loops. Documentation reflects new behavior.
Client Initialization Cleanup
dash-spv/src/client/lifecycle.rs
LoggingEventHandler import and the logic that automatically prepended it to event_handlers in DashSpvClient::new are removed. Client now uses only the handlers provided by the caller.
Monitor Naming Standardization
dash-spv/src/client/sync_coordinator.rs
Monitor identifier strings passed to spawn_broadcast_monitor are renamed from space-separated format (e.g., "Sync event") to enum-style format (e.g., "SyncEvent") for consistency.
Test Updates
dash-spv/src/client/mod.rs
The test asserting automatic LoggingEventHandler injection is removed. A new test verifies that client.wallet() exposes the internally stored shared WalletManager by acquiring a read lock on it.

🎯 2 (Simple) | ⏱️ ~12 minutes

A handler once logged each event with care,
Now monitors hop in and log them there,
Display traits spring to life,
Reducing redundant strife,
The SPV client's logging is clean and fair! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor(dash-spv): inline event logging into monitor tasks' accurately and concisely describes the main objective of the changeset: moving event logging from a dedicated LoggingEventHandler into the monitor task dispatch loops.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/inline-event-logging

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.

@xdustinface
xdustinface marked this pull request as ready for review May 11, 2026 22:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
dash-spv/src/client/event_handler.rs (1)

109-115: ⚡ Quick win

Avoid holding watch borrow guards while dispatching callbacks.

Clone the SyncProgress snapshot first, then drop the guard before logging/iterating handlers. This reduces lock hold time and avoids sender backpressure when callbacks are slow.

Proposed refactor
-        {
-            let guard = receiver.borrow_and_update();
-            let progress: &SyncProgress = &guard;
-            tracing::info!("SyncProgress: {}", progress);
-            for handler in handlers.iter() {
-                handler.on_progress(progress);
-            }
-        }
+        {
+            let progress = receiver.borrow_and_update().clone();
+            tracing::info!("SyncProgress: {}", progress);
+            for handler in handlers.iter() {
+                handler.on_progress(&progress);
+            }
+        }
@@
-                            let guard = receiver.borrow_and_update();
-                            let progress: &SyncProgress = &guard;
-                            tracing::info!("SyncProgress: {}", progress);
+                            let progress = receiver.borrow_and_update().clone();
+                            tracing::info!("SyncProgress: {}", progress);
                             for handler in handlers.iter() {
-                                handler.on_progress(progress);
+                                handler.on_progress(&progress);
                             }

Also applies to: 123-127

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dash-spv/src/client/event_handler.rs` around lines 109 - 115, The code
currently holds a watch borrow guard (receiver.borrow_and_update()) while
logging and calling handlers, which can cause long lock holds and backpressure;
change this by cloning the SyncProgress snapshot from the guard (e.g., let
progress = guard.clone() or create a copied value) immediately after obtaining
it, then drop the guard before calling tracing::info! and iterating handlers;
apply the same change for the other occurrence around lines 123-127 so that
handler.on_progress receives the cloned progress and no watch guard is held
during callbacks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dash-spv/src/sync/events.rs`:
- Around line 282-286: Add an in-module unit test that asserts the new Display
impl for SyncEvent returns the same string as description(); e.g., create a
#[cfg(test)] mod tests and a test function that constructs representative
SyncEvent variants and checks event.to_string() == event.description() (use a
few variants such as a simple enum variant and one with data) so future changes
cannot drift the Display implementation from description().

---

Nitpick comments:
In `@dash-spv/src/client/event_handler.rs`:
- Around line 109-115: The code currently holds a watch borrow guard
(receiver.borrow_and_update()) while logging and calling handlers, which can
cause long lock holds and backpressure; change this by cloning the SyncProgress
snapshot from the guard (e.g., let progress = guard.clone() or create a copied
value) immediately after obtaining it, then drop the guard before calling
tracing::info! and iterating handlers; apply the same change for the other
occurrence around lines 123-127 so that handler.on_progress receives the cloned
progress and no watch guard is held during callbacks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 763af338-acc7-4b88-8bc4-4b228b021f59

📥 Commits

Reviewing files that changed from the base of the PR and between 78cf339 and 3b1739c.

📒 Files selected for processing (7)
  • dash-spv/src/client/event_handler.rs
  • dash-spv/src/client/lifecycle.rs
  • dash-spv/src/client/mod.rs
  • dash-spv/src/client/sync_coordinator.rs
  • dash-spv/src/network/event.rs
  • dash-spv/src/sync/events.rs
  • key-wallet-manager/src/events.rs
💤 Files with no reviewable changes (2)
  • dash-spv/src/client/mod.rs
  • dash-spv/src/client/lifecycle.rs

Comment thread dash-spv/src/sync/events.rs
@codecov

codecov Bot commented May 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.23%. Comparing base (229ca25) to head (3b1739c).
⚠️ Report is 1 commits behind head on v0.42-dev.

Files with missing lines Patch % Lines
key-wallet-manager/src/events.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##           v0.42-dev     #757      +/-   ##
=============================================
- Coverage      72.25%   72.23%   -0.03%     
=============================================
  Files            320      320              
  Lines          69651    69629      -22     
=============================================
- Hits           50325    50294      -31     
- Misses         19326    19335       +9     
Flag Coverage Δ
core 76.30% <ø> (ø)
ffi 45.28% <ø> (ø)
rpc 20.00% <ø> (ø)
spv 89.84% <100.00%> (-0.06%) ⬇️
wallet 71.20% <0.00%> (-0.02%) ⬇️
Files with missing lines Coverage Δ
dash-spv/src/client/event_handler.rs 96.80% <100.00%> (+0.85%) ⬆️
dash-spv/src/client/lifecycle.rs 77.83% <ø> (-0.45%) ⬇️
dash-spv/src/client/mod.rs 100.00% <ø> (ø)
dash-spv/src/client/sync_coordinator.rs 77.92% <ø> (ø)
dash-spv/src/network/event.rs 100.00% <100.00%> (ø)
dash-spv/src/sync/events.rs 93.47% <100.00%> (+0.45%) ⬆️
key-wallet-manager/src/events.rs 70.20% <0.00%> (-1.09%) ⬇️

... and 2 files with indirect coverage changes

@github-actions github-actions Bot added the ready-for-review CodeRabbit has approved this PR label May 11, 2026
@xdustinface
xdustinface merged commit 6550218 into v0.42-dev May 12, 2026
44 checks passed
@xdustinface
xdustinface deleted the refactor/inline-event-logging branch May 12, 2026 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review CodeRabbit has approved this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants