-
Notifications
You must be signed in to change notification settings - Fork 870
Store peer penality records in the PeerDB in PeerInfo #7320
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
Open
Patchoulis
wants to merge
9
commits into
sigp:unstable
Choose a base branch
from
Patchoulis:t-7245
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6209ba1
WIP
Patchoulis a562e1d
WIP
Patchoulis f96167b
Added Tests
Patchoulis fd7fc6b
Fixing up something from the rebase to unstable
Patchoulis b40942d
Fixed up an error message
Patchoulis a1ee181
Small cleanup
Patchoulis 9f7f97a
Nvm
Patchoulis 0e0baf1
Applied all the suggestions
Patchoulis 1dd344e
Removed the derive items for Ban Operation since it now uses score tr…
Patchoulis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,11 +5,12 @@ | |||||
//! As the logic develops this documentation will advance. | ||||||
//! | ||||||
//! The scoring algorithms are currently experimental. | ||||||
use super::ScoreTransitionResult; | ||||||
use crate::service::gossipsub_scoring_parameters::GREYLIST_THRESHOLD as GOSSIPSUB_GREYLIST_THRESHOLD; | ||||||
use serde::Serialize; | ||||||
use std::cmp::Ordering; | ||||||
use std::sync::LazyLock; | ||||||
use std::time::Instant; | ||||||
use std::time::{Instant, SystemTime, UNIX_EPOCH}; | ||||||
use strum::AsRefStr; | ||||||
use tokio::time::Duration; | ||||||
|
||||||
|
@@ -39,11 +40,48 @@ const GOSSIPSUB_NEGATIVE_SCORE_WEIGHT: f64 = | |||||
(MIN_SCORE_BEFORE_DISCONNECT + 1.0) / GOSSIPSUB_GREYLIST_THRESHOLD; | ||||||
const GOSSIPSUB_POSITIVE_SCORE_WEIGHT: f64 = GOSSIPSUB_NEGATIVE_SCORE_WEIGHT; | ||||||
|
||||||
pub(crate) const MAX_STORED_PENALTY_RECORDS: usize = 20; | ||||||
|
||||||
#[derive(Clone, Debug, Serialize)] | ||||||
pub struct PenaltyRecord { | ||||||
/// The action that caused the penalty | ||||||
pub action: PeerAction, | ||||||
/// Where the penalty came from | ||||||
pub source: ReportSource, | ||||||
/// The penalty message | ||||||
pub msg: String, | ||||||
/// The result of the penalty | ||||||
pub result: ScoreTransitionResult, | ||||||
/// The time when the penalty occured in unix millis | ||||||
pub time_stamp: u128, | ||||||
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.
Suggested change
|
||||||
} | ||||||
|
||||||
impl PenaltyRecord { | ||||||
/// Create a new penalty record | ||||||
pub fn new( | ||||||
action: PeerAction, | ||||||
source: ReportSource, | ||||||
msg: impl Into<String>, | ||||||
result: ScoreTransitionResult, | ||||||
) -> PenaltyRecord { | ||||||
let time_stamp: u128 = SystemTime::now() | ||||||
.duration_since(UNIX_EPOCH) | ||||||
.map_or(0, |dur| dur.as_millis()); | ||||||
PenaltyRecord { | ||||||
action: action, | ||||||
source: source, | ||||||
msg: msg.into(), | ||||||
result: result, | ||||||
time_stamp: time_stamp, | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
/// A collection of actions a peer can perform which will adjust its score. | ||||||
/// Each variant has an associated score change. | ||||||
// To easily assess the behaviour of scores changes the number of variants should stay low, and | ||||||
// somewhat generic. | ||||||
#[derive(Debug, Clone, Copy, AsRefStr)] | ||||||
#[derive(Debug, Clone, Copy, AsRefStr, Serialize)] | ||||||
#[strum(serialize_all = "snake_case")] | ||||||
pub enum PeerAction { | ||||||
/// We should not communicate more with this peer. | ||||||
|
@@ -66,7 +104,7 @@ pub enum PeerAction { | |||||
} | ||||||
|
||||||
/// Service reporting a `PeerAction` for a peer. | ||||||
#[derive(Debug)] | ||||||
#[derive(Clone, Debug, Serialize, AsRefStr)] | ||||||
pub enum ReportSource { | ||||||
Gossipsub, | ||||||
RPC, | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can happen in a race condition, not sure if it should be an error log