Call unban only when necessary (#1821)

This PR prevents a user-facing error. 

It prevents optimistically unbanning a peer and instead checks the state of the peer before requesting the peers state to be unbanned.
This commit is contained in:
Age Manning 2020-10-24 03:24:19 +00:00
parent 1644289a08
commit a3cc1a1e0f

View File

@ -179,15 +179,18 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
GoodbyeReason::BadScore, GoodbyeReason::BadScore,
)); ));
peer_db.notify_disconnecting(peer_id); peer_db.notify_disconnecting(peer_id);
} } else if info.is_banned() {
unban_peer = Some(peer_id); unban_peer = Some(peer_id);
} }
}
ScoreState::Healthy => { ScoreState::Healthy => {
debug!(self.log, "Peer transitioned to healthy state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string()); debug!(self.log, "Peer transitioned to healthy state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string());
// unban the peer if it was previously banned. // unban the peer if it was previously banned.
if info.is_banned() {
unban_peer = Some(peer_id); unban_peer = Some(peer_id);
} }
} }
}
} else { } else {
debug!(self.log, "Peer score adjusted"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string()); debug!(self.log, "Peer score adjusted"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string());
} }
@ -675,7 +678,9 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
ScoreState::Disconnected => { ScoreState::Disconnected => {
debug!(self.log, "Peer transitioned to disconnect state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string()); debug!(self.log, "Peer transitioned to disconnect state"; "peer_id" => peer_id.to_string(), "score" => info.score().to_string(), "past_state" => previous_state.to_string());
// disconnect the peer if it's currently connected or dialing // disconnect the peer if it's currently connected or dialing
if info.is_banned() {
to_unban_peers.push(peer_id.clone()); to_unban_peers.push(peer_id.clone());
}
if info.is_connected_or_dialing() { if info.is_connected_or_dialing() {
// Change the state to inform that we are disconnecting the peer. // Change the state to inform that we are disconnecting the peer.
info.disconnecting(false); info.disconnecting(false);