mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 05:51:02 +00:00
Parachains shared.rs to Frame V2 (#3425)
* gotta migrate them all * migrate rococo construct_runtime * trigger ci * fix warnings * get mocks to work * add pallet to test runtime * comments * calm down mr tabrizi lol
This commit is contained in:
@@ -730,7 +730,7 @@ impl<T: Config> Module<T> {
|
||||
|
||||
/// Return the session index that should be used for any future scheduled changes.
|
||||
fn scheduled_session() -> SessionIndex {
|
||||
shared::Module::<T>::scheduled_session()
|
||||
shared::Pallet::<T>::scheduled_session()
|
||||
}
|
||||
|
||||
/// Forcibly set the active config. This should be used with extreme care, and typically
|
||||
|
||||
@@ -1292,7 +1292,7 @@ impl<T: Config> Pallet<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
new_test_ext, Test, Configuration, Paras, Shared, Hrmp, System, MockGenesisConfig,
|
||||
new_test_ext, Test, Configuration, Paras, ParasShared, Hrmp, System, MockGenesisConfig,
|
||||
Event as MockEvent,
|
||||
};
|
||||
use frame_support::{assert_noop, assert_ok, traits::Currency as _};
|
||||
@@ -1308,18 +1308,18 @@ mod tests {
|
||||
// NOTE: this is in reverse initialization order.
|
||||
Hrmp::initializer_finalize();
|
||||
Paras::initializer_finalize();
|
||||
Shared::initializer_finalize();
|
||||
ParasShared::initializer_finalize();
|
||||
|
||||
if new_session.as_ref().map_or(false, |v| v.contains(&(b + 1))) {
|
||||
let notification = crate::initializer::SessionChangeNotification {
|
||||
prev_config: config.clone(),
|
||||
new_config: config.clone(),
|
||||
session_index: Shared::session_index() + 1,
|
||||
session_index: ParasShared::session_index() + 1,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// NOTE: this is in initialization order.
|
||||
Shared::initializer_on_new_session(
|
||||
ParasShared::initializer_on_new_session(
|
||||
notification.session_index,
|
||||
notification.random_seed,
|
||||
¬ification.new_config,
|
||||
@@ -1335,7 +1335,7 @@ mod tests {
|
||||
System::set_block_number(b + 1);
|
||||
|
||||
// NOTE: this is in initialization order.
|
||||
Shared::initializer_initialize(b + 1);
|
||||
ParasShared::initializer_initialize(b + 1);
|
||||
Paras::initializer_initialize(b + 1);
|
||||
Hrmp::initializer_initialize(b + 1);
|
||||
}
|
||||
|
||||
@@ -253,8 +253,8 @@ impl<T: Config> Pallet<T> {
|
||||
unchecked_bitfields: UncheckedSignedAvailabilityBitfields,
|
||||
core_lookup: impl Fn(CoreIndex) -> Option<ParaId>,
|
||||
) -> Result<Vec<(CoreIndex, CandidateHash)>, DispatchError> {
|
||||
let validators = shared::Module::<T>::active_validator_keys();
|
||||
let session_index = shared::Module::<T>::session_index();
|
||||
let validators = shared::Pallet::<T>::active_validator_keys();
|
||||
let session_index = shared::Pallet::<T>::session_index();
|
||||
|
||||
let mut assigned_paras_record: Vec<_> = (0..expected_bits)
|
||||
.map(|bit_index| core_lookup(CoreIndex::from(bit_index as u32)))
|
||||
@@ -407,7 +407,7 @@ impl<T: Config> Pallet<T> {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
|
||||
let validators = shared::Module::<T>::active_validator_keys();
|
||||
let validators = shared::Pallet::<T>::active_validator_keys();
|
||||
let parent_hash = <frame_system::Pallet<T>>::parent_hash();
|
||||
|
||||
// At the moment we assume (and in fact enforce, below) that the relay-parent is always one
|
||||
@@ -434,7 +434,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let signing_context = SigningContext {
|
||||
parent_hash,
|
||||
session_index: shared::Module::<T>::session_index(),
|
||||
session_index: shared::Pallet::<T>::session_index(),
|
||||
};
|
||||
|
||||
// We combine an outer loop over candidates with an inner loop over the scheduled,
|
||||
@@ -951,7 +951,7 @@ mod tests {
|
||||
use sc_keystore::LocalKeystore;
|
||||
use crate::mock::{
|
||||
new_test_ext, Configuration, Paras, System, ParaInclusion,
|
||||
MockGenesisConfig, Test, Shared,
|
||||
MockGenesisConfig, Test, ParasShared,
|
||||
};
|
||||
use crate::initializer::SessionChangeNotification;
|
||||
use crate::configuration::HostConfiguration;
|
||||
@@ -1080,10 +1080,10 @@ mod tests {
|
||||
|
||||
ParaInclusion::initializer_finalize();
|
||||
Paras::initializer_finalize();
|
||||
Shared::initializer_finalize();
|
||||
ParasShared::initializer_finalize();
|
||||
|
||||
if let Some(notification) = new_session(b + 1) {
|
||||
Shared::initializer_on_new_session(
|
||||
ParasShared::initializer_on_new_session(
|
||||
notification.session_index,
|
||||
notification.random_seed,
|
||||
¬ification.new_config,
|
||||
@@ -1098,7 +1098,7 @@ mod tests {
|
||||
System::on_initialize(b + 1);
|
||||
System::set_block_number(b + 1);
|
||||
|
||||
Shared::initializer_initialize(b + 1);
|
||||
ParasShared::initializer_initialize(b + 1);
|
||||
Paras::initializer_initialize(b + 1);
|
||||
ParaInclusion::initializer_initialize(b + 1);
|
||||
}
|
||||
@@ -1113,11 +1113,11 @@ mod tests {
|
||||
}
|
||||
|
||||
fn default_availability_votes() -> BitVec<BitOrderLsb0, u8> {
|
||||
bitvec::bitvec![BitOrderLsb0, u8; 0; Shared::active_validator_keys().len()]
|
||||
bitvec::bitvec![BitOrderLsb0, u8; 0; ParasShared::active_validator_keys().len()]
|
||||
}
|
||||
|
||||
fn default_backing_bitfield() -> BitVec<BitOrderLsb0, u8> {
|
||||
bitvec::bitvec![BitOrderLsb0, u8; 0; Shared::active_validator_keys().len()]
|
||||
bitvec::bitvec![BitOrderLsb0, u8; 0; ParasShared::active_validator_keys().len()]
|
||||
}
|
||||
|
||||
fn backing_bitfield(v: &[usize]) -> BitVec<BitOrderLsb0, u8> {
|
||||
@@ -1264,8 +1264,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
let signing_context = SigningContext {
|
||||
parent_hash: System::parent_hash(),
|
||||
@@ -1498,8 +1498,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
let signing_context = SigningContext {
|
||||
parent_hash: System::parent_hash(),
|
||||
@@ -1663,8 +1663,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
run_to_block(5, |_| None);
|
||||
|
||||
@@ -2187,8 +2187,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
run_to_block(5, |_| None);
|
||||
|
||||
@@ -2384,8 +2384,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
run_to_block(5, |_| None);
|
||||
|
||||
@@ -2481,8 +2481,8 @@ mod tests {
|
||||
let validator_public = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(genesis_config(paras)).execute_with(|| {
|
||||
shared::Module::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Module::<Test>::set_session_index(5);
|
||||
shared::Pallet::<Test>::set_active_validators_ascending(validator_public.clone());
|
||||
shared::Pallet::<Test>::set_session_index(5);
|
||||
|
||||
let validators_new = vec![
|
||||
Sr25519Keyring::Alice,
|
||||
@@ -2545,7 +2545,7 @@ mod tests {
|
||||
|
||||
run_to_block(11, |_| None);
|
||||
|
||||
assert_eq!(shared::Module::<Test>::session_index(), 5);
|
||||
assert_eq!(shared::Pallet::<Test>::session_index(), 5);
|
||||
|
||||
assert!(<AvailabilityBitfields<Test>>::get(&ValidatorIndex(0)).is_some());
|
||||
assert!(<AvailabilityBitfields<Test>>::get(&ValidatorIndex(1)).is_some());
|
||||
@@ -2568,7 +2568,7 @@ mod tests {
|
||||
_ => None,
|
||||
});
|
||||
|
||||
assert_eq!(shared::Module::<Test>::session_index(), 6);
|
||||
assert_eq!(shared::Pallet::<Test>::session_index(), 6);
|
||||
|
||||
assert!(<AvailabilityBitfields<Test>>::get(&ValidatorIndex(0)).is_none());
|
||||
assert!(<AvailabilityBitfields<Test>>::get(&ValidatorIndex(1)).is_none());
|
||||
|
||||
@@ -133,7 +133,7 @@ pub mod pallet {
|
||||
// - UMP
|
||||
// - HRMP
|
||||
let total_weight = configuration::Module::<T>::initializer_initialize(now) +
|
||||
shared::Module::<T>::initializer_initialize(now) +
|
||||
shared::Pallet::<T>::initializer_initialize(now) +
|
||||
paras::Pallet::<T>::initializer_initialize(now) +
|
||||
scheduler::Module::<T>::initializer_initialize(now) +
|
||||
inclusion::Pallet::<T>::initializer_initialize(now) +
|
||||
@@ -158,7 +158,7 @@ pub mod pallet {
|
||||
inclusion::Pallet::<T>::initializer_finalize();
|
||||
scheduler::Module::<T>::initializer_finalize();
|
||||
paras::Pallet::<T>::initializer_finalize();
|
||||
shared::Module::<T>::initializer_finalize();
|
||||
shared::Pallet::<T>::initializer_finalize();
|
||||
configuration::Module::<T>::initializer_finalize();
|
||||
|
||||
// Apply buffered session changes as the last thing. This way the runtime APIs and the
|
||||
@@ -217,7 +217,7 @@ impl<T: Config> Pallet<T> {
|
||||
|
||||
let new_config = <configuration::Module<T>>::config();
|
||||
|
||||
let validators = shared::Module::<T>::initializer_on_new_session(
|
||||
let validators = shared::Pallet::<T>::initializer_on_new_session(
|
||||
session_index,
|
||||
random_seed.clone(),
|
||||
&new_config,
|
||||
|
||||
@@ -47,7 +47,7 @@ frame_support::construct_runtime!(
|
||||
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
|
||||
Paras: paras::{Pallet, Origin, Call, Storage, Event, Config},
|
||||
Configuration: configuration::{Pallet, Call, Storage, Config<T>},
|
||||
Shared: shared::{Pallet, Call, Storage},
|
||||
ParasShared: shared::{Pallet, Call, Storage},
|
||||
ParaInclusion: inclusion::{Pallet, Call, Storage, Event<T>},
|
||||
Scheduler: scheduler::{Pallet, Call, Storage},
|
||||
Initializer: initializer::{Pallet, Call, Storage},
|
||||
|
||||
@@ -1016,18 +1016,18 @@ mod tests {
|
||||
use primitives::v1::BlockNumber;
|
||||
use frame_support::assert_ok;
|
||||
|
||||
use crate::mock::{new_test_ext, Paras, Shared, System, MockGenesisConfig};
|
||||
use crate::mock::{new_test_ext, Paras, ParasShared, System, MockGenesisConfig};
|
||||
use crate::configuration::HostConfiguration;
|
||||
|
||||
fn run_to_block(to: BlockNumber, new_session: Option<Vec<BlockNumber>>) {
|
||||
while System::block_number() < to {
|
||||
let b = System::block_number();
|
||||
Paras::initializer_finalize();
|
||||
Shared::initializer_finalize();
|
||||
ParasShared::initializer_finalize();
|
||||
if new_session.as_ref().map_or(false, |v| v.contains(&(b + 1))) {
|
||||
let mut session_change_notification = SessionChangeNotification::default();
|
||||
session_change_notification.session_index = Shared::session_index() + 1;
|
||||
Shared::initializer_on_new_session(
|
||||
session_change_notification.session_index = ParasShared::session_index() + 1;
|
||||
ParasShared::initializer_on_new_session(
|
||||
session_change_notification.session_index,
|
||||
session_change_notification.random_seed,
|
||||
&session_change_notification.new_config,
|
||||
@@ -1040,7 +1040,7 @@ mod tests {
|
||||
System::on_initialize(b + 1);
|
||||
System::set_block_number(b + 1);
|
||||
|
||||
Shared::initializer_initialize(b + 1);
|
||||
ParasShared::initializer_initialize(b + 1);
|
||||
Paras::initializer_initialize(b + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ decl_module! {
|
||||
);
|
||||
|
||||
// Handle disputes logic.
|
||||
let current_session = <shared::Module<T>>::session_index();
|
||||
let current_session = <shared::Pallet<T>>::session_index();
|
||||
let freed_disputed: Vec<(_, FreedReason)> = {
|
||||
let fresh_disputes = T::DisputesHandler::provide_multi_dispute_data(disputes)?;
|
||||
if T::DisputesHandler::is_frozen() {
|
||||
|
||||
@@ -35,7 +35,7 @@ fn validators_to_reward<C, T, I>(validators: &'_ [T], indirect_indices: I) -> im
|
||||
C: shared::Config,
|
||||
I: IntoIterator<Item = ValidatorIndex>
|
||||
{
|
||||
let validator_indirection = <shared::Module<C>>::active_validator_indices();
|
||||
let validator_indirection = <shared::Pallet<C>>::active_validator_indices();
|
||||
|
||||
indirect_indices.into_iter()
|
||||
.filter_map(move |i| validator_indirection.get(i.0 as usize).map(|v| v.clone()))
|
||||
@@ -65,7 +65,7 @@ mod tests {
|
||||
use super::*;
|
||||
use primitives::v1::ValidatorId;
|
||||
use crate::configuration::HostConfiguration;
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, Shared, Test};
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, ParasShared, Test};
|
||||
use keyring::Sr25519Keyring;
|
||||
|
||||
#[test]
|
||||
@@ -88,7 +88,7 @@ mod tests {
|
||||
|
||||
let pubkeys = validator_pubkeys(&validators);
|
||||
|
||||
let shuffled_pubkeys = Shared::initializer_on_new_session(
|
||||
let shuffled_pubkeys = ParasShared::initializer_on_new_session(
|
||||
1,
|
||||
[1; 32],
|
||||
&config,
|
||||
@@ -107,7 +107,7 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Shared::active_validator_indices(),
|
||||
ParasShared::active_validator_indices(),
|
||||
vec![
|
||||
ValidatorIndex(4),
|
||||
ValidatorIndex(1),
|
||||
|
||||
@@ -32,7 +32,7 @@ use crate::{initializer, inclusion, scheduler, configuration, paras, session_inf
|
||||
|
||||
/// Implementation for the `validators` function of the runtime API.
|
||||
pub fn validators<T: initializer::Config>() -> Vec<ValidatorId> {
|
||||
<shared::Module<T>>::active_validator_keys()
|
||||
<shared::Pallet<T>>::active_validator_keys()
|
||||
}
|
||||
|
||||
/// Implementation for the `validator_groups` function of the runtime API.
|
||||
@@ -231,7 +231,7 @@ pub fn session_index_for_child<T: initializer::Config>() -> SessionIndex {
|
||||
//
|
||||
// Incidentally, this is also the rationale for why it is OK to query validators or
|
||||
// occupied cores or etc. and expect the correct response "for child".
|
||||
<shared::Module<T>>::session_index()
|
||||
<shared::Pallet<T>>::session_index()
|
||||
}
|
||||
|
||||
/// Implementation for the `AuthorityDiscoveryApi::authorities()` function of the runtime API.
|
||||
|
||||
@@ -740,7 +740,7 @@ mod tests {
|
||||
};
|
||||
use keyring::Sr25519Keyring;
|
||||
|
||||
use crate::mock::{new_test_ext, Configuration, Paras, Shared, System, Scheduler, MockGenesisConfig};
|
||||
use crate::mock::{new_test_ext, Configuration, Paras, ParasShared, System, Scheduler, MockGenesisConfig};
|
||||
use crate::initializer::SessionChangeNotification;
|
||||
use crate::configuration::HostConfiguration;
|
||||
use crate::paras::ParaGenesisArgs;
|
||||
@@ -767,7 +767,7 @@ mod tests {
|
||||
let mut notification_with_session_index = notification;
|
||||
// We will make every session change trigger an action queue. Normally this may require 2 or more session changes.
|
||||
if notification_with_session_index.session_index == SessionIndex::default() {
|
||||
notification_with_session_index.session_index = Shared::scheduled_session();
|
||||
notification_with_session_index.session_index = ParasShared::scheduled_session();
|
||||
}
|
||||
Paras::initializer_on_new_session(¬ification_with_session_index);
|
||||
Scheduler::initializer_on_new_session(¬ification_with_session_index);
|
||||
|
||||
@@ -89,7 +89,7 @@ impl<T: Config> Module<T> {
|
||||
let validators = notification.validators.clone();
|
||||
let discovery_keys = <T as AuthorityDiscoveryConfig>::authorities();
|
||||
let assignment_keys = AssignmentKeysUnsafe::get();
|
||||
let active_set = <shared::Module<T>>::active_validator_indices();
|
||||
let active_set = <shared::Pallet<T>>::active_validator_indices();
|
||||
|
||||
let validator_groups = <scheduler::Module<T>>::validator_groups();
|
||||
let n_cores = <scheduler::Module<T>>::availability_cores().len() as u32;
|
||||
@@ -169,7 +169,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
new_test_ext, Configuration, SessionInfo, System, MockGenesisConfig,
|
||||
Origin, Shared,
|
||||
Origin, ParasShared,
|
||||
};
|
||||
use crate::initializer::SessionChangeNotification;
|
||||
use crate::configuration::HostConfiguration;
|
||||
@@ -185,14 +185,14 @@ mod tests {
|
||||
let b = System::block_number();
|
||||
|
||||
SessionInfo::initializer_finalize();
|
||||
Shared::initializer_finalize();
|
||||
ParasShared::initializer_finalize();
|
||||
Configuration::initializer_finalize();
|
||||
|
||||
if let Some(notification) = new_session(b + 1) {
|
||||
Configuration::initializer_on_new_session(
|
||||
¬ification.session_index,
|
||||
);
|
||||
Shared::initializer_on_new_session(
|
||||
ParasShared::initializer_on_new_session(
|
||||
notification.session_index,
|
||||
notification.random_seed,
|
||||
¬ification.new_config,
|
||||
@@ -207,7 +207,7 @@ mod tests {
|
||||
System::set_block_number(b + 1);
|
||||
|
||||
Configuration::initializer_initialize(b + 1);
|
||||
Shared::initializer_initialize(b + 1);
|
||||
ParasShared::initializer_initialize(b + 1);
|
||||
SessionInfo::initializer_initialize(b + 1);
|
||||
}
|
||||
}
|
||||
@@ -342,12 +342,12 @@ mod tests {
|
||||
let validators = take_active_subset(&active_set, &unscrambled_validators);
|
||||
|
||||
new_test_ext(genesis_config()).execute_with(|| {
|
||||
Shared::set_active_validators_with_indices(
|
||||
ParasShared::set_active_validators_with_indices(
|
||||
active_set.clone(),
|
||||
validators.clone(),
|
||||
);
|
||||
|
||||
assert_eq!(Shared::active_validator_indices(), active_set);
|
||||
assert_eq!(ParasShared::active_validator_indices(), active_set);
|
||||
|
||||
AssignmentKeysUnsafe::set(unscrambled_assignment.clone());
|
||||
crate::mock::set_discovery_authorities(unscrambled_discovery.clone());
|
||||
|
||||
@@ -14,16 +14,13 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! A module for any shared state that other pallets may want access to.
|
||||
//! A pallet for any shared state that other pallets may want access to.
|
||||
//!
|
||||
//! To avoid cyclic dependencies, it is important that this module is not
|
||||
//! dependent on any of the other modules.
|
||||
//! To avoid cyclic dependencies, it is important that this pallet is not
|
||||
//! dependent on any of the other pallets.
|
||||
|
||||
use primitives::v1::{SessionIndex, ValidatorId, ValidatorIndex};
|
||||
use frame_support::{
|
||||
decl_storage, decl_module, decl_error,
|
||||
weights::Weight,
|
||||
};
|
||||
use frame_support::pallet_prelude::*;
|
||||
use sp_std::vec::Vec;
|
||||
|
||||
use rand::{SeedableRng, seq::SliceRandom};
|
||||
@@ -31,44 +28,52 @@ use rand_chacha::ChaCha20Rng;
|
||||
|
||||
use crate::configuration::HostConfiguration;
|
||||
|
||||
pub trait Config: frame_system::Config { }
|
||||
pub use pallet::*;
|
||||
|
||||
// `SESSION_DELAY` is used to delay any changes to Paras registration or configurations.
|
||||
// Wait until the session index is 2 larger then the current index to apply any changes,
|
||||
// which guarantees that at least one full session has passed before any changes are applied.
|
||||
pub(crate) const SESSION_DELAY: SessionIndex = 2;
|
||||
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Config> as ParasShared {
|
||||
/// The current session index.
|
||||
CurrentSessionIndex get(fn session_index): SessionIndex;
|
||||
/// All the validators actively participating in parachain consensus.
|
||||
/// Indices are into the broader validator set.
|
||||
ActiveValidatorIndices get(fn active_validator_indices): Vec<ValidatorIndex>;
|
||||
/// The parachain attestation keys of the validators actively participating in parachain consensus.
|
||||
/// This should be the same length as `ActiveValidatorIndices`.
|
||||
ActiveValidatorKeys get(fn active_validator_keys): Vec<ValidatorId>;
|
||||
}
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
pub struct Pallet<T>(_);
|
||||
|
||||
#[pallet::config]
|
||||
pub trait Config: frame_system::Config {}
|
||||
|
||||
/// The current session index.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn session_index)]
|
||||
pub(super) type CurrentSessionIndex<T: Config> = StorageValue<_, SessionIndex, ValueQuery>;
|
||||
|
||||
/// All the validators actively participating in parachain consensus.
|
||||
/// Indices are into the broader validator set.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn active_validator_indices)]
|
||||
pub(super) type ActiveValidatorIndices<T: Config> = StorageValue<_, Vec<ValidatorIndex>, ValueQuery>;
|
||||
|
||||
/// The parachain attestation keys of the validators actively participating in parachain consensus.
|
||||
/// This should be the same length as `ActiveValidatorIndices`.
|
||||
#[pallet::storage]
|
||||
#[pallet::getter(fn active_validator_keys)]
|
||||
pub(super) type ActiveValidatorKeys<T: Config> = StorageValue<_, Vec<ValidatorId>, ValueQuery>;
|
||||
|
||||
#[pallet::call]
|
||||
impl<T: Config> Pallet<T> {}
|
||||
}
|
||||
|
||||
decl_error! {
|
||||
pub enum Error for Module<T: Config> { }
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
/// The session info module.
|
||||
pub struct Module<T: Config> for enum Call where origin: <T as frame_system::Config>::Origin {
|
||||
type Error = Error<T>;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config> Module<T> {
|
||||
/// Called by the initializer to initialize the configuration module.
|
||||
impl<T: Config> Pallet<T> {
|
||||
/// Called by the initializer to initialize the configuration pallet.
|
||||
pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight {
|
||||
0
|
||||
}
|
||||
|
||||
/// Called by the initializer to finalize the configuration module.
|
||||
/// Called by the initializer to finalize the configuration pallet.
|
||||
pub(crate) fn initializer_finalize() { }
|
||||
|
||||
/// Called by the initializer to note that a new session has started.
|
||||
@@ -80,7 +85,7 @@ impl<T: Config> Module<T> {
|
||||
new_config: &HostConfiguration<T::BlockNumber>,
|
||||
all_validators: Vec<ValidatorId>,
|
||||
) -> Vec<ValidatorId> {
|
||||
CurrentSessionIndex::set(session_index);
|
||||
CurrentSessionIndex::<T>::set(session_index);
|
||||
let mut rng: ChaCha20Rng = SeedableRng::from_seed(random_seed);
|
||||
|
||||
let mut shuffled_indices: Vec<_> = (0..all_validators.len())
|
||||
@@ -99,8 +104,8 @@ impl<T: Config> Module<T> {
|
||||
&all_validators,
|
||||
);
|
||||
|
||||
ActiveValidatorIndices::set(shuffled_indices);
|
||||
ActiveValidatorKeys::set(active_validator_keys.clone());
|
||||
ActiveValidatorIndices::<T>::set(shuffled_indices);
|
||||
ActiveValidatorKeys::<T>::set(active_validator_keys.clone());
|
||||
|
||||
active_validator_keys
|
||||
}
|
||||
@@ -113,15 +118,15 @@ impl<T: Config> Module<T> {
|
||||
/// Test function for setting the current session index.
|
||||
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]
|
||||
pub fn set_session_index(index: SessionIndex) {
|
||||
CurrentSessionIndex::set(index);
|
||||
CurrentSessionIndex::<T>::set(index);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub(crate) fn set_active_validators_ascending(active: Vec<ValidatorId>) {
|
||||
ActiveValidatorIndices::set(
|
||||
ActiveValidatorIndices::<T>::set(
|
||||
(0..active.len()).map(|i| ValidatorIndex(i as _)).collect()
|
||||
);
|
||||
ActiveValidatorKeys::set(active);
|
||||
ActiveValidatorKeys::<T>::set(active);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -130,8 +135,8 @@ impl<T: Config> Module<T> {
|
||||
keys: Vec<ValidatorId>,
|
||||
) {
|
||||
assert_eq!(indices.len(), keys.len());
|
||||
ActiveValidatorIndices::set(indices);
|
||||
ActiveValidatorKeys::set(keys);
|
||||
ActiveValidatorIndices::<T>::set(indices);
|
||||
ActiveValidatorKeys::<T>::set(keys);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +144,7 @@ impl<T: Config> Module<T> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::configuration::HostConfiguration;
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, Shared};
|
||||
use crate::mock::{new_test_ext, MockGenesisConfig, ParasShared};
|
||||
use keyring::Sr25519Keyring;
|
||||
|
||||
fn validator_pubkeys(val_ids: &[Sr25519Keyring]) -> Vec<ValidatorId> {
|
||||
@@ -162,7 +167,7 @@ mod tests {
|
||||
let pubkeys = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
|
||||
let validators = Shared::initializer_on_new_session(
|
||||
let validators = ParasShared::initializer_on_new_session(
|
||||
1,
|
||||
[1; 32],
|
||||
&config,
|
||||
@@ -181,12 +186,12 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Shared::active_validator_keys(),
|
||||
ParasShared::active_validator_keys(),
|
||||
validators,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Shared::active_validator_indices(),
|
||||
ParasShared::active_validator_indices(),
|
||||
vec![
|
||||
ValidatorIndex(4),
|
||||
ValidatorIndex(1),
|
||||
@@ -214,7 +219,7 @@ mod tests {
|
||||
let pubkeys = validator_pubkeys(&validators);
|
||||
|
||||
new_test_ext(MockGenesisConfig::default()).execute_with(|| {
|
||||
let validators = Shared::initializer_on_new_session(
|
||||
let validators = ParasShared::initializer_on_new_session(
|
||||
1,
|
||||
[1; 32],
|
||||
&config,
|
||||
@@ -230,12 +235,12 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Shared::active_validator_keys(),
|
||||
ParasShared::active_validator_keys(),
|
||||
validators,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
Shared::active_validator_indices(),
|
||||
ParasShared::active_validator_indices(),
|
||||
vec![
|
||||
ValidatorIndex(4),
|
||||
ValidatorIndex(1),
|
||||
|
||||
Reference in New Issue
Block a user