refactor: split FiltersProgress.current_height into committed/stored#446
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThis change replaces a single Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dash-spv/src/sync/filters/progress.rs (1)
144-161:⚠️ Potential issue | 🔴 CriticalBug: Format arguments are in the wrong order — percentage and stored_height are swapped.
The format string has
({:.1}%)followed bystored:{}, but the arguments supplyself.stored_height(u32) for the percentage slot andpct(f64) for the stored slot. This will output something likeSyncing 100/1000 (500%) stored:85.3instead of the intendedSyncing 100/1000 (85.3%) stored:500.🐛 Proposed fix: swap the argument order
write!( f, "{:?} {}/{} ({:.1}%) stored:{}, downloaded: {}, processed: {}, matched: {}, last_activity: {}s", self.state, self.committed_height, self.target_height, - self.stored_height, pct, + self.stored_height, self.downloaded, self.processed, self.matched, self.last_activity.elapsed().as_secs(), )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dash-spv/src/sync/filters/progress.rs` around lines 144 - 161, The Display impl for FiltersProgress has the percentage and stored_height arguments swapped; in fn fmt(&self, f: &mut fmt::Formatter<'_>) change the order of the arguments passed to write! so that pct (from self.percentage() * 100.0) fills the ({:.1}%) placeholder and self.stored_height fills the stored:{} placeholder—i.e., pass self.state, self.committed_height, self.target_height, pct, self.stored_height, self.downloaded, self.processed, self.matched, self.last_activity.elapsed().as_secs() to write!.
🧹 Nitpick comments (1)
dash-spv/src/sync/filters/progress.rs (1)
93-103: Consider adding monotonic guards toupdate_committed_heightandupdate_stored_height.
update_target_height(line 107-112) enforces monotonic increase, but these new setters allow arbitrary values. The manager code inmanager.rsline 500 manually checksend > self.progress.committed_height()before callingupdate_committed_height, suggesting the invariant exists but isn't enforced at the progress level. This is low-risk since callers currently handle it, but centralizing the guard would be more defensive.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@dash-spv/src/sync/filters/progress.rs` around lines 93 - 103, Add monotonic guards inside update_committed_height and update_stored_height so they only change state when the new height is greater than the current value (mirror the behavior of update_target_height). Specifically, in update_committed_height(&mut self, height: u32) and update_stored_height(&mut self, height: u32) check the existing self.committed_height and self.stored_height respectively and return early if the incoming height is <= current; only assign the field and call bump_last_activity() when the height strictly increases. This centralizes the invariant and avoids relying on callers (e.g., manager.rs) to enforce monotonicity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@dash-spv/src/sync/filters/progress.rs`:
- Around line 144-161: The Display impl for FiltersProgress has the percentage
and stored_height arguments swapped; in fn fmt(&self, f: &mut
fmt::Formatter<'_>) change the order of the arguments passed to write! so that
pct (from self.percentage() * 100.0) fills the ({:.1}%) placeholder and
self.stored_height fills the stored:{} placeholder—i.e., pass self.state,
self.committed_height, self.target_height, pct, self.stored_height,
self.downloaded, self.processed, self.matched,
self.last_activity.elapsed().as_secs() to write!.
---
Nitpick comments:
In `@dash-spv/src/sync/filters/progress.rs`:
- Around line 93-103: Add monotonic guards inside update_committed_height and
update_stored_height so they only change state when the new height is greater
than the current value (mirror the behavior of update_target_height).
Specifically, in update_committed_height(&mut self, height: u32) and
update_stored_height(&mut self, height: u32) check the existing
self.committed_height and self.stored_height respectively and return early if
the incoming height is <= current; only assign the field and call
bump_last_activity() when the height strictly increases. This centralizes the
invariant and avoids relying on callers (e.g., manager.rs) to enforce
monotonicity.
684aa42 to
6f9cff5
Compare
Split ambiguous `current_height` in `FiltersProgress` into two fields: - `committed_height`: fully processed by wallet - `stored_height`: downloaded to filter storage Moves `committed_height` tracking from `FiltersManager` struct into `FiltersProgress` and update the relevant FFI code.
6f9cff5 to
845ed40
Compare
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing touches🧪 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 |
Split ambiguous
current_heightinFiltersProgressinto two fields:committed_height: fully processed by walletstored_height: downloaded to filter storageMoves
committed_heighttracking fromFiltersManagerstruct intoFiltersProgressand update the relevant FFI code.Based on:
Summary by CodeRabbit
Refactor
Tests