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

Add support for outbound only configs on request/response protocols #6343

Merged
merged 2 commits into from
Nov 26, 2022
Merged
Changes from all 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
39 changes: 29 additions & 10 deletions node/network/protocol/src/request_response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ const STATEMENT_RESPONSE_SIZE: u64 = MAX_CODE_SIZE as u64 + 10_000;
pub const DISPUTE_REQUEST_TIMEOUT: Duration = Duration::from_secs(12);

impl Protocol {
/// Get a configuration for a given Request response protocol.
///
/// Returns a `ProtocolConfig` for this protocol.
/// Use this if you plan only to send requests for this protocol.
pub fn get_outbound_only_config(
self,
req_protocol_names: &ReqProtocolNames,
) -> RequestResponseConfig {
self.create_config(req_protocol_names, None)
}

/// Get a configuration for a given Request response protocol.
///
/// Returns a receiver for messages received on this protocol and the requested
Expand All @@ -134,18 +145,27 @@ impl Protocol {
self,
req_protocol_names: &ReqProtocolNames,
) -> (mpsc::Receiver<network::IncomingRequest>, RequestResponseConfig) {
let (tx, rx) = mpsc::channel(self.get_channel_size());
let cfg = self.create_config(req_protocol_names, Some(tx));
(rx, cfg)
}

fn create_config(
self,
req_protocol_names: &ReqProtocolNames,
tx: Option<mpsc::Sender<network::IncomingRequest>>,
) -> RequestResponseConfig {
let name = req_protocol_names.get_name(self);
let fallback_names = self.get_fallback_names();
let (tx, rx) = mpsc::channel(self.get_channel_size());
let cfg = match self {
match self {
Protocol::ChunkFetchingV1 => RequestResponseConfig {
name,
fallback_names,
max_request_size: 1_000,
max_response_size: POV_RESPONSE_SIZE as u64 * 3,
// We are connected to all validators:
request_timeout: CHUNK_REQUEST_TIMEOUT,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::CollationFetchingV1 => RequestResponseConfig {
name,
Expand All @@ -154,15 +174,15 @@ impl Protocol {
max_response_size: POV_RESPONSE_SIZE,
// Taken from initial implementation in collator protocol:
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::PoVFetchingV1 => RequestResponseConfig {
name,
fallback_names,
max_request_size: 1_000,
max_response_size: POV_RESPONSE_SIZE,
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::AvailableDataFetchingV1 => RequestResponseConfig {
name,
Expand All @@ -171,7 +191,7 @@ impl Protocol {
// Available data size is dominated by the PoV size.
max_response_size: POV_RESPONSE_SIZE,
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::StatementFetchingV1 => RequestResponseConfig {
name,
Expand All @@ -189,7 +209,7 @@ impl Protocol {
// fail, but this is desired, so we can quickly move on to a faster one - we should
// also decrease its reputation.
request_timeout: Duration::from_secs(1),
inbound_queue: Some(tx),
inbound_queue: tx,
},
Protocol::DisputeSendingV1 => RequestResponseConfig {
name,
Expand All @@ -199,10 +219,9 @@ impl Protocol {
/// plenty.
max_response_size: 100,
request_timeout: DISPUTE_REQUEST_TIMEOUT,
inbound_queue: Some(tx),
inbound_queue: tx,
},
};
(rx, cfg)
}
}

// Channel sizes for the supported protocols.
Expand Down