Skip to content

Commit d2080c3

Browse files
lexnvdmitry-markin
authored andcommitted
litep2p/req-resp: Always provide main protocol name in responses (paritytech#6603)
Request responses are initialized with a main protocol name, and optional protocol names as a fallback. Running litep2p in kusama as a validator has surfaced a `debug_asserts` coming from the sync component: https://github.com/paritytech/polkadot-sdk/blob/3906c578c96d97a8a099a4bdac4685acbe375a7c/substrate/client/network/sync/src/strategy/chain_sync.rs#L640-L646 The issue is that we initiate a request-response over the main protocol name `/genesis/sync/2` but receive a response over the legacy procotol `ksm/sync/2`. This behavior is correct because litep2p propagates to the higher levels the protocol that responded. In contrast, libp2p provides the main protocol name regardless of negotiating a legacy protocol. Because of this, higher level components assume that only the main protocol name will respond. To not break this assumption, this PR alings litep2p shim layer with the libp2p behavior. Closes: paritytech#6581 --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: Dmitry Markin <[email protected]>
1 parent f095c9b commit d2080c3

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

prdoc/pr_6603.prdoc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
2+
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json
3+
4+
title: Always provide main protocol name in litep2p responses
5+
6+
doc:
7+
- audience: [ Node Dev, Node Operator ]
8+
description: |
9+
This PR aligns litep2p behavior with libp2p. Previously, litep2p network backend
10+
would provide the actual negotiated request-response protocol that produced a
11+
response message. After this PR, only the main protocol name is reported to other
12+
subsystems.
13+
14+
crates:
15+
- name: sc-network
16+
bump: patch

substrate/client/network/src/litep2p/shim/request_response/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl RequestResponseProtocol {
320320
&mut self,
321321
peer: litep2p::PeerId,
322322
request_id: RequestId,
323-
fallback: Option<litep2p::ProtocolName>,
323+
_fallback: Option<litep2p::ProtocolName>,
324324
response: Vec<u8>,
325325
) {
326326
match self.pending_inbound_responses.remove(&request_id) {
@@ -337,10 +337,7 @@ impl RequestResponseProtocol {
337337
response.len(),
338338
);
339339

340-
let _ = tx.send(Ok((
341-
response,
342-
fallback.map_or_else(|| self.protocol.clone(), Into::into),
343-
)));
340+
let _ = tx.send(Ok((response, self.protocol.clone())));
344341
self.metrics.register_outbound_request_success(started.elapsed());
345342
},
346343
}

0 commit comments

Comments
 (0)