Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
gossip-support: disconnect when we're no longer in other's reserved s…
Browse files Browse the repository at this point in the history
…et (#6024)

* gossip-support: disconnect when we're no longer in the reserved set

* fmt
  • Loading branch information
ordian authored and bredamatt committed Sep 27, 2022
1 parent 37c7f05 commit 1842234
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 6 deletions.
16 changes: 10 additions & 6 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ where
let mut connections = authorities_past_present_future(sender, leaf).await?;

// Remove all of our locally controlled validator indices so we don't connect to ourself.
// If we control none of them, don't issue connection requests - we're outside
// of the 'clique' of recent validators.
if remove_all_controlled(&self.keystore, &mut connections).await != 0 {
self.issue_connection_request(sender, connections).await;
}
let connections =
if remove_all_controlled(&self.keystore, &mut connections).await != 0 {
connections
} else {
// If we control none of them, issue an empty connection request
// to clean up all connections.
Vec::new()
};
self.issue_connection_request(sender, connections).await;
}

if is_new_session {
Expand Down Expand Up @@ -353,7 +357,7 @@ where

// issue another request for the same session
// if at least a third of the authorities were not resolved.
if 3 * failures >= num {
if num != 0 && 3 * failures >= num {
let timestamp = Instant::now();
match self.failure_start {
None => self.failure_start = Some(timestamp),
Expand Down
58 changes: 58 additions & 0 deletions node/network/gossip-support/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,64 @@ fn issues_connection_request_to_past_present_future() {
});
}

#[test]
fn disconnect_when_not_in_past_present_future() {
sp_tracing::try_init_simple();
let hash = Hash::repeat_byte(0xAA);
test_harness(make_subsystem(), |mut virtual_overseer| async move {
let overseer = &mut virtual_overseer;
overseer_signal_active_leaves(overseer, hash).await;
assert_matches!(
overseer_recv(overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::SessionIndexForChild(tx),
)) => {
assert_eq!(relay_parent, hash);
tx.send(Ok(1)).unwrap();
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::SessionInfo(s, tx),
)) => {
assert_eq!(relay_parent, hash);
assert_eq!(s, 1);
let mut heute_leider_nicht = make_session_info();
heute_leider_nicht.discovery_keys = AUTHORITIES_WITHOUT_US.clone();
tx.send(Ok(Some(heute_leider_nicht))).unwrap();
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::Authorities(tx),
)) => {
assert_eq!(relay_parent, hash);
tx.send(Ok(AUTHORITIES_WITHOUT_US.clone())).unwrap();
}
);

assert_matches!(
overseer_recv(overseer).await,
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::ConnectToResolvedValidators {
validator_addrs,
peer_set,
}) => {
assert!(validator_addrs.is_empty());
assert_eq!(peer_set, PeerSet::Validation);
}
);

virtual_overseer
});
}

#[test]
fn test_log_output() {
sp_tracing::try_init_simple();
Expand Down

0 comments on commit 1842234

Please sign in to comment.