Skip to content

Commit

Permalink
Introduce collectives_polkadot_runtime_constants and removed hard-c…
Browse files Browse the repository at this point in the history
…oded numbers usage for indexes (#182)

This PR solves older TODO + addresses
#109 (comment).

<!-- Remember that you can run `/merge` to enable auto-merge in the PR
-->

<!-- Remember to modify the changelog. If you don't need to modify it,
you can check the following box.
Instead, if you have already modified it, simply delete the following
line. -->

- [X] Does not require a CHANGELOG entry

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
bkontur and bkchr authored Mar 11, 2024
1 parent e42821d commit cc43238
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 16 deletions.
7 changes: 7 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
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 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" }
kusama-runtime-constants = { path = "../../../relay/kusama/constants", default-features = false}
polkadot-runtime-constants = { path = "../../../relay/polkadot/constants", default-features = false}

Expand Down
22 changes: 19 additions & 3 deletions system-parachains/asset-hubs/asset-hub-polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,23 @@ impl Contains<Location> 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
)
]
)
)
}
}
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions system-parachains/collectives/collectives-polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
Original file line number Diff line number Diff line change
@@ -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
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/>.

#![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;
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(<crate::FellowshipSalary as PalletInfoAccess>::index() as u8).into();
}

const USDT_UNITS: u128 = 1_000_000;
Expand Down Expand Up @@ -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(<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 @@ -1058,22 +1058,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

0 comments on commit cc43238

Please sign in to comment.