refactor(dash-spv): inline event logging into monitor tasks#757
Conversation
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.
📝 WalkthroughWalkthroughThe PR refactors event logging in the Dash SPV client by implementing ChangesEvent Logging Architecture Refactoring
🎯 2 (Simple) | ⏱️ ~12 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dash-spv/src/client/event_handler.rs (1)
109-115: ⚡ Quick winAvoid holding
watchborrow guards while dispatching callbacks.Clone the
SyncProgresssnapshot 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
📒 Files selected for processing (7)
dash-spv/src/client/event_handler.rsdash-spv/src/client/lifecycle.rsdash-spv/src/client/mod.rsdash-spv/src/client/sync_coordinator.rsdash-spv/src/network/event.rsdash-spv/src/sync/events.rskey-wallet-manager/src/events.rs
💤 Files with no reviewable changes (2)
- dash-spv/src/client/mod.rs
- dash-spv/src/client/lifecycle.rs
Codecov Report❌ Patch coverage is
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
|
Drop
LoggingEventHandlerand the auto-prepend inDashSpvClient::new. Instead, havespawn_broadcast_monitorlog every received event viatracing::info!("{}: {}", name, event)before consumer handlers run, and havespawn_progress_monitorlog progress directly alongside itson_progressdispatch. AddDisplayimpls onSyncEvent,NetworkEvent, andWalletEventthat delegate to their existingdescription()so the helper can format generically with anE: Displaybound.Summary by CodeRabbit