Substrate companion: Authority discovery multiple peer ids (#4295)

* Substrate companion: Authority discovery multiple peer ids

Authority discovery before had a fixed mapping from `PeerId` to
`AuthorityId`. This wasn't correct, as a `PeerId` can actually map to
multiple `AuthorityId`s. The linked Substrate pr fixes this.

https://github.com/paritytech/substrate/pull/10259

* Update node/network/availability-distribution/src/requester/mod.rs

* Update node/network/collator-protocol/src/validator_side/mod.rs

* Update node/network/statement-distribution/src/tests.rs

* Update guide

* Adapt to Substrate pr

* Update Substrate
This commit is contained in:
Bastian Köcher
2021-11-17 11:35:02 +01:00
committed by GitHub
parent 6664019e9d
commit 620a4e45de
17 changed files with 281 additions and 256 deletions
@@ -413,8 +413,8 @@ impl PeerRelayParentKnowledge {
struct PeerData {
view: View,
view_knowledge: HashMap<Hash, PeerRelayParentKnowledge>,
// Peer might be an authority.
maybe_authority: Option<AuthorityDiscoveryId>,
/// Peer might be known as authority with the given ids.
maybe_authority: Option<HashSet<AuthorityDiscoveryId>>,
}
impl PeerData {
@@ -1466,14 +1466,18 @@ async fn handle_network_update(
maybe_authority: maybe_authority.clone(),
},
);
if let Some(authority) = maybe_authority {
authorities.insert(authority, peer);
if let Some(authority_ids) = maybe_authority {
authority_ids.into_iter().for_each(|a| {
authorities.insert(a, peer);
});
}
},
NetworkBridgeEvent::PeerDisconnected(peer) => {
tracing::trace!(target: LOG_TARGET, ?peer, "Peer disconnected");
if let Some(auth_id) = peers.remove(&peer).and_then(|p| p.maybe_authority) {
authorities.remove(&auth_id);
if let Some(auth_ids) = peers.remove(&peer).and_then(|p| p.maybe_authority) {
auth_ids.into_iter().for_each(|a| {
authorities.remove(&a);
});
}
},
NetworkBridgeEvent::NewGossipTopology(new_peers) => {
@@ -944,7 +944,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
NetworkBridgeEvent::PeerConnected(
peer_a.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Alice.public().into()),
Some(HashSet::from([Sr25519Keyring::Alice.public().into()])),
),
),
})
@@ -956,7 +956,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
NetworkBridgeEvent::PeerConnected(
peer_b.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Bob.public().into()),
Some(HashSet::from([Sr25519Keyring::Bob.public().into()])),
),
),
})
@@ -967,7 +967,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
NetworkBridgeEvent::PeerConnected(
peer_c.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Charlie.public().into()),
Some(HashSet::from([Sr25519Keyring::Charlie.public().into()])),
),
),
})
@@ -1444,7 +1444,7 @@ fn share_prioritizes_backing_group() {
NetworkBridgeEvent::PeerConnected(
peer,
ObservedRole::Full,
Some(pair.public().into()),
Some(HashSet::from([pair.public().into()])),
),
),
})
@@ -1466,7 +1466,7 @@ fn share_prioritizes_backing_group() {
NetworkBridgeEvent::PeerConnected(
peer_a.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Alice.public().into()),
Some(HashSet::from([Sr25519Keyring::Alice.public().into()])),
),
),
})
@@ -1477,7 +1477,7 @@ fn share_prioritizes_backing_group() {
NetworkBridgeEvent::PeerConnected(
peer_b.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Bob.public().into()),
Some(HashSet::from([Sr25519Keyring::Bob.public().into()])),
),
),
})
@@ -1488,7 +1488,7 @@ fn share_prioritizes_backing_group() {
NetworkBridgeEvent::PeerConnected(
peer_c.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Charlie.public().into()),
Some(HashSet::from([Sr25519Keyring::Charlie.public().into()])),
),
),
})
@@ -1506,7 +1506,7 @@ fn share_prioritizes_backing_group() {
NetworkBridgeEvent::PeerConnected(
peer_other_group.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Dave.public().into()),
Some(HashSet::from([Sr25519Keyring::Dave.public().into()])),
),
),
})
@@ -1728,7 +1728,7 @@ fn peer_cant_flood_with_large_statements() {
NetworkBridgeEvent::PeerConnected(
peer_a.clone(),
ObservedRole::Full,
Some(Sr25519Keyring::Alice.public().into()),
Some(HashSet::from([Sr25519Keyring::Alice.public().into()])),
),
),
})