Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce collectives_polkadot_runtime_constants and removed hard-coded numbers usage for indexes #182

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions system-parachains/asset-hubs/asset-hub-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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", default-features = false}
bkchr marked this conversation as resolved.
Show resolved Hide resolved
kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false}
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}

Expand Down Expand Up @@ -166,6 +167,7 @@ std = [
"bp-bridge-hub-kusama/std",
"bp-bridge-hub-polkadot/std",
"codec/std",
"collectives-polkadot-runtime-constants/std",
bkchr marked this conversation as resolved.
Show resolved Hide resolved
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ match_types! {
// Fellowship Plurality
MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) } |
// Fellowship Salary Pallet
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(64)) } |
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(collectives_polkadot_runtime_constants::FELLOWSHIP_SALARY_PALLET_INDEX)) } |
// Fellowship Treasury Pallet
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(65)) }
MultiLocation { parents: 1, interior: X2(Parachain(1001), PalletInstance(collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX)) }
};
}

Expand Down Expand Up @@ -740,7 +740,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();
Expand Down
9 changes: 7 additions & 2 deletions system-parachains/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ hex-literal = { version = "0.4.1" }
log = { version = "0.4.20", default-features = false }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }

# Local
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}
system-parachains-constants = { path = "../../constants", default-features = false }

# Substrate
frame-benchmarking = { default-features = false, optional = true, version = "25.0.0" }
frame-executive = { default-features = false, version = "25.0.0" }
Expand Down Expand Up @@ -62,7 +66,6 @@ pallet-xcm = { default-features = false, version = "4.0.0" }
polkadot-core-primitives = { default-features = false, version = "4.0.0" }
polkadot-parachain-primitives = { default-features = false, version = "3.0.0" }
polkadot-runtime-common = { default-features = false, version = "4.0.0" }
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}
xcm = { package = "staging-xcm", default-features = false, version = "4.0.0" }
xcm-builder = { package = "staging-xcm-builder", default-features = false, version = "4.0.0" }
xcm-executor = { package = "staging-xcm-executor", default-features = false, version = "4.0.2" }
Expand All @@ -79,7 +82,9 @@ cumulus-primitives-utility = { default-features = false , version = "0.4.0" }
pallet-collator-selection = { default-features = false , version = "6.0.0" }
parachain-info = { package = "staging-parachain-info", default-features = false , version = "0.4.0" }
parachains-common = { default-features = false , version = "4.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 = "14.0.0" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "collectives-polkadot-runtime-constants"
repository.workspace = true
version.workspace = true
authors.workspace = true
edition.workspace = true
license.workspace = true

[features]
default = ["std"]
std = []
bkchr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
bkontur marked this conversation as resolved.
Show resolved Hide resolved
bkchr marked this conversation as resolved.
Show resolved Hide resolved

/// 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;
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ parameter_types! {
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: InteriorMultiLocation = PalletInstance(64).into();
// pallet instance. This sovereign account will need funding.
pub Interior: InteriorMultiLocation =
PalletInstance(<crate::FellowshipSalary as PalletInfoAccess>::index() as u8).into();
}

const USDT_UNITS: u128 = 1_000_000;
Expand Down Expand Up @@ -260,7 +261,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: InteriorMultiLocation =
PalletInstance(<crate::FellowshipTreasury as PalletInfoAccess>::index() as u8).into();
}
Expand Down
14 changes: 8 additions & 6 deletions system-parachains/collectives/collectives-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,22 +959,24 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
}

// 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!(<FellowshipSalary as PalletInfoAccess>::index() as u8, 64u8);
assert_eq!(
<FellowshipSalary as PalletInfoAccess>::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!(<FellowshipTreasury as PalletInfoAccess>::index() as u8, 65u8);
assert_eq!(
<FellowshipTreasury as PalletInfoAccess>::index() as u8,
collectives_polkadot_runtime_constants::FELLOWSHIP_TREASURY_PALLET_INDEX
);
}

#[test]
Expand Down
Loading