refactor(dash-spv): reputation module cleanup#328
Conversation
|
Warning Review limit reached
Next review available in: 1 minute Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughA new ChangesTyped peer penalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
3ca989d to
4a7925a
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
efa632e to
5ffcc04
Compare
78a5600 to
4ea8874
Compare
a8387fc to
78eef0b
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
833114f to
b3e1b8a
Compare
b3e1b8a to
cbe3b30
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
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/network/reputation.rs (1)
117-187: Decay moves scores away from neutral; should trend toward 0.
apply_decaysubtractsDECAY_AMOUNTregardless of sign, which makes negative (good) scores grow more negative over time without new positive behavior. If decay is meant to normalize toward neutral, adjust based on the sign.🐛 Suggested fix
- let decay = intervals_i32.saturating_mul(DECAY_AMOUNT); - self.score = (self.score - decay).max(MIN_MISBEHAVIOR_SCORE); + let decay = intervals_i32.saturating_mul(DECAY_AMOUNT); + if self.score > 0 { + self.score = (self.score - decay).max(0); + } else if self.score < 0 { + self.score = (self.score + decay).min(0); + }
🧹 Nitpick comments (2)
dash-spv/src/network/reputation.rs (1)
200-215: Avoid silently discarding reputation load failures.Swallowing the storage error hides corruption and makes diagnostics harder; consider logging it before falling back to an empty map.
♻️ Suggested tweak
- let mut reputations = - storage.load_peers_reputation().await.unwrap_or_else(|_| HashMap::new()); + let mut reputations = match storage.load_peers_reputation().await { + Ok(reputations) => reputations, + Err(e) => { + log::warn!("Failed to load peer reputations: {e}"); + HashMap::new() + } + };dash-spv/src/network/manager.rs (1)
170-173: Avoid awaiting while holding the reputation mutex (possible contention / clippy::await_holding_lock).Patterns like
lock().await.*(...).awaithold the mutex across.await, andsave_to_storagealso awaits IO. Consider makingPeerReputationManagermethods synchronous or snapshotting reputations before async IO so the lock can be released early. As per coding guidelines, please ensure clippy passes with warnings-as-errors.Also applies to: 758-759, 1023-1025
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
cbe3b30 to
e4c1f51
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #328 +/- ##
==========================================
+ Coverage 73.16% 73.20% +0.03%
==========================================
Files 323 323
Lines 72438 72381 -57
==========================================
- Hits 52999 52985 -14
+ Misses 19439 19396 -43
|
e4c1f51 to
bf25b4c
Compare
bf25b4c to
5e8918a
Compare
5e8918a to
8e03090
Compare
Refactors the reputation system from manual (score: i32, reason: &str) calls to a typed ChangeReason enum, and removes dead code surfaced along the way. No behavior change
Summary by CodeRabbit