Skip to content

Commit 20cac46

Browse files
authored
Merge of #5325
2 parents ee6f667 + 4573be0 commit 20cac46

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

beacon_node/lighthouse_network/src/peer_manager/peerdb.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
168168
fn score_state_banned_or_disconnected(&self, peer_id: &PeerId) -> bool {
169169
if let Some(peer) = self.peers.get(peer_id) {
170170
match peer.score_state() {
171-
ScoreState::Banned | ScoreState::Disconnected => true,
171+
ScoreState::Banned | ScoreState::ForcedDisconnect => true,
172172
_ => self.ip_is_banned(peer).is_some(),
173173
}
174174
} else {
@@ -1062,12 +1062,12 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
10621062
log: &slog::Logger,
10631063
) -> ScoreTransitionResult {
10641064
match (info.score_state(), previous_state) {
1065-
(ScoreState::Banned, ScoreState::Healthy | ScoreState::Disconnected) => {
1065+
(ScoreState::Banned, ScoreState::Healthy | ScoreState::ForcedDisconnect) => {
10661066
debug!(log, "Peer has been banned"; "peer_id" => %peer_id, "score" => %info.score());
10671067
ScoreTransitionResult::Banned
10681068
}
1069-
(ScoreState::Disconnected, ScoreState::Banned | ScoreState::Healthy) => {
1070-
debug!(log, "Peer transitioned to disconnect state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
1069+
(ScoreState::ForcedDisconnect, ScoreState::Banned | ScoreState::Healthy) => {
1070+
debug!(log, "Peer transitioned to forced disconnect score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
10711071
// disconnect the peer if it's currently connected or dialing
10721072
if info.is_connected_or_dialing() {
10731073
ScoreTransitionResult::Disconnected
@@ -1079,18 +1079,20 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
10791079
ScoreTransitionResult::NoAction
10801080
}
10811081
}
1082-
(ScoreState::Healthy, ScoreState::Disconnected) => {
1083-
debug!(log, "Peer transitioned to healthy state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
1082+
(ScoreState::Healthy, ScoreState::ForcedDisconnect) => {
1083+
debug!(log, "Peer transitioned to healthy score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
10841084
ScoreTransitionResult::NoAction
10851085
}
10861086
(ScoreState::Healthy, ScoreState::Banned) => {
1087-
debug!(log, "Peer transitioned to healthy state"; "peer_id" => %peer_id, "score" => %info.score(), "past_state" => %previous_state);
1087+
debug!(log, "Peer transitioned to healthy score state"; "peer_id" => %peer_id, "score" => %info.score(), "past_score_state" => %previous_state);
10881088
// unban the peer if it was previously banned.
10891089
ScoreTransitionResult::Unbanned
10901090
}
10911091
// Explicitly ignore states that haven't transitioned.
10921092
(ScoreState::Healthy, ScoreState::Healthy) => ScoreTransitionResult::NoAction,
1093-
(ScoreState::Disconnected, ScoreState::Disconnected) => ScoreTransitionResult::NoAction,
1093+
(ScoreState::ForcedDisconnect, ScoreState::ForcedDisconnect) => {
1094+
ScoreTransitionResult::NoAction
1095+
}
10941096

10951097
(ScoreState::Banned, ScoreState::Banned) => ScoreTransitionResult::NoAction,
10961098
}

beacon_node/lighthouse_network/src/peer_manager/peerdb/score.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub(crate) enum ScoreState {
104104
/// We are content with the peers performance. We permit connections and messages.
105105
Healthy,
106106
/// The peer should be disconnected. We allow re-connections if the peer is persistent.
107-
Disconnected,
107+
ForcedDisconnect,
108108
/// The peer is banned. We disallow new connections until it's score has decayed into a
109109
/// tolerable threshold.
110110
Banned,
@@ -115,7 +115,7 @@ impl std::fmt::Display for ScoreState {
115115
match self {
116116
ScoreState::Healthy => write!(f, "Healthy"),
117117
ScoreState::Banned => write!(f, "Banned"),
118-
ScoreState::Disconnected => write!(f, "Disconnected"),
118+
ScoreState::ForcedDisconnect => write!(f, "Disconnected"),
119119
}
120120
}
121121
}
@@ -313,7 +313,7 @@ impl Score {
313313
pub(crate) fn state(&self) -> ScoreState {
314314
match self.score() {
315315
x if x <= MIN_SCORE_BEFORE_BAN => ScoreState::Banned,
316-
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::Disconnected,
316+
x if x <= MIN_SCORE_BEFORE_DISCONNECT => ScoreState::ForcedDisconnect,
317317
_ => ScoreState::Healthy,
318318
}
319319
}
@@ -407,7 +407,7 @@ mod tests {
407407
assert!(score.score() < 0.0);
408408
assert_eq!(score.state(), ScoreState::Healthy);
409409
score.test_add(-1.0001);
410-
assert_eq!(score.state(), ScoreState::Disconnected);
410+
assert_eq!(score.state(), ScoreState::ForcedDisconnect);
411411
}
412412

413413
#[test]

0 commit comments

Comments
 (0)