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

Commit

Permalink
Don't try to connect to ourselves. (#3855)
Browse files Browse the repository at this point in the history
* Don't try to connecto to ourselves.

* Use swap_remove instead of remove O(1)

Co-authored-by: Andronik Ordian <write@reusable.software>

Co-authored-by: Andronik Ordian <write@reusable.software>
  • Loading branch information
eskimor and ordian authored Sep 16, 2021
1 parent a3902fb commit 1c1c37f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
13 changes: 9 additions & 4 deletions node/network/gossip-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,19 @@ impl State {
);
}

let authorities = determine_relevant_authorities(ctx, relay_parent).await?;
let our_index = ensure_i_am_an_authority(keystore, &authorities).await?;
let all_authorities = determine_relevant_authorities(ctx, relay_parent).await?;
let our_index = ensure_i_am_an_authority(keystore, &all_authorities).await?;
let other_authorities = {
let mut authorities = all_authorities.clone();
authorities.swap_remove(our_index);
authorities
};

self.issue_connection_request(ctx, authorities.clone()).await?;
self.issue_connection_request(ctx, other_authorities).await?;

if is_new_session {
self.last_session_index = Some(session_index);
update_gossip_topology(ctx, our_index, authorities, relay_parent).await?;
update_gossip_topology(ctx, our_index, all_authorities, relay_parent).await?;
}
}
}
Expand Down
21 changes: 14 additions & 7 deletions node/network/gossip-support/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,27 @@ async fn overseer_recv(overseer: &mut VirtualOverseer) -> AllMessages {
}

fn authorities() -> Vec<AuthorityDiscoveryId> {
let mut authorities = other_authorities();
authorities.push(Sr25519Keyring::Ferdie.public().into());
authorities
}

// Authorities other than ourselves:
fn other_authorities() -> Vec<AuthorityDiscoveryId> {
vec![
Sr25519Keyring::Alice.public().into(),
Sr25519Keyring::Bob.public().into(),
Sr25519Keyring::Charlie.public().into(),
Sr25519Keyring::Ferdie.public().into(),
Sr25519Keyring::Eve.public().into(),
Sr25519Keyring::One.public().into(),
Sr25519Keyring::Two.public().into(),
]
}

fn neighbors() -> Vec<AuthorityDiscoveryId> {
vec![
Sr25519Keyring::One.public().into(),
Sr25519Keyring::Alice.public().into(),
Sr25519Keyring::Two.public().into(),
Sr25519Keyring::Charlie.public().into(),
Sr25519Keyring::Eve.public().into(),
]
}
Expand Down Expand Up @@ -177,7 +184,7 @@ fn issues_a_connection_request_on_new_session() {
peer_set,
failed,
}) => {
assert_eq!(validator_ids, authorities());
assert_eq!(validator_ids, other_authorities());
assert_eq!(peer_set, PeerSet::Validation);
failed.send(0).unwrap();
}
Expand Down Expand Up @@ -245,7 +252,7 @@ fn issues_a_connection_request_on_new_session() {
peer_set,
failed,
}) => {
assert_eq!(validator_ids, authorities());
assert_eq!(validator_ids, other_authorities());
assert_eq!(peer_set, PeerSet::Validation);
failed.send(0).unwrap();
}
Expand Down Expand Up @@ -293,7 +300,7 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
peer_set,
failed,
}) => {
assert_eq!(validator_ids, authorities());
assert_eq!(validator_ids, other_authorities());
assert_eq!(peer_set, PeerSet::Validation);
failed.send(2).unwrap();
}
Expand Down Expand Up @@ -340,7 +347,7 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
peer_set,
failed,
}) => {
assert_eq!(validator_ids, authorities());
assert_eq!(validator_ids, other_authorities());
assert_eq!(peer_set, PeerSet::Validation);
failed.send(1).unwrap();
}
Expand Down

0 comments on commit 1c1c37f

Please sign in to comment.