mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-22 19:41:07 +00:00
session: add handler for genesis session (#3413)
* session: add handler for genesis session * node: bump spec version * aura: handle on_genesis_session * srml: make sure we don't re-initialize genesis authorities * session: fix mock * node: remove genesis authorities from chain spec * staking: fix mock * srml: don't initialize genesis authorities twice * aura: don't reinitialize genesis authorities * aura: fix runtime_io dependency * Bump runtime
This commit is contained in:
committed by
Svyatoslav Nikolsky
parent
3590c9c33f
commit
d1dde7e087
@@ -10,6 +10,7 @@ codec = { package = "parity-scale-codec", version = "1.0.0", default-features =
|
||||
primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false }
|
||||
substrate-finality-grandpa-primitives = { path = "../../core/finality-grandpa/primitives", default-features = false }
|
||||
rstd = { package = "sr-std", path = "../../core/sr-std", default-features = false }
|
||||
runtime_io = { package = "sr-io", path = "../../core/sr-io", default-features = false, features = [ "wasm-nice-panic-message" ] }
|
||||
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
|
||||
srml-support = { path = "../support", default-features = false }
|
||||
system = { package = "srml-system", path = "../system", default-features = false }
|
||||
|
||||
@@ -133,7 +133,7 @@ decl_event!(
|
||||
decl_storage! {
|
||||
trait Store for Module<T: Trait> as GrandpaFinality {
|
||||
/// The current authority set.
|
||||
Authorities get(authorities) config(): Vec<(AuthorityId, AuthorityWeight)>;
|
||||
Authorities get(authorities): Vec<(AuthorityId, AuthorityWeight)>;
|
||||
|
||||
/// State of the current authority set.
|
||||
State get(state): StoredState<T::BlockNumber> = StoredState::Live;
|
||||
@@ -147,6 +147,18 @@ decl_storage! {
|
||||
/// `true` if we are currently stalled.
|
||||
Stalled get(stalled): Option<(T::BlockNumber, T::BlockNumber)>;
|
||||
}
|
||||
add_extra_genesis {
|
||||
config(authorities): Vec<(AuthorityId, AuthorityWeight)>;
|
||||
build(|
|
||||
storage: &mut (sr_primitives::StorageOverlay, sr_primitives::ChildrenStorageOverlay),
|
||||
config: &GenesisConfig
|
||||
| {
|
||||
runtime_io::with_storage(
|
||||
storage,
|
||||
|| Module::<T>::initialize_authorities(&config.authorities),
|
||||
);
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
decl_module! {
|
||||
@@ -310,6 +322,13 @@ impl<T: Trait> Module<T> {
|
||||
let log: DigestItem<T::Hash> = DigestItem::Consensus(GRANDPA_ENGINE_ID, log.encode());
|
||||
<system::Module<T>>::deposit_log(log.into());
|
||||
}
|
||||
|
||||
fn initialize_authorities(authorities: &[(AuthorityId, AuthorityWeight)]) {
|
||||
if !authorities.is_empty() {
|
||||
assert!(Authorities::get().is_empty(), "Authorities are already initialized!");
|
||||
Authorities::put_ref(authorities);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Trait> Module<T> {
|
||||
@@ -346,12 +365,19 @@ impl<T: Trait> Module<T> {
|
||||
impl<T: Trait> session::OneSessionHandler<T::AccountId> for Module<T> {
|
||||
type Key = AuthorityId;
|
||||
|
||||
fn on_genesis_session<'a, I: 'a>(validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, AuthorityId)>
|
||||
{
|
||||
let authorities = validators.map(|(_, k)| (k, 1)).collect::<Vec<_>>();
|
||||
Self::initialize_authorities(&authorities);
|
||||
}
|
||||
|
||||
fn on_new_session<'a, I: 'a>(changed: bool, validators: I, _queued_validators: I)
|
||||
where I: Iterator<Item=(&'a T::AccountId, AuthorityId)>
|
||||
{
|
||||
// instant changes
|
||||
if changed {
|
||||
let next_authorities = validators.map(|(_, k)| (k, 1u64)).collect::<Vec<_>>();
|
||||
let next_authorities = validators.map(|(_, k)| (k, 1)).collect::<Vec<_>>();
|
||||
let last_authorities = <Module<T>>::grandpa_authorities();
|
||||
if next_authorities != last_authorities {
|
||||
if let Some((further_wait, median)) = <Stalled<T>>::take() {
|
||||
|
||||
@@ -85,7 +85,7 @@ pub fn new_test_ext(authorities: Vec<(u64, u64)>) -> runtime_io::TestExternaliti
|
||||
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
|
||||
GenesisConfig {
|
||||
authorities: to_authorities(authorities),
|
||||
}.assimilate_storage(&mut t).unwrap();
|
||||
}.assimilate_storage::<Test>(&mut t).unwrap();
|
||||
t.into()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user