Improve logging around peer scoring (#5325)
* Improve logging around score states * Improve logs also
This commit is contained in:
parent
ee6f667702
commit
f919f82e4f
@ -168,7 +168,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
|||||||
fn score_state_banned_or_disconnected(&self, peer_id: &PeerId) -> bool {
|
fn score_state_banned_or_disconnected(&self, peer_id: &PeerId) -> bool {
|
||||||
if let Some(peer) = self.peers.get(peer_id) {
|
if let Some(peer) = self.peers.get(peer_id) {
|
||||||
match peer.score_state() {
|
match peer.score_state() {
|
||||||
ScoreState::Banned | ScoreState::Disconnected => true,
|
ScoreState::Banned | ScoreState::ForcedDisconnect => true,
|
||||||
_ => self.ip_is_banned(peer).is_some(),
|
_ => self.ip_is_banned(peer).is_some(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1062,12 +1062,12 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
|||||||
log: &slog::Logger,
|
log: &slog::Logger,
|
||||||
) -> ScoreTransitionResult {
|
) -> ScoreTransitionResult {
|
||||||
match (info.score_state(), previous_state) {
|
match (info.score_state(), previous_state) {
|
||||||
(ScoreState::Banned, ScoreState::Healthy | ScoreState::Disconnected) => {
|
(ScoreState::Banned, ScoreState::Healthy | ScoreState::ForcedDisconnect) => {
|
||||||
debug!(log, "Peer has been banned"; "peer_id" => %peer_id, "score" => %info.score());
|
debug!(log, "Peer has been banned"; "peer_id" => %peer_id, "score" => %info.score());
|
||||||
ScoreTransitionResult::Banned
|
ScoreTransitionResult::Banned
|
||||||
}
|
}
|
||||||
(ScoreState::Disconnected, ScoreState::Banned | ScoreState::Healthy) => {
|
(ScoreState::ForcedDisconnect, ScoreState::Banned | ScoreState::Healthy) => {
|
||||||
debug!(log, "Peer transitioned to disconnect state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
|
debug!(log, "Peer transitioned to forced disconnect score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
|
||||||
// disconnect the peer if it's currently connected or dialing
|
// disconnect the peer if it's currently connected or dialing
|
||||||
if info.is_connected_or_dialing() {
|
if info.is_connected_or_dialing() {
|
||||||
ScoreTransitionResult::Disconnected
|
ScoreTransitionResult::Disconnected
|
||||||
@ -1079,18 +1079,20 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
|
|||||||
ScoreTransitionResult::NoAction
|
ScoreTransitionResult::NoAction
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(ScoreState::Healthy, ScoreState::Disconnected) => {
|
(ScoreState::Healthy, ScoreState::ForcedDisconnect) => {
|
||||||
debug!(log, "Peer transitioned to healthy state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
|
debug!(log, "Peer transitioned to healthy score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
|
||||||
ScoreTransitionResult::NoAction
|
ScoreTransitionResult::NoAction
|
||||||
}
|
}
|
||||||
(ScoreState::Healthy, ScoreState::Banned) => {
|
(ScoreState::Healthy, ScoreState::Banned) => {
|
||||||
debug!(log, "Peer transitioned to healthy state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
|
debug!(log, "Peer transitioned to healthy score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
|
||||||
// unban the peer if it was previously banned.
|
// unban the peer if it was previously banned.
|
||||||
ScoreTransitionResult::Unbanned
|
ScoreTransitionResult::Unbanned
|
||||||
}
|
}
|
||||||
// Explicitly ignore states that haven't transitioned.
|
// Explicitly ignore states that haven't transitioned.
|
||||||
(ScoreState::Healthy, ScoreState::Healthy) => ScoreTransitionResult::NoAction,
|
(ScoreState::Healthy, ScoreState::Healthy) => ScoreTransitionResult::NoAction,
|
||||||
(ScoreState::Disconnected, ScoreState::Disconnected) => ScoreTransitionResult::NoAction,
|
(ScoreState::ForcedDisconnect, ScoreState::ForcedDisconnect) => {
|
||||||
|
ScoreTransitionResult::NoAction
|
||||||
|
}
|
||||||
|
|
||||||
(ScoreState::Banned, ScoreState::Banned) => ScoreTransitionResult::NoAction,
|
(ScoreState::Banned, ScoreState::Banned) => ScoreTransitionResult::NoAction,
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ pub(crate) enum ScoreState {
|
|||||||
/// We are content with the peers performance. We permit connections and messages.
|
/// We are content with the peers performance. We permit connections and messages.
|
||||||
Healthy,
|
Healthy,
|
||||||
/// The peer should be disconnected. We allow re-connections if the peer is persistent.
|
/// The peer should be disconnected. We allow re-connections if the peer is persistent.
|
||||||
Disconnected,
|
ForcedDisconnect,
|
||||||
/// The peer is banned. We disallow new connections until it's score has decayed into a
|
/// The peer is banned. We disallow new connections until it's score has decayed into a
|
||||||
/// tolerable threshold.
|
/// tolerable threshold.
|
||||||
Banned,
|
Banned,
|
||||||
@ -115,7 +115,7 @@ impl std::fmt::Display for ScoreState {
|
|||||||
match self {
|
match self {
|
||||||
ScoreState::Healthy => write!(f, "Healthy"),
|
ScoreState::Healthy => write!(f, "Healthy"),
|
||||||
ScoreState::Banned => write!(f, "Banned"),
|
ScoreState::Banned => write!(f, "Banned"),
|
||||||
ScoreState::Disconnected => write!(f, "Disconnected"),
|
ScoreState::ForcedDisconnect => write!(f, "Disconnected"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +313,7 @@ impl Score {
|
|||||||
pub(crate) fn state(&self) -> ScoreState {
|
pub(crate) fn state(&self) -> ScoreState {
|
||||||
match self.score() {
|
match self.score() {
|
||||||
x if x <= MIN_SCORE_BEFORE_BAN => ScoreState::Banned,
|
x if x <= MIN_SCORE_BEFORE_BAN => ScoreState::Banned,
|
||||||
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::Disconnected,
|
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::ForcedDisconnect,
|
||||||
_ => ScoreState::Healthy,
|
_ => ScoreState::Healthy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -407,7 +407,7 @@ mod tests {
|
|||||||
assert!(score.score() < 0.0);
|
assert!(score.score() < 0.0);
|
||||||
assert_eq!(score.state(), ScoreState::Healthy);
|
assert_eq!(score.state(), ScoreState::Healthy);
|
||||||
score.test_add(-1.0001);
|
score.test_add(-1.0001);
|
||||||
assert_eq!(score.state(), ScoreState::Disconnected);
|
assert_eq!(score.state(), ScoreState::ForcedDisconnect);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user