-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add peer reputation penalization for invalid ChainLocks #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
847d8a8
ea36d36
78b3996
36d4b86
c6bac8b
007138b
bacb2cd
ad9c49e
d0a6bca
5c86456
aaa74cc
bb0d8c1
8f0cb2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -313,6 +313,24 @@ impl PeerReputationManager { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Temporarily ban a peer for a specified duration, regardless of score. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// This can be used for critical protocol violations (e.g., invalid ChainLocks). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub async fn temporary_ban_peer(&self, peer: SocketAddr, duration: Duration, reason: &str) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut reputations = self.reputations.write().await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let reputation = reputations.entry(peer).or_default(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reputation.banned_until = Some(Instant::now() + duration); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reputation.ban_count += 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log::warn!( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Peer {} temporarily banned for {:?} (ban #{}, reason: {})", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| peer, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| duration, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reputation.ban_count, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+319
to
+335
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Double ban_count increment for invalid ChainLocks. The This results in Solution 1 (recommended): Add a parameter to control whether to increment ban_count: - pub async fn temporary_ban_peer(&self, peer: SocketAddr, duration: Duration, reason: &str) {
+ pub async fn temporary_ban_peer(&self, peer: SocketAddr, duration: Duration, reason: &str, increment_ban_count: bool) {
let mut reputations = self.reputations.write().await;
let reputation = reputations.entry(peer).or_default();
reputation.banned_until = Some(Instant::now() + duration);
- reputation.ban_count += 1;
+ if increment_ban_count {
+ reputation.ban_count += 1;
+ }
log::warn!(
"Peer {} temporarily banned for {:?} (ban #{}, reason: {})",Then in - self.reputation_manager
- .temporary_ban_peer(addr, Duration::from_secs(10 * 60), reason)
- .await;
+ self.reputation_manager
+ .temporary_ban_peer(addr, Duration::from_secs(10 * 60), reason, false)
+ .await;Solution 2: Only call 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Record a connection attempt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub async fn record_connection_attempt(&self, peer: SocketAddr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut reputations = self.reputations.write().await; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.