From 731e7d77c7ceea151eedac0e8a90c98b39b96c0c Mon Sep 17 00:00:00 2001
From: Roman Borschel <romanb@users.noreply.github.com>
Date: Thu, 11 Jun 2020 11:55:55 +0200
Subject: [PATCH] Find the alive incoming entry on disconnect. (#6320)

When a peer in `Incoming` state disconnects, the "alive" entry
in the `incoming` list for that peer must be updated (set to `false`).
Currently the entry that is updated may be an earlier entry for the
same peer that is already no longer alive. This can happen if a
peer repeatedly connects (incoming) and disconnects between invocations to
`poll()` of the behaviour.
---
 .../client/network/src/protocol/generic_proto/behaviour.rs    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/substrate/client/network/src/protocol/generic_proto/behaviour.rs b/substrate/client/network/src/protocol/generic_proto/behaviour.rs
index cf6188726da..be2451c3f4a 100644
--- a/substrate/client/network/src/protocol/generic_proto/behaviour.rs
+++ b/substrate/client/network/src/protocol/generic_proto/behaviour.rs
@@ -1086,7 +1086,9 @@ impl NetworkBehaviour for GenericProto {
 			// In the incoming state, we don't report "Dropped". Instead we will just ignore the
 			// corresponding Accept/Reject.
 			Some(PeerState::Incoming { }) => {
-				if let Some(state) = self.incoming.iter_mut().find(|i| i.peer_id == *peer_id) {
+				if let Some(state) = self.incoming.iter_mut()
+					.find(|i| i.alive && i.peer_id == *peer_id)
+				{
 					debug!(target: "sub-libp2p",
 						"Libp2p => Disconnected({}): Was in incoming mode with id {:?}.",
 						peer_id, state.incoming_id);
-- 
GitLab