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) => {