From c5aa51dca79c62d887d74798057e679ab95a9741 Mon Sep 17 00:00:00 2001 From: Gorka Irazoqui Date: Mon, 23 Nov 2020 11:20:37 +0100 Subject: [PATCH] fix(chain manager): drop beacon-coincident outbound peers if different superblock consensus --- node/.Cargo.toml.swp | Bin 0 -> 1024 bytes node/src/actors/chain_manager/mod.rs | 5 +++- node/src/actors/messages.rs | 7 ++++++ node/src/actors/sessions_manager/handlers.rs | 23 ++++++++++++++++--- node/src/actors/sessions_manager/mod.rs | 16 +++++++++---- 5 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 node/.Cargo.toml.swp diff --git a/node/.Cargo.toml.swp b/node/.Cargo.toml.swp new file mode 100644 index 0000000000000000000000000000000000000000..cb506d0ded5de69a091d3e6b8763158900541383 GIT binary patch literal 1024 zcmYc?$V<%2S1{7E)H7y40?#EG7}7I~607pFGm(U`GGXd;Lozb+vI7!RbVE!m3^0}I zXXNLm>cdp)yQCIpm*f}dmuHsbrIzRxl@^!i=jErQ>N_VErRVFF for SessionsManager { self.last_beacon = Some(msg.beacon); } } + +impl Handler for SessionsManager { + type Result = ::Result; + + fn handle(&mut self, _msg: DropOutboundPeers, _ctx: &mut Context) -> Self::Result { + let outbound_peers: Vec = self + .sessions + .outbound_consolidated + .collection + .keys() + .cloned() + .collect(); + self.drop_outbound_peers(outbound_peers.as_ref()); + } +} diff --git a/node/src/actors/sessions_manager/mod.rs b/node/src/actors/sessions_manager/mod.rs index 65cf8f31f..9b2cae2b1 100644 --- a/node/src/actors/sessions_manager/mod.rs +++ b/node/src/actors/sessions_manager/mod.rs @@ -260,12 +260,8 @@ impl SessionsManager { ); } // Unregister peers out of consensus + act.drop_outbound_peers(peers_to_unregister.as_ref()); for peer in peers_to_unregister { - if let Some(a) = - act.sessions.outbound_consolidated.collection.get(&peer) - { - a.reference.do_send(CloseSession); - } peers_to_keep.remove(&peer); } // Mark remaining peers as safu @@ -291,6 +287,16 @@ impl SessionsManager { .cloned(), ); } + + /// Drop outbound peers + fn drop_outbound_peers(&mut self, peers_to_unregister: &[SocketAddr]) { + // Unregister peers out of consensus + for peer in peers_to_unregister { + if let Some(a) = self.sessions.outbound_consolidated.collection.get(&peer) { + a.reference.do_send(CloseSession); + } + } + } } /// Required traits for being able to retrieve SessionsManager address from registry