From 8d9c10e4456978a4a2c4e219bcd2b7fa10eb831a Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 10 Mar 2023 15:51:40 +0100 Subject: [PATCH 1/5] updated xcm configs for collectives and statemint --- parachains/common/src/lib.rs | 1 + parachains/common/src/prod_or_fast.rs | 47 +++++++++++++++++++ .../assets/statemint/src/xcm_config.rs | 11 ++++- .../collectives-polkadot/Cargo.toml | 2 + .../src/fellowship/tracks.rs | 9 ++-- .../collectives-polkadot/src/xcm_config.rs | 11 ++++- 6 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 parachains/common/src/prod_or_fast.rs diff --git a/parachains/common/src/lib.rs b/parachains/common/src/lib.rs index 8ac464ea077..ab314dfaabc 100644 --- a/parachains/common/src/lib.rs +++ b/parachains/common/src/lib.rs @@ -16,6 +16,7 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod impls; +pub mod prod_or_fast; pub mod xcm_config; pub use constants::*; pub use opaque::*; diff --git a/parachains/common/src/prod_or_fast.rs b/parachains/common/src/prod_or_fast.rs new file mode 100644 index 00000000000..4c2b6677788 --- /dev/null +++ b/parachains/common/src/prod_or_fast.rs @@ -0,0 +1,47 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus 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. + +// Cumulus 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 Cumulus. If not, see . + +//! "fast-runtime" feature utils. + +/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value +/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected). +/// Note that the environment variable is evaluated _at compile time_. +/// +/// Usage: +/// ```Rust +/// parameter_types! { +/// // Note that the env variable version parameter cannot be const. +/// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD"); +/// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES); +/// } +/// ``` +#[macro_export] +macro_rules! prod_or_fast { + ($prod:expr, $test:expr) => { + if cfg!(feature = "fast-runtime") { + $test + } else { + $prod + } + }; + ($prod:expr, $test:expr, $env:expr) => { + if cfg!(feature = "fast-runtime") { + core::option_env!($env).map(|s| s.parse().ok()).flatten().unwrap_or($test) + } else { + $prod + } + }; +} diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index eb6581f2f1f..f645ce3df58 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -144,6 +144,9 @@ match_types! { MultiLocation { parents: 1, interior: Here } | MultiLocation { parents: 1, interior: X1(_) } }; + pub type FellowsPlurality: impl Contains = { + MultiLocation { parents: 1, interior: X2(Parachain(1001), Plurality { id: BodyId::Technical, ..}) } + }; } /// A call filter for the XCM Transact instruction. This is a temporary measure until we properly @@ -177,7 +180,8 @@ impl Contains for SafeCallFilter { pallet_collator_selection::Call::set_desired_candidates { .. } | pallet_collator_selection::Call::set_candidacy_bond { .. } | pallet_collator_selection::Call::register_as_candidate { .. } | - pallet_collator_selection::Call::leave_intent { .. }, + pallet_collator_selection::Call::leave_intent { .. } | + pallet_collator_selection::Call::set_invulnerables { .. }, ) | RuntimeCall::Session(pallet_session::Call::purge_keys { .. }) | RuntimeCall::XcmpQueue(..) | @@ -237,6 +241,9 @@ impl Contains for SafeCallFilter { pallet_uniques::Call::set_collection_max_supply { .. } | pallet_uniques::Call::set_price { .. } | pallet_uniques::Call::buy_item { .. }, + ) | + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | pallet_xcm::Call::send { .. }, ) => true, _ => false, } @@ -258,6 +265,8 @@ pub type Barrier = DenyThenTry< AllowExplicitUnpaidExecutionFrom, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, + // Fellows plurality gets free execution. + AllowExplicitUnpaidExecutionFrom, ), UniversalLocation, ConstU32<8>, diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 31555b1e2dd..477dbc648b6 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -188,3 +188,5 @@ std = [ "pallet-referenda/std", "pallet-ranked-collective/std", ] +# Set timing constants (e.g. session period) to faster versions to speed up testing. +fast-runtime = [] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs index 5d75bde9e18..9289963e190 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs @@ -17,6 +17,7 @@ //! Track configurations for Fellowship. use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, DOLLARS, MINUTES}; +use parachains_common::prod_or_fast; use sp_runtime::Perbill; /// Referendum `TrackId` type. @@ -117,10 +118,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "fellows", max_deciding: 10, decision_deposit: 10 * DOLLARS, - prepare_period: 30 * MINUTES, - decision_period: 7 * DAYS, - confirm_period: 30 * MINUTES, - min_enactment_period: 1 * MINUTES, + prepare_period: prod_or_fast!(30 * MINUTES, 2), + decision_period: prod_or_fast!(7 * DAYS, 1), + confirm_period: prod_or_fast!(30 * MINUTES, 1), + min_enactment_period: prod_or_fast!(1 * MINUTES, 1), min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index cac30d0e213..860f741dbae 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -182,7 +182,16 @@ impl Contains for SafeCallFilter { pallet_collective::Call::disapprove_proposal { .. } | pallet_collective::Call::close { .. }, ) | - RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) => true, + RuntimeCall::PolkadotXcm( + pallet_xcm::Call::force_xcm_version { .. } | pallet_xcm::Call::send { .. }, + ) | + RuntimeCall::FellowshipCollective( + pallet_ranked_collective::Call::add_member { .. } | + pallet_ranked_collective::Call::promote_member { .. } | + pallet_ranked_collective::Call::demote_member { .. } | + pallet_ranked_collective::Call::remove_member { .. }, + ) => true, + _ => false, } } From 46c047a19bb36cb9b540f0f1677b4dea6681651d Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 10 Mar 2023 16:30:48 +0100 Subject: [PATCH 2/5] remove xcm send from safe filter --- parachains/runtimes/assets/statemint/src/xcm_config.rs | 4 +--- .../collectives/collectives-polkadot/src/xcm_config.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index f645ce3df58..03db80b5e84 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -242,9 +242,7 @@ impl Contains for SafeCallFilter { pallet_uniques::Call::set_price { .. } | pallet_uniques::Call::buy_item { .. }, ) | - RuntimeCall::PolkadotXcm( - pallet_xcm::Call::force_xcm_version { .. } | pallet_xcm::Call::send { .. }, - ) => true, + RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) => true, _ => false, } } diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 860f741dbae..9837cc76332 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -182,9 +182,7 @@ impl Contains for SafeCallFilter { pallet_collective::Call::disapprove_proposal { .. } | pallet_collective::Call::close { .. }, ) | - RuntimeCall::PolkadotXcm( - pallet_xcm::Call::force_xcm_version { .. } | pallet_xcm::Call::send { .. }, - ) | + RuntimeCall::PolkadotXcm(pallet_xcm::Call::force_xcm_version { .. }) | RuntimeCall::FellowshipCollective( pallet_ranked_collective::Call::add_member { .. } | pallet_ranked_collective::Call::promote_member { .. } | From 41d9d08ae6a1d82cf37125fd14814dee6000f7fe Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 10 Mar 2023 23:33:11 +0100 Subject: [PATCH 3/5] remove prod_or_fast --- parachains/common/src/lib.rs | 1 - parachains/common/src/prod_or_fast.rs | 47 ------------------- .../collectives-polkadot/Cargo.toml | 2 - .../src/fellowship/tracks.rs | 9 ++-- 4 files changed, 4 insertions(+), 55 deletions(-) delete mode 100644 parachains/common/src/prod_or_fast.rs diff --git a/parachains/common/src/lib.rs b/parachains/common/src/lib.rs index ab314dfaabc..8ac464ea077 100644 --- a/parachains/common/src/lib.rs +++ b/parachains/common/src/lib.rs @@ -16,7 +16,6 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod impls; -pub mod prod_or_fast; pub mod xcm_config; pub use constants::*; pub use opaque::*; diff --git a/parachains/common/src/prod_or_fast.rs b/parachains/common/src/prod_or_fast.rs deleted file mode 100644 index 4c2b6677788..00000000000 --- a/parachains/common/src/prod_or_fast.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2021 Parity Technologies (UK) Ltd. -// This file is part of Cumulus. - -// Cumulus 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. - -// Cumulus 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 Cumulus. If not, see . - -//! "fast-runtime" feature utils. - -/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value -/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected). -/// Note that the environment variable is evaluated _at compile time_. -/// -/// Usage: -/// ```Rust -/// parameter_types! { -/// // Note that the env variable version parameter cannot be const. -/// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD"); -/// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES); -/// } -/// ``` -#[macro_export] -macro_rules! prod_or_fast { - ($prod:expr, $test:expr) => { - if cfg!(feature = "fast-runtime") { - $test - } else { - $prod - } - }; - ($prod:expr, $test:expr, $env:expr) => { - if cfg!(feature = "fast-runtime") { - core::option_env!($env).map(|s| s.parse().ok()).flatten().unwrap_or($test) - } else { - $prod - } - }; -} diff --git a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml index 477dbc648b6..31555b1e2dd 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml +++ b/parachains/runtimes/collectives/collectives-polkadot/Cargo.toml @@ -188,5 +188,3 @@ std = [ "pallet-referenda/std", "pallet-ranked-collective/std", ] -# Set timing constants (e.g. session period) to faster versions to speed up testing. -fast-runtime = [] diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs index 9289963e190..5d75bde9e18 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/fellowship/tracks.rs @@ -17,7 +17,6 @@ //! Track configurations for Fellowship. use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, DOLLARS, MINUTES}; -use parachains_common::prod_or_fast; use sp_runtime::Perbill; /// Referendum `TrackId` type. @@ -118,10 +117,10 @@ impl pallet_referenda::TracksInfo for TracksInfo { name: "fellows", max_deciding: 10, decision_deposit: 10 * DOLLARS, - prepare_period: prod_or_fast!(30 * MINUTES, 2), - decision_period: prod_or_fast!(7 * DAYS, 1), - confirm_period: prod_or_fast!(30 * MINUTES, 1), - min_enactment_period: prod_or_fast!(1 * MINUTES, 1), + prepare_period: 30 * MINUTES, + decision_period: 7 * DAYS, + confirm_period: 30 * MINUTES, + min_enactment_period: 1 * MINUTES, min_approval: pallet_referenda::Curve::LinearDecreasing { length: Perbill::from_percent(100), floor: Perbill::from_percent(50), From a17c7eeea595c9d531056baafb2a3c1ff99f9c0c Mon Sep 17 00:00:00 2001 From: muharem Date: Fri, 10 Mar 2023 23:35:06 +0100 Subject: [PATCH 4/5] remove empty line --- .../runtimes/collectives/collectives-polkadot/src/xcm_config.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs index 9837cc76332..25426f1406d 100644 --- a/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs +++ b/parachains/runtimes/collectives/collectives-polkadot/src/xcm_config.rs @@ -189,7 +189,6 @@ impl Contains for SafeCallFilter { pallet_ranked_collective::Call::demote_member { .. } | pallet_ranked_collective::Call::remove_member { .. }, ) => true, - _ => false, } } From 99c461022bdbe09dd148a7568f5af685ac5defdf Mon Sep 17 00:00:00 2001 From: muharem Date: Sat, 11 Mar 2023 09:58:20 +0100 Subject: [PATCH 5/5] drop redundant aggregation --- parachains/runtimes/assets/statemint/src/xcm_config.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/parachains/runtimes/assets/statemint/src/xcm_config.rs b/parachains/runtimes/assets/statemint/src/xcm_config.rs index 03db80b5e84..259d3a223e2 100644 --- a/parachains/runtimes/assets/statemint/src/xcm_config.rs +++ b/parachains/runtimes/assets/statemint/src/xcm_config.rs @@ -259,12 +259,10 @@ pub type Barrier = DenyThenTry< ( // If the message is one that immediately attemps to pay for execution, then allow it. AllowTopLevelPaidExecutionFrom, - // Parent and its plurality (i.e. governance bodies) gets free execution. - AllowExplicitUnpaidExecutionFrom, + // Parent, its plurality (i.e. governance bodies) and Fellows plurality gets free execution. + AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality, FellowsPlurality)>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, - // Fellows plurality gets free execution. - AllowExplicitUnpaidExecutionFrom, ), UniversalLocation, ConstU32<8>,