Correct peer connection transition logic (#2725)

## Description

This PR updates the peer connection transition logic. It is acceptable for a peer to immediately transition from a disconnected state to a disconnecting state. This can occur when we are at our peer limit and a new peer's dial us.
This commit is contained in:
Age Manning
2021-10-17 04:04:36 +00:00
parent a7b675460d
commit 180c90bf6d
2 changed files with 17 additions and 17 deletions

View File

@@ -782,15 +782,15 @@ impl<TSpec: EthSpec> PeerDB<TSpec> {
}
/* Handle the transition to the disconnecting state */
(
PeerConnectionStatus::Banned { .. } | PeerConnectionStatus::Disconnected { .. },
NewConnectionState::Disconnecting { to_ban },
) => {
error!(self.log, "Disconnecting from an already disconnected peer"; "peer_id" => %peer_id);
(PeerConnectionStatus::Banned { .. }, NewConnectionState::Disconnecting { to_ban }) => {
error!(self.log, "Disconnecting from a banned peer"; "peer_id" => %peer_id);
info.set_connection_status(PeerConnectionStatus::Disconnecting { to_ban });
}
(_, NewConnectionState::Disconnecting { to_ban }) => {
// We overwrite all states and set this peer to be disconnecting.
// NOTE: A peer can be in the disconnected state and transition straight to a
// disconnected state. This occurs when a disconnected peer dials us, we have too
// many peers and we transition them straight to the disconnecting state.
info.set_connection_status(PeerConnectionStatus::Disconnecting { to_ban });
}