mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
validator_discovery: simplification (#3009)
* validator_discovery: simplification * compilation fixes * compilation fixes II * compilation fixes III * compilation fixes IV
This commit is contained in:
@@ -18,22 +18,19 @@
|
||||
//! and issuing a connection request to the validators relevant to
|
||||
//! the gossiping subsystems on every new session.
|
||||
|
||||
use futures::{channel::mpsc, FutureExt as _};
|
||||
use futures::{channel::oneshot, FutureExt as _};
|
||||
use polkadot_node_subsystem::{
|
||||
messages::{
|
||||
GossipSupportMessage,
|
||||
AllMessages, GossipSupportMessage, NetworkBridgeMessage,
|
||||
},
|
||||
ActiveLeavesUpdate, FromOverseer, OverseerSignal,
|
||||
Subsystem, SpawnedSubsystem, SubsystemContext,
|
||||
};
|
||||
use polkadot_node_subsystem_util::{
|
||||
validator_discovery,
|
||||
self as util,
|
||||
};
|
||||
use polkadot_node_subsystem_util as util;
|
||||
use polkadot_primitives::v1::{
|
||||
Hash, SessionIndex, AuthorityDiscoveryId,
|
||||
};
|
||||
use polkadot_node_network_protocol::{peer_set::PeerSet, PeerId};
|
||||
use polkadot_node_network_protocol::peer_set::PeerSet;
|
||||
use sp_keystore::{CryptoStore, SyncCryptoStorePtr};
|
||||
use sp_application_crypto::{Public, AppKey};
|
||||
|
||||
@@ -48,7 +45,7 @@ pub struct GossipSupport {
|
||||
struct State {
|
||||
last_session_index: Option<SessionIndex>,
|
||||
/// when we overwrite this, it automatically drops the previous request
|
||||
_last_connection_request: Option<mpsc::Receiver<(AuthorityDiscoveryId, PeerId)>>,
|
||||
_last_connection_request: Option<oneshot::Sender<()>>,
|
||||
}
|
||||
|
||||
impl GossipSupport {
|
||||
@@ -123,6 +120,24 @@ async fn ensure_i_am_an_authority(
|
||||
Err(util::Error::NotAValidator)
|
||||
}
|
||||
|
||||
/// A helper function for making a `ConnectToValidators` request.
|
||||
pub async fn connect_to_authorities(
|
||||
ctx: &mut impl SubsystemContext,
|
||||
validator_ids: Vec<AuthorityDiscoveryId>,
|
||||
peer_set: PeerSet,
|
||||
) -> oneshot::Sender<()> {
|
||||
let (keep_alive_handle, keep_alive) = oneshot::channel();
|
||||
|
||||
ctx.send_message(AllMessages::NetworkBridge(
|
||||
NetworkBridgeMessage::ConnectToValidators {
|
||||
validator_ids,
|
||||
peer_set,
|
||||
keep_alive,
|
||||
}
|
||||
)).await;
|
||||
|
||||
keep_alive_handle
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// 1. Determine if the current session index has changed.
|
||||
@@ -147,14 +162,14 @@ impl State {
|
||||
ensure_i_am_an_authority(keystore, &authorities).await?;
|
||||
tracing::debug!(target: LOG_TARGET, num = ?authorities.len(), "Issuing a connection request");
|
||||
|
||||
let request = validator_discovery::connect_to_authorities(
|
||||
let keep_alive_handle = connect_to_authorities(
|
||||
ctx,
|
||||
authorities,
|
||||
PeerSet::Validation,
|
||||
).await;
|
||||
|
||||
self.last_session_index = Some(new_session);
|
||||
self._last_connection_request = Some(request);
|
||||
self._last_connection_request = Some(keep_alive_handle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user