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:
Chris Sosnin
2023-09-27 13:32:02 +03:00
committed by GitHub
parent 5a2833cceb
commit 7cbe0c76ef
107 changed files with 2410 additions and 2792 deletions
+1 -1
View File
@@ -237,7 +237,7 @@ async fn test_startup(virtual_overseer: &mut VirtualOverseer, test_state: &TestS
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingAsyncBackingParams(tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::AsyncBackingParams(tx))
) if parent == test_state.relay_parent => {
tx.send(Err(ASYNC_BACKING_DISABLED_ERROR)).unwrap();
}
@@ -20,12 +20,12 @@ use polkadot_node_subsystem::{
messages::{ChainApiMessage, FragmentTreeMembership},
ActivatedLeaf, TimeoutExt,
};
use polkadot_primitives::{vstaging as vstaging_primitives, BlockNumber, Header, OccupiedCore};
use polkadot_primitives::{AsyncBackingParams, BlockNumber, Header, OccupiedCore};
use super::*;
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 };
struct TestLeaf {
activated: ActivatedLeaf,
@@ -56,7 +56,7 @@ async fn activate_leaf(
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingAsyncBackingParams(tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::AsyncBackingParams(tx))
) if parent == leaf_hash => {
tx.send(Ok(ASYNC_BACKING_PARAMETERS)).unwrap();
}
@@ -43,7 +43,7 @@ use polkadot_node_subsystem_util::runtime::{
self, key_ownership_proof, submit_report_dispute_lost, RuntimeInfo,
};
use polkadot_primitives::{
vstaging, BlockNumber, CandidateHash, CandidateReceipt, CompactStatement, DisputeStatement,
slashing, BlockNumber, CandidateHash, CandidateReceipt, CompactStatement, DisputeStatement,
DisputeStatementSet, Hash, ScrapedOnChainVotes, SessionIndex, ValidDisputeStatementKind,
ValidatorId, ValidatorIndex,
};
@@ -385,7 +385,7 @@ impl Initialized {
&mut self,
ctx: &mut Context,
relay_parent: Hash,
unapplied_slashes: Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>,
unapplied_slashes: Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>,
) {
for (session_index, candidate_hash, pending) in unapplied_slashes {
gum::info!(
@@ -422,11 +422,9 @@ impl Initialized {
match res {
Ok(Some(key_ownership_proof)) => {
key_ownership_proofs.push(key_ownership_proof);
let time_slot = vstaging::slashing::DisputesTimeSlot::new(
session_index,
candidate_hash,
);
let dispute_proof = vstaging::slashing::DisputeProof {
let time_slot =
slashing::DisputesTimeSlot::new(session_index, candidate_hash);
let dispute_proof = slashing::DisputeProof {
time_slot,
kind: pending.kind,
validator_index: *validator_index,
@@ -96,10 +96,10 @@ use std::{
use super::LOG_TARGET;
use bitvec::prelude::*;
use polkadot_node_subsystem_util::inclusion_emulator::staging::{
use polkadot_node_subsystem_util::inclusion_emulator::{
ConstraintModifications, Constraints, Fragment, ProspectiveCandidate, RelayChainBlockInfo,
};
use polkadot_primitives::vstaging::{
use polkadot_primitives::{
BlockNumber, CandidateHash, CommittedCandidateReceipt, Hash, HeadData, Id as ParaId,
PersistedValidationData,
};
@@ -981,10 +981,8 @@ impl FragmentNode {
mod tests {
use super::*;
use assert_matches::assert_matches;
use polkadot_node_subsystem_util::inclusion_emulator::staging::InboundHrmpLimitations;
use polkadot_primitives::vstaging::{
BlockNumber, CandidateCommitments, CandidateDescriptor, HeadData,
};
use polkadot_node_subsystem_util::inclusion_emulator::InboundHrmpLimitations;
use polkadot_primitives::{BlockNumber, CandidateCommitments, CandidateDescriptor, HeadData};
use polkadot_primitives_test_helpers as test_helpers;
fn make_constraints(
@@ -22,7 +22,7 @@
//! backing phases of parachain consensus.
//!
//! This is primarily an implementation of "Fragment Trees", as described in
//! [`polkadot_node_subsystem_util::inclusion_emulator::staging`].
//! [`polkadot_node_subsystem_util::inclusion_emulator`].
//!
//! This subsystem also handles concerns such as the relay-chain being forkful and session changes.
@@ -42,13 +42,14 @@ use polkadot_node_subsystem::{
overseer, ActiveLeavesUpdate, FromOrchestra, OverseerSignal, SpawnedSubsystem, SubsystemError,
};
use polkadot_node_subsystem_util::{
inclusion_emulator::staging::{Constraints, RelayChainBlockInfo},
inclusion_emulator::{Constraints, RelayChainBlockInfo},
request_session_index_for_child,
runtime::{prospective_parachains_mode, ProspectiveParachainsMode},
};
use polkadot_primitives::vstaging::{
BlockNumber, CandidateHash, CandidatePendingAvailability, CommittedCandidateReceipt, CoreState,
Hash, HeadData, Header, Id as ParaId, PersistedValidationData,
use polkadot_primitives::{
async_backing::CandidatePendingAvailability, BlockNumber, CandidateHash,
CommittedCandidateReceipt, CoreState, Hash, HeadData, Header, Id as ParaId,
PersistedValidationData,
};
use crate::{
@@ -792,7 +793,7 @@ async fn fetch_backing_state<Context>(
let (tx, rx) = oneshot::channel();
ctx.send_message(RuntimeApiMessage::Request(
relay_parent,
RuntimeApiRequest::StagingParaBackingState(para_id, tx),
RuntimeApiRequest::ParaBackingState(para_id, tx),
))
.await;
@@ -25,7 +25,7 @@ use polkadot_node_subsystem::{
};
use polkadot_node_subsystem_test_helpers as test_helpers;
use polkadot_primitives::{
vstaging::{AsyncBackingParams, BackingState, Constraints, InboundHrmpLimitations},
async_backing::{AsyncBackingParams, BackingState, Constraints, InboundHrmpLimitations},
CommittedCandidateReceipt, HeadData, Header, PersistedValidationData, ScheduledCore,
ValidationCodeHash,
};
@@ -219,7 +219,7 @@ async fn handle_leaf_activation(
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingAsyncBackingParams(tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::AsyncBackingParams(tx))
) if parent == *hash => {
tx.send(Ok(async_backing_params)).unwrap();
}
@@ -284,7 +284,7 @@ async fn handle_leaf_activation(
let para_id = match message {
AllMessages::RuntimeApi(RuntimeApiMessage::Request(
_,
RuntimeApiRequest::StagingParaBackingState(p_id, _),
RuntimeApiRequest::ParaBackingState(p_id, _),
)) => p_id,
_ => panic!("received unexpected message {:?}", message),
};
@@ -303,7 +303,7 @@ async fn handle_leaf_activation(
assert_matches!(
message,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingParaBackingState(p_id, tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::ParaBackingState(p_id, tx))
) if parent == *hash && p_id == para_id => {
tx.send(Ok(Some(backing_state))).unwrap();
}
@@ -499,7 +499,7 @@ fn should_do_no_work_if_async_backing_disabled_for_leaf() {
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingAsyncBackingParams(tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::AsyncBackingParams(tx))
) if parent == hash => {
tx.send(Err(ASYNC_BACKING_DISABLED_ERROR)).unwrap();
}
@@ -1569,7 +1569,7 @@ fn uses_ancestry_only_within_session() {
assert_matches!(
virtual_overseer.recv().await,
AllMessages::RuntimeApi(
RuntimeApiMessage::Request(parent, RuntimeApiRequest::StagingAsyncBackingParams(tx))
RuntimeApiMessage::Request(parent, RuntimeApiRequest::AsyncBackingParams(tx))
) if parent == hash => {
tx.send(Ok(AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: ancestry_len })).unwrap();
}
+35 -39
View File
@@ -20,12 +20,12 @@ use schnellru::{ByLength, LruMap};
use sp_consensus_babe::Epoch;
use polkadot_primitives::{
vstaging, AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams,
GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash, ValidatorId, ValidatorIndex,
ValidatorSignature,
async_backing, slashing, AuthorityDiscoveryId, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
ExecutorParams, GroupRotationInfo, Hash, Id as ParaId, InboundDownwardMessage,
InboundHrmpMessage, OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement,
ScrapedOnChainVotes, SessionIndex, SessionInfo, ValidationCode, ValidationCodeHash,
ValidatorId, ValidatorIndex, ValidatorSignature,
};
/// For consistency we have the same capacity for all caches. We use 128 as we'll only need that
@@ -61,14 +61,11 @@ pub(crate) struct RequestResultCache {
LruMap<(Hash, ParaId, OccupiedCoreAssumption), Option<ValidationCodeHash>>,
version: LruMap<Hash, u32>,
disputes: LruMap<Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>>,
unapplied_slashes:
LruMap<Hash, Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>>,
key_ownership_proof:
LruMap<(Hash, ValidatorId), Option<vstaging::slashing::OpaqueKeyOwnershipProof>>,
unapplied_slashes: LruMap<Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>>,
key_ownership_proof: LruMap<(Hash, ValidatorId), Option<slashing::OpaqueKeyOwnershipProof>>,
minimum_backing_votes: LruMap<SessionIndex, u32>,
staging_para_backing_state: LruMap<(Hash, ParaId), Option<vstaging::BackingState>>,
staging_async_backing_params: LruMap<Hash, vstaging::AsyncBackingParams>,
para_backing_state: LruMap<(Hash, ParaId), Option<async_backing::BackingState>>,
async_backing_params: LruMap<Hash, async_backing::AsyncBackingParams>,
}
impl Default for RequestResultCache {
@@ -100,8 +97,8 @@ impl Default for RequestResultCache {
key_ownership_proof: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
minimum_backing_votes: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
staging_para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
staging_async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
para_backing_state: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
async_backing_params: LruMap::new(ByLength::new(DEFAULT_CACHE_CAP)),
}
}
}
@@ -401,14 +398,14 @@ impl RequestResultCache {
pub(crate) fn unapplied_slashes(
&mut self,
relay_parent: &Hash,
) -> Option<&Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>> {
) -> Option<&Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>> {
self.unapplied_slashes.get(relay_parent).map(|v| &*v)
}
pub(crate) fn cache_unapplied_slashes(
&mut self,
relay_parent: Hash,
value: Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>,
value: Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>,
) {
self.unapplied_slashes.insert(relay_parent, value);
}
@@ -416,14 +413,14 @@ impl RequestResultCache {
pub(crate) fn key_ownership_proof(
&mut self,
key: (Hash, ValidatorId),
) -> Option<&Option<vstaging::slashing::OpaqueKeyOwnershipProof>> {
) -> Option<&Option<slashing::OpaqueKeyOwnershipProof>> {
self.key_ownership_proof.get(&key).map(|v| &*v)
}
pub(crate) fn cache_key_ownership_proof(
&mut self,
key: (Hash, ValidatorId),
value: Option<vstaging::slashing::OpaqueKeyOwnershipProof>,
value: Option<slashing::OpaqueKeyOwnershipProof>,
) {
self.key_ownership_proof.insert(key, value);
}
@@ -431,7 +428,7 @@ impl RequestResultCache {
// This request is never cached, hence always returns `None`.
pub(crate) fn submit_report_dispute_lost(
&mut self,
_key: (Hash, vstaging::slashing::DisputeProof, vstaging::slashing::OpaqueKeyOwnershipProof),
_key: (Hash, slashing::DisputeProof, slashing::OpaqueKeyOwnershipProof),
) -> Option<&Option<()>> {
None
}
@@ -448,34 +445,34 @@ impl RequestResultCache {
self.minimum_backing_votes.insert(session_index, minimum_backing_votes);
}
pub(crate) fn staging_para_backing_state(
pub(crate) fn para_backing_state(
&mut self,
key: (Hash, ParaId),
) -> Option<&Option<vstaging::BackingState>> {
self.staging_para_backing_state.get(&key).map(|v| &*v)
) -> Option<&Option<async_backing::BackingState>> {
self.para_backing_state.get(&key).map(|v| &*v)
}
pub(crate) fn cache_staging_para_backing_state(
pub(crate) fn cache_para_backing_state(
&mut self,
key: (Hash, ParaId),
value: Option<vstaging::BackingState>,
value: Option<async_backing::BackingState>,
) {
self.staging_para_backing_state.insert(key, value);
self.para_backing_state.insert(key, value);
}
pub(crate) fn staging_async_backing_params(
pub(crate) fn async_backing_params(
&mut self,
key: &Hash,
) -> Option<&vstaging::AsyncBackingParams> {
self.staging_async_backing_params.get(key).map(|v| &*v)
) -> Option<&async_backing::AsyncBackingParams> {
self.async_backing_params.get(key).map(|v| &*v)
}
pub(crate) fn cache_staging_async_backing_params(
pub(crate) fn cache_async_backing_params(
&mut self,
key: Hash,
value: vstaging::AsyncBackingParams,
value: async_backing::AsyncBackingParams,
) {
self.staging_async_backing_params.insert(key, value);
self.async_backing_params.insert(key, value);
}
}
@@ -515,16 +512,15 @@ pub(crate) enum RequestResult {
ValidationCodeHash(Hash, ParaId, OccupiedCoreAssumption, Option<ValidationCodeHash>),
Version(Hash, u32),
Disputes(Hash, Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumber>)>),
UnappliedSlashes(Hash, Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>),
KeyOwnershipProof(Hash, ValidatorId, Option<vstaging::slashing::OpaqueKeyOwnershipProof>),
UnappliedSlashes(Hash, Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>),
KeyOwnershipProof(Hash, ValidatorId, Option<slashing::OpaqueKeyOwnershipProof>),
// This is a request with side-effects.
SubmitReportDisputeLost(
Hash,
vstaging::slashing::DisputeProof,
vstaging::slashing::OpaqueKeyOwnershipProof,
slashing::DisputeProof,
slashing::OpaqueKeyOwnershipProof,
Option<()>,
),
StagingParaBackingState(Hash, ParaId, Option<vstaging::BackingState>),
StagingAsyncBackingParams(Hash, vstaging::AsyncBackingParams),
ParaBackingState(Hash, ParaId, Option<async_backing::BackingState>),
AsyncBackingParams(Hash, async_backing::AsyncBackingParams),
}
+14 -19
View File
@@ -166,12 +166,11 @@ where
.requests_cache
.cache_key_ownership_proof((relay_parent, validator_id), key_ownership_proof),
SubmitReportDisputeLost(_, _, _, _) => {},
StagingParaBackingState(relay_parent, para_id, constraints) => self
ParaBackingState(relay_parent, para_id, constraints) => self
.requests_cache
.cache_staging_para_backing_state((relay_parent, para_id), constraints),
StagingAsyncBackingParams(relay_parent, params) =>
self.requests_cache.cache_staging_async_backing_params(relay_parent, params),
.cache_para_backing_state((relay_parent, para_id), constraints),
AsyncBackingParams(relay_parent, params) =>
self.requests_cache.cache_async_backing_params(relay_parent, params),
}
}
@@ -297,13 +296,10 @@ where
Request::SubmitReportDisputeLost(dispute_proof, key_ownership_proof, sender)
},
),
Request::StagingParaBackingState(para, sender) =>
query!(staging_para_backing_state(para), sender)
.map(|sender| Request::StagingParaBackingState(para, sender)),
Request::StagingAsyncBackingParams(sender) =>
query!(staging_async_backing_params(), sender)
.map(|sender| Request::StagingAsyncBackingParams(sender)),
Request::ParaBackingState(para, sender) => query!(para_backing_state(para), sender)
.map(|sender| Request::ParaBackingState(para, sender)),
Request::AsyncBackingParams(sender) => query!(async_backing_params(), sender)
.map(|sender| Request::AsyncBackingParams(sender)),
Request::MinimumBackingVotes(index, sender) => {
if let Some(value) = self.requests_cache.minimum_backing_votes(index) {
self.metrics.on_cached_request();
@@ -569,19 +565,18 @@ where
ver = Request::MINIMUM_BACKING_VOTES_RUNTIME_REQUIREMENT,
sender
),
Request::StagingParaBackingState(para, sender) => {
Request::ParaBackingState(para, sender) => {
query!(
StagingParaBackingState,
staging_para_backing_state(para),
ParaBackingState,
para_backing_state(para),
ver = Request::STAGING_BACKING_STATE,
sender
)
},
Request::StagingAsyncBackingParams(sender) => {
Request::AsyncBackingParams(sender) => {
query!(
StagingAsyncBackingParams,
staging_async_backing_params(),
AsyncBackingParams,
async_backing_params(),
ver = Request::STAGING_BACKING_STATE,
sender
)
+11 -11
View File
@@ -20,9 +20,9 @@ use polkadot_node_primitives::{BabeAllowedSlots, BabeEpoch, BabeEpochConfigurati
use polkadot_node_subsystem::SpawnGlue;
use polkadot_node_subsystem_test_helpers::make_subsystem_context;
use polkadot_primitives::{
vstaging, AuthorityDiscoveryId, BlockNumber, CandidateCommitments, CandidateEvent,
CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState, ExecutorParams,
GroupRotationInfo, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
async_backing, slashing, AuthorityDiscoveryId, BlockNumber, CandidateCommitments,
CandidateEvent, CandidateHash, CommittedCandidateReceipt, CoreState, DisputeState,
ExecutorParams, GroupRotationInfo, Id as ParaId, InboundDownwardMessage, InboundHrmpMessage,
OccupiedCoreAssumption, PersistedValidationData, PvfCheckStatement, ScrapedOnChainVotes,
SessionIndex, SessionInfo, Slot, ValidationCode, ValidationCodeHash, ValidatorId,
ValidatorIndex, ValidatorSignature,
@@ -213,7 +213,7 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
async fn unapplied_slashes(
&self,
_: Hash,
) -> Result<Vec<(SessionIndex, CandidateHash, vstaging::slashing::PendingSlashes)>, ApiError> {
) -> Result<Vec<(SessionIndex, CandidateHash, slashing::PendingSlashes)>, ApiError> {
todo!("Not required for tests")
}
@@ -221,15 +221,15 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
&self,
_: Hash,
_: ValidatorId,
) -> Result<Option<vstaging::slashing::OpaqueKeyOwnershipProof>, ApiError> {
) -> Result<Option<slashing::OpaqueKeyOwnershipProof>, ApiError> {
todo!("Not required for tests")
}
async fn submit_report_dispute_lost(
&self,
_: Hash,
_: vstaging::slashing::DisputeProof,
_: vstaging::slashing::OpaqueKeyOwnershipProof,
_: slashing::DisputeProof,
_: slashing::OpaqueKeyOwnershipProof,
) -> Result<Option<()>, ApiError> {
todo!("Not required for tests")
}
@@ -250,18 +250,18 @@ impl RuntimeApiSubsystemClient for MockSubsystemClient {
Ok(self.authorities.clone())
}
async fn staging_async_backing_params(
async fn async_backing_params(
&self,
_: Hash,
) -> Result<vstaging::AsyncBackingParams, ApiError> {
) -> Result<async_backing::AsyncBackingParams, ApiError> {
todo!("Not required for tests")
}
async fn staging_para_backing_state(
async fn para_backing_state(
&self,
_: Hash,
_: ParaId,
) -> Result<Option<vstaging::BackingState>, ApiError> {
) -> Result<Option<async_backing::BackingState>, ApiError> {
todo!("Not required for tests")
}