refactor(dash-spv): reputation module cleanup#328
Conversation
📝 WalkthroughWalkthroughThe pull request refactors the peer reputation system from static misbehavior scores to a ChangeReason enum-based approach. The reputation manager transitions from an Arc<RwLock<>> pattern to Arc<Mutex<>> wrapping, and internal operations shift from async locking to mutable reference-based mutations. Related API signatures and penalty mechanisms are updated accordingly across the codebase. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. |
fe8384e to
833114f
Compare
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. |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.