From bbbee43968def14c26e63d470853043354611776 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 25 Nov 2022 08:40:47 +0100 Subject: [PATCH 1/2] Add option ot add outbound_only configurations --- .../protocol/src/request_response/mod.rs | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/node/network/protocol/src/request_response/mod.rs b/node/network/protocol/src/request_response/mod.rs index d24537e219c7..f77abeec411f 100644 --- a/node/network/protocol/src/request_response/mod.rs +++ b/node/network/protocol/src/request_response/mod.rs @@ -126,6 +126,16 @@ 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 only a `ProtocolConfig` 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 @@ -134,10 +144,19 @@ impl Protocol { self, req_protocol_names: &ReqProtocolNames, ) -> (mpsc::Receiver, 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>, + ) -> 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, @@ -145,7 +164,7 @@ impl Protocol { 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, @@ -154,7 +173,7 @@ 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, @@ -162,7 +181,7 @@ impl Protocol { 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, @@ -171,7 +190,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, @@ -189,7 +208,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, @@ -199,10 +218,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. From 5e24245f8736e49116edaad76339936d780ded4f Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Fri, 25 Nov 2022 08:51:43 +0100 Subject: [PATCH 2/2] Improve comment --- node/network/protocol/src/request_response/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/network/protocol/src/request_response/mod.rs b/node/network/protocol/src/request_response/mod.rs index f77abeec411f..6ce0c883cc6c 100644 --- a/node/network/protocol/src/request_response/mod.rs +++ b/node/network/protocol/src/request_response/mod.rs @@ -128,7 +128,8 @@ pub const DISPUTE_REQUEST_TIMEOUT: Duration = Duration::from_secs(12); impl Protocol { /// Get a configuration for a given Request response protocol. /// - /// Returns only a `ProtocolConfig` for this 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,