mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 21:57:55 +00:00
Change validation & collation protocol names to include genesis hash & fork id (#5876)
This commit is contained in:
@@ -18,7 +18,9 @@
|
||||
use super::*;
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSet, request_response::ReqProtocolNames, v1 as protocol_v1, PeerId, Versioned,
|
||||
peer_set::{CollationVersion, PeerSet, PeerSetProtocolNames, ValidationVersion},
|
||||
request_response::ReqProtocolNames,
|
||||
v1 as protocol_v1, PeerId, Versioned,
|
||||
};
|
||||
|
||||
use polkadot_node_subsystem::{
|
||||
@@ -53,6 +55,7 @@ pub struct NetworkBridgeTx<N, AD> {
|
||||
authority_discovery_service: AD,
|
||||
metrics: Metrics,
|
||||
req_protocol_names: ReqProtocolNames,
|
||||
peerset_protocol_names: PeerSetProtocolNames,
|
||||
}
|
||||
|
||||
impl<N, AD> NetworkBridgeTx<N, AD> {
|
||||
@@ -65,8 +68,15 @@ impl<N, AD> NetworkBridgeTx<N, AD> {
|
||||
authority_discovery_service: AD,
|
||||
metrics: Metrics,
|
||||
req_protocol_names: ReqProtocolNames,
|
||||
peerset_protocol_names: PeerSetProtocolNames,
|
||||
) -> Self {
|
||||
Self { network_service, authority_discovery_service, metrics, req_protocol_names }
|
||||
Self {
|
||||
network_service,
|
||||
authority_discovery_service,
|
||||
metrics,
|
||||
req_protocol_names,
|
||||
peerset_protocol_names,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,12 +101,14 @@ async fn handle_subsystem_messages<Context, N, AD>(
|
||||
mut authority_discovery_service: AD,
|
||||
metrics: Metrics,
|
||||
req_protocol_names: ReqProtocolNames,
|
||||
peerset_protocol_names: PeerSetProtocolNames,
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
N: Network,
|
||||
AD: validator_discovery::AuthorityDiscovery + Clone,
|
||||
{
|
||||
let mut validator_discovery = validator_discovery::Service::<N, AD>::new();
|
||||
let mut validator_discovery =
|
||||
validator_discovery::Service::<N, AD>::new(peerset_protocol_names.clone());
|
||||
|
||||
loop {
|
||||
match ctx.recv().fuse().await? {
|
||||
@@ -112,6 +124,7 @@ where
|
||||
msg,
|
||||
&metrics,
|
||||
&req_protocol_names,
|
||||
&peerset_protocol_names,
|
||||
)
|
||||
.await;
|
||||
},
|
||||
@@ -128,6 +141,7 @@ async fn handle_incoming_subsystem_communication<Context, N, AD>(
|
||||
msg: NetworkBridgeTxMessage,
|
||||
metrics: &Metrics,
|
||||
req_protocol_names: &ReqProtocolNames,
|
||||
peerset_protocol_names: &PeerSetProtocolNames,
|
||||
) -> (N, AD)
|
||||
where
|
||||
N: Network,
|
||||
@@ -150,7 +164,9 @@ where
|
||||
peer_set = ?peer_set,
|
||||
);
|
||||
|
||||
network_service.disconnect_peer(peer, peer_set);
|
||||
// [`NetworkService`] keeps track of the protocols by their main name.
|
||||
let protocol = peerset_protocol_names.get_main_name(peer_set);
|
||||
network_service.disconnect_peer(peer, protocol);
|
||||
},
|
||||
NetworkBridgeTxMessage::SendValidationMessage(peers, msg) => {
|
||||
gum::trace!(
|
||||
@@ -163,6 +179,7 @@ where
|
||||
Versioned::V1(msg) => send_validation_message_v1(
|
||||
&mut network_service,
|
||||
peers,
|
||||
peerset_protocol_names,
|
||||
WireMessage::ProtocolMessage(msg),
|
||||
&metrics,
|
||||
),
|
||||
@@ -180,6 +197,7 @@ where
|
||||
Versioned::V1(msg) => send_validation_message_v1(
|
||||
&mut network_service,
|
||||
peers,
|
||||
peerset_protocol_names,
|
||||
WireMessage::ProtocolMessage(msg),
|
||||
&metrics,
|
||||
),
|
||||
@@ -197,6 +215,7 @@ where
|
||||
Versioned::V1(msg) => send_collation_message_v1(
|
||||
&mut network_service,
|
||||
peers,
|
||||
peerset_protocol_names,
|
||||
WireMessage::ProtocolMessage(msg),
|
||||
&metrics,
|
||||
),
|
||||
@@ -214,6 +233,7 @@ where
|
||||
Versioned::V1(msg) => send_collation_message_v1(
|
||||
&mut network_service,
|
||||
peers,
|
||||
peerset_protocol_names,
|
||||
WireMessage::ProtocolMessage(msg),
|
||||
&metrics,
|
||||
),
|
||||
@@ -296,6 +316,7 @@ where
|
||||
authority_discovery_service,
|
||||
metrics,
|
||||
req_protocol_names,
|
||||
peerset_protocol_names,
|
||||
} = bridge;
|
||||
|
||||
handle_subsystem_messages(
|
||||
@@ -304,6 +325,7 @@ where
|
||||
authority_discovery_service,
|
||||
metrics,
|
||||
req_protocol_names,
|
||||
peerset_protocol_names,
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -313,17 +335,35 @@ where
|
||||
fn send_validation_message_v1(
|
||||
net: &mut impl Network,
|
||||
peers: Vec<PeerId>,
|
||||
protocol_names: &PeerSetProtocolNames,
|
||||
message: WireMessage<protocol_v1::ValidationProtocol>,
|
||||
metrics: &Metrics,
|
||||
) {
|
||||
send_message(net, peers, PeerSet::Validation, 1, message, metrics);
|
||||
send_message(
|
||||
net,
|
||||
peers,
|
||||
PeerSet::Validation,
|
||||
ValidationVersion::V1.into(),
|
||||
protocol_names,
|
||||
message,
|
||||
metrics,
|
||||
);
|
||||
}
|
||||
|
||||
fn send_collation_message_v1(
|
||||
net: &mut impl Network,
|
||||
peers: Vec<PeerId>,
|
||||
protocol_names: &PeerSetProtocolNames,
|
||||
message: WireMessage<protocol_v1::CollationProtocol>,
|
||||
metrics: &Metrics,
|
||||
) {
|
||||
send_message(net, peers, PeerSet::Collation, 1, message, metrics)
|
||||
send_message(
|
||||
net,
|
||||
peers,
|
||||
PeerSet::Collation,
|
||||
CollationVersion::V1.into(),
|
||||
protocol_names,
|
||||
message,
|
||||
metrics,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ use std::{borrow::Cow, collections::HashSet};
|
||||
use sc_network::{Event as NetworkEvent, IfDisconnected};
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSetProtocolNames,
|
||||
request_response::{outgoing::Requests, ReqProtocolNames},
|
||||
ObservedRole, Versioned,
|
||||
};
|
||||
@@ -55,6 +56,7 @@ pub enum NetworkAction {
|
||||
struct TestNetwork {
|
||||
net_events: Arc<Mutex<Option<metered::MeteredReceiver<NetworkEvent>>>>,
|
||||
action_tx: Arc<Mutex<metered::UnboundedMeteredSender<NetworkAction>>>,
|
||||
peerset_protocol_names: Arc<PeerSetProtocolNames>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -65,9 +67,12 @@ struct TestAuthorityDiscovery;
|
||||
struct TestNetworkHandle {
|
||||
action_rx: metered::UnboundedMeteredReceiver<NetworkAction>,
|
||||
net_tx: metered::MeteredSender<NetworkEvent>,
|
||||
peerset_protocol_names: PeerSetProtocolNames,
|
||||
}
|
||||
|
||||
fn new_test_network() -> (TestNetwork, TestNetworkHandle, TestAuthorityDiscovery) {
|
||||
fn new_test_network(
|
||||
peerset_protocol_names: PeerSetProtocolNames,
|
||||
) -> (TestNetwork, TestNetworkHandle, TestAuthorityDiscovery) {
|
||||
let (net_tx, net_rx) = metered::channel(10);
|
||||
let (action_tx, action_rx) = metered::unbounded();
|
||||
|
||||
@@ -75,8 +80,9 @@ fn new_test_network() -> (TestNetwork, TestNetworkHandle, TestAuthorityDiscovery
|
||||
TestNetwork {
|
||||
net_events: Arc::new(Mutex::new(Some(net_rx))),
|
||||
action_tx: Arc::new(Mutex::new(action_tx)),
|
||||
peerset_protocol_names: Arc::new(peerset_protocol_names.clone()),
|
||||
},
|
||||
TestNetworkHandle { action_rx, net_tx },
|
||||
TestNetworkHandle { action_rx, net_tx, peerset_protocol_names },
|
||||
TestAuthorityDiscovery,
|
||||
)
|
||||
}
|
||||
@@ -117,14 +123,20 @@ impl Network for TestNetwork {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn disconnect_peer(&self, who: PeerId, peer_set: PeerSet) {
|
||||
fn disconnect_peer(&self, who: PeerId, protocol: Cow<'static, str>) {
|
||||
let (peer_set, version) = self.peerset_protocol_names.try_get_protocol(&protocol).unwrap();
|
||||
assert_eq!(version, peer_set.get_main_version());
|
||||
|
||||
self.action_tx
|
||||
.lock()
|
||||
.unbounded_send(NetworkAction::DisconnectPeer(who, peer_set))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn write_notification(&self, who: PeerId, peer_set: PeerSet, message: Vec<u8>) {
|
||||
fn write_notification(&self, who: PeerId, protocol: Cow<'static, str>, message: Vec<u8>) {
|
||||
let (peer_set, version) = self.peerset_protocol_names.try_get_protocol(&protocol).unwrap();
|
||||
assert_eq!(version, peer_set.get_main_version());
|
||||
|
||||
self.action_tx
|
||||
.lock()
|
||||
.unbounded_send(NetworkAction::WriteNotification(who, peer_set, message))
|
||||
@@ -158,7 +170,7 @@ impl TestNetworkHandle {
|
||||
async fn connect_peer(&mut self, peer: PeerId, peer_set: PeerSet, role: ObservedRole) {
|
||||
self.send_network_event(NetworkEvent::NotificationStreamOpened {
|
||||
remote: peer,
|
||||
protocol: peer_set.into_default_protocol_name(),
|
||||
protocol: self.peerset_protocol_names.get_main_name(peer_set),
|
||||
negotiated_fallback: None,
|
||||
role: role.into(),
|
||||
})
|
||||
@@ -178,16 +190,24 @@ struct TestHarness {
|
||||
}
|
||||
|
||||
fn test_harness<T: Future<Output = VirtualOverseer>>(test: impl FnOnce(TestHarness) -> T) {
|
||||
let genesis_hash = Hash::repeat_byte(0xff);
|
||||
let fork_id = None;
|
||||
let req_protocol_names = ReqProtocolNames::new(genesis_hash, fork_id);
|
||||
let peerset_protocol_names = PeerSetProtocolNames::new(genesis_hash, fork_id);
|
||||
|
||||
let pool = sp_core::testing::TaskExecutor::new();
|
||||
let (network, network_handle, discovery) = new_test_network();
|
||||
let (network, network_handle, discovery) = new_test_network(peerset_protocol_names.clone());
|
||||
|
||||
let (context, virtual_overseer) =
|
||||
polkadot_node_subsystem_test_helpers::make_subsystem_context(pool);
|
||||
|
||||
let genesis_hash = Hash::repeat_byte(0xff);
|
||||
let protocol_names = ReqProtocolNames::new(genesis_hash, None);
|
||||
|
||||
let bridge_out = NetworkBridgeTx::new(network, discovery, Metrics(None), protocol_names);
|
||||
let bridge_out = NetworkBridgeTx::new(
|
||||
network,
|
||||
discovery,
|
||||
Metrics(None),
|
||||
req_protocol_names,
|
||||
peerset_protocol_names,
|
||||
);
|
||||
|
||||
let network_bridge_out_fut = run_network_out(bridge_out, context)
|
||||
.map_err(|e| panic!("bridge-out subsystem execution failed {:?}", e))
|
||||
|
||||
Reference in New Issue
Block a user