refactor(dash-spv): reputation module cleanup#328
Conversation
📝 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 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 |
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.14% -0.02%
==========================================
Files 323 323
Lines 72438 72433 -5
==========================================
- Hits 52999 52981 -18
- Misses 19439 19452 +13
|
e4c1f51 to
bf25b4c
Compare
bf25b4c to
5e8918a
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