mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
Migrate polkadot-primitives to v6 (#1543)
- Async-backing related primitives are stable `primitives::v6` - Async-backing API is now part of `api_version(7)` - It's enabled on Rococo and Westend runtimes --------- Signed-off-by: Andrei Sandu <andrei-mihail@parity.io> Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
This commit is contained in:
@@ -22,8 +22,7 @@ use futures::{future::BoxFuture, stream::FuturesUnordered};
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
request_response::{
|
||||
incoming::OutgoingResponse, v1 as protocol_v1, vstaging as protocol_vstaging,
|
||||
IncomingRequest,
|
||||
incoming::OutgoingResponse, v1 as protocol_v1, v2 as protocol_v2, IncomingRequest,
|
||||
},
|
||||
PeerId,
|
||||
};
|
||||
@@ -89,7 +88,7 @@ pub struct WaitingCollationFetches {
|
||||
/// Backwards-compatible wrapper for incoming collations requests.
|
||||
pub enum VersionedCollationRequest {
|
||||
V1(IncomingRequest<protocol_v1::CollationFetchingRequest>),
|
||||
VStaging(IncomingRequest<protocol_vstaging::CollationFetchingRequest>),
|
||||
V2(IncomingRequest<protocol_v2::CollationFetchingRequest>),
|
||||
}
|
||||
|
||||
impl From<IncomingRequest<protocol_v1::CollationFetchingRequest>> for VersionedCollationRequest {
|
||||
@@ -98,11 +97,9 @@ impl From<IncomingRequest<protocol_v1::CollationFetchingRequest>> for VersionedC
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IncomingRequest<protocol_vstaging::CollationFetchingRequest>>
|
||||
for VersionedCollationRequest
|
||||
{
|
||||
fn from(req: IncomingRequest<protocol_vstaging::CollationFetchingRequest>) -> Self {
|
||||
Self::VStaging(req)
|
||||
impl From<IncomingRequest<protocol_v2::CollationFetchingRequest>> for VersionedCollationRequest {
|
||||
fn from(req: IncomingRequest<protocol_v2::CollationFetchingRequest>) -> Self {
|
||||
Self::V2(req)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +108,7 @@ impl VersionedCollationRequest {
|
||||
pub fn para_id(&self) -> ParaId {
|
||||
match self {
|
||||
VersionedCollationRequest::V1(req) => req.payload.para_id,
|
||||
VersionedCollationRequest::VStaging(req) => req.payload.para_id,
|
||||
VersionedCollationRequest::V2(req) => req.payload.para_id,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +116,7 @@ impl VersionedCollationRequest {
|
||||
pub fn relay_parent(&self) -> Hash {
|
||||
match self {
|
||||
VersionedCollationRequest::V1(req) => req.payload.relay_parent,
|
||||
VersionedCollationRequest::VStaging(req) => req.payload.relay_parent,
|
||||
VersionedCollationRequest::V2(req) => req.payload.relay_parent,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +124,7 @@ impl VersionedCollationRequest {
|
||||
pub fn peer_id(&self) -> PeerId {
|
||||
match self {
|
||||
VersionedCollationRequest::V1(req) => req.peer,
|
||||
VersionedCollationRequest::VStaging(req) => req.peer,
|
||||
VersionedCollationRequest::V2(req) => req.peer,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,7 +135,7 @@ impl VersionedCollationRequest {
|
||||
) -> Result<(), ()> {
|
||||
match self {
|
||||
VersionedCollationRequest::V1(req) => req.send_outgoing_response(response),
|
||||
VersionedCollationRequest::VStaging(req) => req.send_outgoing_response(response),
|
||||
VersionedCollationRequest::V2(req) => req.send_outgoing_response(response),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ use polkadot_node_network_protocol::{
|
||||
peer_set::{CollationVersion, PeerSet},
|
||||
request_response::{
|
||||
incoming::{self, OutgoingResponse},
|
||||
v1 as request_v1, vstaging as request_vstaging, IncomingRequestReceiver,
|
||||
v1 as request_v1, v2 as request_v2, IncomingRequestReceiver,
|
||||
},
|
||||
v1 as protocol_v1, vstaging as protocol_vstaging, OurView, PeerId,
|
||||
UnifiedReputationChange as Rep, Versioned, View,
|
||||
v1 as protocol_v1, v2 as protocol_v2, OurView, PeerId, UnifiedReputationChange as Rep,
|
||||
Versioned, View,
|
||||
};
|
||||
use polkadot_node_primitives::{CollationSecondedSignal, PoV, Statement};
|
||||
use polkadot_node_subsystem::{
|
||||
@@ -577,7 +577,7 @@ async fn determine_our_validators<Context>(
|
||||
fn declare_message(
|
||||
state: &mut State,
|
||||
version: CollationVersion,
|
||||
) -> Option<Versioned<protocol_v1::CollationProtocol, protocol_vstaging::CollationProtocol>> {
|
||||
) -> Option<Versioned<protocol_v1::CollationProtocol, protocol_v2::CollationProtocol>> {
|
||||
let para_id = state.collating_on?;
|
||||
Some(match version {
|
||||
CollationVersion::V1 => {
|
||||
@@ -590,17 +590,15 @@ fn declare_message(
|
||||
);
|
||||
Versioned::V1(protocol_v1::CollationProtocol::CollatorProtocol(wire_message))
|
||||
},
|
||||
CollationVersion::VStaging => {
|
||||
CollationVersion::V2 => {
|
||||
let declare_signature_payload =
|
||||
protocol_vstaging::declare_signature_payload(&state.local_peer_id);
|
||||
let wire_message = protocol_vstaging::CollatorProtocolMessage::Declare(
|
||||
protocol_v2::declare_signature_payload(&state.local_peer_id);
|
||||
let wire_message = protocol_v2::CollatorProtocolMessage::Declare(
|
||||
state.collator_pair.public(),
|
||||
para_id,
|
||||
state.collator_pair.sign(&declare_signature_payload),
|
||||
);
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
wire_message,
|
||||
))
|
||||
Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(wire_message))
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -706,15 +704,13 @@ async fn advertise_collation<Context>(
|
||||
collation.status.advance_to_advertised();
|
||||
|
||||
let collation_message = match protocol_version {
|
||||
CollationVersion::VStaging => {
|
||||
let wire_message = protocol_vstaging::CollatorProtocolMessage::AdvertiseCollation {
|
||||
CollationVersion::V2 => {
|
||||
let wire_message = protocol_v2::CollatorProtocolMessage::AdvertiseCollation {
|
||||
relay_parent,
|
||||
candidate_hash: *candidate_hash,
|
||||
parent_head_data_hash: collation.parent_head_data_hash,
|
||||
};
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
wire_message,
|
||||
))
|
||||
Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(wire_message))
|
||||
},
|
||||
CollationVersion::V1 => {
|
||||
let wire_message =
|
||||
@@ -837,7 +833,7 @@ async fn send_collation(
|
||||
let candidate_hash = receipt.hash();
|
||||
|
||||
// The response payload is the same for both versions of protocol
|
||||
// and doesn't have vstaging alias for simplicity.
|
||||
// and doesn't have v2 alias for simplicity.
|
||||
let response = OutgoingResponse {
|
||||
result: Ok(request_v1::CollationFetchingResponse::Collation(receipt, pov)),
|
||||
reputation_changes: Vec::new(),
|
||||
@@ -868,16 +864,13 @@ async fn handle_incoming_peer_message<Context>(
|
||||
runtime: &mut RuntimeInfo,
|
||||
state: &mut State,
|
||||
origin: PeerId,
|
||||
msg: Versioned<
|
||||
protocol_v1::CollatorProtocolMessage,
|
||||
protocol_vstaging::CollatorProtocolMessage,
|
||||
>,
|
||||
msg: Versioned<protocol_v1::CollatorProtocolMessage, protocol_v2::CollatorProtocolMessage>,
|
||||
) -> Result<()> {
|
||||
use protocol_v1::CollatorProtocolMessage as V1;
|
||||
use protocol_vstaging::CollatorProtocolMessage as VStaging;
|
||||
use protocol_v2::CollatorProtocolMessage as V2;
|
||||
|
||||
match msg {
|
||||
Versioned::V1(V1::Declare(..)) | Versioned::VStaging(VStaging::Declare(..)) => {
|
||||
Versioned::V1(V1::Declare(..)) | Versioned::V2(V2::Declare(..)) => {
|
||||
gum::trace!(
|
||||
target: LOG_TARGET,
|
||||
?origin,
|
||||
@@ -888,8 +881,7 @@ async fn handle_incoming_peer_message<Context>(
|
||||
ctx.send_message(NetworkBridgeTxMessage::DisconnectPeer(origin, PeerSet::Collation))
|
||||
.await;
|
||||
},
|
||||
Versioned::V1(V1::AdvertiseCollation(_)) |
|
||||
Versioned::VStaging(VStaging::AdvertiseCollation { .. }) => {
|
||||
Versioned::V1(V1::AdvertiseCollation(_)) | Versioned::V2(V2::AdvertiseCollation { .. }) => {
|
||||
gum::trace!(
|
||||
target: LOG_TARGET,
|
||||
?origin,
|
||||
@@ -904,7 +896,7 @@ async fn handle_incoming_peer_message<Context>(
|
||||
.await;
|
||||
},
|
||||
Versioned::V1(V1::CollationSeconded(relay_parent, statement)) |
|
||||
Versioned::VStaging(VStaging::CollationSeconded(relay_parent, statement)) => {
|
||||
Versioned::V2(V2::CollationSeconded(relay_parent, statement)) => {
|
||||
if !matches!(statement.unchecked_payload(), Statement::Seconded(_)) {
|
||||
gum::warn!(
|
||||
target: LOG_TARGET,
|
||||
@@ -1006,7 +998,7 @@ async fn handle_incoming_request<Context>(
|
||||
let collation = match &req {
|
||||
VersionedCollationRequest::V1(_) if !mode.is_enabled() =>
|
||||
per_relay_parent.collations.values_mut().next(),
|
||||
VersionedCollationRequest::VStaging(req) =>
|
||||
VersionedCollationRequest::V2(req) =>
|
||||
per_relay_parent.collations.get_mut(&req.payload.candidate_hash),
|
||||
_ => {
|
||||
gum::warn!(
|
||||
@@ -1322,7 +1314,7 @@ pub(crate) async fn run<Context>(
|
||||
local_peer_id: PeerId,
|
||||
collator_pair: CollatorPair,
|
||||
req_v1_receiver: IncomingRequestReceiver<request_v1::CollationFetchingRequest>,
|
||||
req_v2_receiver: IncomingRequestReceiver<request_vstaging::CollationFetchingRequest>,
|
||||
req_v2_receiver: IncomingRequestReceiver<request_v2::CollationFetchingRequest>,
|
||||
metrics: Metrics,
|
||||
) -> std::result::Result<(), FatalError> {
|
||||
run_inner(
|
||||
@@ -1344,7 +1336,7 @@ async fn run_inner<Context>(
|
||||
local_peer_id: PeerId,
|
||||
collator_pair: CollatorPair,
|
||||
mut req_v1_receiver: IncomingRequestReceiver<request_v1::CollationFetchingRequest>,
|
||||
mut req_v2_receiver: IncomingRequestReceiver<request_vstaging::CollationFetchingRequest>,
|
||||
mut req_v2_receiver: IncomingRequestReceiver<request_v2::CollationFetchingRequest>,
|
||||
metrics: Metrics,
|
||||
reputation: ReputationAggregator,
|
||||
reputation_interval: Duration,
|
||||
@@ -1425,7 +1417,7 @@ async fn run_inner<Context>(
|
||||
(ProspectiveParachainsMode::Disabled, VersionedCollationRequest::V1(_)) => {
|
||||
per_relay_parent.collations.values().next()
|
||||
},
|
||||
(ProspectiveParachainsMode::Enabled { .. }, VersionedCollationRequest::VStaging(req)) => {
|
||||
(ProspectiveParachainsMode::Enabled { .. }, VersionedCollationRequest::V2(req)) => {
|
||||
per_relay_parent.collations.get(&req.payload.candidate_hash)
|
||||
},
|
||||
_ => {
|
||||
@@ -1476,7 +1468,7 @@ async fn run_inner<Context>(
|
||||
|
||||
log_error(
|
||||
handle_incoming_request(&mut ctx, &mut state, request).await,
|
||||
"Handling incoming collation fetch request VStaging"
|
||||
"Handling incoming collation fetch request V2"
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ impl TestState {
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::StagingAsyncBackingParams(tx)
|
||||
RuntimeApiRequest::AsyncBackingParams(tx)
|
||||
)) => {
|
||||
assert_eq!(relay_parent, self.relay_parent);
|
||||
tx.send(Err(ASYNC_BACKING_DISABLED_ERROR)).unwrap();
|
||||
@@ -212,7 +212,7 @@ type VirtualOverseer = test_helpers::TestSubsystemContextHandle<CollatorProtocol
|
||||
struct TestHarness {
|
||||
virtual_overseer: VirtualOverseer,
|
||||
req_v1_cfg: sc_network::config::RequestResponseConfig,
|
||||
req_vstaging_cfg: sc_network::config::RequestResponseConfig,
|
||||
req_v2_cfg: sc_network::config::RequestResponseConfig,
|
||||
}
|
||||
|
||||
fn test_harness<T: Future<Output = TestHarness>>(
|
||||
@@ -236,7 +236,7 @@ fn test_harness<T: Future<Output = TestHarness>>(
|
||||
|
||||
let (collation_req_receiver, req_v1_cfg) =
|
||||
IncomingRequest::get_config_receiver(&req_protocol_names);
|
||||
let (collation_req_vstaging_receiver, req_vstaging_cfg) =
|
||||
let (collation_req_v2_receiver, req_v2_cfg) =
|
||||
IncomingRequest::get_config_receiver(&req_protocol_names);
|
||||
let subsystem = async {
|
||||
run_inner(
|
||||
@@ -244,7 +244,7 @@ fn test_harness<T: Future<Output = TestHarness>>(
|
||||
local_peer_id,
|
||||
collator_pair,
|
||||
collation_req_receiver,
|
||||
collation_req_vstaging_receiver,
|
||||
collation_req_v2_receiver,
|
||||
Default::default(),
|
||||
reputation,
|
||||
REPUTATION_CHANGE_TEST_INTERVAL,
|
||||
@@ -253,7 +253,7 @@ fn test_harness<T: Future<Output = TestHarness>>(
|
||||
.unwrap();
|
||||
};
|
||||
|
||||
let test_fut = test(TestHarness { virtual_overseer, req_v1_cfg, req_vstaging_cfg });
|
||||
let test_fut = test(TestHarness { virtual_overseer, req_v1_cfg, req_v2_cfg });
|
||||
|
||||
futures::pin_mut!(test_fut);
|
||||
futures::pin_mut!(subsystem);
|
||||
@@ -330,7 +330,7 @@ async fn setup_system(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::StagingAsyncBackingParams(tx)
|
||||
RuntimeApiRequest::AsyncBackingParams(tx)
|
||||
)) => {
|
||||
assert_eq!(relay_parent, test_state.relay_parent);
|
||||
tx.send(Err(ASYNC_BACKING_DISABLED_ERROR)).unwrap();
|
||||
@@ -545,7 +545,7 @@ async fn expect_declare_msg(
|
||||
|
||||
/// Check that the next received message is a collation advertisement message.
|
||||
///
|
||||
/// Expects vstaging message if `expected_candidate_hashes` is `Some`, v1 otherwise.
|
||||
/// Expects v2 message if `expected_candidate_hashes` is `Some`, v1 otherwise.
|
||||
async fn expect_advertise_collation_msg(
|
||||
virtual_overseer: &mut VirtualOverseer,
|
||||
peer: &PeerId,
|
||||
@@ -579,13 +579,13 @@ async fn expect_advertise_collation_msg(
|
||||
},
|
||||
(
|
||||
Some(candidate_hashes),
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(
|
||||
wire_message,
|
||||
)),
|
||||
) => {
|
||||
assert_matches!(
|
||||
wire_message,
|
||||
protocol_vstaging::CollatorProtocolMessage::AdvertiseCollation {
|
||||
protocol_v2::CollatorProtocolMessage::AdvertiseCollation {
|
||||
relay_parent,
|
||||
candidate_hash,
|
||||
..
|
||||
@@ -634,7 +634,7 @@ fn advertise_and_send_collation() {
|
||||
|test_harness| async move {
|
||||
let mut virtual_overseer = test_harness.virtual_overseer;
|
||||
let mut req_v1_cfg = test_harness.req_v1_cfg;
|
||||
let req_vstaging_cfg = test_harness.req_vstaging_cfg;
|
||||
let req_v2_cfg = test_harness.req_v2_cfg;
|
||||
|
||||
setup_system(&mut virtual_overseer, &test_state).await;
|
||||
|
||||
@@ -789,7 +789,7 @@ fn advertise_and_send_collation() {
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_vstaging_cfg }
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_v2_cfg }
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -807,7 +807,7 @@ fn delay_reputation_change() {
|
||||
|test_harness| async move {
|
||||
let mut virtual_overseer = test_harness.virtual_overseer;
|
||||
let mut req_v1_cfg = test_harness.req_v1_cfg;
|
||||
let req_vstaging_cfg = test_harness.req_vstaging_cfg;
|
||||
let req_v2_cfg = test_harness.req_v2_cfg;
|
||||
|
||||
setup_system(&mut virtual_overseer, &test_state).await;
|
||||
|
||||
@@ -903,15 +903,15 @@ fn delay_reputation_change() {
|
||||
);
|
||||
}
|
||||
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_vstaging_cfg }
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_v2_cfg }
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Tests that collator side works with vstaging network protocol
|
||||
/// Tests that collator side works with v2 network protocol
|
||||
/// before async backing is enabled.
|
||||
#[test]
|
||||
fn advertise_collation_vstaging_protocol() {
|
||||
fn advertise_collation_v2_protocol() {
|
||||
let test_state = TestState::default();
|
||||
let local_peer_id = test_state.local_peer_id;
|
||||
let collator_pair = test_state.collator_pair.clone();
|
||||
@@ -941,21 +941,16 @@ fn advertise_collation_vstaging_protocol() {
|
||||
Some(validators[0].clone()),
|
||||
)
|
||||
.await;
|
||||
// The rest with vstaging.
|
||||
// The rest with v2.
|
||||
for (val, peer) in validators.iter().zip(peer_ids.iter()).skip(1) {
|
||||
connect_peer(
|
||||
virtual_overseer,
|
||||
*peer,
|
||||
CollationVersion::VStaging,
|
||||
Some(val.clone()),
|
||||
)
|
||||
.await;
|
||||
connect_peer(virtual_overseer, *peer, CollationVersion::V2, Some(val.clone()))
|
||||
.await;
|
||||
}
|
||||
|
||||
// Declare messages.
|
||||
expect_declare_msg(virtual_overseer, &test_state, &peer_ids[0]).await;
|
||||
for peer_id in peer_ids.iter().skip(1) {
|
||||
prospective_parachains::expect_declare_msg_vstaging(
|
||||
prospective_parachains::expect_declare_msg_v2(
|
||||
virtual_overseer,
|
||||
&test_state,
|
||||
&peer_id,
|
||||
@@ -981,7 +976,7 @@ fn advertise_collation_vstaging_protocol() {
|
||||
virtual_overseer,
|
||||
peer_id,
|
||||
test_state.relay_parent,
|
||||
Some(vec![candidate.hash()]), // This is `Some`, advertisement is vstaging.
|
||||
Some(vec![candidate.hash()]), // This is `Some`, advertisement is v2.
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -1405,7 +1400,7 @@ fn connect_to_buffered_groups() {
|
||||
|test_harness| async move {
|
||||
let mut virtual_overseer = test_harness.virtual_overseer;
|
||||
let mut req_cfg = test_harness.req_v1_cfg;
|
||||
let req_vstaging_cfg = test_harness.req_vstaging_cfg;
|
||||
let req_v2_cfg = test_harness.req_v2_cfg;
|
||||
|
||||
setup_system(&mut virtual_overseer, &test_state).await;
|
||||
|
||||
@@ -1510,7 +1505,7 @@ fn connect_to_buffered_groups() {
|
||||
}
|
||||
);
|
||||
|
||||
TestHarness { virtual_overseer, req_v1_cfg: req_cfg, req_vstaging_cfg }
|
||||
TestHarness { virtual_overseer, req_v1_cfg: req_cfg, req_v2_cfg }
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
+19
-20
@@ -19,10 +19,10 @@
|
||||
use super::*;
|
||||
|
||||
use polkadot_node_subsystem::messages::{ChainApiMessage, ProspectiveParachainsMessage};
|
||||
use polkadot_primitives::{vstaging as vstaging_primitives, Header, OccupiedCore};
|
||||
use polkadot_primitives::{AsyncBackingParams, Header, OccupiedCore};
|
||||
|
||||
const ASYNC_BACKING_PARAMETERS: vstaging_primitives::AsyncBackingParams =
|
||||
vstaging_primitives::AsyncBackingParams { max_candidate_depth: 4, allowed_ancestry_len: 3 };
|
||||
const ASYNC_BACKING_PARAMETERS: AsyncBackingParams =
|
||||
AsyncBackingParams { max_candidate_depth: 4, allowed_ancestry_len: 3 };
|
||||
|
||||
fn get_parent_hash(hash: Hash) -> Hash {
|
||||
Hash::from_low_u64_be(hash.to_low_u64_be() + 1)
|
||||
@@ -52,7 +52,7 @@ async fn update_view(
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
parent,
|
||||
RuntimeApiRequest::StagingAsyncBackingParams(tx),
|
||||
RuntimeApiRequest::AsyncBackingParams(tx),
|
||||
)) => {
|
||||
tx.send(Ok(ASYNC_BACKING_PARAMETERS)).unwrap();
|
||||
(parent, new_view.get(&parent).copied().expect("Unknown parent requested"))
|
||||
@@ -124,7 +124,7 @@ async fn update_view(
|
||||
}
|
||||
|
||||
/// Check that the next received message is a `Declare` message.
|
||||
pub(super) async fn expect_declare_msg_vstaging(
|
||||
pub(super) async fn expect_declare_msg_v2(
|
||||
virtual_overseer: &mut VirtualOverseer,
|
||||
test_state: &TestState,
|
||||
peer: &PeerId,
|
||||
@@ -133,20 +133,20 @@ pub(super) async fn expect_declare_msg_vstaging(
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendCollationMessage(
|
||||
to,
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(
|
||||
wire_message,
|
||||
)),
|
||||
)) => {
|
||||
assert_eq!(to[0], *peer);
|
||||
assert_matches!(
|
||||
wire_message,
|
||||
protocol_vstaging::CollatorProtocolMessage::Declare(
|
||||
protocol_v2::CollatorProtocolMessage::Declare(
|
||||
collator_id,
|
||||
para_id,
|
||||
signature,
|
||||
) => {
|
||||
assert!(signature.verify(
|
||||
&*protocol_vstaging::declare_signature_payload(&test_state.local_peer_id),
|
||||
&*protocol_v2::declare_signature_payload(&test_state.local_peer_id),
|
||||
&collator_id),
|
||||
);
|
||||
assert_eq!(collator_id, test_state.collator_pair.public());
|
||||
@@ -203,13 +203,12 @@ fn distribute_collation_from_implicit_view() {
|
||||
.into_iter()
|
||||
.zip(validator_peer_ids.clone())
|
||||
{
|
||||
connect_peer(virtual_overseer, peer, CollationVersion::VStaging, Some(val.clone()))
|
||||
.await;
|
||||
connect_peer(virtual_overseer, peer, CollationVersion::V2, Some(val.clone())).await;
|
||||
}
|
||||
|
||||
// Collator declared itself to each peer.
|
||||
for peer_id in &validator_peer_ids {
|
||||
expect_declare_msg_vstaging(virtual_overseer, &test_state, peer_id).await;
|
||||
expect_declare_msg_v2(virtual_overseer, &test_state, peer_id).await;
|
||||
}
|
||||
|
||||
let pov = PoV { block_data: BlockData(vec![1, 2, 3]) };
|
||||
@@ -386,7 +385,7 @@ fn advertise_and_send_collation_by_hash() {
|
||||
|test_harness| async move {
|
||||
let mut virtual_overseer = test_harness.virtual_overseer;
|
||||
let req_v1_cfg = test_harness.req_v1_cfg;
|
||||
let mut req_vstaging_cfg = test_harness.req_vstaging_cfg;
|
||||
let mut req_v2_cfg = test_harness.req_v2_cfg;
|
||||
|
||||
let head_a = Hash::from_low_u64_be(128);
|
||||
let head_a_num: u32 = 64;
|
||||
@@ -435,11 +434,11 @@ fn advertise_and_send_collation_by_hash() {
|
||||
connect_peer(
|
||||
&mut virtual_overseer,
|
||||
peer,
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
Some(validator_id.clone()),
|
||||
)
|
||||
.await;
|
||||
expect_declare_msg_vstaging(&mut virtual_overseer, &test_state, &peer).await;
|
||||
expect_declare_msg_v2(&mut virtual_overseer, &test_state, &peer).await;
|
||||
|
||||
// Head `b` is not a leaf, but both advertisements are still relevant.
|
||||
send_peer_view_change(&mut virtual_overseer, &peer, vec![head_b]).await;
|
||||
@@ -449,13 +448,13 @@ fn advertise_and_send_collation_by_hash() {
|
||||
|
||||
for (candidate, pov_block) in candidates {
|
||||
let (pending_response, rx) = oneshot::channel();
|
||||
req_vstaging_cfg
|
||||
req_v2_cfg
|
||||
.inbound_queue
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.send(RawIncomingRequest {
|
||||
peer,
|
||||
payload: request_vstaging::CollationFetchingRequest {
|
||||
payload: request_v2::CollationFetchingRequest {
|
||||
relay_parent: head_b,
|
||||
para_id: test_state.para_id,
|
||||
candidate_hash: candidate.hash(),
|
||||
@@ -469,7 +468,7 @@ fn advertise_and_send_collation_by_hash() {
|
||||
assert_matches!(
|
||||
rx.await,
|
||||
Ok(full_response) => {
|
||||
// Response is the same for vstaging.
|
||||
// Response is the same for v2.
|
||||
let request_v1::CollationFetchingResponse::Collation(receipt, pov): request_v1::CollationFetchingResponse
|
||||
= request_v1::CollationFetchingResponse::decode(
|
||||
&mut full_response.result
|
||||
@@ -482,7 +481,7 @@ fn advertise_and_send_collation_by_hash() {
|
||||
);
|
||||
}
|
||||
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_vstaging_cfg }
|
||||
TestHarness { virtual_overseer, req_v1_cfg, req_v2_cfg }
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -552,11 +551,11 @@ fn advertise_core_occupied() {
|
||||
connect_peer(
|
||||
virtual_overseer,
|
||||
peer_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
Some(validators[0].clone()),
|
||||
)
|
||||
.await;
|
||||
expect_declare_msg_vstaging(virtual_overseer, &test_state, &peer_ids[0]).await;
|
||||
expect_declare_msg_v2(virtual_overseer, &test_state, &peer_ids[0]).await;
|
||||
// Peer is aware of the leaf.
|
||||
send_peer_view_change(virtual_overseer, &peer_ids[0], vec![head_a]).await;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ use polkadot_node_subsystem_util::reputation::ReputationAggregator;
|
||||
use sp_keystore::KeystorePtr;
|
||||
|
||||
use polkadot_node_network_protocol::{
|
||||
request_response::{v1 as request_v1, vstaging as protocol_vstaging, IncomingRequestReceiver},
|
||||
request_response::{v1 as request_v1, v2 as protocol_v2, IncomingRequestReceiver},
|
||||
PeerId, UnifiedReputationChange as Rep,
|
||||
};
|
||||
use polkadot_primitives::CollatorPair;
|
||||
@@ -83,9 +83,8 @@ pub enum ProtocolSide {
|
||||
collator_pair: CollatorPair,
|
||||
/// Receiver for v1 collation fetching requests.
|
||||
request_receiver_v1: IncomingRequestReceiver<request_v1::CollationFetchingRequest>,
|
||||
/// Receiver for vstaging collation fetching requests.
|
||||
request_receiver_vstaging:
|
||||
IncomingRequestReceiver<protocol_vstaging::CollationFetchingRequest>,
|
||||
/// Receiver for v2 collation fetching requests.
|
||||
request_receiver_v2: IncomingRequestReceiver<protocol_v2::CollationFetchingRequest>,
|
||||
/// Metrics.
|
||||
metrics: collator_side::Metrics,
|
||||
},
|
||||
@@ -121,14 +120,14 @@ impl<Context> CollatorProtocolSubsystem {
|
||||
peer_id,
|
||||
collator_pair,
|
||||
request_receiver_v1,
|
||||
request_receiver_vstaging,
|
||||
request_receiver_v2,
|
||||
metrics,
|
||||
} => collator_side::run(
|
||||
ctx,
|
||||
peer_id,
|
||||
collator_pair,
|
||||
request_receiver_v1,
|
||||
request_receiver_vstaging,
|
||||
request_receiver_v2,
|
||||
metrics,
|
||||
)
|
||||
.map_err(|e| SubsystemError::with_origin("collator-protocol", e))
|
||||
|
||||
@@ -119,7 +119,7 @@ impl PendingCollation {
|
||||
}
|
||||
}
|
||||
|
||||
/// vstaging advertisement that was rejected by the backing
|
||||
/// v2 advertisement that was rejected by the backing
|
||||
/// subsystem. Validator may fetch it later if its fragment
|
||||
/// membership gets recognized before relay parent goes out of view.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
@@ -34,10 +34,10 @@ use polkadot_node_network_protocol::{
|
||||
peer_set::{CollationVersion, PeerSet},
|
||||
request_response::{
|
||||
outgoing::{Recipient, RequestError},
|
||||
v1 as request_v1, vstaging as request_vstaging, OutgoingRequest, Requests,
|
||||
v1 as request_v1, v2 as request_v2, OutgoingRequest, Requests,
|
||||
},
|
||||
v1 as protocol_v1, vstaging as protocol_vstaging, OurView, PeerId,
|
||||
UnifiedReputationChange as Rep, Versioned, View,
|
||||
v1 as protocol_v1, v2 as protocol_v2, OurView, PeerId, UnifiedReputationChange as Rep,
|
||||
Versioned, View,
|
||||
};
|
||||
use polkadot_node_primitives::{SignedFullStatement, Statement};
|
||||
use polkadot_node_subsystem::{
|
||||
@@ -624,13 +624,9 @@ async fn notify_collation_seconded(
|
||||
CollationVersion::V1 => Versioned::V1(protocol_v1::CollationProtocol::CollatorProtocol(
|
||||
protocol_v1::CollatorProtocolMessage::CollationSeconded(relay_parent, statement),
|
||||
)),
|
||||
CollationVersion::VStaging =>
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
protocol_vstaging::CollatorProtocolMessage::CollationSeconded(
|
||||
relay_parent,
|
||||
statement,
|
||||
),
|
||||
)),
|
||||
CollationVersion::V2 => Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(
|
||||
protocol_v2::CollatorProtocolMessage::CollationSeconded(relay_parent, statement),
|
||||
)),
|
||||
};
|
||||
sender
|
||||
.send_message(NetworkBridgeTxMessage::SendCollationMessage(vec![peer_id], wire_message))
|
||||
@@ -694,16 +690,12 @@ async fn request_collation(
|
||||
let requests = Requests::CollationFetchingV1(req);
|
||||
(requests, response_recv.boxed())
|
||||
},
|
||||
(CollationVersion::VStaging, Some(ProspectiveCandidate { candidate_hash, .. })) => {
|
||||
(CollationVersion::V2, Some(ProspectiveCandidate { candidate_hash, .. })) => {
|
||||
let (req, response_recv) = OutgoingRequest::new(
|
||||
Recipient::Peer(peer_id),
|
||||
request_vstaging::CollationFetchingRequest {
|
||||
relay_parent,
|
||||
para_id,
|
||||
candidate_hash,
|
||||
},
|
||||
request_v2::CollationFetchingRequest { relay_parent, para_id, candidate_hash },
|
||||
);
|
||||
let requests = Requests::CollationFetchingVStaging(req);
|
||||
let requests = Requests::CollationFetchingV2(req);
|
||||
(requests, response_recv.boxed())
|
||||
},
|
||||
_ => return Err(FetchError::ProtocolMismatch),
|
||||
@@ -758,18 +750,15 @@ async fn process_incoming_peer_message<Context>(
|
||||
ctx: &mut Context,
|
||||
state: &mut State,
|
||||
origin: PeerId,
|
||||
msg: Versioned<
|
||||
protocol_v1::CollatorProtocolMessage,
|
||||
protocol_vstaging::CollatorProtocolMessage,
|
||||
>,
|
||||
msg: Versioned<protocol_v1::CollatorProtocolMessage, protocol_v2::CollatorProtocolMessage>,
|
||||
) {
|
||||
use protocol_v1::CollatorProtocolMessage as V1;
|
||||
use protocol_vstaging::CollatorProtocolMessage as VStaging;
|
||||
use protocol_v2::CollatorProtocolMessage as V2;
|
||||
use sp_runtime::traits::AppVerify;
|
||||
|
||||
match msg {
|
||||
Versioned::V1(V1::Declare(collator_id, para_id, signature)) |
|
||||
Versioned::VStaging(VStaging::Declare(collator_id, para_id, signature)) => {
|
||||
Versioned::V2(V2::Declare(collator_id, para_id, signature)) => {
|
||||
if collator_peer_id(&state.peer_data, &collator_id).is_some() {
|
||||
modify_reputation(
|
||||
&mut state.reputation,
|
||||
@@ -881,7 +870,7 @@ async fn process_incoming_peer_message<Context>(
|
||||
modify_reputation(&mut state.reputation, ctx.sender(), origin, rep).await;
|
||||
}
|
||||
},
|
||||
Versioned::VStaging(VStaging::AdvertiseCollation {
|
||||
Versioned::V2(V2::AdvertiseCollation {
|
||||
relay_parent,
|
||||
candidate_hash,
|
||||
parent_head_data_hash,
|
||||
@@ -901,15 +890,14 @@ async fn process_incoming_peer_message<Context>(
|
||||
?relay_parent,
|
||||
?candidate_hash,
|
||||
error = ?err,
|
||||
"Rejected vstaging advertisement",
|
||||
"Rejected v2 advertisement",
|
||||
);
|
||||
|
||||
if let Some(rep) = err.reputation_changes() {
|
||||
modify_reputation(&mut state.reputation, ctx.sender(), origin, rep).await;
|
||||
}
|
||||
},
|
||||
Versioned::V1(V1::CollationSeconded(..)) |
|
||||
Versioned::VStaging(VStaging::CollationSeconded(..)) => {
|
||||
Versioned::V1(V1::CollationSeconded(..)) | Versioned::V2(V2::CollationSeconded(..)) => {
|
||||
gum::warn!(
|
||||
target: LOG_TARGET,
|
||||
peer_id = ?origin,
|
||||
@@ -1074,7 +1062,7 @@ where
|
||||
};
|
||||
|
||||
if relay_parent_mode.is_enabled() && prospective_candidate.is_none() {
|
||||
// Expected vstaging advertisement.
|
||||
// Expected v2 advertisement.
|
||||
return Err(AdvertisementError::ProtocolMismatch)
|
||||
}
|
||||
|
||||
|
||||
@@ -357,7 +357,7 @@ async fn assert_fetch_collation_request(
|
||||
),
|
||||
Some(candidate_hash) => assert_matches!(
|
||||
req,
|
||||
Requests::CollationFetchingVStaging(req) => {
|
||||
Requests::CollationFetchingV2(req) => {
|
||||
let payload = req.payload;
|
||||
assert_eq!(payload.relay_parent, relay_parent);
|
||||
assert_eq!(payload.para_id, para_id);
|
||||
@@ -394,12 +394,11 @@ async fn connect_and_declare_collator(
|
||||
para_id,
|
||||
collator.sign(&protocol_v1::declare_signature_payload(&peer)),
|
||||
)),
|
||||
CollationVersion::VStaging =>
|
||||
Versioned::VStaging(protocol_vstaging::CollatorProtocolMessage::Declare(
|
||||
collator.public(),
|
||||
para_id,
|
||||
collator.sign(&protocol_v1::declare_signature_payload(&peer)),
|
||||
)),
|
||||
CollationVersion::V2 => Versioned::V2(protocol_v2::CollatorProtocolMessage::Declare(
|
||||
collator.public(),
|
||||
para_id,
|
||||
collator.sign(&protocol_v1::declare_signature_payload(&peer)),
|
||||
)),
|
||||
};
|
||||
|
||||
overseer_send(
|
||||
@@ -421,7 +420,7 @@ async fn advertise_collation(
|
||||
) {
|
||||
let wire_message = match candidate {
|
||||
Some((candidate_hash, parent_head_data_hash)) =>
|
||||
Versioned::VStaging(protocol_vstaging::CollatorProtocolMessage::AdvertiseCollation {
|
||||
Versioned::V2(protocol_v2::CollatorProtocolMessage::AdvertiseCollation {
|
||||
relay_parent,
|
||||
candidate_hash,
|
||||
parent_head_data_hash,
|
||||
@@ -444,7 +443,7 @@ async fn assert_async_backing_params_request(virtual_overseer: &mut VirtualOvers
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
relay_parent,
|
||||
RuntimeApiRequest::StagingAsyncBackingParams(tx)
|
||||
RuntimeApiRequest::AsyncBackingParams(tx)
|
||||
)) => {
|
||||
assert_eq!(relay_parent, hash);
|
||||
tx.send(Err(ASYNC_BACKING_DISABLED_ERROR)).unwrap();
|
||||
@@ -499,10 +498,10 @@ fn act_on_advertisement() {
|
||||
});
|
||||
}
|
||||
|
||||
/// Tests that validator side works with vstaging network protocol
|
||||
/// Tests that validator side works with v2 network protocol
|
||||
/// before async backing is enabled.
|
||||
#[test]
|
||||
fn act_on_advertisement_vstaging() {
|
||||
fn act_on_advertisement_v2() {
|
||||
let test_state = TestState::default();
|
||||
|
||||
test_harness(ReputationAggregator::new(|_| true), |test_harness| async move {
|
||||
@@ -529,13 +528,13 @@ fn act_on_advertisement_vstaging() {
|
||||
peer_b,
|
||||
pair.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
let candidate_hash = CandidateHash::default();
|
||||
let parent_head_data_hash = Hash::zero();
|
||||
// vstaging advertisement.
|
||||
// v2 advertisement.
|
||||
advertise_collation(
|
||||
&mut virtual_overseer,
|
||||
peer_b,
|
||||
|
||||
+18
-18
@@ -20,12 +20,12 @@ use super::*;
|
||||
|
||||
use polkadot_node_subsystem::messages::ChainApiMessage;
|
||||
use polkadot_primitives::{
|
||||
vstaging as vstaging_primitives, BlockNumber, CandidateCommitments, CommittedCandidateReceipt,
|
||||
Header, SigningContext, ValidatorId,
|
||||
AsyncBackingParams, BlockNumber, CandidateCommitments, CommittedCandidateReceipt, Header,
|
||||
SigningContext, ValidatorId,
|
||||
};
|
||||
|
||||
const ASYNC_BACKING_PARAMETERS: vstaging_primitives::AsyncBackingParams =
|
||||
vstaging_primitives::AsyncBackingParams { max_candidate_depth: 4, allowed_ancestry_len: 3 };
|
||||
const ASYNC_BACKING_PARAMETERS: AsyncBackingParams =
|
||||
AsyncBackingParams { max_candidate_depth: 4, allowed_ancestry_len: 3 };
|
||||
|
||||
fn get_parent_hash(hash: Hash) -> Hash {
|
||||
Hash::from_low_u64_be(hash.to_low_u64_be() + 1)
|
||||
@@ -97,7 +97,7 @@ async fn update_view(
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
|
||||
parent,
|
||||
RuntimeApiRequest::StagingAsyncBackingParams(tx),
|
||||
RuntimeApiRequest::AsyncBackingParams(tx),
|
||||
)) => {
|
||||
tx.send(Ok(ASYNC_BACKING_PARAMETERS)).unwrap();
|
||||
(parent, new_view.get(&parent).copied().expect("Unknown parent requested"))
|
||||
@@ -226,8 +226,8 @@ async fn assert_collation_seconded(
|
||||
overseer_recv(virtual_overseer).await,
|
||||
AllMessages::NetworkBridgeTx(NetworkBridgeTxMessage::SendCollationMessage(
|
||||
peers,
|
||||
Versioned::VStaging(protocol_vstaging::CollationProtocol::CollatorProtocol(
|
||||
protocol_vstaging::CollatorProtocolMessage::CollationSeconded(
|
||||
Versioned::V2(protocol_v2::CollationProtocol::CollatorProtocol(
|
||||
protocol_v2::CollatorProtocolMessage::CollationSeconded(
|
||||
_relay_parent,
|
||||
..,
|
||||
),
|
||||
@@ -306,7 +306,7 @@ fn accept_advertisements_from_implicit_view() {
|
||||
peer_a,
|
||||
pair_a.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
connect_and_declare_collator(
|
||||
@@ -314,7 +314,7 @@ fn accept_advertisements_from_implicit_view() {
|
||||
peer_b,
|
||||
pair_b.clone(),
|
||||
test_state.chain_ids[1],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -406,7 +406,7 @@ fn second_multiple_candidates_per_relay_parent() {
|
||||
peer_a,
|
||||
pair.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -457,7 +457,7 @@ fn second_multiple_candidates_per_relay_parent() {
|
||||
let pov = PoV { block_data: BlockData(vec![1]) };
|
||||
|
||||
response_channel
|
||||
.send(Ok(request_vstaging::CollationFetchingResponse::Collation(
|
||||
.send(Ok(request_v2::CollationFetchingResponse::Collation(
|
||||
candidate.clone(),
|
||||
pov.clone(),
|
||||
)
|
||||
@@ -514,7 +514,7 @@ fn second_multiple_candidates_per_relay_parent() {
|
||||
peer_b,
|
||||
pair_b.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -562,7 +562,7 @@ fn fetched_collation_sanity_check() {
|
||||
peer_a,
|
||||
pair.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -611,7 +611,7 @@ fn fetched_collation_sanity_check() {
|
||||
let pov = PoV { block_data: BlockData(vec![1]) };
|
||||
|
||||
response_channel
|
||||
.send(Ok(request_vstaging::CollationFetchingResponse::Collation(
|
||||
.send(Ok(request_v2::CollationFetchingResponse::Collation(
|
||||
candidate.clone(),
|
||||
pov.clone(),
|
||||
)
|
||||
@@ -668,7 +668,7 @@ fn advertisement_spam_protection() {
|
||||
peer_a,
|
||||
pair_a.clone(),
|
||||
test_state.chain_ids[1],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -748,7 +748,7 @@ fn backed_candidate_unblocks_advertisements() {
|
||||
peer_a,
|
||||
pair_a.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
connect_and_declare_collator(
|
||||
@@ -756,7 +756,7 @@ fn backed_candidate_unblocks_advertisements() {
|
||||
peer_b,
|
||||
pair_b.clone(),
|
||||
test_state.chain_ids[1],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -856,7 +856,7 @@ fn active_leave_unblocks_advertisements() {
|
||||
*peer_id,
|
||||
peer.clone(),
|
||||
test_state.chain_ids[0],
|
||||
CollationVersion::VStaging,
|
||||
CollationVersion::V2,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user