mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 23:18:01 +00:00
validator_discovery: pass PeerSet to the request (#2372)
* validator_discovery: pass PeerSet to the request * validator_discovery: track PeerSet of connected peers * validator_discovery: fix tests * validator_discovery: fix long line * some fixes * some validator_discovery logs * log validator discovery request * Also connect to validators on `DistributePoV`. * validator_discovery: store the whole state per peer_set * bump spec versions in kusama, polkadot and westend * Correcting doc. * validator_discovery: bump channel capacity * pov-distribution: some cleanup * this should fix the test, but it does not * I just got some brain damage while fixing this Why are you even reading this??? * wrap long line * address some review nits Co-authored-by: Robert Klotzner <robert.klotzner@gmx.at>
This commit is contained in:
@@ -33,6 +33,7 @@ use polkadot_node_subsystem::{
|
||||
SubsystemContext,
|
||||
};
|
||||
use polkadot_primitives::v1::{Hash, ValidatorId, AuthorityDiscoveryId, SessionIndex};
|
||||
use polkadot_node_network_protocol::peer_set::PeerSet;
|
||||
use sc_network::PeerId;
|
||||
use crate::Error;
|
||||
|
||||
@@ -41,16 +42,24 @@ pub async fn connect_to_validators<Context: SubsystemContext>(
|
||||
ctx: &mut Context,
|
||||
relay_parent: Hash,
|
||||
validators: Vec<ValidatorId>,
|
||||
peer_set: PeerSet,
|
||||
) -> Result<ConnectionRequest, Error> {
|
||||
let current_index = crate::request_session_index_for_child_ctx(relay_parent, ctx).await?.await??;
|
||||
connect_to_past_session_validators(ctx, relay_parent, validators, current_index).await
|
||||
connect_to_validators_in_session(
|
||||
ctx,
|
||||
relay_parent,
|
||||
validators,
|
||||
peer_set,
|
||||
current_index,
|
||||
).await
|
||||
}
|
||||
|
||||
/// Utility function to make it easier to connect to validators in the past sessions.
|
||||
pub async fn connect_to_past_session_validators<Context: SubsystemContext>(
|
||||
/// Utility function to make it easier to connect to validators in the given session.
|
||||
pub async fn connect_to_validators_in_session<Context: SubsystemContext>(
|
||||
ctx: &mut Context,
|
||||
relay_parent: Hash,
|
||||
validators: Vec<ValidatorId>,
|
||||
peer_set: PeerSet,
|
||||
session_index: SessionIndex,
|
||||
) -> Result<ConnectionRequest, Error> {
|
||||
let session_info = crate::request_session_info_ctx(
|
||||
@@ -66,6 +75,14 @@ pub async fn connect_to_past_session_validators<Context: SubsystemContext>(
|
||||
).into()),
|
||||
};
|
||||
|
||||
tracing::trace!(
|
||||
target: "network_bridge",
|
||||
validators = ?validators,
|
||||
discovery_keys = ?discovery_keys,
|
||||
session_index,
|
||||
"Trying to serve the validator discovery request",
|
||||
);
|
||||
|
||||
let id_to_index = session_validators.iter()
|
||||
.zip(0usize..)
|
||||
.collect::<HashMap<_, _>>();
|
||||
@@ -88,7 +105,7 @@ pub async fn connect_to_past_session_validators<Context: SubsystemContext>(
|
||||
.filter_map(|(k, v)| v.map(|v| (v, k)))
|
||||
.collect::<HashMap<AuthorityDiscoveryId, ValidatorId>>();
|
||||
|
||||
let connections = connect_to_authorities(ctx, authorities).await;
|
||||
let connections = connect_to_authorities(ctx, authorities, peer_set).await;
|
||||
|
||||
Ok(ConnectionRequest {
|
||||
validator_map,
|
||||
@@ -99,14 +116,16 @@ pub async fn connect_to_past_session_validators<Context: SubsystemContext>(
|
||||
async fn connect_to_authorities<Context: SubsystemContext>(
|
||||
ctx: &mut Context,
|
||||
validator_ids: Vec<AuthorityDiscoveryId>,
|
||||
peer_set: PeerSet,
|
||||
) -> mpsc::Receiver<(AuthorityDiscoveryId, PeerId)> {
|
||||
const PEERS_CAPACITY: usize = 8;
|
||||
const PEERS_CAPACITY: usize = 32;
|
||||
|
||||
let (connected, connected_rx) = mpsc::channel(PEERS_CAPACITY);
|
||||
|
||||
ctx.send_message(AllMessages::NetworkBridge(
|
||||
NetworkBridgeMessage::ConnectToValidators {
|
||||
validator_ids,
|
||||
peer_set,
|
||||
connected,
|
||||
}
|
||||
)).await;
|
||||
|
||||
Reference in New Issue
Block a user