diff --git a/cumulus/pallets/collator-selection/src/mock.rs b/cumulus/pallets/collator-selection/src/mock.rs index 459b1cb5fdf2..d13f9e9d8c44 100644 --- a/cumulus/pallets/collator-selection/src/mock.rs +++ b/cumulus/pallets/collator-selection/src/mock.rs @@ -187,7 +187,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { candidacy_bond: 10, invulnerables, }; - let session = pallet_session::GenesisConfig:: { keys }; + let session = pallet_session::GenesisConfig:: { keys, ..Default::default() }; pallet_balances::GenesisConfig:: { balances } .assimilate_storage(&mut t) .unwrap(); diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs index 3a87322664d9..82f86e2b32ef 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-rococo/src/genesis.rs @@ -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), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs index 219d1306906c..fd84030ed13b 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/assets/asset-hub-westend/src/genesis.rs @@ -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), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/genesis.rs index 12778215b132..3786d529ea65 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-rococo/src/genesis.rs @@ -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), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs index 4be68e510f4d..a160d18d4cf7 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/bridges/bridge-hub-westend/src/genesis.rs @@ -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), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend/src/genesis.rs index 6a28b1a9dddb..d4ef184ea392 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/collectives/collectives-westend/src/genesis.rs @@ -51,6 +51,7 @@ pub fn genesis() -> Storage { ) }) .collect(), + ..Default::default() }, polkadot_xcm: collectives_westend_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo/src/genesis.rs index f72de52c4932..e0f035c368e3 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-rococo/src/genesis.rs @@ -51,6 +51,7 @@ pub fn genesis() -> Storage { ) }) .collect(), + ..Default::default() }, polkadot_xcm: coretime_rococo_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend/src/genesis.rs index 222ffe7a63ab..239ad3760c11 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/coretime/coretime-westend/src/genesis.rs @@ -51,6 +51,7 @@ pub fn genesis() -> Storage { ) }) .collect(), + ..Default::default() }, polkadot_xcm: coretime_westend_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs index b14009933029..43d182facdd5 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-rococo/src/genesis.rs @@ -47,6 +47,7 @@ pub fn genesis() -> Storage { ) }) .collect(), + ..Default::default() }, polkadot_xcm: people_rococo_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend/src/genesis.rs index d385fbebc821..0b99f19bc130 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/people/people-westend/src/genesis.rs @@ -47,6 +47,7 @@ pub fn genesis() -> Storage { ) }) .collect(), + ..Default::default() }, polkadot_xcm: people_westend_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION), diff --git a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs index 450439f5ea30..260875088bbc 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/parachains/testing/penpal/src/genesis.rs @@ -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), diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs index 074a1de5e185..9cb25b403600 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/rococo/src/genesis.rs @@ -75,6 +75,7 @@ pub fn genesis() -> Storage { ) }) .collect::>(), + ..Default::default() }, babe: rococo_runtime::BabeConfig { authorities: Default::default(), diff --git a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs index b9f12932b84e..172e6e0ac93e 100644 --- a/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs +++ b/cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/genesis.rs @@ -77,6 +77,7 @@ pub fn genesis() -> Storage { ) }) .collect::>(), + ..Default::default() }, staking: westend_runtime::StakingConfig { validator_count: validators::initial_authorities().len() as u32, diff --git a/cumulus/parachains/runtimes/test-utils/src/lib.rs b/cumulus/parachains/runtimes/test-utils/src/lib.rs index 3fc3822a63eb..940aa1b734df 100644 --- a/cumulus/parachains/runtimes/test-utils/src/lib.rs +++ b/cumulus/parachains/runtimes/test-utils/src/lib.rs @@ -242,7 +242,7 @@ impl ExtBuilder { .assimilate_storage(&mut t) .unwrap(); - pallet_session::GenesisConfig:: { keys: self.keys } + pallet_session::GenesisConfig:: { keys: self.keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs index 45920cdb6146..af5bccdc416f 100644 --- a/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs +++ b/cumulus/polkadot-parachain/src/chain_spec/asset_hubs.rs @@ -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), diff --git a/prdoc/pr_5078.prdoc b/prdoc/pr_5078.prdoc new file mode 100644 index 000000000000..1805a27c3f28 --- /dev/null +++ b/prdoc/pr_5078.prdoc @@ -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 \ No newline at end of file diff --git a/substrate/bin/node/cli/tests/res/default_genesis_config.json b/substrate/bin/node/cli/tests/res/default_genesis_config.json index b63e5ff549ef..a2e52837d882 100644 --- a/substrate/bin/node/cli/tests/res/default_genesis_config.json +++ b/substrate/bin/node/cli/tests/res/default_genesis_config.json @@ -34,7 +34,9 @@ "maxNominatorCount": null }, "session": { - "keys": [] + "keys": [], + "nonAuthorityKeys": [] + }, "democracy": {}, "council": { diff --git a/substrate/bin/node/testing/src/genesis.rs b/substrate/bin/node/testing/src/genesis.rs index c79612d68444..7f5364744c66 100644 --- a/substrate/bin/node/testing/src/genesis.rs +++ b/substrate/bin/node/testing/src/genesis.rs @@ -54,6 +54,7 @@ pub fn config_endowed(extra_endowed: Vec) -> 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![ diff --git a/substrate/frame/babe/src/mock.rs b/substrate/frame/babe/src/mock.rs index e193a2e3b645..912cb3e27cd5 100644 --- a/substrate/frame/babe/src/mock.rs +++ b/substrate/frame/babe/src/mock.rs @@ -319,7 +319,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec) -> sp_io::Tes // NOTE: this will initialize the babe authorities // through OneSessionHandler::on_genesis_session - pallet_session::GenesisConfig:: { keys: session_keys } + pallet_session::GenesisConfig:: { keys: session_keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/substrate/frame/beefy-mmr/src/mock.rs b/substrate/frame/beefy-mmr/src/mock.rs index 3adef4f32bf4..1102f9677aaa 100644 --- a/substrate/frame/beefy-mmr/src/mock.rs +++ b/substrate/frame/beefy-mmr/src/mock.rs @@ -187,7 +187,7 @@ pub fn new_test_ext_raw_authorities(authorities: Vec<(u64, BeefyId)>) -> TestExt } }); - pallet_session::GenesisConfig:: { keys: session_keys } + pallet_session::GenesisConfig:: { keys: session_keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/substrate/frame/beefy/src/mock.rs b/substrate/frame/beefy/src/mock.rs index a0880660d051..b423fa0bda89 100644 --- a/substrate/frame/beefy/src/mock.rs +++ b/substrate/frame/beefy/src/mock.rs @@ -269,7 +269,7 @@ impl ExtBuilder { } }); - pallet_session::GenesisConfig:: { keys: session_keys } + pallet_session::GenesisConfig:: { keys: session_keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs index 5c64f2a0bc20..d148c05e4d0d 100644 --- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs +++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/src/mock.rs @@ -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); diff --git a/substrate/frame/grandpa/src/mock.rs b/substrate/frame/grandpa/src/mock.rs index 5ba7da7f9fda..ae230a0209a7 100644 --- a/substrate/frame/grandpa/src/mock.rs +++ b/substrate/frame/grandpa/src/mock.rs @@ -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:: { keys: session_keys } + pallet_session::GenesisConfig:: { keys: session_keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/substrate/frame/root-offences/src/mock.rs b/substrate/frame/root-offences/src/mock.rs index ab43b723e8a9..af073d7672cf 100644 --- a/substrate/frame/root-offences/src/mock.rs +++ b/substrate/frame/root-offences/src/mock.rs @@ -246,6 +246,7 @@ impl ExtBuilder { .into_iter() .map(|(id, ..)| (id, id, SessionKeys { other: id.into() })) .collect(), + ..Default::default() } .assimilate_storage(&mut storage); diff --git a/substrate/frame/session/src/historical/mod.rs b/substrate/frame/session/src/historical/mod.rs index fac580b49b3a..a19364d577f6 100644 --- a/substrate/frame/session/src/historical/mod.rs +++ b/substrate/frame/session/src/historical/mod.rs @@ -396,7 +396,7 @@ pub(crate) mod tests { frame_system::Pallet::::inc_providers(k); } }); - pallet_session::GenesisConfig:: { keys } + pallet_session::GenesisConfig:: { keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); sp_io::TestExternalities::new(t) diff --git a/substrate/frame/session/src/historical/offchain.rs b/substrate/frame/session/src/historical/offchain.rs index 685a0be8e191..e9ced89a8f19 100644 --- a/substrate/frame/session/src/historical/offchain.rs +++ b/substrate/frame/session/src/historical/offchain.rs @@ -171,7 +171,9 @@ mod tests { } }); - crate::GenesisConfig:: { keys }.assimilate_storage(&mut t).unwrap(); + crate::GenesisConfig:: { keys, ..Default::default() } + .assimilate_storage(&mut t) + .unwrap(); let mut ext = sp_io::TestExternalities::new(t); diff --git a/substrate/frame/session/src/lib.rs b/substrate/frame/session/src/lib.rs index e1a2a31911fe..325758d54dd8 100644 --- a/substrate/frame/session/src/lib.rs +++ b/substrate/frame/session/src/lib.rs @@ -423,7 +423,14 @@ pub mod pallet { #[pallet::genesis_config] #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { + /// 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] @@ -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::::inner_set_keys(&val, keys) .expect("genesis config must not contain duplicates; qed"); if frame_system::Pallet::::inc_consumers_without_limit(&account).is_err() { @@ -676,7 +685,7 @@ impl Pallet { 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` diff --git a/substrate/frame/session/src/mock.rs b/substrate/frame/session/src/mock.rs index 25b81668cc08..745b57d1be41 100644 --- a/substrate/frame/session/src/mock.rs +++ b/substrate/frame/session/src/mock.rs @@ -215,7 +215,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities { // An additional identity that we use. frame_system::Pallet::::inc_providers(&69); }); - pallet_session::GenesisConfig:: { keys } + pallet_session::GenesisConfig:: { keys, ..Default::default() } .assimilate_storage(&mut t) .unwrap(); diff --git a/substrate/frame/staking/src/mock.rs b/substrate/frame/staking/src/mock.rs index 7e6a87955b08..7cc8e865916d 100644 --- a/substrate/frame/staking/src/mock.rs +++ b/substrate/frame/staking/src/mock.rs @@ -535,6 +535,7 @@ impl ExtBuilder { .map(|id| (id, id, SessionKeys { other: id.into() })) .collect() }, + ..Default::default() } .assimilate_storage(&mut storage);