add fallback request for req-response protocols (#2771)

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 https://github.com/polkadot-fellows/RFCs/pull/47

TODO:
- [x]  add tests
- [x] add guidance docs in polkadot about req-response protocol
versioning
This commit is contained in:
Alin Dima
2024-01-10 15:19:50 +02:00
committed by GitHub
parent af2e30e383
commit f2a750ee86
29 changed files with 802 additions and 304 deletions
@@ -50,6 +50,7 @@ use polkadot_primitives_test_helpers::{
dummy_committed_candidate_receipt, dummy_hash, AlwaysZeroRng,
};
use sc_keystore::LocalKeystore;
use sc_network::ProtocolName;
use sp_application_crypto::{sr25519::Pair, AppCrypto, Pair as TraitPair};
use sp_authority_discovery::AuthorityPair;
use sp_keyring::Sr25519Keyring;
@@ -1330,7 +1331,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
bad
};
let response = StatementFetchingResponse::Statement(bad_candidate);
outgoing.pending_response.send(Ok(response.encode())).unwrap();
outgoing.pending_response.send(Ok((response.encode(), ProtocolName::from("")))).unwrap();
}
);
@@ -1382,7 +1383,7 @@ fn receiving_large_statement_from_one_sends_to_another_and_to_candidate_backing(
// On retry, we should have reverse order:
assert_eq!(outgoing.peer, Recipient::Peer(peer_c));
let response = StatementFetchingResponse::Statement(candidate.clone());
outgoing.pending_response.send(Ok(response.encode())).unwrap();
outgoing.pending_response.send(Ok((response.encode(), ProtocolName::from("")))).unwrap();
}
);
@@ -1869,7 +1870,7 @@ fn delay_reputation_changes() {
bad
};
let response = StatementFetchingResponse::Statement(bad_candidate);
outgoing.pending_response.send(Ok(response.encode())).unwrap();
outgoing.pending_response.send(Ok((response.encode(), ProtocolName::from("")))).unwrap();
}
);
@@ -1913,7 +1914,7 @@ fn delay_reputation_changes() {
// On retry, we should have reverse order:
assert_eq!(outgoing.peer, Recipient::Peer(peer_c));
let response = StatementFetchingResponse::Statement(candidate.clone());
outgoing.pending_response.send(Ok(response.encode())).unwrap();
outgoing.pending_response.send(Ok((response.encode(), ProtocolName::from("")))).unwrap();
}
);
@@ -38,6 +38,7 @@ use polkadot_primitives::{
SessionIndex, SessionInfo, ValidatorPair,
};
use sc_keystore::LocalKeystore;
use sc_network::ProtocolName;
use sp_application_crypto::Pair as PairT;
use sp_authority_discovery::AuthorityPair as AuthorityDiscoveryPair;
use sp_keyring::Sr25519Keyring;
@@ -684,7 +685,7 @@ async fn handle_sent_request(
persisted_validation_data,
statements,
};
outgoing.pending_response.send(Ok(res.encode())).unwrap();
outgoing.pending_response.send(Ok((res.encode(), ProtocolName::from("")))).unwrap();
}
);
}
@@ -22,8 +22,9 @@ use polkadot_node_network_protocol::{
request_response::v2 as request_v2, v2::BackedCandidateManifest,
};
use polkadot_primitives_test_helpers::make_candidate;
use sc_network::config::{
IncomingRequest as RawIncomingRequest, OutgoingResponse as RawOutgoingResponse,
use sc_network::{
config::{IncomingRequest as RawIncomingRequest, OutgoingResponse as RawOutgoingResponse},
ProtocolName,
};
#[test]
@@ -1342,7 +1343,7 @@ fn when_validator_disabled_after_sending_the_request() {
persisted_validation_data: pvd,
statements,
};
outgoing.pending_response.send(Ok(res.encode())).unwrap();
outgoing.pending_response.send(Ok((res.encode(), ProtocolName::from("")))).unwrap();
}
);
}