From cc4323850994ef818a309e6901cccc6ac223d215 Mon Sep 17 00:00:00 2001 From: Branislav Kontur Date: Mon, 11 Mar 2024 15:30:19 +0100 Subject: [PATCH] Introduce `collectives_polkadot_runtime_constants` and removed hard-coded numbers usage for indexes (#182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR solves older TODO + addresses https://github.com/polkadot-fellows/runtimes/pull/109#discussion_r1420818182. - [X] Does not require a CHANGELOG entry --------- Co-authored-by: Bastian Köcher --- Cargo.lock | 7 ++++++ Cargo.toml | 1 + .../assets/asset-hub-polkadot/Cargo.toml | 1 + .../src/tests/fellowship_treasury.rs | 11 +++++++-- .../asset-hubs/asset-hub-polkadot/Cargo.toml | 1 + .../asset-hub-polkadot/src/xcm_config.rs | 22 +++++++++++++++--- .../collectives-polkadot/Cargo.toml | 3 +++ .../collectives-polkadot/constants/Cargo.toml | 7 ++++++ .../collectives-polkadot/constants/src/lib.rs | 23 +++++++++++++++++++ .../src/fellowship/mod.rs | 12 ++++++---- .../collectives-polkadot/src/lib.rs | 14 ++++++----- 11 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 system-parachains/collectives/collectives-polkadot/constants/Cargo.toml create mode 100644 system-parachains/collectives/collectives-polkadot/constants/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 2aa42c95c7..325aa0bbac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -563,6 +563,7 @@ dependencies = [ "assert_matches", "asset-hub-polkadot-runtime", "asset-test-utils", + "collectives-polkadot-runtime-constants", "cumulus-pallet-parachain-system", "cumulus-pallet-xcmp-queue", "emulated-integration-tests-common", @@ -594,6 +595,7 @@ dependencies = [ "bp-asset-hub-polkadot", "bp-bridge-hub-kusama", "bp-bridge-hub-polkadot", + "collectives-polkadot-runtime-constants", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -1986,6 +1988,7 @@ dependencies = [ name = "collectives-polkadot-runtime" version = "1.0.0" dependencies = [ + "collectives-polkadot-runtime-constants", "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", @@ -2055,6 +2058,10 @@ dependencies = [ "system-parachains-constants", ] +[[package]] +name = "collectives-polkadot-runtime-constants" +version = "1.0.0" + [[package]] name = "colorchoice" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index daf6373db0..7c4f766baa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ members = [ "system-parachains/bridge-hubs/bridge-hub-polkadot", "system-parachains/bridge-hubs/bridge-hub-polkadot/primitives", "system-parachains/collectives/collectives-polkadot", + "system-parachains/collectives/collectives-polkadot/constants", "system-parachains/constants", "system-parachains/encointer", "system-parachains/gluttons/glutton-kusama", diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/Cargo.toml b/integration-tests/emulated/tests/assets/asset-hub-polkadot/Cargo.toml index ce1a8587cf..706bcfaca4 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/Cargo.toml +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/Cargo.toml @@ -34,6 +34,7 @@ cumulus-pallet-parachain-system = { features = ["parameterized-consensus-hook"], # Local asset-hub-polkadot-runtime = { path = "../../../../../system-parachains/asset-hubs/asset-hub-polkadot" } +collectives-polkadot-runtime-constants = { path = "../../../../../system-parachains/collectives/collectives-polkadot/constants" } integration-tests-helpers = { path = "../../../helpers" } polkadot-runtime = { path = "../../../../../relay/polkadot" } polkadot-system-emulated-network = { path = "../../../networks/polkadot-system" } diff --git a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs index 7425fa7e4c..d13e50fdbc 100644 --- a/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs +++ b/integration-tests/emulated/tests/assets/asset-hub-polkadot/src/tests/fellowship_treasury.rs @@ -24,8 +24,15 @@ fn create_and_claim_treasury_spend() { const ASSET_ID: u32 = 1984; const SPEND_AMOUNT: u128 = 1_000_000; // treasury location from a sibling parachain. - let treasury_location: Location = - Location::new(1, [Parachain(CollectivesPolkadot::para_id().into()), PalletInstance(65)]); + let treasury_location: Location = Location::new( + 1, + [ + Parachain(CollectivesPolkadot::para_id().into()), + PalletInstance( + collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX, + ), + ], + ); // treasury account on a sibling parachain. let treasury_account = asset_hub_polkadot_runtime::xcm_config::LocationToAccountId::convert_location( diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml index 2c2affff30..1bc9e18891 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml @@ -19,6 +19,7 @@ bp-asset-hub-kusama = { path = "../asset-hub-kusama/primitives", default-feature bp-asset-hub-polkadot = { path = "./primitives", default-features = false} bp-bridge-hub-kusama = { path = "../../bridge-hubs/bridge-hub-kusama/primitives", default-features = false} bp-bridge-hub-polkadot = { path = "../../bridge-hubs/bridge-hub-polkadot/primitives", default-features = false} +collectives-polkadot-runtime-constants = { path = "../../collectives/collectives-polkadot/constants" } kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false} polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false} diff --git a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs index fe276f1d2f..5bd37b32db 100644 --- a/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs @@ -203,8 +203,23 @@ impl Contains for FellowshipEntities { Parachain(system_parachain::COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. } ] - ) | (1, [Parachain(system_parachain::COLLECTIVES_ID), PalletInstance(64)]) | - (1, [Parachain(system_parachain::COLLECTIVES_ID), PalletInstance(65)]) + ) | ( + 1, + [ + Parachain(system_parachain::COLLECTIVES_ID), + PalletInstance( + collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX + ) + ] + ) | ( + 1, + [ + Parachain(system_parachain::COLLECTIVES_ID), + PalletInstance( + collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX + ) + ] + ) ) } } @@ -736,7 +751,8 @@ fn foreign_pallet_has_correct_local_account() { use xcm_executor::traits::ConvertLocation; const COLLECTIVES_PARAID: u32 = 1001; - const FELLOWSHIP_SALARY_PALLET_ID: u8 = 64; + const FELLOWSHIP_SALARY_PALLET_ID: u8 = + collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX; let fellowship_salary = (Parent, Parachain(COLLECTIVES_PARAID), PalletInstance(FELLOWSHIP_SALARY_PALLET_ID)); let account = LocationToAccountId::convert_location(&fellowship_salary.into()).unwrap(); diff --git a/system-parachains/collectives/collectives-polkadot/Cargo.toml b/system-parachains/collectives/collectives-polkadot/Cargo.toml index 4f471ef555..270ffb4433 100644 --- a/system-parachains/collectives/collectives-polkadot/Cargo.toml +++ b/system-parachains/collectives/collectives-polkadot/Cargo.toml @@ -82,6 +82,9 @@ parachain-info = { package = "staging-parachain-info", default-features = false parachains-common = { default-features = false , version = "8.0.0" } system-parachains-constants = { path = "../../constants", default-features = false } +[dev-dependencies] +collectives-polkadot-runtime-constants = { path = "constants" } + [build-dependencies] substrate-wasm-builder = { optional = true , version = "18.0.0" } diff --git a/system-parachains/collectives/collectives-polkadot/constants/Cargo.toml b/system-parachains/collectives/collectives-polkadot/constants/Cargo.toml new file mode 100644 index 0000000000..3684a9aabf --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/constants/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "collectives-polkadot-runtime-constants" +repository.workspace = true +version.workspace = true +authors.workspace = true +edition.workspace = true +license.workspace = true \ No newline at end of file diff --git a/system-parachains/collectives/collectives-polkadot/constants/src/lib.rs b/system-parachains/collectives/collectives-polkadot/constants/src/lib.rs new file mode 100644 index 0000000000..4fef9073f3 --- /dev/null +++ b/system-parachains/collectives/collectives-polkadot/constants/src/lib.rs @@ -0,0 +1,23 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +#![no_std] + +/// Polkadot Collectives Salary pallet instance. +pub const FELLOWSHIP_SALARY_PALLET_INDEX: u8 = 64; + +/// Polkadot Collectives Treasury pallet instance. +pub const FELLOWSHIP_TREASURY_PALLET_INDEX: u8 = 65; diff --git a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs index fc6ee446cd..3505587d19 100644 --- a/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs +++ b/system-parachains/collectives/collectives-polkadot/src/fellowship/mod.rs @@ -44,7 +44,9 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use polkadot_runtime_common::impls::{ LocatableAssetConverter, VersionedLocatableAsset, VersionedLocationConverter, }; -use polkadot_runtime_constants::{currency::GRAND, time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX}; +use polkadot_runtime_constants::{ + currency::GRAND, system_parachain, time::HOURS, xcm::body::FELLOWSHIP_ADMIN_INDEX, +}; use sp_arithmetic::Permill; use sp_core::{ConstU128, ConstU32}; use sp_runtime::traits::{ConstU16, ConvertToValue, IdentityLookup, Replace, TakeFirst}; @@ -214,15 +216,15 @@ pub type FellowshipSalaryInstance = pallet_salary::Instance1; use xcm::prelude::*; parameter_types! { - pub AssetHub: Location = (Parent, Parachain(1000)).into(); + pub AssetHub: Location = (Parent, Parachain(system_parachain::ASSET_HUB_ID)).into(); pub AssetHubUsdtId: AssetId = (PalletInstance(50), GeneralIndex(1984)).into(); pub UsdtAsset: LocatableAssetId = LocatableAssetId { location: AssetHub::get(), asset_id: AssetHubUsdtId::get(), }; // The interior location on AssetHub for the paying account. This is the Fellowship Salary - // pallet instance (which sits at index 64). This sovereign account will need funding. - pub Interior: InteriorLocation = PalletInstance(64).into(); + // pallet instance. This sovereign account will need funding. + pub Interior: InteriorLocation = PalletInstance(::index() as u8).into(); } const USDT_UNITS: u128 = 1_000_000; @@ -269,7 +271,7 @@ parameter_types! { pub const Burn: Permill = Permill::from_percent(0); pub const MaxBalance: Balance = Balance::max_value(); // The asset's interior location for the paying account. This is the Fellowship Treasury - // pallet instance (which sits at index 65). + // pallet instance. pub FellowshipTreasuryInteriorLocation: InteriorLocation = PalletInstance(::index() as u8).into(); } diff --git a/system-parachains/collectives/collectives-polkadot/src/lib.rs b/system-parachains/collectives/collectives-polkadot/src/lib.rs index 0eef46e9a0..4931e773d4 100644 --- a/system-parachains/collectives/collectives-polkadot/src/lib.rs +++ b/system-parachains/collectives/collectives-polkadot/src/lib.rs @@ -1058,22 +1058,24 @@ cumulus_pallet_parachain_system::register_validate_block! { BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::, } -// TODO: Move these pallet index declarations to some `system-parachains/common` so that other -// runtimes can import them without depending on the entire remote runtime. -// Part of https://github.com/polkadot-fellows/runtimes/issues/59 - #[test] fn fellowship_salary_pallet_index() { use frame_support::pallet_prelude::PalletInfoAccess; // Remote accounts with funds depend on this pallet staying in the same index. - assert_eq!(::index() as u8, 64u8); + assert_eq!( + ::index() as u8, + collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX + ); } #[test] fn fellowship_treasury_pallet_index() { use frame_support::pallet_prelude::PalletInfoAccess; // Remote accounts with funds depend on this pallet staying in the same index. - assert_eq!(::index() as u8, 65u8); + assert_eq!( + ::index() as u8, + collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX + ); } #[test]