mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01:02 +00:00
Inclusion Module (#1242)
* add availability bitfield types to primitives * begin inclusion module * use GitHub issue link for limitation * fix some compiler errors * integrate validators into initializer * add generic signing context * make signing-context more generic * fix issues with inclusion module * add TODO * guide: add validators and session index to inclusion * guide: add session index to change notification * implement session change logic * add BackedCandidate type * guide: refine inclusion pipeline * guide: rename group_on to group_validators * guide: add check about collator for parathread * guide: add last_code_upgrade to paras and use in inclusion * implement Paras::last_code_upgrade * implement most checks in process_candidates * make candidate receipt structs more generic * make BackedCandidate struct more generic * use hash param, not block number * check that candidate is in context of the parent block * include inclusion module in initializer * implement enact-candidate * check that only occupied cores have bits set * finish implementing bitfield processing * restructure consistency checks on candidates * make some more primitives generic * signature checking logic for backed candidates * finish implementing process_candidates * implement collect_pending * add some trait implementations to primitives * implement InclusionInherent and squash warnings * test bitfield signing checks * rename parachain head to para_head * fix note_new_head bug in paras * test bitfield enactment in inclusion * helpers for candidate checks * add test for most candidate checks * add test for backing setting storage * test session change logic * remove extraneous type parameter * remove some allow(unused)s * extract threshold computation to const fn * remove some more allow(unused)s * improve doc * add debug assertion * fix primitive test compilation * tag unanimous variant as unused
This commit is contained in:
committed by
GitHub
parent
7accc6e499
commit
879892d3f9
@@ -27,7 +27,7 @@ use primitives::{
|
||||
use frame_support::{
|
||||
decl_storage, decl_module, decl_error, traits::Randomness,
|
||||
};
|
||||
use crate::{configuration::{self, HostConfiguration}, paras, scheduler};
|
||||
use crate::{configuration::{self, HostConfiguration}, paras, scheduler, inclusion};
|
||||
|
||||
/// Information about a session change that has just occurred.
|
||||
#[derive(Default, Clone)]
|
||||
@@ -42,9 +42,13 @@ pub struct SessionChangeNotification<BlockNumber> {
|
||||
pub new_config: HostConfiguration<BlockNumber>,
|
||||
/// A secure random seed for the session, gathered from BABE.
|
||||
pub random_seed: [u8; 32],
|
||||
/// New session index.
|
||||
pub session_index: sp_staking::SessionIndex,
|
||||
}
|
||||
|
||||
pub trait Trait: system::Trait + configuration::Trait + paras::Trait + scheduler::Trait {
|
||||
pub trait Trait:
|
||||
system::Trait + configuration::Trait + paras::Trait + scheduler::Trait + inclusion::Trait
|
||||
{
|
||||
/// A randomness beacon.
|
||||
type Randomness: Randomness<Self::Hash>;
|
||||
}
|
||||
@@ -81,7 +85,8 @@ decl_module! {
|
||||
// - Validity
|
||||
let total_weight = configuration::Module::<T>::initializer_initialize(now) +
|
||||
paras::Module::<T>::initializer_initialize(now) +
|
||||
scheduler::Module::<T>::initializer_initialize(now);
|
||||
scheduler::Module::<T>::initializer_initialize(now) +
|
||||
inclusion::Module::<T>::initializer_initialize(now);
|
||||
|
||||
HasInitialized::set(Some(()));
|
||||
|
||||
@@ -91,6 +96,7 @@ decl_module! {
|
||||
fn on_finalize() {
|
||||
// reverse initialization order.
|
||||
|
||||
inclusion::Module::<T>::initializer_finalize();
|
||||
scheduler::Module::<T>::initializer_finalize();
|
||||
paras::Module::<T>::initializer_finalize();
|
||||
configuration::Module::<T>::initializer_finalize();
|
||||
@@ -101,16 +107,25 @@ decl_module! {
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
/// Should be called when a new session occurs. Forwards the session notification to all
|
||||
/// wrapped modules.
|
||||
/// wrapped modules. If `queued` is `None`, the `validators` are considered queued.
|
||||
///
|
||||
/// Panics if the modules have already been initialized.
|
||||
fn on_new_session<'a, I: 'a>(_changed: bool, validators: I, queued: I)
|
||||
fn on_new_session<'a, I: 'a>(
|
||||
_changed: bool,
|
||||
session_index: sp_staking::SessionIndex,
|
||||
validators: I,
|
||||
queued: Option<I>,
|
||||
)
|
||||
where I: Iterator<Item=(&'a T::AccountId, ValidatorId)>
|
||||
{
|
||||
assert!(HasInitialized::get().is_none());
|
||||
|
||||
let validators: Vec<_> = validators.map(|(_, v)| v).collect();
|
||||
let queued: Vec<_> = queued.map(|(_, v)| v).collect();
|
||||
let queued: Vec<_> = if let Some(queued) = queued {
|
||||
queued.map(|(_, v)| v).collect()
|
||||
} else {
|
||||
validators.clone()
|
||||
};
|
||||
|
||||
let prev_config = <configuration::Module<T>>::config();
|
||||
|
||||
@@ -134,10 +149,12 @@ impl<T: Trait> Module<T> {
|
||||
prev_config,
|
||||
new_config,
|
||||
random_seed,
|
||||
session_index,
|
||||
};
|
||||
|
||||
paras::Module::<T>::initializer_on_new_session(¬ification);
|
||||
scheduler::Module::<T>::initializer_on_new_session(¬ification);
|
||||
inclusion::Module::<T>::initializer_on_new_session(¬ification);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +162,7 @@ impl<T: Trait> sp_runtime::BoundToRuntimeAppPublic for Module<T> {
|
||||
type Public = ValidatorId;
|
||||
}
|
||||
|
||||
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
impl<T: session::Trait + Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
type Key = ValidatorId;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(_validators: I)
|
||||
@@ -157,7 +174,8 @@ impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, queued: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, Self::Key)>
|
||||
{
|
||||
<Module<T>>::on_new_session(changed, validators, queued);
|
||||
let session_index = <session::Module<T>>::current_index();
|
||||
<Module<T>>::on_new_session(changed, session_index, validators, Some(queued));
|
||||
}
|
||||
|
||||
fn on_disabled(_i: usize) { }
|
||||
@@ -175,7 +193,12 @@ mod tests {
|
||||
fn panics_if_session_changes_after_on_initialize() {
|
||||
new_test_ext(Default::default()).execute_with(|| {
|
||||
Initializer::on_initialize(1);
|
||||
Initializer::on_new_session(false, Vec::new().into_iter(), Vec::new().into_iter());
|
||||
Initializer::on_new_session(
|
||||
false,
|
||||
1,
|
||||
Vec::new().into_iter(),
|
||||
Some(Vec::new().into_iter()),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user