Skip to content

Commit

Permalink
add fallback request for req-response protocols (paritytech#2771)
Browse files Browse the repository at this point in the history
Previously, it was only possible to retry the same request on a
different protocol name that had the exact same binary payloads.

Introduce a way of trying a different request on a different protocol if
the first one fails with Unsupported protocol.

This helps with adding new req-response versions in polkadot while
preserving compatibility with unupgraded nodes.

The way req-response protocols were bumped previously was that they were
bundled with some other notifications protocol upgrade, like for async
backing (but that is more complicated, especially if the feature does
not require any changes to a notifications protocol). Will be needed for
implementing polkadot-fellows/RFCs#47

TODO:
- [x]  add tests
- [x] add guidance docs in polkadot about req-response protocol
versioning
  • Loading branch information
alindima authored Jan 10, 2024
1 parent 047f6fe commit d1e8e33
Show file tree
Hide file tree
Showing 12 changed files with 428 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
};

/// Response type received from network.
type Response = Result<Vec<u8>, RequestFailure>;
type Response = Result<(Vec<u8>, ProtocolName), RequestFailure>;
/// Used to receive a response from the network.
type ResponseReceiver = oneshot::Receiver<Response>;

Expand Down Expand Up @@ -125,6 +125,7 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
peer,
self.protocol_name.clone(),
payload,
None,
tx,
IfDisconnected::ImmediateError,
);
Expand Down Expand Up @@ -204,7 +205,7 @@ impl<B: Block> OnDemandJustificationsEngine<B> {
},
}
})
.and_then(|encoded| {
.and_then(|(encoded, _)| {
decode_and_verify_finality_proof::<B>(
&encoded[..],
req_info.block,
Expand Down
15 changes: 11 additions & 4 deletions substrate/client/network/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,20 @@ impl<B: BlockT> Behaviour<B> {
pub fn send_request(
&mut self,
target: &PeerId,
protocol: &str,
protocol: ProtocolName,
request: Vec<u8>,
pending_response: oneshot::Sender<Result<Vec<u8>, RequestFailure>>,
fallback_request: Option<(Vec<u8>, ProtocolName)>,
pending_response: oneshot::Sender<Result<(Vec<u8>, ProtocolName), RequestFailure>>,
connect: IfDisconnected,
) {
self.request_responses
.send_request(target, protocol, request, pending_response, connect)
self.request_responses.send_request(
target,
protocol,
request,
fallback_request,
pending_response,
connect,
)
}

/// Returns a shared reference to the user protocol.
Expand Down
Loading

0 comments on commit d1e8e33

Please sign in to comment.