Skip to content

Commit

Permalink
add possibility to inject non-authorities session-keys in genesis (pa…
Browse files Browse the repository at this point in the history
…ritytech#5078)

Add the possibility of injecting session-keys in genesis for
non-validators. Currently all keys injected in genesis were considered
as part of the initial validators set, this PR allows to inject a new
vector with non-authority keys

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
2 people authored and TarekkMA committed Aug 2, 2024
1 parent e9d6abd commit a9f10c3
Show file tree
Hide file tree
Showing 29 changed files with 76 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cumulus/pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
candidacy_bond: 10,
invulnerables,
};
let session = pallet_session::GenesisConfig::<Test> { keys };
let session = pallet_session::GenesisConfig::<Test> { keys, ..Default::default() };
pallet_balances::GenesisConfig::<Test> { balances }
.assimilate_storage(&mut t)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: asset_hub_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: asset_hub_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: bridge_hub_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: bridge_hub_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: collectives_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: coretime_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: coretime_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: people_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub fn genesis() -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: people_westend_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn genesis(para_id: u32) -> Storage {
)
})
.collect(),
..Default::default()
},
polkadot_xcm: penpal_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub fn genesis() -> Storage {
)
})
.collect::<Vec<_>>(),
..Default::default()
},
babe: rococo_runtime::BabeConfig {
authorities: Default::default(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub fn genesis() -> Storage {
)
})
.collect::<Vec<_>>(),
..Default::default()
},
staking: westend_runtime::StakingConfig {
validator_count: validators::initial_authorities().len() as u32,
Expand Down
2 changes: 1 addition & 1 deletion cumulus/parachains/runtimes/test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<Runtime: BasicParachainRuntime> ExtBuilder<Runtime> {
.assimilate_storage(&mut t)
.unwrap();

pallet_session::GenesisConfig::<Runtime> { keys: self.keys }
pallet_session::GenesisConfig::<Runtime> { keys: self.keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ fn asset_hub_rococo_genesis(
)
})
.collect(),
..Default::default()
},
"polkadotXcm": asset_hub_rococo_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
Expand Down
34 changes: 34 additions & 0 deletions prdoc/pr_5078.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
title: Add possibility to inject non-authorities session-keys in genesis

doc:
- audience: Runtime Dev
description: |
Allows to inject a set of registered session-keys in pallet-session that are not
part of the first initial set of validators
crates:
- name: pallet-session
bump: major
- name: parachains-runtimes-test-utils
bump: patch
- name: pallet-staking
bump: none
- name: pallet-collator-selection
bump: none
- name: pallet-root-offences
bump: none
- name: pallet-babe
bump: none
- name: pallet-staking
bump: none
- name: pallet-grandpa
bump: none
- name: pallet-collator-selection
bump: none
- name: pallet-beefy
bump: none
- name: pallet-beefy-mmr
bump: none
- name: pallet-root-offences
bump: none
- name: polkadot-parachain-bin
bump: none
4 changes: 3 additions & 1 deletion substrate/bin/node/cli/tests/res/default_genesis_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
"maxNominatorCount": null
},
"session": {
"keys": []
"keys": [],
"nonAuthorityKeys": []

},
"democracy": {},
"council": {
Expand Down
1 change: 1 addition & 0 deletions substrate/bin/node/testing/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub fn config_endowed(extra_endowed: Vec<AccountId>) -> RuntimeGenesisConfig {
(bob(), eve(), session_keys_from_seed(Ed25519Keyring::Bob.into())),
(charlie(), ferdie(), session_keys_from_seed(Ed25519Keyring::Charlie.into())),
],
..Default::default()
},
staking: StakingConfig {
stakers: vec![
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/babe/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<AuthorityId>) -> sp_io::Tes

// NOTE: this will initialize the babe authorities
// through OneSessionHandler::on_genesis_session
pallet_session::GenesisConfig::<Test> { keys: session_keys }
pallet_session::GenesisConfig::<Test> { keys: session_keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/beefy-mmr/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestExt
}
});

