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

Commit

Permalink
Change request-response protocol names to include genesis hash & fork…
Browse files Browse the repository at this point in the history
… id (#5870)
  • Loading branch information
dmitry-markin committed Aug 12, 2022
1 parent edf5df5 commit 93f45f9
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 73 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions node/network/availability-distribution/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use std::collections::HashSet;

use futures::{executor, future, Future};

use polkadot_node_network_protocol::request_response::IncomingRequest;
use polkadot_primitives::v2::CoreState;
use polkadot_node_network_protocol::request_response::{IncomingRequest, ReqProtocolNames};
use polkadot_primitives::v2::{CoreState, Hash};
use sp_keystore::SyncCryptoStorePtr;

use polkadot_node_subsystem_test_helpers as test_helpers;
Expand All @@ -41,9 +41,12 @@ fn test_harness<T: Future<Output = ()>>(

let pool = sp_core::testing::TaskExecutor::new();
let (context, virtual_overseer) = test_helpers::make_subsystem_context(pool.clone());
let genesis_hash = Hash::repeat_byte(0xff);
let req_protocol_names = ReqProtocolNames::new(&genesis_hash, None);

let (pov_req_receiver, pov_req_cfg) = IncomingRequest::get_config_receiver();
let (chunk_req_receiver, chunk_req_cfg) = IncomingRequest::get_config_receiver();
let (pov_req_receiver, pov_req_cfg) = IncomingRequest::get_config_receiver(&req_protocol_names);
let (chunk_req_receiver, chunk_req_cfg) =
IncomingRequest::get_config_receiver(&req_protocol_names);
let subsystem = AvailabilityDistributionSubsystem::new(
keystore,
IncomingRequestReceivers { pov_req_receiver, chunk_req_receiver },
Expand Down
13 changes: 9 additions & 4 deletions node/network/availability-recovery/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use futures::{executor, future};
use futures_timer::Delay;

use parity_scale_codec::Encode;
use polkadot_node_network_protocol::request_response::IncomingRequest;
use polkadot_node_network_protocol::request_response::{IncomingRequest, ReqProtocolNames};

use super::*;

Expand All @@ -36,11 +36,14 @@ use polkadot_node_subsystem::{
};
use polkadot_node_subsystem_test_helpers::{make_subsystem_context, TestSubsystemContextHandle};
use polkadot_node_subsystem_util::TimeoutExt;
use polkadot_primitives::v2::{AuthorityDiscoveryId, HeadData, PersistedValidationData};
use polkadot_primitives::v2::{AuthorityDiscoveryId, Hash, HeadData, PersistedValidationData};
use polkadot_primitives_test_helpers::{dummy_candidate_receipt, dummy_hash};

type VirtualOverseer = TestSubsystemContextHandle<AvailabilityRecoveryMessage>;

// Deterministic genesis hash for protocol names
const GENESIS_HASH: Hash = Hash::repeat_byte(0xff);

fn test_harness_fast_path<T: Future<Output = (VirtualOverseer, RequestResponseConfig)>>(
test: impl FnOnce(VirtualOverseer, RequestResponseConfig) -> T,
) {
Expand All @@ -53,7 +56,8 @@ fn test_harness_fast_path<T: Future<Output = (VirtualOverseer, RequestResponseCo

let (context, virtual_overseer) = make_subsystem_context(pool.clone());

let (collation_req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let (collation_req_receiver, req_cfg) =
IncomingRequest::get_config_receiver(&ReqProtocolNames::new(&GENESIS_HASH, None));
let subsystem =
AvailabilityRecoverySubsystem::with_fast_path(collation_req_receiver, Metrics::new_dummy());
let subsystem = async {
Expand Down Expand Up @@ -87,7 +91,8 @@ fn test_harness_chunks_only<T: Future<Output = (VirtualOverseer, RequestResponse

let (context, virtual_overseer) = make_subsystem_context(pool.clone());

let (collation_req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let (collation_req_receiver, req_cfg) =
IncomingRequest::get_config_receiver(&ReqProtocolNames::new(&GENESIS_HASH, None));
let subsystem = AvailabilityRecoverySubsystem::with_chunks_only(
collation_req_receiver,
Metrics::new_dummy(),
Expand Down
6 changes: 4 additions & 2 deletions node/network/bridge/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sc_network_common::service::{

use polkadot_node_network_protocol::{
peer_set::PeerSet,
request_response::{OutgoingRequest, Recipient, Requests},
request_response::{OutgoingRequest, Recipient, ReqProtocolNames, Requests},
PeerId, ProtocolVersion, UnifiedReputationChange as Rep,
};
use polkadot_primitives::v2::{AuthorityDiscoveryId, Block, Hash};
Expand Down Expand Up @@ -100,6 +100,7 @@ pub trait Network: Clone + Send + 'static {
&self,
authority_discovery: &mut AD,
req: Requests,
req_protocol_names: &ReqProtocolNames,
if_disconnected: IfDisconnected,
);

Expand Down Expand Up @@ -152,6 +153,7 @@ impl Network for Arc<NetworkService<Block, Hash>> {
&self,
authority_discovery: &mut AD,
req: Requests,
req_protocol_names: &ReqProtocolNames,
if_disconnected: IfDisconnected,
) {
let (protocol, OutgoingRequest { peer, payload, pending_response }) = req.encode_request();
Expand Down Expand Up @@ -197,7 +199,7 @@ impl Network for Arc<NetworkService<Block, Hash>> {
NetworkService::start_request(
&*self,
peer_id,
protocol.into_protocol_name(),
req_protocol_names.get_name(protocol),
payload,
pending_response,
if_disconnected,
Expand Down
4 changes: 3 additions & 1 deletion node/network/bridge/src/rx/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use std::{
use sc_network::{Event as NetworkEvent, IfDisconnected};

use polkadot_node_network_protocol::{
request_response::outgoing::Requests, view, ObservedRole, Versioned,
request_response::{outgoing::Requests, ReqProtocolNames},
view, ObservedRole, Versioned,
};
use polkadot_node_subsystem::{
jaeger,
Expand Down Expand Up @@ -117,6 +118,7 @@ impl Network for TestNetwork {
&self,
_: &mut AD,
_: Requests,
_: &ReqProtocolNames,
_: IfDisconnected,
) {
}
Expand Down
42 changes: 35 additions & 7 deletions node/network/bridge/src/tx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
//! The Network Bridge Subsystem - handles _outgoing_ messages, from subsystem to the network.
use super::*;

use polkadot_node_network_protocol::{peer_set::PeerSet, v1 as protocol_v1, PeerId, Versioned};
use polkadot_node_network_protocol::{
peer_set::PeerSet, request_response::ReqProtocolNames, v1 as protocol_v1, PeerId, Versioned,
};

use polkadot_node_subsystem::{
errors::SubsystemError, messages::NetworkBridgeTxMessage, overseer, FromOrchestra,
Expand Down Expand Up @@ -50,15 +52,21 @@ pub struct NetworkBridgeTx<N, AD> {
network_service: N,
authority_discovery_service: AD,
metrics: Metrics,
req_protocol_names: ReqProtocolNames,
}

impl<N, AD> NetworkBridgeTx<N, AD> {
/// Create a new network bridge subsystem with underlying network service and authority discovery service.
///
/// This assumes that the network service has had the notifications protocol for the network
/// bridge already registered. See [`peers_sets_info`](peers_sets_info).
pub fn new(network_service: N, authority_discovery_service: AD, metrics: Metrics) -> Self {
Self { network_service, authority_discovery_service, metrics }
pub fn new(
network_service: N,
authority_discovery_service: AD,
metrics: Metrics,
req_protocol_names: ReqProtocolNames,
) -> Self {
Self { network_service, authority_discovery_service, metrics, req_protocol_names }
}
}

Expand All @@ -82,6 +90,7 @@ async fn handle_subsystem_messages<Context, N, AD>(
mut network_service: N,
mut authority_discovery_service: AD,
metrics: Metrics,
req_protocol_names: ReqProtocolNames,
) -> Result<(), Error>
where
N: Network,
Expand All @@ -102,6 +111,7 @@ where
authority_discovery_service.clone(),
msg,
&metrics,
&req_protocol_names,
)
.await;
},
Expand All @@ -117,6 +127,7 @@ async fn handle_incoming_subsystem_communication<Context, N, AD>(
mut authority_discovery_service: AD,
msg: NetworkBridgeTxMessage,
metrics: &Metrics,
req_protocol_names: &ReqProtocolNames,
) -> (N, AD)
where
N: Network,
Expand Down Expand Up @@ -218,7 +229,12 @@ where

for req in reqs {
network_service
.start_request(&mut authority_discovery_service, req, if_disconnected)
.start_request(
&mut authority_discovery_service,
req,
req_protocol_names,
if_disconnected,
)
.await;
}
},
Expand Down Expand Up @@ -275,9 +291,21 @@ where
N: Network,
AD: validator_discovery::AuthorityDiscovery + Clone + Sync,
{
let NetworkBridgeTx { network_service, authority_discovery_service, metrics } = bridge;

handle_subsystem_messages(ctx, network_service, authority_discovery_service, metrics).await?;
let NetworkBridgeTx {
network_service,
authority_discovery_service,
metrics,
req_protocol_names,
} = bridge;

handle_subsystem_messages(
ctx,
network_service,
authority_discovery_service,
metrics,
req_protocol_names,
)
.await?;

Ok(())
}
Expand Down
11 changes: 8 additions & 3 deletions node/network/bridge/src/tx/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ use std::{borrow::Cow, collections::HashSet};
use sc_network::{Event as NetworkEvent, IfDisconnected};

use polkadot_node_network_protocol::{
request_response::outgoing::Requests, ObservedRole, Versioned,
request_response::{outgoing::Requests, ReqProtocolNames},
ObservedRole, Versioned,
};
use polkadot_node_subsystem::{FromOrchestra, OverseerSignal};
use polkadot_node_subsystem_test_helpers::TestSubsystemContextHandle;
use polkadot_node_subsystem_util::metered;
use polkadot_primitives::v2::AuthorityDiscoveryId;
use polkadot_primitives::v2::{AuthorityDiscoveryId, Hash};
use polkadot_primitives_test_helpers::dummy_collator_signature;
use sc_network::Multiaddr;
use sp_keyring::Sr25519Keyring;
Expand Down Expand Up @@ -104,6 +105,7 @@ impl Network for TestNetwork {
&self,
_: &mut AD,
_: Requests,
_: &ReqProtocolNames,
_: IfDisconnected,
) {
}
Expand Down Expand Up @@ -182,7 +184,10 @@ fn test_harness<T: Future<Output = VirtualOverseer>>(test: impl FnOnce(TestHarne
let (context, virtual_overseer) =
polkadot_node_subsystem_test_helpers::make_subsystem_context(pool);

let bridge_out = NetworkBridgeTx::new(network, discovery, Metrics(None));
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 network_bridge_out_fut = run_network_out(bridge_out, context)
.map_err(|e| panic!("bridge-out subsystem execution failed {:?}", e))
Expand Down
6 changes: 5 additions & 1 deletion node/network/bridge/src/validator_discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ mod tests {

use async_trait::async_trait;
use futures::stream::BoxStream;
use polkadot_node_network_protocol::{request_response::outgoing::Requests, PeerId};
use polkadot_node_network_protocol::{
request_response::{outgoing::Requests, ReqProtocolNames},
PeerId,
};
use sc_network::{Event as NetworkEvent, IfDisconnected};
use sp_keyring::Sr25519Keyring;
use std::{
Expand Down Expand Up @@ -236,6 +239,7 @@ mod tests {
&self,
_: &mut AD,
_: Requests,
_: &ReqProtocolNames,
_: IfDisconnected,
) {
}
Expand Down
12 changes: 10 additions & 2 deletions node/network/collator-protocol/src/collator_side/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ use sp_core::crypto::Pair;
use sp_keyring::Sr25519Keyring;
use sp_runtime::traits::AppVerify;

use polkadot_node_network_protocol::{our_view, request_response::IncomingRequest, view};
use polkadot_node_network_protocol::{
our_view,
request_response::{IncomingRequest, ReqProtocolNames},
view,
};
use polkadot_node_primitives::BlockData;
use polkadot_node_subsystem::{
jaeger,
Expand Down Expand Up @@ -201,7 +205,11 @@ fn test_harness<T: Future<Output = TestHarness>>(

let (context, virtual_overseer) = test_helpers::make_subsystem_context(pool.clone());

let (collation_req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let genesis_hash = Hash::repeat_byte(0xff);
let req_protocol_names = ReqProtocolNames::new(&genesis_hash, None);

let (collation_req_receiver, req_cfg) =
IncomingRequest::get_config_receiver(&req_protocol_names);
let subsystem = async {
run(context, local_peer_id, collator_pair, collation_req_receiver, Default::default())
.await
Expand Down
6 changes: 4 additions & 2 deletions node/network/dispute-distribution/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use parity_scale_codec::{Decode, Encode};
use sc_network::config::RequestResponseConfig;

use polkadot_node_network_protocol::{
request_response::{v1::DisputeRequest, IncomingRequest},
request_response::{v1::DisputeRequest, IncomingRequest, ReqProtocolNames},
PeerId,
};
use sp_keyring::Sr25519Keyring;
Expand Down Expand Up @@ -723,7 +723,9 @@ where
sp_tracing::try_init_simple();
let keystore = make_ferdie_keystore();

let (req_receiver, req_cfg) = IncomingRequest::get_config_receiver();
let genesis_hash = Hash::repeat_byte(0xff);
let req_protocol_names = ReqProtocolNames::new(&genesis_hash, None);
let (req_receiver, req_cfg) = IncomingRequest::get_config_receiver(&req_protocol_names);
let subsystem = DisputeDistributionSubsystem::new(
keystore,
req_receiver,
Expand Down
1 change: 1 addition & 0 deletions node/network/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "Primitives types for the Node-side"

[dependencies]
async-trait = "0.1.53"
hex = "0.4.3"
polkadot-primitives = { path = "../../../primitives" }
polkadot-node-primitives = { path = "../../primitives" }
polkadot-node-jaeger = { path = "../../jaeger" }
Expand Down
8 changes: 5 additions & 3 deletions node/network/protocol/src/request_response/incoming/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use parity_scale_codec::{Decode, Encode};

use sc_network::{config as netconfig, config::RequestResponseConfig, PeerId};

use super::IsRequest;
use super::{IsRequest, ReqProtocolNames};
use crate::UnifiedReputationChange;

mod error;
Expand Down Expand Up @@ -55,8 +55,10 @@ where
///
/// This Register that config with substrate networking and receive incoming requests via the
/// returned `IncomingRequestReceiver`.
pub fn get_config_receiver() -> (IncomingRequestReceiver<Req>, RequestResponseConfig) {
let (raw, cfg) = Req::PROTOCOL.get_config();
pub fn get_config_receiver(
req_protocol_names: &ReqProtocolNames,
) -> (IncomingRequestReceiver<Req>, RequestResponseConfig) {
let (raw, cfg) = Req::PROTOCOL.get_config(req_protocol_names);
(IncomingRequestReceiver { raw, phantom: PhantomData {} }, cfg)
}

Expand Down

0 comments on commit 93f45f9

Please sign in to comment.