Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Change validation & collation protocol names to include genesis hash & fork id #5876

Merged
merged 13 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions node/network/approval-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use super::*;
use assert_matches::assert_matches;
use futures::{executor, future, Future};
use polkadot_node_network_protocol::{our_view, view, ObservedRole};
use polkadot_node_network_protocol::{our_view, peer_set::ValidationVersion, view, ObservedRole};
use polkadot_node_primitives::approval::{
AssignmentCertKind, VRFOutput, VRFProof, RELAY_VRF_MODULO_CONTEXT,
};
Expand Down Expand Up @@ -174,7 +174,7 @@ async fn setup_peer_with_view(
ApprovalDistributionMessage::NetworkBridgeUpdate(NetworkBridgeEvent::PeerConnected(
peer_id.clone(),
ObservedRole::Full,
1,
ValidationVersion::V1.into(),
None,
)),
)
Expand Down
10 changes: 8 additions & 2 deletions node/network/bitfield-distribution/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use bitvec::bitvec;
use futures::executor;
use maplit::hashmap;
use polkadot_node_network_protocol::{
grid_topology::SessionBoundGridTopologyStorage, our_view, view, ObservedRole,
grid_topology::SessionBoundGridTopologyStorage, our_view, peer_set::ValidationVersion, view,
ObservedRole,
};
use polkadot_node_subsystem::{
jaeger,
Expand Down Expand Up @@ -568,7 +569,12 @@ fn changing_view() {
&mut ctx,
&mut state,
&Default::default(),
NetworkBridgeEvent::PeerConnected(peer_b.clone(), ObservedRole::Full, 1, None),
NetworkBridgeEvent::PeerConnected(
peer_b.clone(),
ObservedRole::Full,
ValidationVersion::V1.into(),
None
),
&mut rng,
));

Expand Down
3 changes: 2 additions & 1 deletion node/network/bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use parking_lot::Mutex;
use sp_consensus::SyncOracle;

use polkadot_node_network_protocol::{
peer_set::PeerSet, PeerId, ProtocolVersion, UnifiedReputationChange as Rep, View,
peer_set::{PeerSet, ProtocolVersion},
PeerId, UnifiedReputationChange as Rep, View,
};

/// Peer set info for network initialization.
Expand Down
4 changes: 2 additions & 2 deletions node/network/bridge/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Metrics(pub(crate) Option<MetricsInner>);

fn peer_set_label(peer_set: PeerSet, version: ProtocolVersion) -> &'static str {
// Higher level code is meant to protect against this ever happening.
peer_set.get_protocol_name_static(version).unwrap_or("<internal error>")
peer_set.get_protocol_label(version).unwrap_or("<internal error>")
}

#[allow(missing_docs)]
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Metrics {
self.0.as_ref().map(|metrics| {
metrics
.desired_peer_count
.with_label_values(&[peer_set.get_default_protocol_name()])
.with_label_values(&[peer_set.get_label()])
.set(size as u64)
});
}
Expand Down
32 changes: 15 additions & 17 deletions node/network/bridge/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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
Expand All @@ -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);
bkchr marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}

Expand Down Expand Up @@ -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]
Expand All @@ -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>(
Expand Down
Loading