mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 11:01:01 +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:
@@ -28,7 +28,7 @@ use crate::{
|
||||
};
|
||||
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
|
||||
use pallet_balances::Error as BalancesError;
|
||||
use primitives::{v5::ValidationCode, BlockNumber, SessionIndex};
|
||||
use primitives::{BlockNumber, SessionIndex, ValidationCode};
|
||||
use sp_std::collections::btree_map::BTreeMap;
|
||||
|
||||
fn schedule_blank_para(id: ParaId, parakind: ParaKind) {
|
||||
|
||||
@@ -26,7 +26,7 @@ use polkadot_parachain_primitives::primitives::{
|
||||
MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM,
|
||||
};
|
||||
use primitives::{
|
||||
vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex, LEGACY_MIN_BACKING_VOTES,
|
||||
AsyncBackingParams, Balance, ExecutorParams, SessionIndex, LEGACY_MIN_BACKING_VOTES,
|
||||
MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
|
||||
};
|
||||
use sp_runtime::{traits::Zero, Perbill};
|
||||
|
||||
@@ -21,7 +21,7 @@ use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use primitives::{vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex};
|
||||
use primitives::{AsyncBackingParams, Balance, ExecutorParams, SessionIndex};
|
||||
#[cfg(feature = "try-runtime")]
|
||||
use sp_std::prelude::*;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ use frame_support::{
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex};
|
||||
use primitives::{AsyncBackingParams, Balance, ExecutorParams, SessionIndex};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use frame_support::traits::OnRuntimeUpgrade;
|
||||
|
||||
@@ -24,8 +24,7 @@ use frame_support::{
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{
|
||||
vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex,
|
||||
ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
|
||||
AsyncBackingParams, Balance, ExecutorParams, SessionIndex, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE,
|
||||
};
|
||||
use sp_runtime::Perbill;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
@@ -51,7 +51,7 @@ use frame_support::{
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
use primitives::{
|
||||
vstaging::slashing::{DisputeProof, DisputesTimeSlot, PendingSlashes, SlashingOffenceKind},
|
||||
slashing::{DisputeProof, DisputesTimeSlot, PendingSlashes, SlashingOffenceKind},
|
||||
CandidateHash, SessionIndex, ValidatorId, ValidatorIndex,
|
||||
};
|
||||
use scale_info::TypeInfo;
|
||||
|
||||
@@ -25,5 +25,6 @@
|
||||
//! 1. Bump the version of the stable module (e.g. `v2` becomes `v3`)
|
||||
//! 2. Move methods from `vstaging` to `v3`. The new stable version should include all methods from
|
||||
//! `vstaging` tagged with the new version number (e.g. all `v3` methods).
|
||||
pub mod v5;
|
||||
|
||||
pub mod v7;
|
||||
pub mod vstaging;
|
||||
|
||||
+102
-1
@@ -18,12 +18,16 @@
|
||||
//! functions.
|
||||
|
||||
use crate::{
|
||||
disputes, dmp, hrmp, inclusion, initializer, paras, paras_inherent,
|
||||
configuration, disputes, dmp, hrmp, inclusion, initializer, paras, paras_inherent,
|
||||
scheduler::{self, CoreOccupied},
|
||||
session_info, shared,
|
||||
};
|
||||
use frame_system::pallet_prelude::*;
|
||||
use primitives::{
|
||||
async_backing::{
|
||||
AsyncBackingParams, BackingState, CandidatePendingAvailability, Constraints,
|
||||
InboundHrmpLimitations, OutboundHrmpChannelLimitations,
|
||||
},
|
||||
slashing, AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt,
|
||||
CoreIndex, CoreState, DisputeState, ExecutorParams, GroupIndex, GroupRotationInfo, Hash,
|
||||
Id as ParaId, InboundDownwardMessage, InboundHrmpMessage, OccupiedCore, OccupiedCoreAssumption,
|
||||
@@ -395,3 +399,100 @@ pub fn submit_unsigned_slashing_report<T: disputes::slashing::Config>(
|
||||
key_ownership_proof,
|
||||
)
|
||||
}
|
||||
|
||||
/// Return the min backing votes threshold from the configuration.
|
||||
pub fn minimum_backing_votes<T: initializer::Config>() -> u32 {
|
||||
<configuration::Pallet<T>>::config().minimum_backing_votes
|
||||
}
|
||||
|
||||
/// Implementation for `ParaBackingState` function from the runtime API
|
||||
pub fn backing_state<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
) -> Option<BackingState<T::Hash, BlockNumberFor<T>>> {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
// Async backing is only expected to be enabled with a tracker capacity of 1.
|
||||
// Subsequent configuration update gets applied on new session, which always
|
||||
// clears the buffer.
|
||||
//
|
||||
// Thus, minimum relay parent is ensured to have asynchronous backing enabled.
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let min_relay_parent_number = <shared::Pallet<T>>::allowed_relay_parents()
|
||||
.hypothetical_earliest_block_number(now, config.async_backing_params.allowed_ancestry_len);
|
||||
|
||||
let required_parent = <paras::Pallet<T>>::para_head(para_id)?;
|
||||
let validation_code_hash = <paras::Pallet<T>>::current_code_hash(para_id)?;
|
||||
|
||||
let upgrade_restriction = <paras::Pallet<T>>::upgrade_restriction_signal(para_id);
|
||||
let future_validation_code =
|
||||
<paras::Pallet<T>>::future_code_upgrade_at(para_id).and_then(|block_num| {
|
||||
// Only read the storage if there's a pending upgrade.
|
||||
Some(block_num).zip(<paras::Pallet<T>>::future_code_hash(para_id))
|
||||
});
|
||||
|
||||
let (ump_msg_count, ump_total_bytes) =
|
||||
<inclusion::Pallet<T>>::relay_dispatch_queue_size(para_id);
|
||||
let ump_remaining = config.max_upward_queue_count - ump_msg_count;
|
||||
let ump_remaining_bytes = config.max_upward_queue_size - ump_total_bytes;
|
||||
|
||||
let dmp_remaining_messages = <dmp::Pallet<T>>::dmq_contents(para_id)
|
||||
.into_iter()
|
||||
.map(|msg| msg.sent_at)
|
||||
.collect();
|
||||
|
||||
let valid_watermarks = <hrmp::Pallet<T>>::valid_watermarks(para_id);
|
||||
let hrmp_inbound = InboundHrmpLimitations { valid_watermarks };
|
||||
let hrmp_channels_out = <hrmp::Pallet<T>>::outbound_remaining_capacity(para_id)
|
||||
.into_iter()
|
||||
.map(|(para, (messages_remaining, bytes_remaining))| {
|
||||
(para, OutboundHrmpChannelLimitations { messages_remaining, bytes_remaining })
|
||||
})
|
||||
.collect();
|
||||
|
||||
let constraints = Constraints {
|
||||
min_relay_parent_number,
|
||||
max_pov_size: config.max_pov_size,
|
||||
max_code_size: config.max_code_size,
|
||||
ump_remaining,
|
||||
ump_remaining_bytes,
|
||||
max_ump_num_per_candidate: config.max_upward_message_num_per_candidate,
|
||||
dmp_remaining_messages,
|
||||
hrmp_inbound,
|
||||
hrmp_channels_out,
|
||||
max_hrmp_num_per_candidate: config.hrmp_max_message_num_per_candidate,
|
||||
required_parent,
|
||||
validation_code_hash,
|
||||
upgrade_restriction,
|
||||
future_validation_code,
|
||||
};
|
||||
|
||||
let pending_availability = {
|
||||
// Note: the API deals with a `Vec` as it is future-proof for cases
|
||||
// where there may be multiple candidates pending availability at a time.
|
||||
// But at the moment only one candidate can be pending availability per
|
||||
// parachain.
|
||||
crate::inclusion::PendingAvailability::<T>::get(¶_id)
|
||||
.and_then(|pending| {
|
||||
let commitments =
|
||||
crate::inclusion::PendingAvailabilityCommitments::<T>::get(¶_id);
|
||||
commitments.map(move |c| (pending, c))
|
||||
})
|
||||
.map(|(pending, commitments)| {
|
||||
CandidatePendingAvailability {
|
||||
candidate_hash: pending.candidate_hash(),
|
||||
descriptor: pending.candidate_descriptor().clone(),
|
||||
commitments,
|
||||
relay_parent_number: pending.relay_parent_number(),
|
||||
max_pov_size: constraints.max_pov_size, // assume always same in session.
|
||||
}
|
||||
})
|
||||
.into_iter()
|
||||
.collect()
|
||||
};
|
||||
|
||||
Some(BackingState { constraints, pending_availability })
|
||||
}
|
||||
|
||||
/// Implementation for `AsyncBackingParams` function from the runtime API
|
||||
pub fn async_backing_params<T: configuration::Config>() -> AsyncBackingParams {
|
||||
<configuration::Pallet<T>>::config().async_backing_params
|
||||
}
|
||||
@@ -15,111 +15,3 @@
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Put implementations of functions from staging APIs here.
|
||||
|
||||
use crate::{configuration, dmp, hrmp, inclusion, initializer, paras, shared};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{
|
||||
vstaging::{
|
||||
AsyncBackingParams, BackingState, CandidatePendingAvailability, Constraints,
|
||||
InboundHrmpLimitations, OutboundHrmpChannelLimitations,
|
||||
},
|
||||
Id as ParaId,
|
||||
};
|
||||
use sp_std::prelude::*;
|
||||
|
||||
/// Implementation for `StagingParaBackingState` function from the runtime API
|
||||
pub fn backing_state<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
) -> Option<BackingState<T::Hash, BlockNumberFor<T>>> {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
// Async backing is only expected to be enabled with a tracker capacity of 1.
|
||||
// Subsequent configuration update gets applied on new session, which always
|
||||
// clears the buffer.
|
||||
//
|
||||
// Thus, minimum relay parent is ensured to have asynchronous backing enabled.
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let min_relay_parent_number = <shared::Pallet<T>>::allowed_relay_parents()
|
||||
.hypothetical_earliest_block_number(now, config.async_backing_params.allowed_ancestry_len);
|
||||
|
||||
let required_parent = <paras::Pallet<T>>::para_head(para_id)?;
|
||||
let validation_code_hash = <paras::Pallet<T>>::current_code_hash(para_id)?;
|
||||
|
||||
let upgrade_restriction = <paras::Pallet<T>>::upgrade_restriction_signal(para_id);
|
||||
let future_validation_code =
|
||||
<paras::Pallet<T>>::future_code_upgrade_at(para_id).and_then(|block_num| {
|
||||
// Only read the storage if there's a pending upgrade.
|
||||
Some(block_num).zip(<paras::Pallet<T>>::future_code_hash(para_id))
|
||||
});
|
||||
|
||||
let (ump_msg_count, ump_total_bytes) =
|
||||
<inclusion::Pallet<T>>::relay_dispatch_queue_size(para_id);
|
||||
let ump_remaining = config.max_upward_queue_count - ump_msg_count;
|
||||
let ump_remaining_bytes = config.max_upward_queue_size - ump_total_bytes;
|
||||
|
||||
let dmp_remaining_messages = <dmp::Pallet<T>>::dmq_contents(para_id)
|
||||
.into_iter()
|
||||
.map(|msg| msg.sent_at)
|
||||
.collect();
|
||||
|
||||
let valid_watermarks = <hrmp::Pallet<T>>::valid_watermarks(para_id);
|
||||
let hrmp_inbound = InboundHrmpLimitations { valid_watermarks };
|
||||
let hrmp_channels_out = <hrmp::Pallet<T>>::outbound_remaining_capacity(para_id)
|
||||
.into_iter()
|
||||
.map(|(para, (messages_remaining, bytes_remaining))| {
|
||||
(para, OutboundHrmpChannelLimitations { messages_remaining, bytes_remaining })
|
||||
})
|
||||
.collect();
|
||||
|
||||
let constraints = Constraints {
|
||||
min_relay_parent_number,
|
||||
max_pov_size: config.max_pov_size,
|
||||
max_code_size: config.max_code_size,
|
||||
ump_remaining,
|
||||
ump_remaining_bytes,
|
||||
max_ump_num_per_candidate: config.max_upward_message_num_per_candidate,
|
||||
dmp_remaining_messages,
|
||||
hrmp_inbound,
|
||||
hrmp_channels_out,
|
||||
max_hrmp_num_per_candidate: config.hrmp_max_message_num_per_candidate,
|
||||
required_parent,
|
||||
validation_code_hash,
|
||||
upgrade_restriction,
|
||||
future_validation_code,
|
||||
};
|
||||
|
||||
let pending_availability = {
|
||||
// Note: the API deals with a `Vec` as it is future-proof for cases
|
||||
// where there may be multiple candidates pending availability at a time.
|
||||
// But at the moment only one candidate can be pending availability per
|
||||
// parachain.
|
||||
crate::inclusion::PendingAvailability::<T>::get(¶_id)
|
||||
.and_then(|pending| {
|
||||
let commitments =
|
||||
crate::inclusion::PendingAvailabilityCommitments::<T>::get(¶_id);
|
||||
commitments.map(move |c| (pending, c))
|
||||
})
|
||||
.map(|(pending, commitments)| {
|
||||
CandidatePendingAvailability {
|
||||
candidate_hash: pending.candidate_hash(),
|
||||
descriptor: pending.candidate_descriptor().clone(),
|
||||
commitments,
|
||||
relay_parent_number: pending.relay_parent_number(),
|
||||
max_pov_size: constraints.max_pov_size, // assume always same in session.
|
||||
}
|
||||
})
|
||||
.into_iter()
|
||||
.collect()
|
||||
};
|
||||
|
||||
Some(BackingState { constraints, pending_availability })
|
||||
}
|
||||
|
||||
/// Implementation for `StagingAsyncBackingParams` function from the runtime API
|
||||
pub fn async_backing_params<T: configuration::Config>() -> AsyncBackingParams {
|
||||
<configuration::Pallet<T>>::config().async_backing_params
|
||||
}
|
||||
|
||||
/// Return the min backing votes threshold from the configuration.
|
||||
pub fn minimum_backing_votes<T: initializer::Config>() -> u32 {
|
||||
<configuration::Pallet<T>>::config().minimum_backing_votes
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user