pallet_session::GenesisConfig::<Test> { keys: session_keys }
pallet_session::GenesisConfig::<Test> { keys: session_keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl ExtBuilder {
}
});

pallet_session::GenesisConfig::<Test> { keys: session_keys }
pallet_session::GenesisConfig::<Test> { keys: session_keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ impl ExtBuilder {
.into_iter()
.map(|(id, ..)| (id, id, SessionKeys { other: (id as u64).into() }))
.collect(),
..Default::default()
}
.assimilate_storage(&mut storage);

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/grandpa/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ pub fn new_test_ext_raw_authorities(authorities: AuthorityList) -> sp_io::TestEx

// NOTE: this will initialize the grandpa authorities
// through OneSessionHandler::on_genesis_session
pallet_session::GenesisConfig::<Test> { keys: session_keys }
pallet_session::GenesisConfig::<Test> { keys: session_keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/root-offences/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ impl ExtBuilder {
.into_iter()
.map(|(id, ..)| (id, id, SessionKeys { other: id.into() }))
.collect(),
..Default::default()
}
.assimilate_storage(&mut storage);

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/session/src/historical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ pub(crate) mod tests {
frame_system::Pallet::<Test>::inc_providers(k);
}
});
pallet_session::GenesisConfig::<Test> { keys }
pallet_session::GenesisConfig::<Test> { keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();
sp_io::TestExternalities::new(t)
Expand Down
4 changes: 3 additions & 1 deletion substrate/frame/session/src/historical/offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ mod tests {
}
});

crate::GenesisConfig::<Test> { keys }.assimilate_storage(&mut t).unwrap();
crate::GenesisConfig::<Test> { keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

let mut ext = sp_io::TestExternalities::new(t);

Expand Down
13 changes: 11 additions & 2 deletions substrate/frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,14 @@ pub mod pallet {
#[pallet::genesis_config]
#[derive(frame_support::DefaultNoBound)]
pub struct GenesisConfig<T: Config> {
/// Initial list of validator at genesis representing by their `(AccountId, ValidatorId,
/// Keys)`. These keys will be considered authorities for the first two sessions and they
/// will be valid at least until session 2
pub keys: Vec<(T::AccountId, T::ValidatorId, T::Keys)>,
/// List of (AccountId, ValidatorId, Keys) that will be registered at genesis, but not as
/// active validators. These keys are set, together with `keys`, as authority candidates
/// for future sessions (enactable from session 2 onwards)
pub non_authority_keys: Vec<(T::AccountId, T::ValidatorId, T::Keys)>,
}

#[pallet::genesis_build]
Expand All @@ -446,7 +453,9 @@ pub mod pallet {
}
});

for (account, val, keys) in self.keys.iter().cloned() {
for (account, val, keys) in
self.keys.iter().chain(self.non_authority_keys.iter()).cloned()
{
Pallet::<T>::inner_set_keys(&val, keys)
.expect("genesis config must not contain duplicates; qed");
if frame_system::Pallet::<T>::inc_consumers_without_limit(&account).is_err() {
Expand Down Expand Up @@ -676,7 +685,7 @@ impl<T: Config> Pallet<T> {
let mut now_session_keys = session_keys.iter();
let mut check_next_changed = |keys: &T::Keys| {
if changed {
return
return;
}
// since a new validator set always leads to `changed` starting
// as true, we can ensure that `now_session_keys` and `next_validators`
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/session/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
// An additional identity that we use.
frame_system::Pallet::<Test>::inc_providers(&69);
});
pallet_session::GenesisConfig::<Test> { keys }
pallet_session::GenesisConfig::<Test> { keys, ..Default::default() }
.assimilate_storage(&mut t)
.unwrap();

Expand Down
1 change: 1 addition & 0 deletions substrate/frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ impl ExtBuilder {
.map(|id| (id, id, SessionKeys { other: id.into() }))
.collect()
},
..Default::default()
}
.assimilate_storage(&mut storage);

Expand Down

0 comments on commit a9f10c3

Please sign in to comment.