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

Commit add2412

Browse files
skunertdmitry-markin
authored andcommitted
Add support for outbound only configs on request/response protocols (#6343)
* Add option ot add outbound_only configurations * Improve comment
1 parent f35d5b3 commit add2412

File tree

1 file changed

+29
-10
lines changed
  • node/network/protocol/src/request_response

1 file changed

+29
-10
lines changed

node/network/protocol/src/request_response/mod.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,17 @@ const STATEMENT_RESPONSE_SIZE: u64 = MAX_CODE_SIZE as u64 + 10_000;
126126
pub const DISPUTE_REQUEST_TIMEOUT: Duration = Duration::from_secs(12);
127127

128128
impl Protocol {
129+
/// Get a configuration for a given Request response protocol.
130+
///
131+
/// Returns a `ProtocolConfig` for this protocol.
132+
/// Use this if you plan only to send requests for this protocol.
133+
pub fn get_outbound_only_config(
134+
self,
135+
req_protocol_names: &ReqProtocolNames,
136+
) -> RequestResponseConfig {
137+
self.create_config(req_protocol_names, None)
138+
}
139+
129140
/// Get a configuration for a given Request response protocol.
130141
///
131142
/// Returns a receiver for messages received on this protocol and the requested
@@ -134,18 +145,27 @@ impl Protocol {
134145
self,
135146
req_protocol_names: &ReqProtocolNames,
136147
) -> (mpsc::Receiver<network::IncomingRequest>, RequestResponseConfig) {
148+
let (tx, rx) = mpsc::channel(self.get_channel_size());
149+
let cfg = self.create_config(req_protocol_names, Some(tx));
150+
(rx, cfg)
151+
}
152+
153+
fn create_config(
154+
self,
155+
req_protocol_names: &ReqProtocolNames,
156+
tx: Option<mpsc::Sender<network::IncomingRequest>>,
157+
) -> RequestResponseConfig {
137158
let name = req_protocol_names.get_name(self);
138159
let fallback_names = self.get_fallback_names();
139-
let (tx, rx) = mpsc::channel(self.get_channel_size());
140-
let cfg = match self {
160+
match self {
141161
Protocol::ChunkFetchingV1 => RequestResponseConfig {
142162
name,
143163
fallback_names,
144164
max_request_size: 1_000,
145165
max_response_size: POV_RESPONSE_SIZE as u64 * 3,
146166
// We are connected to all validators:
147167
request_timeout: CHUNK_REQUEST_TIMEOUT,
148-
inbound_queue: Some(tx),
168+
inbound_queue: tx,
149169
},
150170
Protocol::CollationFetchingV1 => RequestResponseConfig {
151171
name,
@@ -154,15 +174,15 @@ impl Protocol {
154174
max_response_size: POV_RESPONSE_SIZE,
155175
// Taken from initial implementation in collator protocol:
156176
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
157-
inbound_queue: Some(tx),
177+
inbound_queue: tx,
158178
},
159179
Protocol::PoVFetchingV1 => RequestResponseConfig {
160180
name,
161181
fallback_names,
162182
max_request_size: 1_000,
163183
max_response_size: POV_RESPONSE_SIZE,
164184
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
165-
inbound_queue: Some(tx),
185+
inbound_queue: tx,
166186
},
167187
Protocol::AvailableDataFetchingV1 => RequestResponseConfig {
168188
name,
@@ -171,7 +191,7 @@ impl Protocol {
171191
// Available data size is dominated by the PoV size.
172192
max_response_size: POV_RESPONSE_SIZE,
173193
request_timeout: POV_REQUEST_TIMEOUT_CONNECTED,
174-
inbound_queue: Some(tx),
194+
inbound_queue: tx,
175195
},
176196
Protocol::StatementFetchingV1 => RequestResponseConfig {
177197
name,
@@ -189,7 +209,7 @@ impl Protocol {
189209
// fail, but this is desired, so we can quickly move on to a faster one - we should
190210
// also decrease its reputation.
191211
request_timeout: Duration::from_secs(1),
192-
inbound_queue: Some(tx),
212+
inbound_queue: tx,
193213
},
194214
Protocol::DisputeSendingV1 => RequestResponseConfig {
195215
name,
@@ -199,10 +219,9 @@ impl Protocol {
199219
/// plenty.
200220
max_response_size: 100,
201221
request_timeout: DISPUTE_REQUEST_TIMEOUT,
202-
inbound_queue: Some(tx),
222+
inbound_queue: tx,
203223
},
204-
};
205-
(rx, cfg)
224+
}
206225
}
207226

208227
// Channel sizes for the supported protocols.

0 commit comments

Comments
 (0)