mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 05:11:02 +00:00
Moves Block to frame_system instead of construct_runtime and removes Header and BlockNumber (#7431)
* Companion for substrate * Minor update * Formatting * Fixes for cumulus * Fixes tests in polkadot-runtime-parachains * Minor update * Removes unused import * Fixes tests in polkadot-runtime-common * Minor fix * Update roadmap/implementers-guide/src/runtime/configuration.md Co-authored-by: ordian <write@reusable.software> * ".git/.scripts/commands/fmt/fmt.sh" * update lockfile for {"substrate"} --------- Co-authored-by: ordian <write@reusable.software> Co-authored-by: command-bot <>
This commit is contained in:
@@ -22,6 +22,7 @@ use crate::{
|
||||
};
|
||||
use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::*;
|
||||
use primitives::{
|
||||
collator_signature_payload, AvailabilityBitfield, BackedCandidate, CandidateCommitments,
|
||||
CandidateDescriptor, CandidateHash, CollatorId, CollatorSignature, CommittedCandidateReceipt,
|
||||
@@ -69,7 +70,7 @@ pub(crate) struct BenchBuilder<T: paras_inherent::Config> {
|
||||
/// Active validators. Validators should be declared prior to all other setup.
|
||||
validators: Option<IndexedVec<ValidatorIndex, ValidatorId>>,
|
||||
/// Starting block number; we expect it to get incremented on session setup.
|
||||
block_number: T::BlockNumber,
|
||||
block_number: BlockNumberFor<T>,
|
||||
/// Starting session; we expect it to get incremented on session setup.
|
||||
session: SessionIndex,
|
||||
/// Session we want the scenario to take place in. We will roll to this session.
|
||||
@@ -97,9 +98,9 @@ pub(crate) struct BenchBuilder<T: paras_inherent::Config> {
|
||||
/// Paras inherent `enter` benchmark scenario.
|
||||
#[cfg(any(feature = "runtime-benchmarks", test))]
|
||||
pub(crate) struct Bench<T: paras_inherent::Config> {
|
||||
pub(crate) data: ParachainsInherentData<T::Header>,
|
||||
pub(crate) data: ParachainsInherentData<HeaderFor<T>>,
|
||||
pub(crate) _session: u32,
|
||||
pub(crate) _block_number: T::BlockNumber,
|
||||
pub(crate) _block_number: BlockNumberFor<T>,
|
||||
}
|
||||
|
||||
impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
@@ -150,8 +151,8 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
}
|
||||
|
||||
/// Mock header.
|
||||
pub(crate) fn header(block_number: T::BlockNumber) -> T::Header {
|
||||
T::Header::new(
|
||||
pub(crate) fn header(block_number: BlockNumberFor<T>) -> HeaderFor<T> {
|
||||
HeaderFor::<T>::new(
|
||||
block_number, // `block_number`,
|
||||
Default::default(), // `extrinsics_root`,
|
||||
Default::default(), // `storage_root`,
|
||||
@@ -260,8 +261,8 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
core_idx: CoreIndex,
|
||||
candidate_hash: CandidateHash,
|
||||
availability_votes: BitVec<u8, BitOrderLsb0>,
|
||||
) -> inclusion::CandidatePendingAvailability<T::Hash, T::BlockNumber> {
|
||||
inclusion::CandidatePendingAvailability::<T::Hash, T::BlockNumber>::new(
|
||||
) -> inclusion::CandidatePendingAvailability<T::Hash, BlockNumberFor<T>> {
|
||||
inclusion::CandidatePendingAvailability::<T::Hash, BlockNumberFor<T>>::new(
|
||||
core_idx, // core
|
||||
candidate_hash, // hash
|
||||
Self::candidate_descriptor_mock(), // candidate descriptor
|
||||
@@ -405,7 +406,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
Self::run_to_block(block);
|
||||
}
|
||||
|
||||
let block_number = <T as frame_system::Config>::BlockNumber::from(block);
|
||||
let block_number = BlockNumberFor::<T>::from(block);
|
||||
let header = Self::header(block_number.clone());
|
||||
|
||||
frame_system::Pallet::<T>::reset_events();
|
||||
@@ -523,7 +524,7 @@ impl<T: paras_inherent::Config> BenchBuilder<T> {
|
||||
// candidate receipt.
|
||||
paras::Pallet::<T>::heads_insert(¶_id, head_data.clone());
|
||||
|
||||
let mut past_code_meta = paras::ParaPastCodeMeta::<T::BlockNumber>::default();
|
||||
let mut past_code_meta = paras::ParaPastCodeMeta::<BlockNumberFor<T>>::default();
|
||||
past_code_meta.note_replacement(0u32.into(), 0u32.into());
|
||||
|
||||
let group_validators = scheduler::Pallet::<T>::group_validators(group_idx).unwrap();
|
||||
|
||||
@@ -503,7 +503,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn config)]
|
||||
pub(crate) type ActiveConfig<T: Config> =
|
||||
StorageValue<_, HostConfiguration<T::BlockNumber>, ValueQuery>;
|
||||
StorageValue<_, HostConfiguration<BlockNumberFor<T>>, ValueQuery>;
|
||||
|
||||
/// Pending configuration changes.
|
||||
///
|
||||
@@ -514,7 +514,7 @@ pub mod pallet {
|
||||
/// 2 items: for the next session and for the `scheduled_session`.
|
||||
#[pallet::storage]
|
||||
pub(crate) type PendingConfigs<T: Config> =
|
||||
StorageValue<_, Vec<(SessionIndex, HostConfiguration<T::BlockNumber>)>, ValueQuery>;
|
||||
StorageValue<_, Vec<(SessionIndex, HostConfiguration<BlockNumberFor<T>>)>, ValueQuery>;
|
||||
|
||||
/// If this is set, then the configuration setters will bypass the consistency checks. This
|
||||
/// is meant to be used only as the last resort.
|
||||
@@ -524,7 +524,7 @@ pub mod pallet {
|
||||
#[pallet::genesis_config]
|
||||
#[derive(DefaultNoBound)]
|
||||
pub struct GenesisConfig<T: Config> {
|
||||
pub config: HostConfiguration<T::BlockNumber>,
|
||||
pub config: HostConfiguration<BlockNumberFor<T>>,
|
||||
}
|
||||
|
||||
#[pallet::genesis_build]
|
||||
@@ -545,7 +545,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_validation_upgrade_cooldown(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -561,7 +561,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_validation_upgrade_delay(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -577,7 +577,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_code_retention_period(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -658,7 +658,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_group_rotation_frequency(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -674,7 +674,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_chain_availability_period(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -690,7 +690,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_thread_availability_period(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -761,7 +761,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_dispute_post_conclusion_acceptance_period(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -1087,7 +1087,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn set_minimum_validation_upgrade_delay(
|
||||
origin: OriginFor<T>,
|
||||
new: T::BlockNumber,
|
||||
new: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
Self::schedule_config_update(|config| {
|
||||
@@ -1162,7 +1162,7 @@ pub struct SessionChangeOutcome<BlockNumber> {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the configuration pallet.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -1176,7 +1176,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// be the same.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
session_index: &SessionIndex,
|
||||
) -> SessionChangeOutcome<T::BlockNumber> {
|
||||
) -> SessionChangeOutcome<BlockNumberFor<T>> {
|
||||
let pending_configs = <PendingConfigs<T>>::get();
|
||||
let prev_config = ActiveConfig::<T>::get();
|
||||
|
||||
@@ -1217,7 +1217,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// Forcibly set the active config. This should be used with extreme care, and typically
|
||||
/// only when enabling parachains runtime pallets for the first time on a chain which has
|
||||
/// been running without them.
|
||||
pub fn force_set_active_config(config: HostConfiguration<T::BlockNumber>) {
|
||||
pub fn force_set_active_config(config: HostConfiguration<BlockNumberFor<T>>) {
|
||||
ActiveConfig::<T>::set(config);
|
||||
}
|
||||
|
||||
@@ -1237,7 +1237,7 @@ impl<T: Config> Pallet<T> {
|
||||
// the sake of essentially avoiding an indirect call. Doesn't worth it.
|
||||
#[inline(never)]
|
||||
pub(crate) fn schedule_config_update(
|
||||
updater: impl FnOnce(&mut HostConfiguration<T::BlockNumber>),
|
||||
updater: impl FnOnce(&mut HostConfiguration<BlockNumberFor<T>>),
|
||||
) -> DispatchResult {
|
||||
let mut pending_configs = <PendingConfigs<T>>::get();
|
||||
|
||||
|
||||
@@ -298,9 +298,9 @@ impl<BlockNumber: Ord> DisputesHandler<BlockNumber> for () {
|
||||
fn initializer_on_new_session(_notification: &SessionChangeNotification<BlockNumber>) {}
|
||||
}
|
||||
|
||||
impl<T: Config> DisputesHandler<T::BlockNumber> for pallet::Pallet<T>
|
||||
impl<T: Config> DisputesHandler<BlockNumberFor<T>> for pallet::Pallet<T>
|
||||
where
|
||||
T::BlockNumber: Ord,
|
||||
BlockNumberFor<T>: Ord,
|
||||
{
|
||||
fn is_frozen() -> bool {
|
||||
pallet::Pallet::<T>::is_frozen()
|
||||
@@ -308,7 +308,7 @@ where
|
||||
|
||||
fn filter_dispute_data(
|
||||
set: DisputeStatementSet,
|
||||
post_conclusion_acceptance_period: T::BlockNumber,
|
||||
post_conclusion_acceptance_period: BlockNumberFor<T>,
|
||||
) -> Option<CheckedDisputeStatementSet> {
|
||||
pallet::Pallet::<T>::filter_dispute_data(&set, post_conclusion_acceptance_period)
|
||||
.filter_statement_set(set)
|
||||
@@ -323,7 +323,7 @@ where
|
||||
fn note_included(
|
||||
session: SessionIndex,
|
||||
candidate_hash: CandidateHash,
|
||||
included_in: T::BlockNumber,
|
||||
included_in: BlockNumberFor<T>,
|
||||
) {
|
||||
pallet::Pallet::<T>::note_included(session, candidate_hash, included_in)
|
||||
}
|
||||
@@ -331,7 +331,7 @@ where
|
||||
fn included_state(
|
||||
session: SessionIndex,
|
||||
candidate_hash: CandidateHash,
|
||||
) -> Option<T::BlockNumber> {
|
||||
) -> Option<BlockNumberFor<T>> {
|
||||
pallet::Pallet::<T>::included_state(session, candidate_hash)
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ where
|
||||
pallet::Pallet::<T>::concluded_invalid(session, candidate_hash)
|
||||
}
|
||||
|
||||
fn initializer_initialize(now: T::BlockNumber) -> Weight {
|
||||
fn initializer_initialize(now: BlockNumberFor<T>) -> Weight {
|
||||
pallet::Pallet::<T>::initializer_initialize(now)
|
||||
}
|
||||
|
||||
@@ -347,7 +347,7 @@ where
|
||||
pallet::Pallet::<T>::initializer_finalize()
|
||||
}
|
||||
|
||||
fn initializer_on_new_session(notification: &SessionChangeNotification<T::BlockNumber>) {
|
||||
fn initializer_on_new_session(notification: &SessionChangeNotification<BlockNumberFor<T>>) {
|
||||
pallet::Pallet::<T>::initializer_on_new_session(notification)
|
||||
}
|
||||
}
|
||||
@@ -373,7 +373,7 @@ pub mod pallet {
|
||||
pub trait Config: frame_system::Config + configuration::Config + session_info::Config {
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
type RewardValidators: RewardValidators;
|
||||
type SlashingHandler: SlashingHandler<Self::BlockNumber>;
|
||||
type SlashingHandler: SlashingHandler<BlockNumberFor<Self>>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
@@ -400,7 +400,7 @@ pub mod pallet {
|
||||
SessionIndex,
|
||||
Blake2_128Concat,
|
||||
CandidateHash,
|
||||
DisputeState<T::BlockNumber>,
|
||||
DisputeState<BlockNumberFor<T>>,
|
||||
>;
|
||||
|
||||
/// Backing votes stored for each dispute.
|
||||
@@ -424,7 +424,7 @@ pub mod pallet {
|
||||
SessionIndex,
|
||||
Blake2_128Concat,
|
||||
CandidateHash,
|
||||
T::BlockNumber,
|
||||
BlockNumberFor<T>,
|
||||
>;
|
||||
|
||||
/// Whether the chain is frozen. Starts as `None`. When this is `Some`,
|
||||
@@ -433,7 +433,7 @@ pub mod pallet {
|
||||
/// It can only be set back to `None` by governance intervention.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn last_valid_block)]
|
||||
pub(super) type Frozen<T: Config> = StorageValue<_, Option<T::BlockNumber>, ValueQuery>;
|
||||
pub(super) type Frozen<T: Config> = StorageValue<_, Option<BlockNumberFor<T>>, ValueQuery>;
|
||||
|
||||
#[pallet::event]
|
||||
#[pallet::generate_deposit(pub fn deposit_event)]
|
||||
@@ -447,7 +447,7 @@ pub mod pallet {
|
||||
/// Block authors should no longer build on top of this head and should
|
||||
/// instead revert the block at the given height. This should be the
|
||||
/// number of the child of the last known valid block in the chain.
|
||||
Revert(T::BlockNumber),
|
||||
Revert(BlockNumberFor<T>),
|
||||
}
|
||||
|
||||
#[pallet::error]
|
||||
@@ -854,7 +854,7 @@ impl StatementSetFilter {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the disputes module.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -863,7 +863,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Called by the initializer to note a new session in the disputes pallet.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
notification: &SessionChangeNotification<T::BlockNumber>,
|
||||
notification: &SessionChangeNotification<BlockNumberFor<T>>,
|
||||
) {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
|
||||
@@ -937,7 +937,7 @@ impl<T: Config> Pallet<T> {
|
||||
// Disputes without enough votes to get confirmed are also filtered out.
|
||||
fn filter_dispute_data(
|
||||
set: &DisputeStatementSet,
|
||||
post_conclusion_acceptance_period: <T as frame_system::Config>::BlockNumber,
|
||||
post_conclusion_acceptance_period: BlockNumberFor<T>,
|
||||
) -> StatementSetFilter {
|
||||
let mut filter = StatementSetFilter::RemoveIndices(Vec::new());
|
||||
|
||||
@@ -1048,7 +1048,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// dispute is fresh.
|
||||
fn process_checked_dispute_data(
|
||||
set: &CheckedDisputeStatementSet,
|
||||
dispute_post_conclusion_acceptance_period: T::BlockNumber,
|
||||
dispute_post_conclusion_acceptance_period: BlockNumberFor<T>,
|
||||
) -> Result<bool, DispatchError> {
|
||||
// Dispute statement sets on any dispute which concluded
|
||||
// before this point are to be rejected.
|
||||
@@ -1189,14 +1189,15 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<T::BlockNumber>)> {
|
||||
pub(crate) fn disputes() -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumberFor<T>>)>
|
||||
{
|
||||
<Disputes<T>>::iter().collect()
|
||||
}
|
||||
|
||||
pub(crate) fn note_included(
|
||||
session: SessionIndex,
|
||||
candidate_hash: CandidateHash,
|
||||
included_in: T::BlockNumber,
|
||||
included_in: BlockNumberFor<T>,
|
||||
) {
|
||||
if included_in.is_zero() {
|
||||
return
|
||||
@@ -1216,7 +1217,7 @@ impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn included_state(
|
||||
session: SessionIndex,
|
||||
candidate_hash: CandidateHash,
|
||||
) -> Option<T::BlockNumber> {
|
||||
) -> Option<BlockNumberFor<T>> {
|
||||
<Included<T>>::get(session, candidate_hash)
|
||||
}
|
||||
|
||||
@@ -1231,7 +1232,7 @@ impl<T: Config> Pallet<T> {
|
||||
Self::last_valid_block().is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn revert_and_freeze(revert_to: T::BlockNumber) {
|
||||
pub(crate) fn revert_and_freeze(revert_to: BlockNumberFor<T>) {
|
||||
if Self::last_valid_block().map_or(true, |last| last > revert_to) {
|
||||
Frozen::<T>::set(Some(revert_to));
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ use frame_support::{
|
||||
traits::{Defensive, Get, KeyOwnerProofSystem, ValidatorSet, ValidatorSetWithIdentification},
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
|
||||
use primitives::{
|
||||
vstaging::slashing::{DisputeProof, DisputesTimeSlot, PendingSlashes, SlashingOffenceKind},
|
||||
@@ -270,7 +271,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> disputes::SlashingHandler<T::BlockNumber> for SlashValidatorsForDisputes<Pallet<T>>
|
||||
impl<T> disputes::SlashingHandler<BlockNumberFor<T>> for SlashValidatorsForDisputes<Pallet<T>>
|
||||
where
|
||||
T: Config<KeyOwnerIdentification = IdentificationTuple<T>>,
|
||||
{
|
||||
@@ -294,7 +295,7 @@ where
|
||||
// NOTE: changing that requires modifying `do_punish` implementation
|
||||
}
|
||||
|
||||
fn initializer_initialize(now: T::BlockNumber) -> Weight {
|
||||
fn initializer_initialize(now: BlockNumberFor<T>) -> Weight {
|
||||
Pallet::<T>::initializer_initialize(now)
|
||||
}
|
||||
|
||||
@@ -529,7 +530,7 @@ pub mod pallet {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the disputes slashing module.
|
||||
fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ use super::*;
|
||||
use crate::{disputes::SlashingHandler, initializer, shared};
|
||||
use frame_benchmarking::{benchmarks, whitelist_account};
|
||||
use frame_support::traits::{OnFinalize, OnInitialize};
|
||||
use frame_system::RawOrigin;
|
||||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
|
||||
use pallet_staking::testing_utils::create_validators;
|
||||
use parity_scale_codec::Decode;
|
||||
use primitives::{Hash, PARACHAIN_KEY_TYPE_ID};
|
||||
@@ -70,13 +70,13 @@ where
|
||||
.expect("session::set_keys should work");
|
||||
}
|
||||
|
||||
pallet_session::Pallet::<T>::on_initialize(T::BlockNumber::one());
|
||||
initializer::Pallet::<T>::on_initialize(T::BlockNumber::one());
|
||||
pallet_session::Pallet::<T>::on_initialize(BlockNumberFor::<T>::one());
|
||||
initializer::Pallet::<T>::on_initialize(BlockNumberFor::<T>::one());
|
||||
// skip sessions until the new validator set is enacted
|
||||
while pallet_session::Pallet::<T>::validators().len() < n as usize {
|
||||
pallet_session::Pallet::<T>::rotate_session();
|
||||
}
|
||||
initializer::Pallet::<T>::on_finalize(T::BlockNumber::one());
|
||||
initializer::Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());
|
||||
|
||||
let session_index = crate::shared::Pallet::<T>::session_index();
|
||||
let session_info = crate::session_info::Pallet::<T>::session_info(session_index);
|
||||
@@ -86,9 +86,9 @@ where
|
||||
let key_owner_proof = pallet_session::historical::Pallet::<T>::prove(key).unwrap();
|
||||
|
||||
// rotate a session to make sure `key_owner_proof` is historical
|
||||
initializer::Pallet::<T>::on_initialize(T::BlockNumber::one());
|
||||
initializer::Pallet::<T>::on_initialize(BlockNumberFor::<T>::one());
|
||||
pallet_session::Pallet::<T>::rotate_session();
|
||||
initializer::Pallet::<T>::on_finalize(T::BlockNumber::one());
|
||||
initializer::Pallet::<T>::on_finalize(BlockNumberFor::<T>::one());
|
||||
|
||||
let idx = crate::shared::Pallet::<T>::session_index();
|
||||
assert!(
|
||||
|
||||
@@ -28,6 +28,7 @@ use frame_support::{
|
||||
assert_err, assert_noop, assert_ok,
|
||||
traits::{OnFinalize, OnInitialize},
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::BlockNumber;
|
||||
use sp_core::{crypto::CryptoType, Pair};
|
||||
|
||||
@@ -2054,9 +2055,10 @@ fn deduplication_and_sorting_works() {
|
||||
|
||||
let disputes_orig = disputes.clone();
|
||||
|
||||
<Pallet<Test> as DisputesHandler<
|
||||
<Test as frame_system::Config>::BlockNumber,
|
||||
>>::deduplicate_and_sort_dispute_data(&mut disputes).unwrap_err();
|
||||
<Pallet<Test> as DisputesHandler<BlockNumberFor<Test>>>::deduplicate_and_sort_dispute_data(
|
||||
&mut disputes,
|
||||
)
|
||||
.unwrap_err();
|
||||
|
||||
// assert ordering of local only disputes, and at the same time, and being free of duplicates
|
||||
assert_eq!(disputes_orig.len(), disputes.len() + 1);
|
||||
@@ -2083,10 +2085,11 @@ fn apply_filter_all<T: Config, I: IntoIterator<Item = DisputeStatementSet>>(
|
||||
|
||||
let mut acc = Vec::<CheckedDisputeStatementSet>::new();
|
||||
for dispute_statement in sets {
|
||||
if let Some(checked) = <Pallet<T> as DisputesHandler<<T>::BlockNumber>>::filter_dispute_data(
|
||||
dispute_statement,
|
||||
post_conclusion_acceptance_period,
|
||||
) {
|
||||
if let Some(checked) =
|
||||
<Pallet<T> as DisputesHandler<BlockNumberFor<T>>>::filter_dispute_data(
|
||||
dispute_statement,
|
||||
post_conclusion_acceptance_period,
|
||||
) {
|
||||
acc.push(checked);
|
||||
}
|
||||
}
|
||||
@@ -2158,9 +2161,11 @@ fn filter_removes_duplicates_within_set() {
|
||||
};
|
||||
|
||||
let post_conclusion_acceptance_period = 10;
|
||||
let statements = <Pallet<Test> as DisputesHandler<
|
||||
<Test as frame_system::Config>::BlockNumber,
|
||||
>>::filter_dispute_data(statements, post_conclusion_acceptance_period);
|
||||
let statements =
|
||||
<Pallet<Test> as DisputesHandler<BlockNumberFor<Test>>>::filter_dispute_data(
|
||||
statements,
|
||||
post_conclusion_acceptance_period,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
statements,
|
||||
@@ -2446,7 +2451,7 @@ fn filter_removes_duplicate_statements_sets() {
|
||||
|
||||
// `Err(())` indicates presence of duplicates
|
||||
assert!(<Pallet::<Test> as DisputesHandler<
|
||||
<Test as frame_system::Config>::BlockNumber,
|
||||
BlockNumberFor<Test>,
|
||||
>>::deduplicate_and_sort_dispute_data(&mut sets)
|
||||
.is_err());
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ use crate::{
|
||||
initializer, FeeTracker,
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{DownwardMessage, Hash, Id as ParaId, InboundDownwardMessage};
|
||||
use sp_core::MAX_POSSIBLE_ALLOCATION;
|
||||
use sp_runtime::{
|
||||
@@ -121,7 +122,7 @@ pub mod pallet {
|
||||
_,
|
||||
Twox64Concat,
|
||||
ParaId,
|
||||
Vec<InboundDownwardMessage<T::BlockNumber>>,
|
||||
Vec<InboundDownwardMessage<BlockNumberFor<T>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
@@ -150,7 +151,7 @@ pub mod pallet {
|
||||
/// Routines and getters related to downward message passing.
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Block initialization logic, called by initializer.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -159,7 +160,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Called by the initializer to note that a new session has started.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
_notification: &initializer::SessionChangeNotification<T::BlockNumber>,
|
||||
_notification: &initializer::SessionChangeNotification<BlockNumberFor<T>>,
|
||||
outgoing_paras: &[ParaId],
|
||||
) {
|
||||
Self::perform_outgoing_para_cleanup(outgoing_paras);
|
||||
@@ -183,7 +184,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// in an error. If this returns `Ok(())` the caller can be certain that a call to
|
||||
/// `queue_downward_message` with the same parameters will be successful.
|
||||
pub fn can_queue_downward_message(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
para: &ParaId,
|
||||
msg: &DownwardMessage,
|
||||
) -> Result<(), QueueDownwardMessageError> {
|
||||
@@ -209,7 +210,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// to a dangling storage. If the caller cannot statically prove that the recipient exists
|
||||
/// then the caller should perform a runtime check.
|
||||
pub fn queue_downward_message(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
para: ParaId,
|
||||
msg: DownwardMessage,
|
||||
) -> Result<(), QueueDownwardMessageError> {
|
||||
@@ -316,7 +317,9 @@ impl<T: Config> Pallet<T> {
|
||||
/// Returns the downward message queue contents for the given para.
|
||||
///
|
||||
/// The most recent messages are the latest in the vector.
|
||||
pub(crate) fn dmq_contents(recipient: ParaId) -> Vec<InboundDownwardMessage<T::BlockNumber>> {
|
||||
pub(crate) fn dmq_contents(
|
||||
recipient: ParaId,
|
||||
) -> Vec<InboundDownwardMessage<BlockNumberFor<T>>> {
|
||||
DownwardMessageQueues::<T>::get(&recipient)
|
||||
}
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ pub mod pallet {
|
||||
/// Invariant:
|
||||
/// - each para `P` used here as a key should satisfy `Paras::is_valid_para(P)` within a session.
|
||||
#[pallet::storage]
|
||||
pub type HrmpWatermarks<T: Config> = StorageMap<_, Twox64Concat, ParaId, T::BlockNumber>;
|
||||
pub type HrmpWatermarks<T: Config> = StorageMap<_, Twox64Concat, ParaId, BlockNumberFor<T>>;
|
||||
|
||||
/// HRMP channel data associated with each para.
|
||||
/// Invariant:
|
||||
@@ -407,7 +407,7 @@ pub mod pallet {
|
||||
_,
|
||||
Twox64Concat,
|
||||
HrmpChannelId,
|
||||
Vec<InboundHrmpMessage<T::BlockNumber>>,
|
||||
Vec<InboundHrmpMessage<BlockNumberFor<T>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
@@ -419,7 +419,7 @@ pub mod pallet {
|
||||
/// same block number.
|
||||
#[pallet::storage]
|
||||
pub type HrmpChannelDigests<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ParaId, Vec<(T::BlockNumber, Vec<ParaId>)>, ValueQuery>;
|
||||
StorageMap<_, Twox64Concat, ParaId, Vec<(BlockNumberFor<T>, Vec<ParaId>)>, ValueQuery>;
|
||||
|
||||
/// Preopen the given HRMP channels.
|
||||
///
|
||||
@@ -659,7 +659,7 @@ fn preopen_hrmp_channel<T: Config>(
|
||||
/// Routines and getters related to HRMP.
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Block initialization logic, called by initializer.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -668,7 +668,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Called by the initializer to note that a new session has started.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
notification: &initializer::SessionChangeNotification<T::BlockNumber>,
|
||||
notification: &initializer::SessionChangeNotification<BlockNumberFor<T>>,
|
||||
outgoing_paras: &[ParaId],
|
||||
) -> Weight {
|
||||
let w1 = Self::perform_outgoing_para_cleanup(¬ification.prev_config, outgoing_paras);
|
||||
@@ -685,7 +685,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// Iterate over all paras that were noted for offboarding and remove all the data
|
||||
/// associated with them.
|
||||
fn perform_outgoing_para_cleanup(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
outgoing: &[ParaId],
|
||||
) -> Weight {
|
||||
let mut w = Self::clean_open_channel_requests(config, outgoing);
|
||||
@@ -710,7 +710,7 @@ impl<T: Config> Pallet<T> {
|
||||
//
|
||||
// This will also perform the refunds for the counterparty if it doesn't offboard.
|
||||
pub(crate) fn clean_open_channel_requests(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
outgoing: &[ParaId],
|
||||
) -> Weight {
|
||||
// First collect all the channel ids of the open requests in which there is at least one
|
||||
@@ -786,7 +786,7 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// - prune the stale requests
|
||||
/// - enact the confirmed requests
|
||||
fn process_hrmp_open_channel_requests(config: &HostConfiguration<T::BlockNumber>) {
|
||||
fn process_hrmp_open_channel_requests(config: &HostConfiguration<BlockNumberFor<T>>) {
|
||||
let mut open_req_channels = HrmpOpenChannelRequestsList::<T>::get();
|
||||
if open_req_channels.is_empty() {
|
||||
return
|
||||
@@ -894,9 +894,9 @@ impl<T: Config> Pallet<T> {
|
||||
/// Check that the candidate of the given recipient controls the HRMP watermark properly.
|
||||
pub(crate) fn check_hrmp_watermark(
|
||||
recipient: ParaId,
|
||||
relay_chain_parent_number: T::BlockNumber,
|
||||
new_hrmp_watermark: T::BlockNumber,
|
||||
) -> Result<(), HrmpWatermarkAcceptanceErr<T::BlockNumber>> {
|
||||
relay_chain_parent_number: BlockNumberFor<T>,
|
||||
new_hrmp_watermark: BlockNumberFor<T>,
|
||||
) -> Result<(), HrmpWatermarkAcceptanceErr<BlockNumberFor<T>>> {
|
||||
// First, check where the watermark CANNOT legally land.
|
||||
//
|
||||
// (a) For ensuring that messages are eventually processed, we require each parablock's
|
||||
@@ -942,7 +942,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
pub(crate) fn check_outbound_hrmp(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
sender: ParaId,
|
||||
out_hrmp_msgs: &[OutboundHrmpMessage<ParaId>],
|
||||
) -> Result<(), OutboundHrmpAcceptanceErr> {
|
||||
@@ -1005,7 +1005,7 @@ impl<T: Config> Pallet<T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn prune_hrmp(recipient: ParaId, new_hrmp_watermark: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn prune_hrmp(recipient: ParaId, new_hrmp_watermark: BlockNumberFor<T>) -> Weight {
|
||||
let mut weight = Weight::zero();
|
||||
|
||||
// sift through the incoming messages digest to collect the paras that sent at least one
|
||||
@@ -1390,7 +1390,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// messages in them are also included.
|
||||
pub(crate) fn inbound_hrmp_channels_contents(
|
||||
recipient: ParaId,
|
||||
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<T::BlockNumber>>> {
|
||||
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumberFor<T>>>> {
|
||||
let sender_set = HrmpIngressChannelsIndex::<T>::get(&recipient);
|
||||
|
||||
let mut inbound_hrmp_channels_contents = BTreeMap::new();
|
||||
|
||||
@@ -33,6 +33,7 @@ use frame_support::{
|
||||
traits::{Defensive, EnqueueMessage},
|
||||
BoundedSlice,
|
||||
};
|
||||
use frame_system::pallet_prelude::*;
|
||||
use pallet_message_queue::OnQueueChanged;
|
||||
use parity_scale_codec::{Decode, Encode};
|
||||
use primitives::{
|
||||
@@ -270,7 +271,7 @@ pub mod pallet {
|
||||
+ configuration::Config
|
||||
{
|
||||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
|
||||
type DisputesHandler: disputes::DisputesHandler<Self::BlockNumber>;
|
||||
type DisputesHandler: disputes::DisputesHandler<BlockNumberFor<Self>>;
|
||||
type RewardValidators: RewardValidators;
|
||||
|
||||
/// The system message queue.
|
||||
@@ -365,12 +366,16 @@ pub mod pallet {
|
||||
/// The latest bitfield for each validator, referred to by their index in the validator set.
|
||||
#[pallet::storage]
|
||||
pub(crate) type AvailabilityBitfields<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ValidatorIndex, AvailabilityBitfieldRecord<T::BlockNumber>>;
|
||||
StorageMap<_, Twox64Concat, ValidatorIndex, AvailabilityBitfieldRecord<BlockNumberFor<T>>>;
|
||||
|
||||
/// Candidates pending availability by `ParaId`.
|
||||
#[pallet::storage]
|
||||
pub(crate) type PendingAvailability<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ParaId, CandidatePendingAvailability<T::Hash, T::BlockNumber>>;
|
||||
pub(crate) type PendingAvailability<T: Config> = StorageMap<
|
||||
_,
|
||||
Twox64Concat,
|
||||
ParaId,
|
||||
CandidatePendingAvailability<T::Hash, BlockNumberFor<T>>,
|
||||
>;
|
||||
|
||||
/// The commitments of candidates pending availability, by `ParaId`.
|
||||
#[pallet::storage]
|
||||
@@ -450,7 +455,7 @@ impl fmt::Debug for UmpAcceptanceCheckErr {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Block initialization logic, called by initializer.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -459,7 +464,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Handle an incoming session change.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
_notification: &crate::initializer::SessionChangeNotification<T::BlockNumber>,
|
||||
_notification: &crate::initializer::SessionChangeNotification<BlockNumberFor<T>>,
|
||||
outgoing_paras: &[ParaId],
|
||||
) {
|
||||
// unlike most drain methods, drained elements are not cleared on `Drop` of the iterator
|
||||
@@ -832,7 +837,7 @@ impl<T: Config> Pallet<T> {
|
||||
&validation_outputs.new_validation_code,
|
||||
validation_outputs.processed_downward_messages,
|
||||
&validation_outputs.upward_messages,
|
||||
T::BlockNumber::from(validation_outputs.hrmp_watermark),
|
||||
BlockNumberFor::<T>::from(validation_outputs.hrmp_watermark),
|
||||
&validation_outputs.horizontal_messages,
|
||||
)
|
||||
.is_err()
|
||||
@@ -849,7 +854,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn enact_candidate(
|
||||
relay_parent_number: T::BlockNumber,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
receipt: CommittedCandidateReceipt<T::Hash>,
|
||||
backers: BitVec<u8, BitOrderLsb0>,
|
||||
availability_votes: BitVec<u8, BitOrderLsb0>,
|
||||
@@ -898,7 +903,7 @@ impl<T: Config> Pallet<T> {
|
||||
));
|
||||
weight.saturating_accrue(<hrmp::Pallet<T>>::prune_hrmp(
|
||||
receipt.descriptor.para_id,
|
||||
T::BlockNumber::from(commitments.hrmp_watermark),
|
||||
BlockNumberFor::<T>::from(commitments.hrmp_watermark),
|
||||
));
|
||||
weight.saturating_accrue(<hrmp::Pallet<T>>::queue_outbound_hrmp(
|
||||
receipt.descriptor.para_id,
|
||||
@@ -921,7 +926,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Check that all the upward messages sent by a candidate pass the acceptance criteria.
|
||||
pub(crate) fn check_upward_messages(
|
||||
config: &HostConfiguration<T::BlockNumber>,
|
||||
config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
para: ParaId,
|
||||
upward_messages: &[UpwardMessage],
|
||||
) -> Result<(), UmpAcceptanceCheckErr> {
|
||||
@@ -1020,7 +1025,7 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// Returns a vector of cleaned-up core IDs.
|
||||
pub(crate) fn collect_pending(
|
||||
pred: impl Fn(CoreIndex, T::BlockNumber) -> bool,
|
||||
pred: impl Fn(CoreIndex, BlockNumberFor<T>) -> bool,
|
||||
) -> Vec<CoreIndex> {
|
||||
let mut cleaned_up_ids = Vec::new();
|
||||
let mut cleaned_up_cores = Vec::new();
|
||||
@@ -1115,7 +1120,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// para provided, if any.
|
||||
pub(crate) fn pending_availability(
|
||||
para: ParaId,
|
||||
) -> Option<CandidatePendingAvailability<T::Hash, T::BlockNumber>> {
|
||||
) -> Option<CandidatePendingAvailability<T::Hash, BlockNumberFor<T>>> {
|
||||
<PendingAvailability<T>>::get(¶)
|
||||
}
|
||||
}
|
||||
@@ -1162,9 +1167,9 @@ impl<T: Config> OnQueueChanged<AggregateMessageOrigin> for Pallet<T> {
|
||||
|
||||
/// A collection of data required for checking a candidate.
|
||||
pub(crate) struct CandidateCheckContext<T: Config> {
|
||||
config: configuration::HostConfiguration<T::BlockNumber>,
|
||||
now: T::BlockNumber,
|
||||
relay_parent_number: T::BlockNumber,
|
||||
config: configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
now: BlockNumberFor<T>,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
}
|
||||
|
||||
/// An error indicating that creating Persisted Validation Data failed
|
||||
@@ -1172,7 +1177,7 @@ pub(crate) struct CandidateCheckContext<T: Config> {
|
||||
pub(crate) struct FailedToCreatePVD;
|
||||
|
||||
impl<T: Config> CandidateCheckContext<T> {
|
||||
pub(crate) fn new(now: T::BlockNumber, relay_parent_number: T::BlockNumber) -> Self {
|
||||
pub(crate) fn new(now: BlockNumberFor<T>, relay_parent_number: BlockNumberFor<T>) -> Self {
|
||||
Self { config: <configuration::Pallet<T>>::config(), now, relay_parent_number }
|
||||
}
|
||||
|
||||
@@ -1244,7 +1249,7 @@ impl<T: Config> CandidateCheckContext<T> {
|
||||
&backed_candidate.candidate.commitments.new_validation_code,
|
||||
backed_candidate.candidate.commitments.processed_downward_messages,
|
||||
&backed_candidate.candidate.commitments.upward_messages,
|
||||
T::BlockNumber::from(backed_candidate.candidate.commitments.hrmp_watermark),
|
||||
BlockNumberFor::<T>::from(backed_candidate.candidate.commitments.hrmp_watermark),
|
||||
&backed_candidate.candidate.commitments.horizontal_messages,
|
||||
) {
|
||||
log::debug!(
|
||||
@@ -1267,9 +1272,9 @@ impl<T: Config> CandidateCheckContext<T> {
|
||||
new_validation_code: &Option<primitives::ValidationCode>,
|
||||
processed_downward_messages: u32,
|
||||
upward_messages: &[primitives::UpwardMessage],
|
||||
hrmp_watermark: T::BlockNumber,
|
||||
hrmp_watermark: BlockNumberFor<T>,
|
||||
horizontal_messages: &[primitives::OutboundHrmpMessage<ParaId>],
|
||||
) -> Result<(), AcceptanceCheckErr<T::BlockNumber>> {
|
||||
) -> Result<(), AcceptanceCheckErr<BlockNumberFor<T>>> {
|
||||
ensure!(
|
||||
head_data.0.len() <= self.config.max_head_data_size as _,
|
||||
AcceptanceCheckErr::HeadDataTooLarge,
|
||||
|
||||
@@ -116,7 +116,7 @@ pub mod pallet {
|
||||
+ hrmp::Config
|
||||
{
|
||||
/// A randomness beacon.
|
||||
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
|
||||
type Randomness: Randomness<Self::Hash, BlockNumberFor<Self>>;
|
||||
/// An origin which is allowed to force updates to parachains.
|
||||
type ForceOrigin: EnsureOrigin<<Self as frame_system::Config>::RuntimeOrigin>;
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
@@ -147,7 +147,7 @@ pub mod pallet {
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_initialize(now: T::BlockNumber) -> Weight {
|
||||
fn on_initialize(now: BlockNumberFor<T>) -> Weight {
|
||||
// The other modules are initialized in this order:
|
||||
// - Configuration
|
||||
// - Paras
|
||||
@@ -174,7 +174,7 @@ pub mod pallet {
|
||||
total_weight
|
||||
}
|
||||
|
||||
fn on_finalize(now: T::BlockNumber) {
|
||||
fn on_finalize(now: BlockNumberFor<T>) {
|
||||
// reverse initialization order.
|
||||
hrmp::Pallet::<T>::initializer_finalize();
|
||||
dmp::Pallet::<T>::initializer_finalize();
|
||||
|
||||
@@ -34,8 +34,8 @@ use frame_support::{
|
||||
use frame_support_test::TestRandomness;
|
||||
use parity_scale_codec::Decode;
|
||||
use primitives::{
|
||||
AuthorityDiscoveryId, Balance, BlockNumber, CandidateHash, Header, Moment, SessionIndex,
|
||||
UpwardMessage, ValidationCode, ValidatorIndex,
|
||||
AuthorityDiscoveryId, Balance, BlockNumber, CandidateHash, Moment, SessionIndex, UpwardMessage,
|
||||
ValidationCode, ValidatorIndex,
|
||||
};
|
||||
use sp_core::{ConstU32, H256};
|
||||
use sp_io::TestExternalities;
|
||||
@@ -47,13 +47,10 @@ use sp_runtime::{
|
||||
use std::{cell::RefCell, collections::HashMap};
|
||||
|
||||
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
|
||||
type Block = frame_system::mocking::MockBlock<Test>;
|
||||
type Block = frame_system::mocking::MockBlockU32<Test>;
|
||||
|
||||
frame_support::construct_runtime!(
|
||||
pub enum Test where
|
||||
Block = Block,
|
||||
NodeBlock = Block,
|
||||
UncheckedExtrinsic = UncheckedExtrinsic,
|
||||
pub enum Test
|
||||
{
|
||||
System: frame_system,
|
||||
Balances: pallet_balances,
|
||||
@@ -100,12 +97,12 @@ impl frame_system::Config for Test {
|
||||
type RuntimeOrigin = RuntimeOrigin;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type Index = u64;
|
||||
type BlockNumber = BlockNumber;
|
||||
|
||||
type Hash = H256;
|
||||
type Hashing = BlakeTwo256;
|
||||
type AccountId = u64;
|
||||
type Lookup = IdentityLookup<u64>;
|
||||
type Header = Header;
|
||||
type Block = Block;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type BlockHashCount = BlockHashCount;
|
||||
type Version = ();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
use super::*;
|
||||
use crate::configuration::HostConfiguration;
|
||||
use frame_benchmarking::benchmarks;
|
||||
use frame_system::RawOrigin;
|
||||
use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin};
|
||||
use primitives::{HeadData, Id as ParaId, ValidationCode, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE};
|
||||
use sp_runtime::traits::{One, Saturating};
|
||||
|
||||
@@ -44,7 +44,7 @@ fn generate_disordered_pruning<T: Config>() {
|
||||
|
||||
for i in 0..SAMPLE_SIZE {
|
||||
let id = ParaId::from(i);
|
||||
let block_number = T::BlockNumber::from(1000u32);
|
||||
let block_number = BlockNumberFor::<T>::from(1000u32);
|
||||
needs_pruning.push((id, block_number));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ pub(crate) fn generate_disordered_upgrades<T: Config>() {
|
||||
|
||||
for i in 0..SAMPLE_SIZE {
|
||||
let id = ParaId::from(i);
|
||||
let block_number = T::BlockNumber::from(1000u32);
|
||||
let block_number = BlockNumberFor::<T>::from(1000u32);
|
||||
upgrades.push((id, block_number));
|
||||
cooldowns.push((id, block_number));
|
||||
}
|
||||
@@ -103,7 +103,7 @@ benchmarks! {
|
||||
let c in 1 .. MAX_CODE_SIZE;
|
||||
let new_code = ValidationCode(vec![0; c as usize]);
|
||||
let para_id = ParaId::from(c as u32);
|
||||
let block = T::BlockNumber::from(c);
|
||||
let block = BlockNumberFor::<T>::from(c);
|
||||
generate_disordered_upgrades::<T>();
|
||||
}: _(RawOrigin::Root, para_id, new_code, block)
|
||||
verify {
|
||||
@@ -118,7 +118,7 @@ benchmarks! {
|
||||
// schedule an expired code upgrade for this `para_id` so that force_note_new_head would use
|
||||
// the worst possible code path
|
||||
let expired = frame_system::Pallet::<T>::block_number().saturating_sub(One::one());
|
||||
let config = HostConfiguration::<T::BlockNumber>::default();
|
||||
let config = HostConfiguration::<BlockNumberFor<T>>::default();
|
||||
generate_disordered_pruning::<T>();
|
||||
Pallet::<T>::schedule_code_upgrade(para_id, ValidationCode(vec![0]), expired, &config);
|
||||
}: _(RawOrigin::Root, para_id, new_head)
|
||||
|
||||
@@ -550,7 +550,7 @@ pub mod pallet {
|
||||
#[pallet::constant]
|
||||
type UnsignedPriority: Get<TransactionPriority>;
|
||||
|
||||
type NextSessionRotation: EstimateNextSessionRotation<Self::BlockNumber>;
|
||||
type NextSessionRotation: EstimateNextSessionRotation<BlockNumberFor<Self>>;
|
||||
|
||||
/// Retrieve how many UMP messages are enqueued for this para-chain.
|
||||
///
|
||||
@@ -623,7 +623,7 @@ pub mod pallet {
|
||||
_,
|
||||
Twox64Concat,
|
||||
ValidationCodeHash,
|
||||
PvfCheckActiveVoteState<T::BlockNumber>,
|
||||
PvfCheckActiveVoteState<BlockNumberFor<T>>,
|
||||
OptionQuery,
|
||||
>;
|
||||
|
||||
@@ -662,7 +662,7 @@ pub mod pallet {
|
||||
/// Corresponding code can be retrieved with [`CodeByHash`].
|
||||
#[pallet::storage]
|
||||
pub(super) type PastCodeHash<T: Config> =
|
||||
StorageMap<_, Twox64Concat, (ParaId, T::BlockNumber), ValidationCodeHash>;
|
||||
StorageMap<_, Twox64Concat, (ParaId, BlockNumberFor<T>), ValidationCodeHash>;
|
||||
|
||||
/// Past code of parachains. The parachains themselves may not be registered anymore,
|
||||
/// but we also keep their code on-chain for the same amount of time as outdated code
|
||||
@@ -670,7 +670,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn past_code_meta)]
|
||||
pub(super) type PastCodeMeta<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ParaId, ParaPastCodeMeta<T::BlockNumber>, ValueQuery>;
|
||||
StorageMap<_, Twox64Concat, ParaId, ParaPastCodeMeta<BlockNumberFor<T>>, ValueQuery>;
|
||||
|
||||
/// Which paras have past code that needs pruning and the relay-chain block at which the code was replaced.
|
||||
/// Note that this is the actual height of the included block, not the expected height at which the
|
||||
@@ -680,7 +680,7 @@ pub mod pallet {
|
||||
/// Multiple entries for a single para are permitted. Ordered ascending by block number.
|
||||
#[pallet::storage]
|
||||
pub(super) type PastCodePruning<T: Config> =
|
||||
StorageValue<_, Vec<(ParaId, T::BlockNumber)>, ValueQuery>;
|
||||
StorageValue<_, Vec<(ParaId, BlockNumberFor<T>)>, ValueQuery>;
|
||||
|
||||
/// The block number at which the planned code change is expected for a para.
|
||||
/// The change will be applied after the first parablock for this ID included which executes
|
||||
@@ -688,7 +688,7 @@ pub mod pallet {
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn future_code_upgrade_at)]
|
||||
pub(super) type FutureCodeUpgrades<T: Config> =
|
||||
StorageMap<_, Twox64Concat, ParaId, T::BlockNumber>;
|
||||
StorageMap<_, Twox64Concat, ParaId, BlockNumberFor<T>>;
|
||||
|
||||
/// The actual future code hash of a para.
|
||||
///
|
||||
@@ -728,7 +728,7 @@ pub mod pallet {
|
||||
/// Ordered ascending by block number.
|
||||
#[pallet::storage]
|
||||
pub(super) type UpgradeCooldowns<T: Config> =
|
||||
StorageValue<_, Vec<(ParaId, T::BlockNumber)>, ValueQuery>;
|
||||
StorageValue<_, Vec<(ParaId, BlockNumberFor<T>)>, ValueQuery>;
|
||||
|
||||
/// The list of upcoming code upgrades. Each item is a pair of which para performs a code
|
||||
/// upgrade and at which relay-chain block it is expected at.
|
||||
@@ -736,7 +736,7 @@ pub mod pallet {
|
||||
/// Ordered ascending by block number.
|
||||
#[pallet::storage]
|
||||
pub(super) type UpcomingUpgrades<T: Config> =
|
||||
StorageValue<_, Vec<(ParaId, T::BlockNumber)>, ValueQuery>;
|
||||
StorageValue<_, Vec<(ParaId, BlockNumberFor<T>)>, ValueQuery>;
|
||||
|
||||
/// The actions to perform during the start of a specific session index.
|
||||
#[pallet::storage]
|
||||
@@ -838,7 +838,7 @@ pub mod pallet {
|
||||
origin: OriginFor<T>,
|
||||
para: ParaId,
|
||||
new_code: ValidationCode,
|
||||
relay_parent_number: T::BlockNumber,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
) -> DispatchResult {
|
||||
ensure_root(origin)?;
|
||||
let config = configuration::Pallet::<T>::config();
|
||||
@@ -1145,13 +1145,13 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Called by the initializer to initialize the paras pallet.
|
||||
pub(crate) fn initializer_initialize(now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(now: BlockNumberFor<T>) -> Weight {
|
||||
let weight = Self::prune_old_code(now);
|
||||
weight + Self::process_scheduled_upgrade_changes(now)
|
||||
}
|
||||
|
||||
/// Called by the initializer to finalize the paras pallet.
|
||||
pub(crate) fn initializer_finalize(now: T::BlockNumber) {
|
||||
pub(crate) fn initializer_finalize(now: BlockNumberFor<T>) {
|
||||
Self::process_scheduled_upgrade_cooldowns(now);
|
||||
}
|
||||
|
||||
@@ -1159,7 +1159,7 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// Returns the list of outgoing paras from the actions queue.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
notification: &SessionChangeNotification<T::BlockNumber>,
|
||||
notification: &SessionChangeNotification<BlockNumberFor<T>>,
|
||||
) -> Vec<ParaId> {
|
||||
let outgoing_paras = Self::apply_actions_queue(notification.session_index);
|
||||
Self::groom_ongoing_pvf_votes(¬ification.new_config, notification.validators.len());
|
||||
@@ -1275,8 +1275,8 @@ impl<T: Config> Pallet<T> {
|
||||
// (i.e. number of `relay_parent` in the receipt)
|
||||
fn note_past_code(
|
||||
id: ParaId,
|
||||
at: T::BlockNumber,
|
||||
now: T::BlockNumber,
|
||||
at: BlockNumberFor<T>,
|
||||
now: BlockNumberFor<T>,
|
||||
old_code_hash: ValidationCodeHash,
|
||||
) -> Weight {
|
||||
PastCodeMeta::<T>::mutate(&id, |past_meta| {
|
||||
@@ -1298,7 +1298,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// looks at old code metadata, compares them to the current acceptance window, and prunes those
|
||||
// that are too old.
|
||||
fn prune_old_code(now: T::BlockNumber) -> Weight {
|
||||
fn prune_old_code(now: BlockNumberFor<T>) -> Weight {
|
||||
let config = configuration::Pallet::<T>::config();
|
||||
let code_retention_period = config.code_retention_period;
|
||||
if now <= code_retention_period {
|
||||
@@ -1310,7 +1310,7 @@ impl<T: Config> Pallet<T> {
|
||||
let pruning_height = now - (code_retention_period + One::one());
|
||||
|
||||
let pruning_tasks_done =
|
||||
PastCodePruning::<T>::mutate(|pruning_tasks: &mut Vec<(_, T::BlockNumber)>| {
|
||||
PastCodePruning::<T>::mutate(|pruning_tasks: &mut Vec<(_, BlockNumberFor<T>)>| {
|
||||
let (pruning_tasks_done, pruning_tasks_to_do) = {
|
||||
// find all past code that has just exited the pruning window.
|
||||
let up_to_idx =
|
||||
@@ -1358,11 +1358,11 @@ impl<T: Config> Pallet<T> {
|
||||
/// the upgrade restriction, that will happen in the `initializer_finalize` function. However,
|
||||
/// this function does count the number of cooldown timers expired so that we can reserve weight
|
||||
/// for the `initializer_finalize` function.
|
||||
fn process_scheduled_upgrade_changes(now: T::BlockNumber) -> Weight {
|
||||
fn process_scheduled_upgrade_changes(now: BlockNumberFor<T>) -> Weight {
|
||||
// account weight for `UpcomingUpgrades::mutate`.
|
||||
let mut weight = T::DbWeight::get().reads_writes(1, 1);
|
||||
let upgrades_signaled = UpcomingUpgrades::<T>::mutate(
|
||||
|upcoming_upgrades: &mut Vec<(ParaId, T::BlockNumber)>| {
|
||||
|upcoming_upgrades: &mut Vec<(ParaId, BlockNumberFor<T>)>| {
|
||||
let num = upcoming_upgrades.iter().take_while(|&(_, at)| at <= &now).count();
|
||||
for (para, _) in upcoming_upgrades.drain(..num) {
|
||||
UpgradeGoAheadSignal::<T>::insert(¶, UpgradeGoAhead::GoAhead);
|
||||
@@ -1389,24 +1389,26 @@ impl<T: Config> Pallet<T> {
|
||||
/// Actually perform unsetting the expired upgrade restrictions.
|
||||
///
|
||||
/// See `process_scheduled_upgrade_changes` for more details.
|
||||
fn process_scheduled_upgrade_cooldowns(now: T::BlockNumber) {
|
||||
UpgradeCooldowns::<T>::mutate(|upgrade_cooldowns: &mut Vec<(ParaId, T::BlockNumber)>| {
|
||||
// Remove all expired signals and also prune the cooldowns.
|
||||
upgrade_cooldowns.retain(|(para, at)| {
|
||||
if at <= &now {
|
||||
UpgradeRestrictionSignal::<T>::remove(¶);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
});
|
||||
fn process_scheduled_upgrade_cooldowns(now: BlockNumberFor<T>) {
|
||||
UpgradeCooldowns::<T>::mutate(
|
||||
|upgrade_cooldowns: &mut Vec<(ParaId, BlockNumberFor<T>)>| {
|
||||
// Remove all expired signals and also prune the cooldowns.
|
||||
upgrade_cooldowns.retain(|(para, at)| {
|
||||
if at <= &now {
|
||||
UpgradeRestrictionSignal::<T>::remove(¶);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Goes over all PVF votes in progress, reinitializes ballots, increments ages and prunes the
|
||||
/// active votes that reached their time-to-live.
|
||||
fn groom_ongoing_pvf_votes(
|
||||
cfg: &configuration::HostConfiguration<T::BlockNumber>,
|
||||
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
new_n_validators: usize,
|
||||
) -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
@@ -1456,11 +1458,11 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
fn enact_pvf_accepted(
|
||||
now: T::BlockNumber,
|
||||
now: BlockNumberFor<T>,
|
||||
code_hash: &ValidationCodeHash,
|
||||
causes: &[PvfCheckCause<T::BlockNumber>],
|
||||
causes: &[PvfCheckCause<BlockNumberFor<T>>],
|
||||
sessions_observed: SessionIndex,
|
||||
cfg: &configuration::HostConfiguration<T::BlockNumber>,
|
||||
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
) -> Weight {
|
||||
let mut weight = Weight::zero();
|
||||
for cause in causes {
|
||||
@@ -1503,9 +1505,9 @@ impl<T: Config> Pallet<T> {
|
||||
fn proceed_with_upgrade(
|
||||
id: ParaId,
|
||||
code_hash: &ValidationCodeHash,
|
||||
now: T::BlockNumber,
|
||||
relay_parent_number: T::BlockNumber,
|
||||
cfg: &configuration::HostConfiguration<T::BlockNumber>,
|
||||
now: BlockNumberFor<T>,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
) -> Weight {
|
||||
let mut weight = Weight::zero();
|
||||
|
||||
@@ -1545,7 +1547,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
fn enact_pvf_rejected(
|
||||
code_hash: &ValidationCodeHash,
|
||||
causes: Vec<PvfCheckCause<T::BlockNumber>>,
|
||||
causes: Vec<PvfCheckCause<BlockNumberFor<T>>>,
|
||||
) -> Weight {
|
||||
let mut weight = Weight::zero();
|
||||
|
||||
@@ -1766,8 +1768,8 @@ impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn schedule_code_upgrade(
|
||||
id: ParaId,
|
||||
new_code: ValidationCode,
|
||||
relay_parent_number: T::BlockNumber,
|
||||
cfg: &configuration::HostConfiguration<T::BlockNumber>,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
) -> Weight {
|
||||
let mut weight = T::DbWeight::get().reads(1);
|
||||
|
||||
@@ -1840,10 +1842,10 @@ impl<T: Config> Pallet<T> {
|
||||
///
|
||||
/// Unconditionally increases the reference count for the passed `code`.
|
||||
fn kick_off_pvf_check(
|
||||
cause: PvfCheckCause<T::BlockNumber>,
|
||||
cause: PvfCheckCause<BlockNumberFor<T>>,
|
||||
code_hash: ValidationCodeHash,
|
||||
code: ValidationCode,
|
||||
cfg: &configuration::HostConfiguration<T::BlockNumber>,
|
||||
cfg: &configuration::HostConfiguration<BlockNumberFor<T>>,
|
||||
) -> Weight {
|
||||
let mut weight = Weight::zero();
|
||||
|
||||
@@ -1912,7 +1914,7 @@ impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn note_new_head(
|
||||
id: ParaId,
|
||||
new_head: HeadData,
|
||||
execution_context: T::BlockNumber,
|
||||
execution_context: BlockNumberFor<T>,
|
||||
) -> Weight {
|
||||
Heads::<T>::insert(&id, new_head);
|
||||
|
||||
|
||||
@@ -191,11 +191,11 @@ pub mod pallet {
|
||||
|
||||
#[pallet::hooks]
|
||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||
fn on_initialize(_: T::BlockNumber) -> Weight {
|
||||
fn on_initialize(_: BlockNumberFor<T>) -> Weight {
|
||||
T::DbWeight::get().reads_writes(1, 1) // in `on_finalize`.
|
||||
}
|
||||
|
||||
fn on_finalize(_: T::BlockNumber) {
|
||||
fn on_finalize(_: BlockNumberFor<T>) {
|
||||
if Included::<T>::take().is_none() {
|
||||
panic!("Bitfields and heads must be included every block");
|
||||
}
|
||||
@@ -262,7 +262,7 @@ pub mod pallet {
|
||||
))]
|
||||
pub fn enter(
|
||||
origin: OriginFor<T>,
|
||||
data: ParachainsInherentData<T::Header>,
|
||||
data: ParachainsInherentData<HeaderFor<T>>,
|
||||
) -> DispatchResultWithPostInfo {
|
||||
ensure_none(origin)?;
|
||||
|
||||
@@ -277,7 +277,7 @@ pub mod pallet {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Create the `ParachainsInherentData` that gets passed to [`Self::enter`] in [`Self::create_inherent`].
|
||||
/// This code is pulled out of [`Self::create_inherent`] so it can be unit tested.
|
||||
fn create_inherent_inner(data: &InherentData) -> Option<ParachainsInherentData<T::Header>> {
|
||||
fn create_inherent_inner(data: &InherentData) -> Option<ParachainsInherentData<HeaderFor<T>>> {
|
||||
let parachains_inherent_data = match data.get_data(&Self::INHERENT_IDENTIFIER) {
|
||||
Ok(Some(d)) => d,
|
||||
Ok(None) => return None,
|
||||
@@ -307,9 +307,9 @@ impl<T: Config> Pallet<T> {
|
||||
/// Returns: Result containing processed inherent data and weight, the processed inherent would
|
||||
/// consume.
|
||||
fn process_inherent_data(
|
||||
data: ParachainsInherentData<T::Header>,
|
||||
data: ParachainsInherentData<HeaderFor<T>>,
|
||||
) -> sp_std::result::Result<
|
||||
(ParachainsInherentData<T::Header>, PostDispatchInfo),
|
||||
(ParachainsInherentData<HeaderFor<T>>, PostDispatchInfo),
|
||||
DispatchErrorWithPostInfo,
|
||||
> {
|
||||
#[cfg(feature = "runtime-metrics")]
|
||||
@@ -530,7 +530,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
// Process backed candidates according to scheduled cores.
|
||||
let parent_storage_root = *parent_header.state_root();
|
||||
let inclusion::ProcessedCandidates::<<T::Header as HeaderT>::Hash> {
|
||||
let inclusion::ProcessedCandidates::<<HeaderFor<T> as HeaderT>::Hash> {
|
||||
core_indices: occupied,
|
||||
candidate_receipt_with_backing_validator_indices,
|
||||
} = <inclusion::Pallet<T>>::process_candidates(
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::{
|
||||
configuration, disputes, dmp, hrmp, inclusion, initializer, paras, paras_inherent, scheduler,
|
||||
session_info, shared,
|
||||
};
|
||||
use frame_system::pallet_prelude::*;
|
||||
use primitives::{
|
||||
slashing, AuthorityDiscoveryId, CandidateEvent, CandidateHash, CommittedCandidateReceipt,
|
||||
CoreIndex, CoreOccupied, CoreState, DisputeState, ExecutorParams, GroupIndex,
|
||||
@@ -39,7 +40,7 @@ pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
|
||||
|
||||
/// Implementation for the `validator_groups` function of the runtime API.
|
||||
pub fn validator_groups<T: initializer::Config>(
|
||||
) -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<T::BlockNumber>) {
|
||||
) -> (Vec<Vec<ValidatorIndex>>, GroupRotationInfo<BlockNumberFor<T>>) {
|
||||
let now = <frame_system::Pallet<T>>::block_number() + One::one();
|
||||
|
||||
let groups = <scheduler::Pallet<T>>::validator_groups();
|
||||
@@ -49,7 +50,7 @@ pub fn validator_groups<T: initializer::Config>(
|
||||
}
|
||||
|
||||
/// Implementation for the `availability_cores` function of the runtime API.
|
||||
pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T::BlockNumber>> {
|
||||
pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, BlockNumberFor<T>>> {
|
||||
let cores = <scheduler::Pallet<T>>::availability_cores();
|
||||
let parachains = <paras::Pallet<T>>::parachains();
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
@@ -176,7 +177,7 @@ pub fn availability_cores<T: initializer::Config>() -> Vec<CoreState<T::Hash, T:
|
||||
|
||||
/// Returns current block number being processed and the corresponding root hash.
|
||||
fn current_relay_parent<T: frame_system::Config>(
|
||||
) -> (<T as frame_system::Config>::BlockNumber, <T as frame_system::Config>::Hash) {
|
||||
) -> (BlockNumberFor<T>, <T as frame_system::Config>::Hash) {
|
||||
use parity_scale_codec::Decode as _;
|
||||
let state_version = <frame_system::Pallet<T>>::runtime_version().state_version();
|
||||
let relay_parent_number = <frame_system::Pallet<T>>::block_number();
|
||||
@@ -214,7 +215,7 @@ where
|
||||
pub fn persisted_validation_data<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
assumption: OccupiedCoreAssumption,
|
||||
) -> Option<PersistedValidationData<T::Hash, T::BlockNumber>> {
|
||||
) -> Option<PersistedValidationData<T::Hash, BlockNumberFor<T>>> {
|
||||
let (relay_parent_number, relay_parent_storage_root) = current_relay_parent::<T>();
|
||||
with_assumption::<T, _, _>(para_id, assumption, || {
|
||||
crate::util::make_persisted_validation_data::<T>(
|
||||
@@ -229,7 +230,7 @@ pub fn persisted_validation_data<T: initializer::Config>(
|
||||
pub fn assumed_validation_data<T: initializer::Config>(
|
||||
para_id: ParaId,
|
||||
expected_persisted_validation_data_hash: Hash,
|
||||
) -> Option<(PersistedValidationData<T::Hash, T::BlockNumber>, ValidationCodeHash)> {
|
||||
) -> Option<(PersistedValidationData<T::Hash, BlockNumberFor<T>>, ValidationCodeHash)> {
|
||||
let (relay_parent_number, relay_parent_storage_root) = current_relay_parent::<T>();
|
||||
// This closure obtains the `persisted_validation_data` for the given `para_id` and matches
|
||||
// its hash against an expected one.
|
||||
@@ -355,14 +356,14 @@ pub fn session_info<T: session_info::Config>(index: SessionIndex) -> Option<Sess
|
||||
/// Implementation for the `dmq_contents` function of the runtime API.
|
||||
pub fn dmq_contents<T: dmp::Config>(
|
||||
recipient: ParaId,
|
||||
) -> Vec<InboundDownwardMessage<T::BlockNumber>> {
|
||||
) -> Vec<InboundDownwardMessage<BlockNumberFor<T>>> {
|
||||
<dmp::Pallet<T>>::dmq_contents(recipient)
|
||||
}
|
||||
|
||||
/// Implementation for the `inbound_hrmp_channels_contents` function of the runtime API.
|
||||
pub fn inbound_hrmp_channels_contents<T: hrmp::Config>(
|
||||
recipient: ParaId,
|
||||
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<T::BlockNumber>>> {
|
||||
) -> BTreeMap<ParaId, Vec<InboundHrmpMessage<BlockNumberFor<T>>>> {
|
||||
<hrmp::Pallet<T>>::inbound_hrmp_channels_contents(recipient)
|
||||
}
|
||||
|
||||
@@ -407,7 +408,7 @@ where
|
||||
|
||||
/// Implementation for `get_session_disputes` function from the runtime API
|
||||
pub fn get_session_disputes<T: disputes::Config>(
|
||||
) -> Vec<(SessionIndex, CandidateHash, DisputeState<T::BlockNumber>)> {
|
||||
) -> Vec<(SessionIndex, CandidateHash, DisputeState<BlockNumberFor<T>>)> {
|
||||
<disputes::Pallet<T>>::disputes()
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
//! over time.
|
||||
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{
|
||||
CollatorId, CoreIndex, CoreOccupied, GroupIndex, GroupRotationInfo, Id as ParaId,
|
||||
ParathreadClaim, ParathreadEntry, ScheduledCore, ValidatorIndex,
|
||||
@@ -208,7 +209,7 @@ pub mod pallet {
|
||||
/// block following the session change, block number of which we save in this storage value.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn session_start_block)]
|
||||
pub(crate) type SessionStartBlock<T: Config> = StorageValue<_, T::BlockNumber, ValueQuery>;
|
||||
pub(crate) type SessionStartBlock<T: Config> = StorageValue<_, BlockNumberFor<T>, ValueQuery>;
|
||||
|
||||
/// Currently scheduled cores - free but up to be occupied.
|
||||
///
|
||||
@@ -224,7 +225,7 @@ pub mod pallet {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the scheduler pallet.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -233,7 +234,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
/// Called by the initializer to note that a new session has started.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
notification: &SessionChangeNotification<T::BlockNumber>,
|
||||
notification: &SessionChangeNotification<BlockNumberFor<T>>,
|
||||
) {
|
||||
let SessionChangeNotification { validators, new_config, .. } = notification;
|
||||
let config = new_config;
|
||||
@@ -421,7 +422,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// ascending order by core index.
|
||||
pub(crate) fn schedule(
|
||||
just_freed_cores: impl IntoIterator<Item = (CoreIndex, FreedReason)>,
|
||||
now: T::BlockNumber,
|
||||
now: BlockNumberFor<T>,
|
||||
) {
|
||||
Self::free_cores(just_freed_cores);
|
||||
|
||||
@@ -590,7 +591,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// or the block number is less than the session start index.
|
||||
pub(crate) fn group_assigned_to_core(
|
||||
core: CoreIndex,
|
||||
at: T::BlockNumber,
|
||||
at: BlockNumberFor<T>,
|
||||
) -> Option<GroupIndex> {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
let session_start_block = <SessionStartBlock<T>>::get();
|
||||
@@ -605,11 +606,12 @@ impl<T: Config> Pallet<T> {
|
||||
return None
|
||||
}
|
||||
|
||||
let rotations_since_session_start: T::BlockNumber =
|
||||
let rotations_since_session_start: BlockNumberFor<T> =
|
||||
(at - session_start_block) / config.group_rotation_frequency.into();
|
||||
|
||||
let rotations_since_session_start =
|
||||
<T::BlockNumber as TryInto<u32>>::try_into(rotations_since_session_start).unwrap_or(0);
|
||||
<BlockNumberFor<T> as TryInto<u32>>::try_into(rotations_since_session_start)
|
||||
.unwrap_or(0);
|
||||
// Error case can only happen if rotations occur only once every u32::max(),
|
||||
// so functionally no difference in behavior.
|
||||
|
||||
@@ -629,7 +631,7 @@ impl<T: Config> Pallet<T> {
|
||||
/// https://github.com/rust-lang/rust/issues/73226
|
||||
/// which prevents us from testing the code if using `impl Trait`.
|
||||
pub(crate) fn availability_timeout_predicate(
|
||||
) -> Option<Box<dyn Fn(CoreIndex, T::BlockNumber) -> bool>> {
|
||||
) -> Option<Box<dyn Fn(CoreIndex, BlockNumberFor<T>) -> bool>> {
|
||||
let now = <frame_system::Pallet<T>>::block_number();
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
|
||||
@@ -670,7 +672,9 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Returns a helper for determining group rotation.
|
||||
pub(crate) fn group_rotation_info(now: T::BlockNumber) -> GroupRotationInfo<T::BlockNumber> {
|
||||
pub(crate) fn group_rotation_info(
|
||||
now: BlockNumberFor<T>,
|
||||
) -> GroupRotationInfo<BlockNumberFor<T>> {
|
||||
let session_start_block = Self::session_start_block();
|
||||
let group_rotation_frequency =
|
||||
<configuration::Pallet<T>>::config().group_rotation_frequency;
|
||||
|
||||
@@ -27,6 +27,7 @@ use frame_support::{
|
||||
pallet_prelude::*,
|
||||
traits::{OneSessionHandler, ValidatorSet, ValidatorSetWithIdentification},
|
||||
};
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{AssignmentId, AuthorityDiscoveryId, ExecutorParams, SessionIndex, SessionInfo};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
@@ -125,7 +126,7 @@ impl<T: pallet_authority_discovery::Config> AuthorityDiscoveryConfig for T {
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Handle an incoming session change.
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
notification: &crate::initializer::SessionChangeNotification<T::BlockNumber>,
|
||||
notification: &crate::initializer::SessionChangeNotification<BlockNumberFor<T>>,
|
||||
) {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
|
||||
@@ -195,7 +196,7 @@ impl<T: Config> Pallet<T> {
|
||||
}
|
||||
|
||||
/// Called by the initializer to initialize the session info pallet.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
//! dependent on any of the other pallets.
|
||||
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{SessionIndex, ValidatorId, ValidatorIndex};
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
@@ -73,7 +74,7 @@ pub mod pallet {
|
||||
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the configuration pallet.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
pub(crate) fn initializer_initialize(_now: BlockNumberFor<T>) -> Weight {
|
||||
Weight::zero()
|
||||
}
|
||||
|
||||
@@ -86,7 +87,7 @@ impl<T: Config> Pallet<T> {
|
||||
pub(crate) fn initializer_on_new_session(
|
||||
session_index: SessionIndex,
|
||||
random_seed: [u8; 32],
|
||||
new_config: &HostConfiguration<T::BlockNumber>,
|
||||
new_config: &HostConfiguration<BlockNumberFor<T>>,
|
||||
all_validators: Vec<ValidatorId>,
|
||||
) -> Vec<ValidatorId> {
|
||||
CurrentSessionIndex::<T>::set(session_index);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! Utilities that don't belong to any particular module but may draw
|
||||
//! on all modules.
|
||||
|
||||
use frame_system::pallet_prelude::BlockNumberFor;
|
||||
use primitives::{Id as ParaId, PersistedValidationData, ValidatorIndex};
|
||||
use sp_std::{collections::btree_set::BTreeSet, vec::Vec};
|
||||
|
||||
@@ -28,9 +29,9 @@ use crate::{configuration, hrmp, paras};
|
||||
/// This ties together the storage of several modules.
|
||||
pub fn make_persisted_validation_data<T: paras::Config + hrmp::Config>(
|
||||
para_id: ParaId,
|
||||
relay_parent_number: T::BlockNumber,
|
||||
relay_parent_number: BlockNumberFor<T>,
|
||||
relay_parent_storage_root: T::Hash,
|
||||
) -> Option<PersistedValidationData<T::Hash, T::BlockNumber>> {
|
||||
) -> Option<PersistedValidationData<T::Hash, BlockNumberFor<T>>> {
|
||||
let config = <configuration::Pallet<T>>::config();
|
||||
|
||||
Some(PersistedValidationData {
|
||||
|
||||
Reference in New Issue
Block a user