refactor(dash-spv): replace run token and running flag with watch#772
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (16)
💤 Files with no reviewable changes (2)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (10)
📝 WalkthroughWalkthroughThe PR migrates the SPV client shutdown from external ChangesSPV Client Shutdown Mechanism Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 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-ffi/tests/test_client.rs (1)
51-57: ⚡ Quick winAssert lifecycle return codes to avoid silent test passes.
Line 54 through Line 57 currently ignore
run/stopresults, so this test can pass even if lifecycle behavior regresses.Proposed test tightening
- let _result = dash_spv_ffi_client_run(client); - let _result = dash_spv_ffi_client_stop(client); - let _result = dash_spv_ffi_client_run(client); - let _result = dash_spv_ffi_client_stop(client); + assert!(!client.is_null()); + assert_eq!(dash_spv_ffi_client_run(client), FFIErrorCode::Success as i32); + assert_eq!(dash_spv_ffi_client_stop(client), FFIErrorCode::Success as i32); + assert_eq!(dash_spv_ffi_client_run(client), FFIErrorCode::Success as i32); + assert_eq!(dash_spv_ffi_client_stop(client), FFIErrorCode::Success as i32);🤖 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-ffi/tests/test_client.rs` around lines 51 - 57, The test currently ignores results from dash_spv_ffi_client_run and dash_spv_ffi_client_stop so regressions can pass silently; update the test to assert each call's return indicates success (i.e., check the run and stop return values for success/non-error) for both the first run/stop pair and the second run/stop pair using the existing dash_spv_ffi_client_run and dash_spv_ffi_client_stop calls, and fail the test if any call returns an error code.
🤖 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/tests/peer_test.rs`:
- Around line 65-66: The tests currently ignore the Results from
client.stop().await and handle.await which can hide shutdown/join failures;
update each occurrence (calls to client.stop().await and joins like
handle.await) to assert or propagate failures instead of discarding—e.g. replace
the let _ = ... forms with .await.expect("stop failed") or
assert!(handle.await.is_ok(), "task join failed") (or use ? in an async test) so
any error from stop() or the spawned task join fails the test and surfaces the
underlying error.
---
Nitpick comments:
In `@dash-spv-ffi/tests/test_client.rs`:
- Around line 51-57: The test currently ignores results from
dash_spv_ffi_client_run and dash_spv_ffi_client_stop so regressions can pass
silently; update the test to assert each call's return indicates success (i.e.,
check the run and stop return values for success/non-error) for both the first
run/stop pair and the second run/stop pair using the existing
dash_spv_ffi_client_run and dash_spv_ffi_client_stop calls, and fail the test if
any call returns an error code.
🪄 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: 6f292dd4-4b59-4747-b31e-347be1948073
📒 Files selected for processing (16)
dash-spv-ffi/Cargo.tomldash-spv-ffi/src/client.rsdash-spv-ffi/tests/test_client.rsdash-spv/examples/filter_sync.rsdash-spv/examples/simple_sync.rsdash-spv/examples/spv_with_wallet.rsdash-spv/src/client/core.rsdash-spv/src/client/lifecycle.rsdash-spv/src/client/mod.rsdash-spv/src/client/sync_coordinator.rsdash-spv/src/lib.rsdash-spv/src/main.rsdash-spv/tests/dashd_masternode/setup.rsdash-spv/tests/dashd_sync/setup.rsdash-spv/tests/peer_test.rsdash-spv/tests/wallet_integration_test.rs
💤 Files with no reviewable changes (2)
- dash-spv-ffi/Cargo.toml
- dash-spv/src/client/mod.rs
`DashSpvClient::run()` took an external `CancellationToken` and the client separately tracked `running: Arc<RwLock<bool>>`, two mechanisms for one concept. Shutdown also relied on the `running` flag being observed only on the next 100ms `sync_coordinator` tick. Both are now a single `Arc<watch::Sender<bool>>`: `true` while running, `false` once a stop is requested. `run()` drops its parameter, subscribes before the internal `start()`, and breaks its loop immediately when the value flips, so `stop()` is an event rather than a poll. `start()`/`stop()` use `send_replace`, so they are correct with zero receivers (the normal state during `run -> stop -> run` and when `stop()` is called without `run()`). `is_running()` keeps its signature, reading the watch via `borrow()`. `stop()` now flips the state before tearing down the sync coordinator, so a concurrent `run()` loop wakes and exits before it can lock the coordinator again. This removes the window where a tick could race the shutdown.
acb7e9b to
6d2cdff
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v0.42-dev #772 +/- ##
=============================================
+ Coverage 72.67% 72.68% +0.01%
=============================================
Files 320 320
Lines 70333 70319 -14
=============================================
+ Hits 51112 51113 +1
+ Misses 19221 19206 -15
|
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
DashSpvClient::run()took an externalCancellationTokenand the client separately trackedrunning: Arc<RwLock<bool>>, two mechanisms for one concept. Shutdown also relied on therunningflag being observed only on the next 100mssync_coordinatortick.Both are now a single
Arc<watch::Sender<bool>>:truewhile running,falseonce a stop is requested.run()drops its parameter, subscribes before the internalstart(), and breaks its loop immediately when the value flips, sostop()is an event rather than a poll.start()/stop()usesend_replace, so they are correct with zero receivers (the normal state duringrun -> stop -> runand whenstop()is called withoutrun()).is_running()keeps its signature, reading the watch viaborrow().stop()now flips the state before tearing down the sync coordinator, so a concurrentrun()loop wakes and exits before it can lock the coordinator again. This removes the window where a tick could race the shutdown.Summary by CodeRabbit
Breaking Changes
Changes
Chores