mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07: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:
Generated
+163
-163
File diff suppressed because it is too large
Load Diff
@@ -661,7 +661,7 @@ async fn handle_network_messages<AD: validator_discovery::AuthorityDiscovery>(
|
||||
};
|
||||
|
||||
let maybe_authority =
|
||||
authority_discovery_service.get_authority_id_by_peer_id(peer).await;
|
||||
authority_discovery_service.get_authority_ids_by_peer_id(peer).await;
|
||||
|
||||
match peer_set {
|
||||
PeerSet::Validation => {
|
||||
|
||||
@@ -143,14 +143,14 @@ impl validator_discovery::AuthorityDiscovery for TestAuthorityDiscovery {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
_authority: AuthorityDiscoveryId,
|
||||
) -> Option<Vec<Multiaddr>> {
|
||||
) -> Option<HashSet<Multiaddr>> {
|
||||
None
|
||||
}
|
||||
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
_peer_id: PeerId,
|
||||
) -> Option<AuthorityDiscoveryId> {
|
||||
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,10 @@ mod tests {
|
||||
use polkadot_node_network_protocol::{request_response::outgoing::Requests, PeerId};
|
||||
use sc_network::{Event as NetworkEvent, IfDisconnected};
|
||||
use sp_keyring::Sr25519Keyring;
|
||||
use std::{borrow::Cow, collections::HashMap};
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
collections::{HashMap, HashSet},
|
||||
};
|
||||
|
||||
fn new_service() -> Service<TestNetwork, TestAuthorityDiscovery> {
|
||||
Service::new()
|
||||
@@ -176,8 +179,8 @@ mod tests {
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
struct TestAuthorityDiscovery {
|
||||
by_authority_id: HashMap<AuthorityDiscoveryId, Multiaddr>,
|
||||
by_peer_id: HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
by_authority_id: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||
by_peer_id: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
}
|
||||
|
||||
impl TestAuthorityDiscovery {
|
||||
@@ -187,12 +190,15 @@ mod tests {
|
||||
let multiaddr = known_multiaddr().into_iter().zip(peer_ids.iter().cloned()).map(
|
||||
|(mut addr, peer_id)| {
|
||||
addr.push(multiaddr::Protocol::P2p(peer_id.into()));
|
||||
addr
|
||||
HashSet::from([addr])
|
||||
},
|
||||
);
|
||||
Self {
|
||||
by_authority_id: authorities.iter().cloned().zip(multiaddr).collect(),
|
||||
by_peer_id: peer_ids.into_iter().zip(authorities.into_iter()).collect(),
|
||||
by_peer_id: peer_ids
|
||||
.into_iter()
|
||||
.zip(authorities.into_iter().map(|a| HashSet::from([a])))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,14 +252,14 @@ mod tests {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
authority: AuthorityDiscoveryId,
|
||||
) -> Option<Vec<Multiaddr>> {
|
||||
self.by_authority_id.get(&authority).cloned().map(|addr| vec![addr])
|
||||
) -> Option<HashSet<Multiaddr>> {
|
||||
self.by_authority_id.get(&authority).cloned()
|
||||
}
|
||||
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
) -> Option<AuthorityDiscoveryId> {
|
||||
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||
self.by_peer_id.get(&peer_id).cloned()
|
||||
}
|
||||
}
|
||||
@@ -283,7 +289,8 @@ mod tests {
|
||||
|
||||
let (ns, ads) = new_network();
|
||||
|
||||
let authority_ids: Vec<_> = ads.by_peer_id.values().cloned().collect();
|
||||
let authority_ids: Vec<_> =
|
||||
ads.by_peer_id.values().map(|v| v.iter()).flatten().cloned().collect();
|
||||
|
||||
futures::executor::block_on(async move {
|
||||
let (failed, _) = oneshot::channel();
|
||||
@@ -299,7 +306,7 @@ mod tests {
|
||||
let state = &service.state[PeerSet::Validation];
|
||||
assert_eq!(state.previously_requested.len(), 1);
|
||||
let peer_1 = extract_peer_ids(
|
||||
vec![ads.by_authority_id.get(&authority_ids[1]).unwrap().clone()].into_iter(),
|
||||
ads.by_authority_id.get(&authority_ids[1]).unwrap().clone().into_iter(),
|
||||
)
|
||||
.iter()
|
||||
.cloned()
|
||||
@@ -315,7 +322,8 @@ mod tests {
|
||||
|
||||
let (ns, ads) = new_network();
|
||||
|
||||
let authority_ids: Vec<_> = ads.by_peer_id.values().cloned().collect();
|
||||
let authority_ids: Vec<_> =
|
||||
ads.by_peer_id.values().map(|v| v.iter()).flatten().cloned().collect();
|
||||
|
||||
futures::executor::block_on(async move {
|
||||
let (failed, failed_rx) = oneshot::channel();
|
||||
@@ -333,7 +341,7 @@ mod tests {
|
||||
let state = &service.state[PeerSet::Validation];
|
||||
assert_eq!(state.previously_requested.len(), 1);
|
||||
let peer_0 = extract_peer_ids(
|
||||
vec![ads.by_authority_id.get(&authority_ids[0]).unwrap().clone()].into_iter(),
|
||||
ads.by_authority_id.get(&authority_ids[0]).unwrap().clone().into_iter(),
|
||||
)
|
||||
.iter()
|
||||
.cloned()
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -197,7 +197,7 @@ where
|
||||
let peer = incoming.peer;
|
||||
|
||||
// Only accept messages from validators:
|
||||
if self.authority_discovery.get_authority_id_by_peer_id(peer).await.is_none() {
|
||||
if self.authority_discovery.get_authority_ids_by_peer_id(peer).await.is_none() {
|
||||
incoming
|
||||
.send_outgoing_response(OutgoingResponse {
|
||||
result: Err(()),
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
|
||||
//! Mock data and utility functions for unit tests in this subsystem.
|
||||
|
||||
use std::{collections::HashMap, sync::Arc};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use lazy_static::lazy_static;
|
||||
@@ -171,19 +174,23 @@ impl AuthorityDiscovery for MockAuthorityDiscovery {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
_authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
||||
) -> Option<Vec<sc_network::Multiaddr>> {
|
||||
) -> Option<HashSet<sc_network::Multiaddr>> {
|
||||
panic!("Not implemented");
|
||||
}
|
||||
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: polkadot_node_network_protocol::PeerId,
|
||||
) -> Option<polkadot_primitives::v1::AuthorityDiscoveryId> {
|
||||
) -> Option<HashSet<polkadot_primitives::v1::AuthorityDiscoveryId>> {
|
||||
for (a, p) in self.peer_ids.iter() {
|
||||
if p == &peer_id {
|
||||
return Some(MOCK_VALIDATORS_DISCOVERY_KEYS.get(&a).unwrap().clone())
|
||||
return Some(HashSet::from([MOCK_VALIDATORS_DISCOVERY_KEYS
|
||||
.get(&a)
|
||||
.unwrap()
|
||||
.clone()]))
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
//! the `NetworkBridgeMessage::NewGossipTopology` message.
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
@@ -94,14 +94,14 @@ pub struct GossipSupport<AD> {
|
||||
/// Successfully resolved connections
|
||||
///
|
||||
/// waiting for actual connection.
|
||||
resolved_authorities: HashMap<AuthorityDiscoveryId, Vec<Multiaddr>>,
|
||||
resolved_authorities: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||
|
||||
/// Actually connected authorities.
|
||||
connected_authorities: HashMap<AuthorityDiscoveryId, PeerId>,
|
||||
/// By `PeerId`.
|
||||
///
|
||||
/// Needed for efficient handling of disconnect events.
|
||||
connected_authorities_by_peer_id: HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
connected_authorities_by_peer_id: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
/// Authority discovery service.
|
||||
authority_discovery: AD,
|
||||
}
|
||||
@@ -299,14 +299,19 @@ where
|
||||
fn handle_connect_disconnect(&mut self, ev: NetworkBridgeEvent<GossipSuppportNetworkMessage>) {
|
||||
match ev {
|
||||
NetworkBridgeEvent::PeerConnected(peer_id, _, o_authority) => {
|
||||
if let Some(authority) = o_authority {
|
||||
self.connected_authorities.insert(authority.clone(), peer_id);
|
||||
self.connected_authorities_by_peer_id.insert(peer_id, authority);
|
||||
if let Some(authority_ids) = o_authority {
|
||||
authority_ids.iter().for_each(|a| {
|
||||
self.connected_authorities.insert(a.clone(), peer_id);
|
||||
});
|
||||
self.connected_authorities_by_peer_id.insert(peer_id, authority_ids);
|
||||
}
|
||||
},
|
||||
NetworkBridgeEvent::PeerDisconnected(peer_id) => {
|
||||
if let Some(authority) = self.connected_authorities_by_peer_id.remove(&peer_id) {
|
||||
self.connected_authorities.remove(&authority);
|
||||
if let Some(authority_ids) = self.connected_authorities_by_peer_id.remove(&peer_id)
|
||||
{
|
||||
authority_ids.into_iter().for_each(|a| {
|
||||
self.connected_authorities.remove(&a);
|
||||
});
|
||||
}
|
||||
},
|
||||
NetworkBridgeEvent::OurViewChange(_) => {},
|
||||
@@ -474,7 +479,7 @@ struct PrettyAuthorities<I>(I);
|
||||
|
||||
impl<'a, I> fmt::Display for PrettyAuthorities<I>
|
||||
where
|
||||
I: Iterator<Item = (&'a AuthorityDiscoveryId, &'a Vec<Multiaddr>)> + Clone,
|
||||
I: Iterator<Item = (&'a AuthorityDiscoveryId, &'a HashSet<Multiaddr>)> + Clone,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let mut authorities = self.0.clone().peekable();
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Unit tests for Gossip Support Subsystem.
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use std::{collections::HashSet, sync::Arc, time::Duration};
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use async_trait::async_trait;
|
||||
@@ -64,8 +64,8 @@ type VirtualOverseer = test_helpers::TestSubsystemContextHandle<GossipSupportMes
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct MockAuthorityDiscovery {
|
||||
addrs: HashMap<AuthorityDiscoveryId, Vec<Multiaddr>>,
|
||||
authorities: HashMap<PeerId, AuthorityDiscoveryId>,
|
||||
addrs: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||
authorities: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||
}
|
||||
|
||||
impl MockAuthorityDiscovery {
|
||||
@@ -77,10 +77,13 @@ impl MockAuthorityDiscovery {
|
||||
.into_iter()
|
||||
.map(|(p, a)| {
|
||||
let multiaddr = Multiaddr::empty().with(Protocol::P2p(p.into()));
|
||||
(a, vec![multiaddr])
|
||||
(a, HashSet::from([multiaddr]))
|
||||
})
|
||||
.collect();
|
||||
Self { addrs, authorities }
|
||||
Self {
|
||||
addrs,
|
||||
authorities: authorities.into_iter().map(|(p, a)| (p, HashSet::from([a]))).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,18 +92,18 @@ impl AuthorityDiscovery for MockAuthorityDiscovery {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
||||
) -> Option<Vec<sc_network::Multiaddr>> {
|
||||
) -> Option<HashSet<sc_network::Multiaddr>> {
|
||||
self.addrs.get(&authority).cloned()
|
||||
}
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: polkadot_node_network_protocol::PeerId,
|
||||
) -> Option<polkadot_primitives::v1::AuthorityDiscoveryId> {
|
||||
) -> Option<HashSet<polkadot_primitives::v1::AuthorityDiscoveryId>> {
|
||||
self.authorities.get(&peer_id).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_other_authorities_addrs() -> Vec<Vec<Multiaddr>> {
|
||||
async fn get_other_authorities_addrs() -> Vec<HashSet<Multiaddr>> {
|
||||
let mut addrs = Vec::with_capacity(OTHER_AUTHORITIES.len());
|
||||
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
||||
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
||||
@@ -111,7 +114,7 @@ async fn get_other_authorities_addrs() -> Vec<Vec<Multiaddr>> {
|
||||
addrs
|
||||
}
|
||||
|
||||
async fn get_other_authorities_addrs_map() -> HashMap<AuthorityDiscoveryId, Vec<Multiaddr>> {
|
||||
async fn get_other_authorities_addrs_map() -> HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>> {
|
||||
let mut addrs = HashMap::with_capacity(OTHER_AUTHORITIES.len());
|
||||
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
||||
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
||||
@@ -332,11 +335,11 @@ fn test_log_output() {
|
||||
let mut m = HashMap::new();
|
||||
let peer_id = PeerId::random();
|
||||
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
|
||||
let addrs = vec![addr.clone(), addr];
|
||||
let addrs = HashSet::from([addr.clone(), addr]);
|
||||
m.insert(alice, addrs);
|
||||
let peer_id = PeerId::random();
|
||||
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
|
||||
let addrs = vec![addr.clone(), addr];
|
||||
let addrs = HashSet::from([addr.clone(), addr]);
|
||||
m.insert(bob, addrs);
|
||||
m
|
||||
};
|
||||
@@ -389,16 +392,14 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
|
||||
assert_matches!(
|
||||
overseer_recv(overseer).await,
|
||||
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
||||
mut validator_addrs,
|
||||
validator_addrs,
|
||||
peer_set,
|
||||
}) => {
|
||||
let mut expected = get_other_authorities_addrs_map().await;
|
||||
expected.remove(&alice);
|
||||
expected.remove(&bob);
|
||||
let mut expected: Vec<Vec<Multiaddr>> = expected.into_iter().map(|(_,v)| v).collect();
|
||||
validator_addrs.sort();
|
||||
expected.sort();
|
||||
assert_eq!(validator_addrs, expected);
|
||||
let expected: HashSet<Multiaddr> = expected.into_iter().map(|(_,v)| v.into_iter()).flatten().collect();
|
||||
assert_eq!(validator_addrs.into_iter().map(|v| v.into_iter()).flatten().collect::<HashSet<_>>(), expected);
|
||||
assert_eq!(peer_set, PeerSet::Validation);
|
||||
}
|
||||
);
|
||||
@@ -443,15 +444,13 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
|
||||
assert_matches!(
|
||||
overseer_recv(overseer).await,
|
||||
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
||||
mut validator_addrs,
|
||||
validator_addrs,
|
||||
peer_set,
|
||||
}) => {
|
||||
let mut expected = get_other_authorities_addrs_map().await;
|
||||
expected.remove(&bob);
|
||||
let mut expected: Vec<Vec<Multiaddr>> = expected.into_iter().map(|(_,v)| v).collect();
|
||||
expected.sort();
|
||||
validator_addrs.sort();
|
||||
assert_eq!(validator_addrs, expected);
|
||||
let expected: HashSet<Multiaddr> = expected.into_iter().map(|(_,v)| v.into_iter()).flatten().collect();
|
||||
assert_eq!(validator_addrs.into_iter().map(|v| v.into_iter()).flatten().collect::<HashSet<_>>(), expected);
|
||||
assert_eq!(peer_set, PeerSet::Validation);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Authority discovery service interfacing.
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::{collections::HashSet, fmt::Debug};
|
||||
|
||||
use async_trait::async_trait;
|
||||
|
||||
@@ -34,12 +34,12 @@ pub trait AuthorityDiscovery: Send + Debug + 'static {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
authority: AuthorityDiscoveryId,
|
||||
) -> Option<Vec<Multiaddr>>;
|
||||
) -> Option<HashSet<Multiaddr>>;
|
||||
/// Get the [`AuthorityId`] for the given [`PeerId`] from the local address cache.
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
) -> Option<AuthorityDiscoveryId>;
|
||||
) -> Option<HashSet<AuthorityDiscoveryId>>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -47,14 +47,14 @@ impl AuthorityDiscovery for AuthorityDiscoveryService {
|
||||
async fn get_addresses_by_authority_id(
|
||||
&mut self,
|
||||
authority: AuthorityDiscoveryId,
|
||||
) -> Option<Vec<Multiaddr>> {
|
||||
) -> Option<HashSet<Multiaddr>> {
|
||||
AuthorityDiscoveryService::get_addresses_by_authority_id(self, authority).await
|
||||
}
|
||||
|
||||
async fn get_authority_id_by_peer_id(
|
||||
async fn get_authority_ids_by_peer_id(
|
||||
&mut self,
|
||||
peer_id: PeerId,
|
||||
) -> Option<AuthorityDiscoveryId> {
|
||||
AuthorityDiscoveryService::get_authority_id_by_peer_id(self, peer_id).await
|
||||
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||
AuthorityDiscoveryService::get_authority_ids_by_peer_id(self, peer_id).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()])),
|
||||
),
|
||||
),
|
||||
})
|
||||
|
||||
@@ -355,7 +355,7 @@ pub enum NetworkBridgeMessage {
|
||||
/// connected to.
|
||||
ConnectToResolvedValidators {
|
||||
/// Each entry corresponds to the addresses of an already resolved validator.
|
||||
validator_addrs: Vec<Vec<Multiaddr>>,
|
||||
validator_addrs: Vec<HashSet<Multiaddr>>,
|
||||
/// The peer set we want the connection on.
|
||||
peer_set: PeerSet,
|
||||
},
|
||||
|
||||
@@ -25,7 +25,7 @@ use polkadot_primitives::v1::AuthorityDiscoveryId;
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum NetworkBridgeEvent<M> {
|
||||
/// A peer has connected.
|
||||
PeerConnected(PeerId, ObservedRole, Option<AuthorityDiscoveryId>),
|
||||
PeerConnected(PeerId, ObservedRole, Option<HashSet<AuthorityDiscoveryId>>),
|
||||
|
||||
/// A peer has disconnected.
|
||||
PeerDisconnected(PeerId),
|
||||
|
||||
@@ -144,7 +144,7 @@ These updates are posted from the [Network Bridge Subsystem](../node/utility/net
|
||||
```rust
|
||||
enum NetworkBridgeEvent<M> {
|
||||
/// A peer with given ID is now connected.
|
||||
PeerConnected(PeerId, ObservedRole),
|
||||
PeerConnected(PeerId, ObservedRole, Option<HashSet<AuthorityDiscoveryId>>),
|
||||
/// A peer with given ID is now disconnected.
|
||||
PeerDisconnected(PeerId),
|
||||
/// Our neighbors in the new gossip topology.
|
||||
|
||||
@@ -567,7 +567,7 @@ enum NetworkBridgeMessage {
|
||||
/// `PeerConnected` events from the network bridge.
|
||||
ConnectToValidators {
|
||||
/// Ids of the validators to connect to.
|
||||
validator_ids: Vec<AuthorityDiscoveryId>,
|
||||
validator_ids: HashSet<AuthorityDiscoveryId>,
|
||||
/// The underlying protocol to use for this request.
|
||||
peer_set: PeerSet,
|
||||
/// Sends back the number of `AuthorityDiscoveryId`s which
|
||||
|
||||
Reference in New Issue
Block a user