validator_discovery: simplification (#3009)

* validator_discovery: simplification

* compilation fixes

* compilation fixes II

* compilation fixes III

* compilation fixes IV
This commit is contained in:
Andronik Ordian
2021-05-13 11:31:15 +02:00
committed by GitHub
parent 0e6c96a8b6
commit 60fbca3c2a
8 changed files with 90 additions and 899 deletions
+3 -44
View File
@@ -23,7 +23,6 @@
use parity_scale_codec::{Encode, Decode};
use parking_lot::Mutex;
use futures::prelude::*;
use futures::channel::mpsc;
use sc_network::Event as NetworkEvent;
use sp_consensus::SyncOracle;
@@ -36,7 +35,7 @@ use polkadot_subsystem::messages::{
NetworkBridgeMessage, AllMessages,
CollatorProtocolMessage, NetworkBridgeEvent,
};
use polkadot_primitives::v1::{Hash, BlockNumber, AuthorityDiscoveryId};
use polkadot_primitives::v1::{Hash, BlockNumber};
use polkadot_node_network_protocol::{
PeerId, peer_set::PeerSet, View, v1 as protocol_v1, OurView, UnifiedReputationChange as Rep,
ObservedRole,
@@ -314,12 +313,6 @@ impl From<SubsystemError> for UnexpectedAbort {
}
}
// notifications to be passed through to the validator discovery worker.
enum ValidatorDiscoveryNotification {
PeerConnected(PeerId, PeerSet, Option<AuthorityDiscoveryId>),
PeerDisconnected(PeerId, PeerSet),
}
#[derive(Default, Clone)]
struct Shared(Arc<Mutex<SharedInner>>);
@@ -339,7 +332,6 @@ async fn handle_subsystem_messages<Context, N, AD>(
mut ctx: Context,
mut network_service: N,
mut authority_discovery_service: AD,
validator_discovery_notifications: mpsc::Receiver<ValidatorDiscoveryNotification>,
shared: Shared,
sync_oracle: Box<dyn SyncOracle + Send>,
metrics: Metrics,
@@ -356,8 +348,6 @@ where
let mut mode = Mode::Syncing(sync_oracle);
let mut validator_discovery_notifications = validator_discovery_notifications.fuse();
loop {
futures::select! {
msg = ctx.recv().fuse() => match msg {
@@ -514,7 +504,7 @@ where
NetworkBridgeMessage::ConnectToValidators {
validator_ids,
peer_set,
connected,
keep_alive,
} => {
tracing::trace!(
target: LOG_TARGET,
@@ -527,7 +517,7 @@ where
let (ns, ads) = validator_discovery.on_request(
validator_ids,
peer_set,
connected,
keep_alive,
network_service,
authority_discovery_service,
).await;
@@ -538,19 +528,6 @@ where
}
Err(e) => return Err(e.into()),
},
notification = validator_discovery_notifications.next().fuse() => match notification {
None => return Ok(()),
Some(ValidatorDiscoveryNotification::PeerConnected(peer, peer_set, maybe_auth)) => {
validator_discovery.on_peer_connected(
peer.clone(),
peer_set,
maybe_auth,
).await;
}
Some(ValidatorDiscoveryNotification::PeerDisconnected(peer, peer_set)) => {
validator_discovery.on_peer_disconnected(&peer, peer_set);
}
},
}
}
}
@@ -560,7 +537,6 @@ async fn handle_network_messages<AD: validator_discovery::AuthorityDiscovery>(
mut network_service: impl Network,
mut authority_discovery_service: AD,
mut request_multiplexer: RequestMultiplexer,
mut validator_discovery_notifications: mpsc::Sender<ValidatorDiscoveryNotification>,
metrics: Metrics,
shared: Shared,
) -> Result<(), UnexpectedAbort> {
@@ -612,13 +588,6 @@ async fn handle_network_messages<AD: validator_discovery::AuthorityDiscovery>(
authority_discovery_service
.get_authority_id_by_peer_id(peer).await;
// Failure here means that the other side of the network bridge
// has concluded and this future will be dropped in due course.
let _ = validator_discovery_notifications.send(
ValidatorDiscoveryNotification::PeerConnected(peer, peer_set, maybe_authority.clone())
).await;
match peer_set {
PeerSet::Validation => {
dispatch_validation_events_to_all(
@@ -694,12 +663,6 @@ async fn handle_network_messages<AD: validator_discovery::AuthorityDiscovery>(
w
};
// Failure here means that the other side of the network bridge
// has concluded and this future will be dropped in due course.
let _ = validator_discovery_notifications.send(
ValidatorDiscoveryNotification::PeerDisconnected(peer.clone(), peer_set)
).await;
if was_connected {
match peer_set {
PeerSet::Validation => dispatch_validation_event_to_all(
@@ -858,14 +821,11 @@ where
.get_statement_fetching()
.expect("Gets initialized, must be `Some` on startup. qed.");
let (validation_worker_tx, validation_worker_rx) = mpsc::channel(1024);
let (remote, network_event_handler) = handle_network_messages(
ctx.sender().clone(),
network_service.clone(),
authority_discovery_service.clone(),
request_multiplexer,
validation_worker_tx,
metrics.clone(),
shared.clone(),
).remote_handle();
@@ -880,7 +840,6 @@ where
ctx,
network_service,
authority_discovery_service,
validation_worker_rx,
shared,
sync_oracle,
metrics,