From 9b76492302f7184ff00bd6141c9b4163611e9d45 Mon Sep 17 00:00:00 2001 From: Sebastian Kunert Date: Tue, 4 Jun 2024 15:32:27 +0200 Subject: [PATCH] Use `parachain_info` in cumulus-test-runtime (#4672) This allows to use custom para_ids with cumulus-test-runtime. Zombienet is patching the genesis entries for `ParachainInfo`. This did not work with `test-parachain` because it was using the `test_pallet` for historic reasons I guess. --- Cargo.lock | 1 + cumulus/test/runtime/Cargo.toml | 2 ++ cumulus/test/runtime/src/lib.rs | 10 ++++------ cumulus/test/runtime/src/test_pallet.rs | 4 ---- cumulus/test/service/src/chain_spec.rs | 4 +++- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec68657800f4..00eea545c712 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4363,6 +4363,7 @@ dependencies = [ "sp-std 14.0.0", "sp-transaction-pool", "sp-version", + "staging-parachain-info", "substrate-wasm-builder", ] diff --git a/cumulus/test/runtime/Cargo.toml b/cumulus/test/runtime/Cargo.toml index 014313aa8919..b14e3b7f040e 100644 --- a/cumulus/test/runtime/Cargo.toml +++ b/cumulus/test/runtime/Cargo.toml @@ -42,6 +42,7 @@ sp-version = { path = "../../../substrate/primitives/version", default-features # Cumulus cumulus-pallet-parachain-system = { path = "../../pallets/parachain-system", default-features = false } +parachain-info = { package = "staging-parachain-info", path = "../../parachains/pallets/parachain-info", default-features = false } cumulus-primitives-aura = { path = "../../primitives/aura", default-features = false } pallet-collator-selection = { path = "../../pallets/collator-selection", default-features = false } cumulus-pallet-aura-ext = { path = "../../pallets/aura-ext", default-features = false } @@ -74,6 +75,7 @@ std = [ "pallet-sudo/std", "pallet-timestamp/std", "pallet-transaction-payment/std", + "parachain-info/std", "scale-info/std", "sp-api/std", "sp-block-builder/std", diff --git a/cumulus/test/runtime/src/lib.rs b/cumulus/test/runtime/src/lib.rs index 22dc5d857b7c..452b3241d0bf 100644 --- a/cumulus/test/runtime/src/lib.rs +++ b/cumulus/test/runtime/src/lib.rs @@ -280,7 +280,7 @@ type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook< >; impl cumulus_pallet_parachain_system::Config for Runtime { type WeightInfo = (); - type SelfParaId = ParachainId; + type SelfParaId = parachain_info::Pallet; type RuntimeEvent = RuntimeEvent; type OnSystemEvent = (); type OutboundXcmpMessageSource = (); @@ -294,6 +294,8 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type ConsensusHook = ConsensusHook; } +impl parachain_info::Config for Runtime {} + impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); @@ -302,11 +304,6 @@ impl pallet_aura::Config for Runtime { type SlotDuration = ConstU64; } -parameter_types! { - // will be set by test_pallet during genesis init - pub storage ParachainId: cumulus_primitives_core::ParaId = PARACHAIN_ID.into(); -} - impl test_pallet::Config for Runtime {} construct_runtime! { @@ -315,6 +312,7 @@ construct_runtime! { System: frame_system, ParachainSystem: cumulus_pallet_parachain_system, Timestamp: pallet_timestamp, + ParachainInfo: parachain_info, Balances: pallet_balances, Sudo: pallet_sudo, TransactionPayment: pallet_transaction_payment, diff --git a/cumulus/test/runtime/src/test_pallet.rs b/cumulus/test/runtime/src/test_pallet.rs index 5d11b7f490c6..7f43f713fadc 100644 --- a/cumulus/test/runtime/src/test_pallet.rs +++ b/cumulus/test/runtime/src/test_pallet.rs @@ -78,7 +78,6 @@ pub mod pallet { #[derive(frame_support::DefaultNoBound)] #[pallet::genesis_config] pub struct GenesisConfig { - pub self_para_id: Option, #[serde(skip)] pub _config: sp_std::marker::PhantomData, } @@ -87,9 +86,6 @@ pub mod pallet { impl BuildGenesisConfig for GenesisConfig { fn build(&self) { sp_io::storage::set(TEST_RUNTIME_UPGRADE_KEY, &[1, 2, 3, 4]); - self.self_para_id.map(|para_id| { - crate::ParachainId::set(¶_id); - }); } } } diff --git a/cumulus/test/service/src/chain_spec.rs b/cumulus/test/service/src/chain_spec.rs index 28faba7377e4..174d478f2575 100644 --- a/cumulus/test/service/src/chain_spec.rs +++ b/cumulus/test/service/src/chain_spec.rs @@ -142,7 +142,9 @@ pub fn testnet_genesis( balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), }, "sudo": cumulus_test_runtime::SudoConfig { key: Some(root_key) }, - "testPallet": cumulus_test_runtime::TestPalletConfig { self_para_id: Some(self_para_id), ..Default::default() }, + "parachainInfo": { + "parachainId": self_para_id, + }, "aura": cumulus_test_runtime::AuraConfig { authorities: invulnerables } }) }