mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +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 =
|
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 {
|
match peer_set {
|
||||||
PeerSet::Validation => {
|
PeerSet::Validation => {
|
||||||
|
|||||||
@@ -143,14 +143,14 @@ impl validator_discovery::AuthorityDiscovery for TestAuthorityDiscovery {
|
|||||||
async fn get_addresses_by_authority_id(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
_authority: AuthorityDiscoveryId,
|
_authority: AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<Multiaddr>> {
|
) -> Option<HashSet<Multiaddr>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_authority_id_by_peer_id(
|
async fn get_authority_ids_by_peer_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
_peer_id: PeerId,
|
_peer_id: PeerId,
|
||||||
) -> Option<AuthorityDiscoveryId> {
|
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,10 @@ mod tests {
|
|||||||
use polkadot_node_network_protocol::{request_response::outgoing::Requests, PeerId};
|
use polkadot_node_network_protocol::{request_response::outgoing::Requests, PeerId};
|
||||||
use sc_network::{Event as NetworkEvent, IfDisconnected};
|
use sc_network::{Event as NetworkEvent, IfDisconnected};
|
||||||
use sp_keyring::Sr25519Keyring;
|
use sp_keyring::Sr25519Keyring;
|
||||||
use std::{borrow::Cow, collections::HashMap};
|
use std::{
|
||||||
|
borrow::Cow,
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
};
|
||||||
|
|
||||||
fn new_service() -> Service<TestNetwork, TestAuthorityDiscovery> {
|
fn new_service() -> Service<TestNetwork, TestAuthorityDiscovery> {
|
||||||
Service::new()
|
Service::new()
|
||||||
@@ -176,8 +179,8 @@ mod tests {
|
|||||||
|
|
||||||
#[derive(Default, Clone, Debug)]
|
#[derive(Default, Clone, Debug)]
|
||||||
struct TestAuthorityDiscovery {
|
struct TestAuthorityDiscovery {
|
||||||
by_authority_id: HashMap<AuthorityDiscoveryId, Multiaddr>,
|
by_authority_id: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||||
by_peer_id: HashMap<PeerId, AuthorityDiscoveryId>,
|
by_peer_id: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestAuthorityDiscovery {
|
impl TestAuthorityDiscovery {
|
||||||
@@ -187,12 +190,15 @@ mod tests {
|
|||||||
let multiaddr = known_multiaddr().into_iter().zip(peer_ids.iter().cloned()).map(
|
let multiaddr = known_multiaddr().into_iter().zip(peer_ids.iter().cloned()).map(
|
||||||
|(mut addr, peer_id)| {
|
|(mut addr, peer_id)| {
|
||||||
addr.push(multiaddr::Protocol::P2p(peer_id.into()));
|
addr.push(multiaddr::Protocol::P2p(peer_id.into()));
|
||||||
addr
|
HashSet::from([addr])
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
Self {
|
Self {
|
||||||
by_authority_id: authorities.iter().cloned().zip(multiaddr).collect(),
|
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(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
authority: AuthorityDiscoveryId,
|
authority: AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<Multiaddr>> {
|
) -> Option<HashSet<Multiaddr>> {
|
||||||
self.by_authority_id.get(&authority).cloned().map(|addr| vec![addr])
|
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,
|
&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
) -> Option<AuthorityDiscoveryId> {
|
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||||
self.by_peer_id.get(&peer_id).cloned()
|
self.by_peer_id.get(&peer_id).cloned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -283,7 +289,8 @@ mod tests {
|
|||||||
|
|
||||||
let (ns, ads) = new_network();
|
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 {
|
futures::executor::block_on(async move {
|
||||||
let (failed, _) = oneshot::channel();
|
let (failed, _) = oneshot::channel();
|
||||||
@@ -299,7 +306,7 @@ mod tests {
|
|||||||
let state = &service.state[PeerSet::Validation];
|
let state = &service.state[PeerSet::Validation];
|
||||||
assert_eq!(state.previously_requested.len(), 1);
|
assert_eq!(state.previously_requested.len(), 1);
|
||||||
let peer_1 = extract_peer_ids(
|
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()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
@@ -315,7 +322,8 @@ mod tests {
|
|||||||
|
|
||||||
let (ns, ads) = new_network();
|
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 {
|
futures::executor::block_on(async move {
|
||||||
let (failed, failed_rx) = oneshot::channel();
|
let (failed, failed_rx) = oneshot::channel();
|
||||||
@@ -333,7 +341,7 @@ mod tests {
|
|||||||
let state = &service.state[PeerSet::Validation];
|
let state = &service.state[PeerSet::Validation];
|
||||||
assert_eq!(state.previously_requested.len(), 1);
|
assert_eq!(state.previously_requested.len(), 1);
|
||||||
let peer_0 = extract_peer_ids(
|
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()
|
.iter()
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|||||||
@@ -165,11 +165,11 @@ impl ValidatorGroup {
|
|||||||
/// Returns `true` if we should advertise our collation to the given peer.
|
/// Returns `true` if we should advertise our collation to the given peer.
|
||||||
fn should_advertise_to(
|
fn should_advertise_to(
|
||||||
&self,
|
&self,
|
||||||
peer_ids: &HashMap<PeerId, AuthorityDiscoveryId>,
|
peer_ids: &HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||||
peer: &PeerId,
|
peer: &PeerId,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
match peer_ids.get(peer) {
|
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,
|
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.
|
/// Should be called after we advertised our collation to the given `peer` to keep track of it.
|
||||||
fn advertised_to_peer(
|
fn advertised_to_peer(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer_ids: &HashMap<PeerId, AuthorityDiscoveryId>,
|
peer_ids: &HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||||
peer: &PeerId,
|
peer: &PeerId,
|
||||||
) {
|
) {
|
||||||
if let Some(validator_id) = peer_ids.get(peer) {
|
if let Some(authority_ids) = peer_ids.get(peer) {
|
||||||
self.advertised_to.insert(validator_id.clone());
|
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 validator groups per active leaf.
|
||||||
our_validators_groups: HashMap<Hash, ValidatorGroup>,
|
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.
|
/// by `PeerConnected` events.
|
||||||
peer_ids: HashMap<PeerId, AuthorityDiscoveryId>,
|
peer_ids: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||||
|
|
||||||
/// Metrics.
|
/// Metrics.
|
||||||
metrics: Metrics,
|
metrics: Metrics,
|
||||||
@@ -907,14 +909,14 @@ where
|
|||||||
// If it is possible that a disconnected validator would attempt a reconnect
|
// If it is possible that a disconnected validator would attempt a reconnect
|
||||||
// it should be handled here.
|
// it should be handled here.
|
||||||
tracing::trace!(target: LOG_TARGET, ?peer_id, ?observed_role, "Peer connected");
|
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!(
|
tracing::trace!(
|
||||||
target: LOG_TARGET,
|
target: LOG_TARGET,
|
||||||
?authority,
|
?authority_ids,
|
||||||
?peer_id,
|
?peer_id,
|
||||||
"Connected to requested validator"
|
"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;
|
declare(ctx, state, peer_id).await;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{collections::HashSet, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use assert_matches::assert_matches;
|
use assert_matches::assert_matches;
|
||||||
use futures::{executor, future, Future, SinkExt};
|
use futures::{executor, future, Future, SinkExt};
|
||||||
@@ -405,7 +405,7 @@ async fn connect_peer(
|
|||||||
CollatorProtocolMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerConnected(
|
CollatorProtocolMessage::NetworkBridgeUpdateV1(NetworkBridgeEvent::PeerConnected(
|
||||||
peer.clone(),
|
peer.clone(),
|
||||||
polkadot_node_network_protocol::ObservedRole::Authority,
|
polkadot_node_network_protocol::ObservedRole::Authority,
|
||||||
authority_id,
|
authority_id.map(|v| HashSet::from([v])),
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ where
|
|||||||
let peer = incoming.peer;
|
let peer = incoming.peer;
|
||||||
|
|
||||||
// Only accept messages from validators:
|
// 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
|
incoming
|
||||||
.send_outgoing_response(OutgoingResponse {
|
.send_outgoing_response(OutgoingResponse {
|
||||||
result: Err(()),
|
result: Err(()),
|
||||||
|
|||||||
@@ -17,7 +17,10 @@
|
|||||||
|
|
||||||
//! Mock data and utility functions for unit tests in this subsystem.
|
//! 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 async_trait::async_trait;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@@ -171,19 +174,23 @@ impl AuthorityDiscovery for MockAuthorityDiscovery {
|
|||||||
async fn get_addresses_by_authority_id(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
_authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
_authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<sc_network::Multiaddr>> {
|
) -> Option<HashSet<sc_network::Multiaddr>> {
|
||||||
panic!("Not implemented");
|
panic!("Not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_authority_id_by_peer_id(
|
async fn get_authority_ids_by_peer_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer_id: polkadot_node_network_protocol::PeerId,
|
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() {
|
for (a, p) in self.peer_ids.iter() {
|
||||||
if p == &peer_id {
|
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
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
//! the `NetworkBridgeMessage::NewGossipTopology` message.
|
//! the `NetworkBridgeMessage::NewGossipTopology` message.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::{HashMap, HashSet},
|
||||||
fmt,
|
fmt,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
@@ -94,14 +94,14 @@ pub struct GossipSupport<AD> {
|
|||||||
/// Successfully resolved connections
|
/// Successfully resolved connections
|
||||||
///
|
///
|
||||||
/// waiting for actual connection.
|
/// waiting for actual connection.
|
||||||
resolved_authorities: HashMap<AuthorityDiscoveryId, Vec<Multiaddr>>,
|
resolved_authorities: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||||
|
|
||||||
/// Actually connected authorities.
|
/// Actually connected authorities.
|
||||||
connected_authorities: HashMap<AuthorityDiscoveryId, PeerId>,
|
connected_authorities: HashMap<AuthorityDiscoveryId, PeerId>,
|
||||||
/// By `PeerId`.
|
/// By `PeerId`.
|
||||||
///
|
///
|
||||||
/// Needed for efficient handling of disconnect events.
|
/// 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 service.
|
||||||
authority_discovery: AD,
|
authority_discovery: AD,
|
||||||
}
|
}
|
||||||
@@ -299,14 +299,19 @@ where
|
|||||||
fn handle_connect_disconnect(&mut self, ev: NetworkBridgeEvent<GossipSuppportNetworkMessage>) {
|
fn handle_connect_disconnect(&mut self, ev: NetworkBridgeEvent<GossipSuppportNetworkMessage>) {
|
||||||
match ev {
|
match ev {
|
||||||
NetworkBridgeEvent::PeerConnected(peer_id, _, o_authority) => {
|
NetworkBridgeEvent::PeerConnected(peer_id, _, o_authority) => {
|
||||||
if let Some(authority) = o_authority {
|
if let Some(authority_ids) = o_authority {
|
||||||
self.connected_authorities.insert(authority.clone(), peer_id);
|
authority_ids.iter().for_each(|a| {
|
||||||
self.connected_authorities_by_peer_id.insert(peer_id, authority);
|
self.connected_authorities.insert(a.clone(), peer_id);
|
||||||
|
});
|
||||||
|
self.connected_authorities_by_peer_id.insert(peer_id, authority_ids);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NetworkBridgeEvent::PeerDisconnected(peer_id) => {
|
NetworkBridgeEvent::PeerDisconnected(peer_id) => {
|
||||||
if let Some(authority) = self.connected_authorities_by_peer_id.remove(&peer_id) {
|
if let Some(authority_ids) = self.connected_authorities_by_peer_id.remove(&peer_id)
|
||||||
self.connected_authorities.remove(&authority);
|
{
|
||||||
|
authority_ids.into_iter().for_each(|a| {
|
||||||
|
self.connected_authorities.remove(&a);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NetworkBridgeEvent::OurViewChange(_) => {},
|
NetworkBridgeEvent::OurViewChange(_) => {},
|
||||||
@@ -474,7 +479,7 @@ struct PrettyAuthorities<I>(I);
|
|||||||
|
|
||||||
impl<'a, I> fmt::Display for PrettyAuthorities<I>
|
impl<'a, I> fmt::Display for PrettyAuthorities<I>
|
||||||
where
|
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 {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut authorities = self.0.clone().peekable();
|
let mut authorities = self.0.clone().peekable();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! Unit tests for Gossip Support Subsystem.
|
//! 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 assert_matches::assert_matches;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -64,8 +64,8 @@ type VirtualOverseer = test_helpers::TestSubsystemContextHandle<GossipSupportMes
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct MockAuthorityDiscovery {
|
struct MockAuthorityDiscovery {
|
||||||
addrs: HashMap<AuthorityDiscoveryId, Vec<Multiaddr>>,
|
addrs: HashMap<AuthorityDiscoveryId, HashSet<Multiaddr>>,
|
||||||
authorities: HashMap<PeerId, AuthorityDiscoveryId>,
|
authorities: HashMap<PeerId, HashSet<AuthorityDiscoveryId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MockAuthorityDiscovery {
|
impl MockAuthorityDiscovery {
|
||||||
@@ -77,10 +77,13 @@ impl MockAuthorityDiscovery {
|
|||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(p, a)| {
|
.map(|(p, a)| {
|
||||||
let multiaddr = Multiaddr::empty().with(Protocol::P2p(p.into()));
|
let multiaddr = Multiaddr::empty().with(Protocol::P2p(p.into()));
|
||||||
(a, vec![multiaddr])
|
(a, HashSet::from([multiaddr]))
|
||||||
})
|
})
|
||||||
.collect();
|
.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(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
authority: polkadot_primitives::v1::AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<sc_network::Multiaddr>> {
|
) -> Option<HashSet<sc_network::Multiaddr>> {
|
||||||
self.addrs.get(&authority).cloned()
|
self.addrs.get(&authority).cloned()
|
||||||
}
|
}
|
||||||
async fn get_authority_id_by_peer_id(
|
async fn get_authority_ids_by_peer_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
peer_id: polkadot_node_network_protocol::PeerId,
|
peer_id: polkadot_node_network_protocol::PeerId,
|
||||||
) -> Option<polkadot_primitives::v1::AuthorityDiscoveryId> {
|
) -> Option<HashSet<polkadot_primitives::v1::AuthorityDiscoveryId>> {
|
||||||
self.authorities.get(&peer_id).cloned()
|
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 addrs = Vec::with_capacity(OTHER_AUTHORITIES.len());
|
||||||
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
||||||
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
||||||
@@ -111,7 +114,7 @@ async fn get_other_authorities_addrs() -> Vec<Vec<Multiaddr>> {
|
|||||||
addrs
|
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 addrs = HashMap::with_capacity(OTHER_AUTHORITIES.len());
|
||||||
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
let mut discovery = MOCK_AUTHORITY_DISCOVERY.clone();
|
||||||
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
for authority in OTHER_AUTHORITIES.iter().cloned() {
|
||||||
@@ -332,11 +335,11 @@ fn test_log_output() {
|
|||||||
let mut m = HashMap::new();
|
let mut m = HashMap::new();
|
||||||
let peer_id = PeerId::random();
|
let peer_id = PeerId::random();
|
||||||
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
|
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);
|
m.insert(alice, addrs);
|
||||||
let peer_id = PeerId::random();
|
let peer_id = PeerId::random();
|
||||||
let addr = Multiaddr::empty().with(Protocol::P2p(peer_id.into()));
|
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.insert(bob, addrs);
|
||||||
m
|
m
|
||||||
};
|
};
|
||||||
@@ -389,16 +392,14 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
overseer_recv(overseer).await,
|
overseer_recv(overseer).await,
|
||||||
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
||||||
mut validator_addrs,
|
validator_addrs,
|
||||||
peer_set,
|
peer_set,
|
||||||
}) => {
|
}) => {
|
||||||
let mut expected = get_other_authorities_addrs_map().await;
|
let mut expected = get_other_authorities_addrs_map().await;
|
||||||
expected.remove(&alice);
|
expected.remove(&alice);
|
||||||
expected.remove(&bob);
|
expected.remove(&bob);
|
||||||
let mut expected: Vec<Vec<Multiaddr>> = expected.into_iter().map(|(_,v)| v).collect();
|
let expected: HashSet<Multiaddr> = expected.into_iter().map(|(_,v)| v.into_iter()).flatten().collect();
|
||||||
validator_addrs.sort();
|
assert_eq!(validator_addrs.into_iter().map(|v| v.into_iter()).flatten().collect::<HashSet<_>>(), expected);
|
||||||
expected.sort();
|
|
||||||
assert_eq!(validator_addrs, expected);
|
|
||||||
assert_eq!(peer_set, PeerSet::Validation);
|
assert_eq!(peer_set, PeerSet::Validation);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -443,15 +444,13 @@ fn issues_a_connection_request_when_last_request_was_mostly_unresolved() {
|
|||||||
assert_matches!(
|
assert_matches!(
|
||||||
overseer_recv(overseer).await,
|
overseer_recv(overseer).await,
|
||||||
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
AllMessages::NetworkBridge(NetworkBridgeMessage::ConnectToResolvedValidators {
|
||||||
mut validator_addrs,
|
validator_addrs,
|
||||||
peer_set,
|
peer_set,
|
||||||
}) => {
|
}) => {
|
||||||
let mut expected = get_other_authorities_addrs_map().await;
|
let mut expected = get_other_authorities_addrs_map().await;
|
||||||
expected.remove(&bob);
|
expected.remove(&bob);
|
||||||
let mut expected: Vec<Vec<Multiaddr>> = expected.into_iter().map(|(_,v)| v).collect();
|
let expected: HashSet<Multiaddr> = expected.into_iter().map(|(_,v)| v.into_iter()).flatten().collect();
|
||||||
expected.sort();
|
assert_eq!(validator_addrs.into_iter().map(|v| v.into_iter()).flatten().collect::<HashSet<_>>(), expected);
|
||||||
validator_addrs.sort();
|
|
||||||
assert_eq!(validator_addrs, expected);
|
|
||||||
assert_eq!(peer_set, PeerSet::Validation);
|
assert_eq!(peer_set, PeerSet::Validation);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//! Authority discovery service interfacing.
|
//! Authority discovery service interfacing.
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::{collections::HashSet, fmt::Debug};
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
|
||||||
@@ -34,12 +34,12 @@ pub trait AuthorityDiscovery: Send + Debug + 'static {
|
|||||||
async fn get_addresses_by_authority_id(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
authority: AuthorityDiscoveryId,
|
authority: AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<Multiaddr>>;
|
) -> Option<HashSet<Multiaddr>>;
|
||||||
/// Get the [`AuthorityId`] for the given [`PeerId`] from the local address cache.
|
/// 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,
|
&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
) -> Option<AuthorityDiscoveryId>;
|
) -> Option<HashSet<AuthorityDiscoveryId>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -47,14 +47,14 @@ impl AuthorityDiscovery for AuthorityDiscoveryService {
|
|||||||
async fn get_addresses_by_authority_id(
|
async fn get_addresses_by_authority_id(
|
||||||
&mut self,
|
&mut self,
|
||||||
authority: AuthorityDiscoveryId,
|
authority: AuthorityDiscoveryId,
|
||||||
) -> Option<Vec<Multiaddr>> {
|
) -> Option<HashSet<Multiaddr>> {
|
||||||
AuthorityDiscoveryService::get_addresses_by_authority_id(self, authority).await
|
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,
|
&mut self,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
) -> Option<AuthorityDiscoveryId> {
|
) -> Option<HashSet<AuthorityDiscoveryId>> {
|
||||||
AuthorityDiscoveryService::get_authority_id_by_peer_id(self, peer_id).await
|
AuthorityDiscoveryService::get_authority_ids_by_peer_id(self, peer_id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -413,8 +413,8 @@ impl PeerRelayParentKnowledge {
|
|||||||
struct PeerData {
|
struct PeerData {
|
||||||
view: View,
|
view: View,
|
||||||
view_knowledge: HashMap<Hash, PeerRelayParentKnowledge>,
|
view_knowledge: HashMap<Hash, PeerRelayParentKnowledge>,
|
||||||
// Peer might be an authority.
|
/// Peer might be known as authority with the given ids.
|
||||||
maybe_authority: Option<AuthorityDiscoveryId>,
|
maybe_authority: Option<HashSet<AuthorityDiscoveryId>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PeerData {
|
impl PeerData {
|
||||||
@@ -1466,14 +1466,18 @@ async fn handle_network_update(
|
|||||||
maybe_authority: maybe_authority.clone(),
|
maybe_authority: maybe_authority.clone(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if let Some(authority) = maybe_authority {
|
if let Some(authority_ids) = maybe_authority {
|
||||||
authorities.insert(authority, peer);
|
authority_ids.into_iter().for_each(|a| {
|
||||||
|
authorities.insert(a, peer);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NetworkBridgeEvent::PeerDisconnected(peer) => {
|
NetworkBridgeEvent::PeerDisconnected(peer) => {
|
||||||
tracing::trace!(target: LOG_TARGET, ?peer, "Peer disconnected");
|
tracing::trace!(target: LOG_TARGET, ?peer, "Peer disconnected");
|
||||||
if let Some(auth_id) = peers.remove(&peer).and_then(|p| p.maybe_authority) {
|
if let Some(auth_ids) = peers.remove(&peer).and_then(|p| p.maybe_authority) {
|
||||||
authorities.remove(&auth_id);
|
auth_ids.into_iter().for_each(|a| {
|
||||||
|
authorities.remove(&a);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NetworkBridgeEvent::NewGossipTopology(new_peers) => {
|
NetworkBridgeEvent::NewGossipTopology(new_peers) => {
|
||||||
|
|||||||
@@ -944,7 +944,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
|
|||||||
NetworkBridgeEvent::PeerConnected(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_a.clone(),
|
peer_a.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_b.clone(),
|
peer_b.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_c.clone(),
|
peer_c.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer,
|
peer,
|
||||||
ObservedRole::Full,
|
ObservedRole::Full,
|
||||||
Some(pair.public().into()),
|
Some(HashSet::from([pair.public().into()])),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
@@ -1466,7 +1466,7 @@ fn share_prioritizes_backing_group() {
|
|||||||
NetworkBridgeEvent::PeerConnected(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_a.clone(),
|
peer_a.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_b.clone(),
|
peer_b.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_c.clone(),
|
peer_c.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_other_group.clone(),
|
peer_other_group.clone(),
|
||||||
ObservedRole::Full,
|
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(
|
NetworkBridgeEvent::PeerConnected(
|
||||||
peer_a.clone(),
|
peer_a.clone(),
|
||||||
ObservedRole::Full,
|
ObservedRole::Full,
|
||||||
Some(Sr25519Keyring::Alice.public().into()),
|
Some(HashSet::from([Sr25519Keyring::Alice.public().into()])),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ pub enum NetworkBridgeMessage {
|
|||||||
/// connected to.
|
/// connected to.
|
||||||
ConnectToResolvedValidators {
|
ConnectToResolvedValidators {
|
||||||
/// Each entry corresponds to the addresses of an already resolved validator.
|
/// 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.
|
/// The peer set we want the connection on.
|
||||||
peer_set: PeerSet,
|
peer_set: PeerSet,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ use polkadot_primitives::v1::AuthorityDiscoveryId;
|
|||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub enum NetworkBridgeEvent<M> {
|
pub enum NetworkBridgeEvent<M> {
|
||||||
/// A peer has connected.
|
/// A peer has connected.
|
||||||
PeerConnected(PeerId, ObservedRole, Option<AuthorityDiscoveryId>),
|
PeerConnected(PeerId, ObservedRole, Option<HashSet<AuthorityDiscoveryId>>),
|
||||||
|
|
||||||
/// A peer has disconnected.
|
/// A peer has disconnected.
|
||||||
PeerDisconnected(PeerId),
|
PeerDisconnected(PeerId),
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ These updates are posted from the [Network Bridge Subsystem](../node/utility/net
|
|||||||
```rust
|
```rust
|
||||||
enum NetworkBridgeEvent<M> {
|
enum NetworkBridgeEvent<M> {
|
||||||
/// A peer with given ID is now connected.
|
/// 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.
|
/// A peer with given ID is now disconnected.
|
||||||
PeerDisconnected(PeerId),
|
PeerDisconnected(PeerId),
|
||||||
/// Our neighbors in the new gossip topology.
|
/// Our neighbors in the new gossip topology.
|
||||||
|
|||||||
@@ -567,7 +567,7 @@ enum NetworkBridgeMessage {
|
|||||||
/// `PeerConnected` events from the network bridge.
|
/// `PeerConnected` events from the network bridge.
|
||||||
ConnectToValidators {
|
ConnectToValidators {
|
||||||
/// Ids of the validators to connect to.
|
/// Ids of the validators to connect to.
|
||||||
validator_ids: Vec<AuthorityDiscoveryId>,
|
validator_ids: HashSet<AuthorityDiscoveryId>,
|
||||||
/// The underlying protocol to use for this request.
|
/// The underlying protocol to use for this request.
|
||||||
peer_set: PeerSet,
|
peer_set: PeerSet,
|
||||||
/// Sends back the number of `AuthorityDiscoveryId`s which
|
/// Sends back the number of `AuthorityDiscoveryId`s which
|
||||||
|
|||||||
Reference in New Issue
Block a user