mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 13:27:57 +00:00
Change validation & collation protocol names to include genesis hash & fork id (#5876)
This commit is contained in:
@@ -31,9 +31,9 @@ use sc_network_common::{
|
||||
};
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
peer_set::PeerSet,
|
||||
peer_set::{PeerSet, PeerSetProtocolNames, ProtocolVersion},
|
||||
request_response::{OutgoingRequest, Recipient, ReqProtocolNames, Requests},
|
||||
PeerId, ProtocolVersion, UnifiedReputationChange as Rep,
|
||||
PeerId, UnifiedReputationChange as Rep,
|
||||
};
|
||||
use polkadot_primitives::v2::{AuthorityDiscoveryId, Block, Hash};
|
||||
|
||||
@@ -52,6 +52,7 @@ pub(crate) fn send_message<M>(
|
||||
mut peers: Vec<PeerId>,
|
||||
peer_set: PeerSet,
|
||||
version: ProtocolVersion,
|
||||
protocol_names: &PeerSetProtocolNames,
|
||||
message: M,
|
||||
metrics: &super::Metrics,
|
||||
) where
|
||||
@@ -67,11 +68,13 @@ pub(crate) fn send_message<M>(
|
||||
// list. The message payload can be quite large. If the underlying
|
||||
// network used `Bytes` this would not be necessary.
|
||||
let last_peer = peers.pop();
|
||||
// optimization: generate the protocol name once.
|
||||
let protocol_name = protocol_names.get_name(peer_set, version);
|
||||
peers.into_iter().for_each(|peer| {
|
||||
net.write_notification(peer, peer_set, message.clone());
|
||||
net.write_notification(peer, protocol_name.clone(), message.clone());
|
||||
});
|
||||
if let Some(peer) = last_peer {
|
||||
net.write_notification(peer, peer_set, message);
|
||||
net.write_notification(peer, protocol_name, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,11 +111,11 @@ pub trait Network: Clone + Send + 'static {
|
||||
/// Report a given peer as either beneficial (+) or costly (-) according to the given scalar.
|
||||
fn report_peer(&self, who: PeerId, cost_benefit: Rep);
|
||||
|
||||
/// Disconnect a given peer from the peer set specified without harming reputation.
|
||||
fn disconnect_peer(&self, who: PeerId, peer_set: PeerSet);
|
||||
/// Disconnect a given peer from the protocol specified without harming reputation.
|
||||
fn disconnect_peer(&self, who: PeerId, protocol: Cow<'static, str>);
|
||||
|
||||
/// Write a notification to a peer on the given peer-set's protocol.
|
||||
fn write_notification(&self, who: PeerId, peer_set: PeerSet, message: Vec<u8>);
|
||||
/// Write a notification to a peer on the given protocol.
|
||||
fn write_notification(&self, who: PeerId, protocol: Cow<'static, str>, message: Vec<u8>);
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -137,17 +140,12 @@ impl Network for Arc<NetworkService<Block, Hash>> {
|
||||
NetworkService::report_peer(&**self, who, cost_benefit.into_base_rep());
|
||||
}
|
||||
|
||||
fn disconnect_peer(&self, who: PeerId, peer_set: PeerSet) {
|
||||
NetworkService::disconnect_peer(&**self, who, peer_set.into_default_protocol_name());
|
||||
fn disconnect_peer(&self, who: PeerId, protocol: Cow<'static, str>) {
|
||||
NetworkService::disconnect_peer(&**self, who, protocol);
|
||||
}
|
||||
|
||||
fn write_notification(&self, who: PeerId, peer_set: PeerSet, message: Vec<u8>) {
|
||||
NetworkService::write_notification(
|
||||
&**self,
|
||||
who,
|
||||
peer_set.into_default_protocol_name(),
|
||||
message,
|
||||
);
|
||||
fn write_notification(&self, who: PeerId, protocol: Cow<'static, str>, message: Vec<u8>) {
|
||||
NetworkService::write_notification(&**self, who, protocol, message);
|
||||
}
|
||||
|
||||
async fn start_request<AD: AuthorityDiscovery>(
|
||||
|
||||
Reference in New Issue
Block a user