mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 09:57:56 +00:00
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:
@@ -165,11 +165,11 @@ impl ValidatorGroup {
|
||||
/// Returns `true` if we should advertise our collation to the given peer.
|
||||
fn should_advertise_to(
|
||||
&self,
|
||||
peer_ids: &HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
peer_ids: &HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
peer: &PeerId,
|
||||
) -> bool {
|
||||
match peer_ids.get(peer) {
|
||||
Some(discovery_id) => !self.advertised_to.contains(discovery_id),
|
||||
Some(discovery_ids) => !discovery_ids.iter().any(|d| self.advertised_to.contains(d)),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
@@ -177,11 +177,13 @@ impl ValidatorGroup {
|
||||
/// Should be called after we advertised our collation to the given `peer` to keep track of it.
|
||||
fn advertised_to_peer(
|
||||
&mut self,
|
||||
peer_ids: &HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
peer_ids: &HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
peer: &PeerId,
|
||||
) {
|
||||
if let Some(validator_id) = peer_ids.get(peer) {
|
||||
self.advertised_to.insert(validator_id.clone());
|
||||
if let Some(authority_ids) = peer_ids.get(peer) {
|
||||
authority_ids.iter().for_each(|a| {
|
||||
self.advertised_to.insert(a.clone());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,9 +276,9 @@ struct State {
|
||||
/// Our validator groups per active leaf.
|
||||
our_validators_groups: HashMap<Hash, ValidatorGroup>,
|
||||
|
||||
/// The mapping from [`PeerId`] to [`ValidatorId`]. This is filled over time as we learn the [`PeerId`]'s
|
||||
/// The mapping from [`PeerId`] to [`HashSet<AuthorityDiscoveryId>`]. This is filled over time as we learn the [`PeerId`]'s
|
||||
/// by `PeerConnected` events.
|
||||
peer_ids: HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
peer_ids: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
|
||||
/// Metrics.
|
||||
metrics: Metrics,
|
||||
@@ -907,14 +909,14 @@ where
|
||||
// If it is possible that a disconnected validator would attempt a reconnect
|
||||
// it should be handled here.
|
||||
tracing::trace!(target: LOG_TARGET, ?peer_id, ?observed_role, "Peer connected");
|
||||
if let Some(authority) = maybe_authority {
|
||||
if let Some(authority_ids) = maybe_authority {
|
||||
tracing::trace!(
|
||||
target: LOG_TARGET,
|
||||
?authority,
|
||||
?authority_ids,
|
||||
?peer_id,
|
||||
"Connected to requested validator"
|
||||
);
|
||||
state.peer_ids.insert(peer_id, authority);
|
||||
state.peer_ids.insert(peer_id, authority_ids);
|
||||
|
||||
declare(ctx, state, peer_id).await;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use std::{collections::HashSet, sync::Arc, time::Duration};
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use futures::{executor, future, Future, SinkExt};
|
||||
@@ -405,7 +405,7 @@ async fn connect_peer(
|
||||
CollatorProtocolMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerConnected(
|
||||
peer.clone(),
|
||||
polkadot_node_network_protocol::ObservedRole::Authority,
|
||||
authority_id,
|
||||
authority_id.map(|v| HashSet::from([v])),
|
||||
)),
|
||||
)
|
||||
.await;
|
||||
|
||||
Reference in New Issue
Block a user