diff --git a/Cargo.lock b/Cargo.lock index 69df2135e8..145dba9ddc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -916,6 +916,7 @@ dependencies = [ "pallet-nfts-runtime-api", "pallet-nomination-pools", "pallet-nomination-pools-benchmarking", + "pallet-parameters", "pallet-preimage", "pallet-proxy", "pallet-rc-migrator", @@ -5460,10 +5461,12 @@ dependencies = [ "kusama-system-emulated-network", "pallet-utility", "pallet-whitelist", + "pallet-xcm", "parity-scale-codec", "people-kusama-runtime", "sp-runtime", "staging-kusama-runtime", + "staging-xcm", ] [[package]] diff --git a/integration-tests/emulated/tests/governance/kusama/Cargo.toml b/integration-tests/emulated/tests/governance/kusama/Cargo.toml index 91a6ca2f0c..646b902d43 100644 --- a/integration-tests/emulated/tests/governance/kusama/Cargo.toml +++ b/integration-tests/emulated/tests/governance/kusama/Cargo.toml @@ -20,23 +20,13 @@ pallet-utility = { workspace = true, default-features = true } # Cumulus emulated-integration-tests-common = { workspace = true } +# Polkadot +pallet-xcm = { workspace = true, default-features = true } +xcm = { workspace = true, default-features = true } + # Local asset-hub-kusama-runtime = { workspace = true } integration-tests-helpers = { workspace = true } people-kusama-runtime = { workspace = true } kusama-runtime = { workspace = true } kusama-system-emulated-network = { workspace = true } - -[features] -runtime-benchmarks = [ - "asset-hub-kusama-runtime/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "integration-tests-helpers/runtime-benchmarks", - "kusama-runtime/runtime-benchmarks", - "kusama-system-emulated-network/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-whitelist/runtime-benchmarks", - "people-kusama-runtime/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] diff --git a/integration-tests/emulated/tests/governance/kusama/src/common.rs b/integration-tests/emulated/tests/governance/kusama/src/common.rs new file mode 100644 index 0000000000..1c88294f38 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/common.rs @@ -0,0 +1,57 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::imports::*; + +/// Kusama Collectives/Fellows **stays on the RC** and dispatches `pallet_xcm::send` +/// with `OriginKind:Xcm` to the dest with encoded whitelisted call hash. +#[cfg(test)] +pub fn collectives_send_whitelist( + dest: Location, + encoded_whitelist_call: impl FnOnce() -> Vec, +) { + Kusama::execute_with(|| { + type RuntimeEvent = ::RuntimeEvent; + type RuntimeCall = ::RuntimeCall; + type RuntimeOrigin = ::RuntimeOrigin; + type Runtime = ::Runtime; + + Dmp::make_parachain_reachable(AssetHubKusama::para_id()); + + let whitelist_call = RuntimeCall::XcmPallet(pallet_xcm::Call::::send { + dest: bx!(VersionedLocation::from(dest)), + message: bx!(VersionedXcm::from(Xcm(vec![ + UnpaidExecution { weight_limit: Unlimited, check_origin: None }, + Transact { + origin_kind: OriginKind::Xcm, + fallback_max_weight: None, + call: encoded_whitelist_call().into(), + } + ]))), + }); + + // Fellows origin can trigger + use kusama_runtime::governance::pallet_custom_origins::Origin::Fellows as FellowsOrigin; + let fellows_origin: RuntimeOrigin = FellowsOrigin.into(); + assert_ok!(whitelist_call.dispatch(fellows_origin)); + assert_expected_events!( + Kusama, + vec![ + RuntimeEvent::XcmPallet(pallet_xcm::Event::Sent { .. }) => {}, + ] + ); + }); +} diff --git a/integration-tests/emulated/tests/governance/kusama/src/lib.rs b/integration-tests/emulated/tests/governance/kusama/src/lib.rs index 21dbf6e412..023a451564 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/lib.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/lib.rs @@ -14,5 +14,35 @@ // See the License for the specific language governing permissions and // limitations under the License. +#[cfg(test)] +mod imports { + pub(crate) use codec::Encode; + pub(crate) use emulated_integration_tests_common::{ + assert_whitelisted, + impls::{assert_expected_events, bx, Parachain, RelayChain, TestExt}, + xcm_emulator::Chain, + xcm_helpers::{ + build_xcm_send_authorize_upgrade_call, call_hash_of, + dispatch_whitelisted_call_with_preimage, + }, + }; + pub(crate) use frame_support::{assert_err, assert_ok}; + pub(crate) use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; + pub(crate) use sp_runtime::{traits::Dispatchable, DispatchError}; + pub(crate) use xcm::{latest::prelude::*, VersionedLocation, VersionedXcm}; + + pub(crate) use kusama_system_emulated_network::{ + AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, + CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, + PeopleKusamaPara as PeopleKusama, + }; +} + +#[cfg(test)] +mod common; + +#[cfg(test)] +mod open_gov_on_asset_hub; + #[cfg(test)] mod open_gov_on_relay; diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs new file mode 100644 index 0000000000..153de3f2c9 --- /dev/null +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_asset_hub.rs @@ -0,0 +1,280 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::{common::collectives_send_whitelist, imports::*}; +use asset_hub_kusama_runtime::governance::pallet_custom_origins::Origin; + +#[test] +fn assethub_can_authorize_upgrade_for_itself() { + let code_hash = [1u8; 32].into(); + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![AssetHubRuntimeCall::System(frame_system::Call::authorize_upgrade { + code_hash, + })], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + let call_hash = call_hash_of::(&authorize_upgrade); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 94, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist from Kusama + collectives_send_whitelist( + Kusama::child_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + AssetHubKusama::execute_with(|| { + assert_whitelisted!(AssetHubKusama, call_hash); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + AssetHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + AssetHubKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash + ) + }); +} + +#[test] +fn assethub_can_authorize_upgrade_for_relay_chain() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let code_hash = [1u8; 32].into(); + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::parent_location(), + &code_hash, + None, + )], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + let call_hash = call_hash_of::(&authorize_upgrade); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 94, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist from Kusama + collectives_send_whitelist( + Kusama::child_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + AssetHubKusama::execute_with(|| { + assert_whitelisted!(AssetHubKusama, call_hash); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + Kusama::execute_with(|| assert!(::System::authorized_upgrade().is_none())); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + Kusama::execute_with(|| { + assert_eq!(::System::authorized_upgrade().unwrap().code_hash(), &code_hash) + }); +} + +#[test] +fn assethub_can_authorize_upgrade_for_system_chains() { + type AssetHubRuntime = ::Runtime; + type AssetHubRuntimeCall = ::RuntimeCall; + type AssetHubRuntimeOrigin = ::RuntimeOrigin; + + let code_hash_bridge_hub = [2u8; 32].into(); + let code_hash_coretime = [4u8; 32].into(); + let code_hash_people = [5u8; 32].into(); + + let authorize_upgrade = + AssetHubRuntimeCall::Utility(pallet_utility::Call::::force_batch { + calls: vec![ + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(BridgeHubKusama::para_id()), + &code_hash_bridge_hub, + None, + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(CoretimeKusama::para_id()), + &code_hash_coretime, + None, + ), + build_xcm_send_authorize_upgrade_call::( + AssetHubKusama::sibling_location_of(PeopleKusama::para_id()), + &code_hash_people, + None, + ), + ], + }); + + // bad origin + let invalid_origin: AssetHubRuntimeOrigin = Origin::StakingAdmin.into(); + // ok origin + let ok_origin: AssetHubRuntimeOrigin = Origin::WhitelistedCaller.into(); + + let call_hash = call_hash_of::(&authorize_upgrade); + + // Err - when dispatch non-whitelisted + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + ok_origin.clone() + ), + DispatchError::Module(sp_runtime::ModuleError { + index: 94, + error: [3, 0, 0, 0], + message: Some("CallIsNotWhitelisted") + }) + ); + + // whitelist from Kusama + collectives_send_whitelist( + Kusama::child_location_of(::para_id()), + || { + AssetHubRuntimeCall::Whitelist( + pallet_whitelist::Call::::whitelist_call { call_hash }, + ) + .encode() + }, + ); + AssetHubKusama::execute_with(|| { + assert_whitelisted!(AssetHubKusama, call_hash); + }); + + // Err - when dispatch wrong origin + assert_err!( + dispatch_whitelisted_call_with_preimage::( + authorize_upgrade.clone(), + invalid_origin + ), + DispatchError::BadOrigin + ); + + // check before + BridgeHubKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + CoretimeKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + PeopleKusama::execute_with(|| { + assert!(::System::authorized_upgrade().is_none()) + }); + + // ok - authorized + assert_ok!(dispatch_whitelisted_call_with_preimage::( + authorize_upgrade, + ok_origin + )); + + // check after - authorized + BridgeHubKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_bridge_hub + ) + }); + CoretimeKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_coretime + ) + }); + PeopleKusama::execute_with(|| { + assert_eq!( + ::System::authorized_upgrade().unwrap().code_hash(), + &code_hash_people + ) + }); +} diff --git a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs index 7aea763133..820753e49b 100644 --- a/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs +++ b/integration-tests/emulated/tests/governance/kusama/src/open_gov_on_relay.rs @@ -13,22 +13,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -use emulated_integration_tests_common::{ - assert_whitelisted, - impls::RelayChain, - xcm_emulator::{Chain, Parachain, TestExt}, - xcm_helpers::{ - build_xcm_send_authorize_upgrade_call, call_hash_of, - dispatch_whitelisted_call_with_preimage, - }, -}; -use frame_support::{assert_err, assert_ok}; -use kusama_runtime::{governance::pallet_custom_origins::Origin, Dmp}; +use crate::imports::*; + use kusama_system_emulated_network::{ - AssetHubKusamaPara as AssetHubKusama, BridgeHubKusamaPara as BridgeHubKusama, - CoretimeKusamaPara as CoretimeKusama, KusamaRelay as Kusama, PeopleKusamaPara as PeopleKusama, + BridgeHubKusamaPara as BridgeHubKusama, CoretimeKusamaPara as CoretimeKusama, + PeopleKusamaPara as PeopleKusama, }; -use sp_runtime::{traits::Dispatchable, DispatchError}; #[test] fn relaychain_can_authorize_upgrade_for_itself() { diff --git a/relay/kusama/src/xcm_config.rs b/relay/kusama/src/xcm_config.rs index 96cad024e7..4de2afb6ac 100644 --- a/relay/kusama/src/xcm_config.rs +++ b/relay/kusama/src/xcm_config.rs @@ -39,7 +39,7 @@ use xcm_builder::{ AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, DescribeAllTerminal, DescribeFamily, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsChildSystemParachain, - IsConcrete, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount, + IsConcrete, LocationAsSuperuser, MintLocation, OriginToPluralityVoice, SendXcmFeeToAccount, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, @@ -104,6 +104,8 @@ type LocalOriginConverter = ( SignedAccountId32AsNative, // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. XcmPassthrough, + // AssetHub can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + LocationAsSuperuser, RuntimeOrigin>, ); parameter_types! { diff --git a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml index a75a404a9d..47fb533157 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml +++ b/system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml @@ -58,6 +58,7 @@ pallet-nomination-pools = { workspace = true } pallet-nft-fractionalization = { workspace = true } pallet-nfts = { workspace = true } pallet-nfts-runtime-api = { workspace = true } +pallet-parameters = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } pallet-recovery = { workspace = true } @@ -181,6 +182,7 @@ runtime-benchmarks = [ "pallet-nfts/runtime-benchmarks", "pallet-nomination-pools-benchmarking/runtime-benchmarks", "pallet-nomination-pools/runtime-benchmarks", + "pallet-parameters/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-rc-migrator/runtime-benchmarks", @@ -249,6 +251,7 @@ try-runtime = [ "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", "pallet-nomination-pools/try-runtime", + "pallet-parameters/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", "pallet-rc-migrator/try-runtime", @@ -327,6 +330,7 @@ std = [ "pallet-nfts/std", "pallet-nomination-pools-benchmarking?/std", "pallet-nomination-pools/std", + "pallet-parameters/std", "pallet-preimage/std", "pallet-proxy/std", "pallet-rc-migrator/std", diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/ah_migration/call_filter.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/ah_migration/call_filter.rs index 95239993d1..0b686e7d50 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/ah_migration/call_filter.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/ah_migration/call_filter.rs @@ -137,6 +137,7 @@ pub fn call_allowed_status( Recovery(..) => OFF, MultiBlockMigrations(..) => OFF, // has not calls Revive(..) => OFF, // TODO: OFF or ON? + Parameters(..) => OFF, // TODO: OFF or ON? }; // Exhaustive match. Compiler ensures that we did not miss any. @@ -208,6 +209,7 @@ pub fn call_allowed_before_migration( XcmpQueue(..) | RemoteProxyRelayChain(..) | NftFractionalization(..) | - Revive(..) => ON, + Revive(..) | + Parameters(..) => ON, // TODO: Parameters OFF or ON? } } diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/governance/mod.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/governance/mod.rs index ec75f9d1c6..35229d5df7 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/governance/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/governance/mod.rs @@ -18,7 +18,10 @@ use super::*; use crate::xcm_config::FellowshipLocation; -use frame_support::traits::EitherOf; +use frame_support::{ + parameter_types, + traits::{EitherOf, EitherOfDiverse}, +}; use frame_system::EnsureRootWithSuccess; use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; use xcm::latest::BodyId; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/governance/origins.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/governance/origins.rs index db9c76f25b..4d6cbfd6fb 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/governance/origins.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/governance/origins.rs @@ -18,7 +18,6 @@ pub use pallet_custom_origins::*; -// From https://github.com/polkadot-fellows/runtimes/blob/7bbf00566d86d51fcd5582779e7e9c37a814405e/relay/polkadot/src/governance/origins.rs#L21-L154 #[frame_support::pallet] pub mod pallet_custom_origins { use crate::{Balance, GRAND, QUID}; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs index e7dc79da23..0ea86e61fb 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs @@ -53,6 +53,7 @@ use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; use frame_support::{ construct_runtime, dispatch::DispatchClass, + dynamic_params::{dynamic_pallet_params, dynamic_params}, genesis_builder_helper::{build_state, get_preset}, ord_parameter_types, parameter_types, traits::{ @@ -60,8 +61,8 @@ use frame_support::{ fungibles, tokens::imbalance::ResolveAssetTo, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, Contains, - EitherOf, EitherOfDiverse, Equals, InstanceFilter, LinearStoragePrice, PrivilegeCmp, - TheseExcept, TransformOrigin, WithdrawReasons, + EitherOf, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg, Equals, InstanceFilter, + LinearStoragePrice, PrivilegeCmp, TheseExcept, TransformOrigin, WithdrawReasons, }, weights::{ConstantMultiplier, Weight}, BoundedVec, PalletId, @@ -70,7 +71,7 @@ use frame_system::{ limits::{BlockLength, BlockWeights}, EnsureRoot, EnsureSigned, EnsureSignedBy, }; -use governance::{pallet_custom_origins, Treasurer, TreasurySpender}; +use governance::{pallet_custom_origins, AuctionAdmin, GeneralAdmin, StakingAdmin, Treasurer}; use kusama_runtime_constants::time::{DAYS as RC_DAYS, HOURS as RC_HOURS, MINUTES as RC_MINUTES}; use pallet_assets::precompiles::{InlineIdConfig, ERC20}; use pallet_nfts::PalletFeatures; @@ -91,7 +92,7 @@ use sp_runtime::{ generic, impl_opaque_keys, traits::{ AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto, - IdentityLookup, Verify, + Verify, }, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, Perbill, Permill, RuntimeDebug, @@ -119,8 +120,8 @@ use xcm::{ VersionedLocation, VersionedXcm, }; use xcm_config::{ - FellowshipLocation, ForeignAssetsConvertedConcreteId, GovernanceLocation, KsmLocation, - LocationToAccountId, PoolAssetsConvertedConcreteId, StakingPot, + FellowshipLocation, ForeignAssetsConvertedConcreteId, KsmLocation, LocationToAccountId, + PoolAssetsConvertedConcreteId, RelayChainLocation, StakingPot, TrustBackedAssetsConvertedConcreteId, TrustBackedAssetsPalletLocation, }; use xcm_runtime_apis::{ @@ -950,7 +951,7 @@ parameter_types! { /// We allow root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EnsureXcm>, >; impl pallet_collator_selection::Config for Runtime { @@ -1240,7 +1241,7 @@ impl pallet_scheduler::Config for Runtime { type MaximumWeight = pallet_ah_migrator::LeftOrRight; // Also allow Treasurer to schedule recurring payments. - type ScheduleOrigin = EitherOf, Treasurer>; + type ScheduleOrigin = EitherOf, AuctionAdmin>, Treasurer>; type MaxScheduledPerBlock = MaxScheduledPerBlock; type WeightInfo = weights::pallet_scheduler::WeightInfo; type OriginPrivilegeCmp = OriginPrivilegeCmp; @@ -1327,6 +1328,65 @@ impl pallet_recovery::Config for Runtime { type BlockNumberProvider = RelaychainDataProvider; } +/// Defines what origin can modify which dynamic parameters. +pub struct DynamicParameterOrigin; +impl EnsureOriginWithArg for DynamicParameterOrigin { + type Success = (); + + fn try_origin( + origin: RuntimeOrigin, + key: &RuntimeParametersKey, + ) -> Result { + use crate::RuntimeParametersKey::*; + + match key { + Treasury(_) => + EitherOf::, GeneralAdmin>::ensure_origin(origin.clone()), + } + .map_err(|_| origin) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin(_key: &RuntimeParametersKey) -> Result { + // Provide the origin for the parameter returned by `Default`: + Ok(RuntimeOrigin::root()) + } +} + +impl pallet_parameters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeParameters = RuntimeParameters; + type AdminOrigin = DynamicParameterOrigin; + type WeightInfo = weights::pallet_parameters::WeightInfo; +} + +/// Dynamic params that can be adjusted at runtime. +#[dynamic_params(RuntimeParameters, pallet_parameters::Parameters::)] +pub mod dynamic_params { + use super::*; + + /// Parameters used by `pallet-treasury` to handle the burn process. + #[dynamic_pallet_params] + #[codec(index = 1)] + pub mod treasury { + #[codec(index = 0)] + pub static BurnPortion: Permill = Permill::from_percent(0); + + #[codec(index = 1)] + pub static BurnDestination: crate::treasury::BurnDestinationAccount = Default::default(); + } +} + +#[cfg(feature = "runtime-benchmarks")] +impl Default for RuntimeParameters { + fn default() -> Self { + RuntimeParameters::Treasury(dynamic_params::treasury::Parameters::BurnPortion( + dynamic_params::treasury::BurnPortion, + Some(Permill::from_percent(0)), + )) + } +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -1340,6 +1400,7 @@ construct_runtime!( MultiBlockMigrations: pallet_migrations = 5, Preimage: pallet_preimage = 6, Scheduler: pallet_scheduler = 7, + Parameters: pallet_parameters = 8, // Monetary stuff. Balances: pallet_balances = 10, @@ -1574,6 +1635,7 @@ mod benches { [pallet_multisig, Multisig] [pallet_nft_fractionalization, NftFractionalization] [pallet_nfts, Nfts] + [pallet_parameters, Parameters] [pallet_preimage, Preimage] [pallet_proxy, Proxy] [pallet_remote_proxy, RemoteProxyRelayChain] diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/treasury.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/treasury.rs index dd3f8bc6a7..7823779402 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/treasury.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/treasury.rs @@ -1,24 +1,31 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// TODO review all module - -use crate::*; -use frame_support::traits::{tokens::UnityOrOuterConversion, FromContains}; +// Copyright (C) Polkadot Fellows. +// 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 . + +//! This file contains relevant configuration of treasury (migrated from the RC with AHM). + +use super::*; + +use crate::governance::{Treasurer, TreasurySpender}; +use frame_support::traits::{ + tokens::UnityOrOuterConversion, Currency, FromContains, Get, OnUnbalanced, +}; use parachains_common::pay::VersionedLocatableAccount; use polkadot_runtime_common::impls::{ContainsParts, VersionedLocatableAsset}; +use scale_info::TypeInfo; +use sp_runtime::traits::IdentityLookup; parameter_types! { pub const SpendPeriod: BlockNumber = 6 * RC_DAYS; @@ -37,14 +44,64 @@ pub type TreasuryPaymaster = parachains_common::pay::LocalPay< xcm_config::LocationToAccountId, >; +#[derive( + Default, + MaxEncodedLen, + Encode, + Decode, + DecodeWithMemTracking, + TypeInfo, + Clone, + Eq, + PartialEq, + Debug, +)] +pub struct BurnDestinationAccount(pub Option); + +impl BurnDestinationAccount { + pub fn is_set(&self) -> bool { + self.0.is_some() + } +} + +pub type BalancesNegativeImbalance = >::NegativeImbalance; +pub struct TreasuryBurnHandler; + +impl OnUnbalanced for TreasuryBurnHandler { + fn on_nonzero_unbalanced(amount: BalancesNegativeImbalance) { + let destination = dynamic_params::treasury::BurnDestination::get(); + + if let BurnDestinationAccount(Some(account)) = destination { + // Must resolve into existing but better to be safe. + Balances::resolve_creating(&account, amount); + } else { + // If no account to destinate the funds to, just drop the + // imbalance. + <() as OnUnbalanced<_>>::on_nonzero_unbalanced(amount) + } + } +} + +impl Get for TreasuryBurnHandler { + fn get() -> Permill { + let destination = dynamic_params::treasury::BurnDestination::get(); + + if destination.is_set() { + dynamic_params::treasury::BurnPortion::get() + } else { + Permill::zero() + } + } +} + impl pallet_treasury::Config for Runtime { type PalletId = TreasuryPalletId; type Currency = Balances; type RejectOrigin = EitherOfDiverse, Treasurer>; type RuntimeEvent = RuntimeEvent; type SpendPeriod = pallet_ah_migrator::LeftOrRight; - type Burn = Burn; - type BurnDestination = (); + type Burn = TreasuryBurnHandler; + type BurnDestination = TreasuryBurnHandler; type SpendFunds = Bounties; type MaxApprovals = MaxApprovals; type WeightInfo = weights::pallet_treasury::WeightInfo; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs index aec5499f54..e8bfe10b90 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/weights/mod.rs @@ -22,33 +22,34 @@ pub mod frame_system; pub mod frame_system_extensions; pub mod pallet_asset_conversion; pub mod pallet_asset_conversion_tx_payment; +pub mod pallet_asset_rate; pub mod pallet_assets_foreign; pub mod pallet_assets_local; pub mod pallet_assets_pool; pub mod pallet_balances; +pub mod pallet_bounties; +pub mod pallet_child_bounties; pub mod pallet_collator_selection; +pub mod pallet_conviction_voting; pub mod pallet_message_queue; pub mod pallet_migrations; pub mod pallet_multisig; pub mod pallet_nft_fractionalization; pub mod pallet_nfts; +pub mod pallet_parameters; +pub mod pallet_preimage; pub mod pallet_proxy; pub mod pallet_remote_proxy; // TODO(#840): uncomment this so that pallet-revive is also benchmarked with this runtime // pub mod pallet_revive; pub mod pallet_ah_migrator; pub mod pallet_ah_ops; -pub mod pallet_asset_rate; pub mod pallet_bags_list; -pub mod pallet_bounties; -pub mod pallet_child_bounties; -pub mod pallet_conviction_voting; pub mod pallet_election_provider_multi_block; pub mod pallet_election_provider_multi_block_signed; pub mod pallet_election_provider_multi_block_unsigned; pub mod pallet_election_provider_multi_block_verifier; pub mod pallet_indices; -pub mod pallet_preimage; pub mod pallet_referenda; pub mod pallet_scheduler; pub mod pallet_session; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/weights/pallet_parameters.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/weights/pallet_parameters.rs new file mode 100644 index 0000000000..56ca1e1ca0 --- /dev/null +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/weights/pallet_parameters.rs @@ -0,0 +1,63 @@ +// Copyright (C) Parity Technologies and the various Polkadot contributors, see Contributions.md +// for a list of specific contributors. +// SPDX-License-Identifier: Apache-2.0 + +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Autogenerated weights for `pallet_parameters` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 47.1.0 +//! DATE: 2025-06-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `4e7e37be56c6`, CPU: `QEMU Virtual CPU version 2.5+` +//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: 1024 + +// Executed Command: +// frame-omni-bencher +// v1 +// benchmark +// pallet +// --extrinsic=* +// --runtime=target/production/wbuild/staging-kusama-runtime/staging_kusama_runtime.wasm +// --pallet=pallet_parameters +// --header=/_work/fellowship-001/runtimes/runtimes/.github/scripts/cmd/file_header.txt +// --output=./relay/kusama/src/weights +// --wasm-execution=compiled +// --steps=50 +// --repeat=20 +// --heap-pages=4096 + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_parameters`. +pub struct WeightInfo(PhantomData); +impl pallet_parameters::WeightInfo for WeightInfo { + /// Storage: `Parameters::Parameters` (r:1 w:1) + /// Proof: `Parameters::Parameters` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) + fn set_parameter() -> Weight { + // Proof Size summary in bytes: + // Measured: `4` + // Estimated: `3518` + // Minimum execution time: 10_330_000 picoseconds. + Weight::from_parts(10_780_000, 0) + .saturating_add(Weight::from_parts(0, 3518)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs index 3e7c69cc2e..4f869e6313 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs @@ -18,9 +18,9 @@ pub use TreasuryAccount as RelayTreasuryPalletAccount; use super::{ AccountId, AllPalletsWithSystem, AssetConversion, Assets, Balance, Balances, CollatorSelection, - NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, + GeneralAdmin, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, - ToPolkadotXcmRouter, WeightToFee, XcmpQueue, + StakingAdmin, ToPolkadotXcmRouter, WeightToFee, XcmpQueue, }; use crate::ForeignAssets; use alloc::{vec, vec::Vec}; @@ -56,16 +56,16 @@ use xcm_builder::{ DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, FungiblesAdapter, GlobalConsensusParachainConvertsFor, HashedDescription, IsConcrete, IsSiblingSystemParachain, LocalMint, MatchedConvertedConcreteId, MintLocation, - NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SingleAssetExchangeAdapter, SovereignSignedViaLocation, StartsWith, - StartsWithExplicitGlobalConsensus, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithLatestLocationConverter, WithUniqueTopic, - XcmFeeManagerFromComponents, + NoChecking, OriginToPluralityVoice, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SingleAssetExchangeAdapter, + SovereignSignedViaLocation, StartsWith, StartsWithExplicitGlobalConsensus, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, + WithLatestLocationConverter, WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::kusama::locations::GovernanceLocation; +pub use system_parachains_constants::kusama::locations::RelayChainLocation; parameter_types! { pub const RootLocation: Location = Location::here(); @@ -82,7 +82,7 @@ parameter_types! { pub PoolAssetsPalletLocation: Location = PalletInstance(::index() as u8).into(); pub CheckingAccount: AccountId = PolkadotXcm::check_account(); - pub const FellowshipLocation: Location = Location::parent(); + pub FellowshipLocation: Location = RelayChainLocation::get(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); pub StakingPot: AccountId = CollatorSelection::account_id(); // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location @@ -438,10 +438,38 @@ impl xcm_executor::Config for XcmConfig { type XcmEventEmitter = PolkadotXcm; } +parameter_types! { + // StakingAdmin pluralistic body. + pub const StakingAdminBodyId: BodyId = BodyId::Defense; + // Fellows pluralistic body. + pub const FellowsBodyId: BodyId = BodyId::Technical; + // `GeneralAdmin` pluralistic body. + pub const GeneralAdminBodyId: BodyId = BodyId::Administration; +} + +/// Type to convert the `StakingAdmin` origin to a Plurality `Location` value. +pub type StakingAdminToPlurality = + OriginToPluralityVoice; + +/// Type to convert the `GeneralAdmin` origin to a Plurality `Location` value. +pub type GeneralAdminToPlurality = + OriginToPluralityVoice; + /// Converts a local signed origin into an XCM `Location`. /// Forms the basis for local origins sending/executing XCMs. pub type LocalSignedOriginToLocation = SignedToAccountId32; +/// Type to convert a pallet `Origin` type value into a `Location` value which represents an +/// interior location of this chain for a destination chain. +pub type LocalPalletOrSignedOriginToLocation = ( + // GeneralAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + GeneralAdminToPlurality, + // StakingAdmin origin to be used in XCM as a corresponding Plurality `Location` value. + StakingAdminToPlurality, + // And a usual Signed origin to be used in XCM as a corresponding `AccountId32`. + SignedToAccountId32, +); + /// Use [`LocalXcmRouter`] instead. pub(crate) type LocalXcmRouterWithoutException = ( // Two routers - use UMP to communicate with the relay chain: @@ -484,7 +512,7 @@ parameter_types! { impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; // Any local signed origin can send XCM messages. - type SendXcmOrigin = EnsureXcmOrigin; + type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = XcmRouter; // Any local signed origin can execute XCM messages. type ExecuteXcmOrigin = EnsureXcmOrigin; diff --git a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs index 6ee018fd8d..ade079686c 100644 --- a/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs +++ b/system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs @@ -23,7 +23,7 @@ use alloc::boxed::Box; use asset_hub_kusama_runtime::{ xcm_config::{ bridging::{self, XcmBridgeHubRouterFeeAssetId}, - CheckingAccount, GovernanceLocation, KsmLocation, LocationToAccountId, + CheckingAccount, KsmLocation, LocationToAccountId, RelayChainLocation, RelayTreasuryLocation, RelayTreasuryPalletAccount, StakingPot, TrustBackedAssetsPalletLocation, XcmConfig, }, @@ -63,6 +63,11 @@ use xcm_runtime_apis::conversions::LocationToAccountHelper; const ALICE: [u8; 32] = [1u8; 32]; const SOME_ASSET_ADMIN: [u8; 32] = [5u8; 32]; +frame_support::parameter_types! { + // Local OpenGov + pub Governance: GovernanceOrigin = GovernanceOrigin::Origin(RuntimeOrigin::root()); +} + type AssetIdForTrustBackedAssetsConvertLatest = assets_common::AssetIdForTrustBackedAssetsConvert; @@ -548,7 +553,7 @@ fn change_xcm_bridge_hub_router_base_fee_by_governance_works() { >( collator_session_keys(), 1000, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), || { log::error!( target: "bridges::estimate", @@ -580,7 +585,7 @@ fn change_xcm_bridge_hub_router_byte_fee_by_governance_works() { >( collator_session_keys(), 1000, - GovernanceOrigin::Location(GovernanceLocation::get()), + Governance::get(), || { ( bridging::XcmBridgeHubRouterByteFee::key().to_vec(), @@ -878,9 +883,7 @@ fn authorized_aliases_work() { #[test] fn governance_authorize_upgrade_works() { - use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; - - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -888,12 +891,13 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - AssetHub + + // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), Either::Right(InstructionError { index: 1, error: XcmError::BadOrigin }) ); @@ -901,9 +905,5 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); - assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< - Runtime, - RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs index 923b61ed3d..5fe7409847 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs @@ -57,8 +57,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, - Everything, TransformOrigin, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOf, + EitherOfDiverse, Everything, TransformOrigin, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -71,7 +71,8 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody}; pub use sp_consensus_aura::sr25519::AuthorityId as AuraId; pub use sp_runtime::{MultiAddress, Perbill, Permill}; use xcm_config::{ - FellowshipLocation, GovernanceLocation, StakingPot, XcmOriginToTransactDispatchOrigin, + AssetHubLocation, FellowshipLocation, RelayChainLocation, StakingPot, + XcmOriginToTransactDispatchOrigin, }; #[cfg(any(feature = "std", test))] @@ -409,7 +410,7 @@ parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = AssetId(xcm_config::KsmRelayLocation::get()); + pub FeeAssetId: AssetId = AssetId(RelayChainLocation::get()); /// The base fee for the message delivery fees. pub const ToSiblingBaseDeliveryFee: u128 = CENTS.saturating_mul(3); pub const ToParentBaseDeliveryFee: u128 = CENTS.saturating_mul(3); @@ -494,7 +495,10 @@ parameter_types! { /// We allow Root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { @@ -634,11 +638,9 @@ mod benches { impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use xcm_config::KsmRelayLocation; - parameter_types! { pub ExistentialDepositAsset: Option = Some(( - KsmRelayLocation::get(), + RelayChainLocation::get(), ExistentialDeposit::get() ).into()); } @@ -700,7 +702,7 @@ mod benches { fn worst_case_holding(_depositable_count: u32) -> Assets { // just concrete assets according to relay chain. let assets: Vec = vec![Asset { - id: AssetId(KsmRelayLocation::get()), + id: AssetId(RelayChainLocation::get()), fun: Fungible(1_000_000 * UNITS), }]; assets.into() @@ -710,7 +712,7 @@ mod benches { parameter_types! { pub TrustedTeleporter: Option<(Location, Asset)> = Some(( AssetHubLocation::get(), - Asset { fun: Fungible(UNITS), id: AssetId(KsmRelayLocation::get()) }, + Asset { fun: Fungible(UNITS), id: AssetId(RelayChainLocation::get()) }, )); pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None; pub const TrustedReserve: Option<(Location, Asset)> = None; @@ -724,7 +726,7 @@ mod benches { type TrustedReserve = TrustedReserve; fn get_asset() -> Asset { - Asset { id: AssetId(KsmRelayLocation::get()), fun: Fungible(UNITS) } + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(UNITS) } } } @@ -757,14 +759,14 @@ mod benches { fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> { let origin = AssetHubLocation::get(); - let assets: Assets = (AssetId(KsmRelayLocation::get()), 1_000 * UNITS).into(); + let assets: Assets = (AssetId(RelayChainLocation::get()), 1_000 * UNITS).into(); let ticket = Location { parents: 0, interior: Here }; Ok((origin, ticket, assets)) } fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> { Ok(( - Asset { id: AssetId(KsmRelayLocation::get()), fun: Fungible(1_000_000 * UNITS) }, + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(1_000_000 * UNITS) }, Limited(Weight::from_parts(5000, 5000)), )) } @@ -1168,7 +1170,7 @@ impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { - let acceptable_assets = vec![AssetId(xcm_config::KsmRelayLocation::get())]; + let acceptable_assets = vec![AssetId(RelayChainLocation::get())]; PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs index dc03c29d41..9bc1e0308e 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/src/xcm_config.rs @@ -36,15 +36,15 @@ use parachains_common::xcm_config::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; -pub use system_parachains_constants::kusama::locations::GovernanceLocation; -use system_parachains_constants::{kusama::locations::AssetHubLocation, TREASURY_PALLET_ID}; +pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AllowExplicitUnpaidExecutionFrom, AllowHrmpNotificationsFromRelayChain, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FrameTransactionalProcessor, - FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser, ParentIsPreset, + FungibleAdapter, HashedDescription, IsConcrete, LocationAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, @@ -54,14 +54,13 @@ use xcm_executor::{traits::ConvertLocation, XcmExecutor}; parameter_types! { pub const RootLocation: Location = Location::here(); - pub const KsmRelayLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const FellowshipLocation: Location = Location::parent(); + pub FellowshipLocation: Location = RelayChainLocation::get(); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); pub RelayTreasuryLocation: Location = (Parent, PalletInstance(kusama_runtime_constants::TREASURY_PALLET_ID)).into(); // Test [`crate::tests::treasury_pallet_account_not_none`] ensures that the result of location @@ -92,7 +91,7 @@ pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an AccountId32 Location into a native chain account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -116,9 +115,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, @@ -176,7 +175,7 @@ pub type WaivedLocations = ( /// Cases where a remote origin is accepted as trusted Teleporter for a given asset: /// - KSM with the parent Relay Chain and sibling parachains. -pub type TrustedTeleporters = ConcreteAssetFromSystem; +pub type TrustedTeleporters = ConcreteAssetFromSystem; /// Defines origin aliasing rules for this chain. /// @@ -203,7 +202,7 @@ impl xcm_executor::Config for XcmConfig { >; type Trader = UsingComponents< WeightToFee, - KsmRelayLocation, + RelayChainLocation, AccountId, Balances, ResolveTo, diff --git a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs index 90f0c1d08e..d8687ad53d 100644 --- a/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs +++ b/system-parachains/bridge-hubs/bridge-hub-kusama/tests/tests.rs @@ -25,7 +25,7 @@ use bridge_hub_kusama_runtime::{ XcmOverBridgeHubPolkadotInstance, }, xcm_config::{ - GovernanceLocation, KsmRelayLocation, LocationToAccountId, RelayNetwork, + AssetHubLocation, LocationToAccountId, RelayChainLocation, RelayNetwork, RelayTreasuryLocation, RelayTreasuryPalletAccount, XcmConfig, }, AllPalletsWithoutSystem, Block, BridgeRejectObsoleteHeadersAndMessages, Executive, @@ -162,14 +162,26 @@ fn test_ed_is_one_tenth_of_relay() { } #[test] -fn initialize_bridge_by_governance_works() { +fn initialize_bridge_by_relay_governance_works() { bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< Runtime, BridgeGrandpaPolkadotInstance, >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), + ) +} + +#[test] +fn initialize_bridge_by_assethub_governance_works() { + bridge_hub_test_utils::test_cases::initialize_bridge_by_governance_works::< + Runtime, + BridgeGrandpaPolkadotInstance, + >( + collator_session_keys(), + bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, + GovernanceOrigin::Location(AssetHubLocation::get()), ) } @@ -182,7 +194,7 @@ fn change_bridge_grandpa_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), ) } @@ -195,7 +207,7 @@ fn change_bridge_parachains_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), ) } @@ -208,7 +220,7 @@ fn change_bridge_messages_pallet_mode_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), ) } @@ -221,7 +233,7 @@ fn change_delivery_reward_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), || (DeliveryRewardInBalance::key().to_vec(), DeliveryRewardInBalance::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -236,7 +248,7 @@ fn change_required_stake_by_governance_works() { >( collator_session_keys(), bp_bridge_hub_kusama::BRIDGE_HUB_KUSAMA_PARACHAIN_ID, - GovernanceOrigin::Location(GovernanceLocation::get()), + GovernanceOrigin::Location(RelayChainLocation::get()), || (RequiredStakeForStakeAndSlash::key().to_vec(), RequiredStakeForStakeAndSlash::get()), |old_value| old_value.checked_mul(2).unwrap(), ) @@ -259,9 +271,9 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() { } }), || ExportMessage { network: Polkadot, destination: Parachain(polkadot_runtime_constants::system_parachain::ASSET_HUB_ID).into(), xcm: Xcm(vec![]) }, - Some((KsmRelayLocation::get(), ExistentialDeposit::get()).into()), + Some((RelayChainLocation::get(), ExistentialDeposit::get()).into()), // value should be >= than value generated by `can_calculate_weight_for_paid_export_message_with_reserve_transfer` - Some((KsmRelayLocation::get(), bp_bridge_hub_kusama::BridgeHubKusamaBaseXcmFeeInKsms::get()).into()), + Some((RelayChainLocation::get(), bp_bridge_hub_kusama::BridgeHubKusamaBaseXcmFeeInKsms::get()).into()), || { PolkadotXcm::force_xcm_version(RuntimeOrigin::root(), Box::new(BridgeHubPolkadotLocation::get()), XCM_VERSION).expect("version saved!"); @@ -270,7 +282,7 @@ fn handle_export_message_from_system_parachain_add_to_outbound_queue_works() { Runtime, XcmOverBridgeHubPolkadotInstance, LocationToAccountId, - KsmRelayLocation, + RelayChainLocation, >( SiblingParachainLocation::get(), BridgedUniversalLocation::get(), @@ -333,7 +345,7 @@ fn relayed_incoming_message_works() { Runtime, XcmOverBridgeHubPolkadotInstance, LocationToAccountId, - KsmRelayLocation, + RelayChainLocation, >( SiblingParachainLocation::get(), BridgedUniversalLocation::get(), @@ -368,7 +380,7 @@ fn free_relay_extrinsic_works() { Runtime, XcmOverBridgeHubPolkadotInstance, LocationToAccountId, - KsmRelayLocation, + RelayChainLocation, >( SiblingParachainLocation::get(), BridgedUniversalLocation::get(), @@ -570,9 +582,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; - - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -580,22 +590,25 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - AssetHub + + // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), - Either::Right(InstructionError { index: 1, error: XcmError::BadOrigin }) + >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), + Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); // ok - relaychain assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/common/Cargo.toml b/system-parachains/common/Cargo.toml deleted file mode 100644 index 467ef28c1e..0000000000 --- a/system-parachains/common/Cargo.toml +++ /dev/null @@ -1,57 +0,0 @@ -[package] -authors.workspace = true -description = "Shared utilities between system-parachains runtimes" -edition.workspace = true -license.workspace = true -name = "system-parachains-common" -repository.workspace = true -version.workspace = true - -[dependencies] -codec = { features = ["derive", "max-encoded-len"], workspace = true } -scale-info = { features = ["derive"], workspace = true } - -sp-api = { workspace = true } -sp-runtime = { workspace = true } -sp-core = { workspace = true } -sp-std = { workspace = true } - -frame-support = { workspace = true } -pallet-treasury = { workspace = true } - -polkadot-runtime-common = { workspace = true } -xcm = { workspace = true } -xcm-executor = { workspace = true } - - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-support/std", - "pallet-treasury/std", - "polkadot-runtime-common/std", - "scale-info/std", - "sp-api/std", - "sp-core/std", - "sp-runtime/std", - "sp-std/std", - "xcm-executor/std", - "xcm/std", -] - -runtime-benchmarks = [ - "frame-support/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", - "xcm/runtime-benchmarks", -] - -try-runtime = [ - "frame-support/try-runtime", - "pallet-treasury/try-runtime", - "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/system-parachains/common/src/lib.rs b/system-parachains/common/src/lib.rs deleted file mode 100644 index 7fac39777d..0000000000 --- a/system-parachains/common/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 . - -//! Shared types between system-parachains runtimes. - -#![cfg_attr(not(feature = "std"), no_std)] - -pub mod pay; diff --git a/system-parachains/common/src/pay.rs b/system-parachains/common/src/pay.rs deleted file mode 100644 index c90aed946b..0000000000 --- a/system-parachains/common/src/pay.rs +++ /dev/null @@ -1,167 +0,0 @@ -// 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 . - -use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen}; -use frame_support::traits::{ - fungibles, - tokens::{PaymentStatus, Preservation}, -}; -use polkadot_runtime_common::impls::VersionedLocatableAsset; -use sp_runtime::{traits::TypedGet, DispatchError, RuntimeDebug}; -use xcm::latest::prelude::*; -use xcm_executor::traits::ConvertLocation; - -/// Versioned locatable account type which contains both an XCM `location` and `account_id` to -/// identify an account which exists on some chain. -#[derive( - Encode, - Decode, - DecodeWithMemTracking, - Eq, - PartialEq, - Clone, - RuntimeDebug, - scale_info::TypeInfo, - MaxEncodedLen, -)] -pub enum VersionedLocatableAccount { - // TODO: remove the V3 variant when V5 is available - #[codec(index = 3)] - V3 { location: xcm::v3::Location, account_id: xcm::v3::Location }, - #[codec(index = 4)] - V4 { location: xcm::v4::Location, account_id: xcm::v4::Location }, -} - -/// Pay on the local chain with `fungibles` implementation if the beneficiary and the asset are both -/// local. -pub struct LocalPay(core::marker::PhantomData<(F, A, C)>); -impl frame_support::traits::tokens::Pay for LocalPay -where - A: TypedGet, - F: fungibles::Mutate + fungibles::Create, - C: ConvertLocation, - A::Type: Eq + Clone, -{ - type Balance = F::Balance; - type Beneficiary = VersionedLocatableAccount; - type AssetKind = VersionedLocatableAsset; - type Id = QueryId; - type Error = DispatchError; - fn pay( - who: &Self::Beneficiary, - asset: Self::AssetKind, - amount: Self::Balance, - ) -> Result { - let who = Self::match_location(who).map_err(|_| DispatchError::Unavailable)?; - let asset = Self::match_asset(&asset).map_err(|_| DispatchError::Unavailable)?; - >::transfer( - asset, - &A::get(), - &who, - amount, - Preservation::Expendable, - )?; - // We use `QueryId::MAX` as a constant identifier for these payments since they are always - // processed immediately and successfully on the local chain. The `QueryId` type is used to - // maintain compatibility with XCM payment implementations. - Ok(Self::Id::MAX) - } - fn check_payment(_: Self::Id) -> PaymentStatus { - PaymentStatus::Success - } - #[cfg(feature = "runtime-benchmarks")] - fn ensure_successful(_: &Self::Beneficiary, asset: Self::AssetKind, amount: Self::Balance) { - let asset = Self::match_asset(&asset).expect("invalid asset"); - >::create(asset.clone(), A::get(), true, amount).unwrap(); - >::mint_into(asset, &A::get(), amount).unwrap(); - } - #[cfg(feature = "runtime-benchmarks")] - fn ensure_concluded(_: Self::Id) {} -} - -impl LocalPay -where - A: TypedGet, - F: fungibles::Mutate + fungibles::Create, - C: ConvertLocation, - A::Type: Eq + Clone, -{ - fn match_location(who: &VersionedLocatableAccount) -> Result { - // only applicable for the local accounts - let account_id: &xcm::v4::Location = match who { - VersionedLocatableAccount::V3 { location, account_id } if location.is_here() => - &(*account_id).try_into().map_err(|_| ())?, - VersionedLocatableAccount::V4 { location, account_id } if location.is_here() => - account_id, - _ => return Err(()), - }; - let account_id_v5 = account_id.clone().try_into().map_err(|_| ())?; - C::convert_location(&account_id_v5).ok_or(()) - } - fn match_asset(asset: &VersionedLocatableAsset) -> Result { - match asset { - VersionedLocatableAsset::V3 { location, asset_id } if location.is_here() => - (*asset_id).try_into().map(|a: xcm::v4::AssetId| a.0).map_err(|_| ()), - VersionedLocatableAsset::V4 { location, asset_id } if location.is_here() => - Ok(asset_id.clone().0), - _ => Err(()), - } - } -} - -#[cfg(feature = "runtime-benchmarks")] -pub mod benchmarks { - use super::*; - use frame_support::traits::Get; - use pallet_treasury::ArgumentsFactory as TreasuryArgumentsFactory; - use sp_core::ConstU8; - use sp_std::marker::PhantomData; - - /// Provides factory methods for the `AssetKind` and the `Beneficiary` that are applicable for - /// the payout made by [`LocalPay`]. - /// - /// ### Parameters: - /// - `PalletId`: The ID of the assets registry pallet. - /// - `AssetId`: The ID of the asset that will be created for the benchmark within `PalletId`. - pub struct LocalPayArguments>(PhantomData); - impl> - TreasuryArgumentsFactory - for LocalPayArguments - { - fn create_asset_kind(seed: u32) -> VersionedLocatableAsset { - VersionedLocatableAsset::V4 { - location: xcm::v4::Location::new(0, []), - asset_id: xcm::v4::Location::new( - 0, - [ - xcm::v4::Junction::PalletInstance(PalletId::get()), - xcm::v4::Junction::GeneralIndex(seed.into()), - ], - ) - .into(), - } - } - fn create_beneficiary(seed: [u8; 32]) -> VersionedLocatableAccount { - VersionedLocatableAccount::V4 { - location: xcm::v4::Location::new(0, []), - account_id: xcm::v4::Location::new( - 0, - [xcm::v4::Junction::AccountId32 { network: None, id: seed }], - ), - } - } - } -} diff --git a/system-parachains/constants/src/kusama.rs b/system-parachains/constants/src/kusama.rs index 5a8f6963d6..aec6925382 100644 --- a/system-parachains/constants/src/kusama.rs +++ b/system-parachains/constants/src/kusama.rs @@ -150,11 +150,10 @@ pub mod locations { use xcm::latest::prelude::{Junction::*, Location}; parameter_types! { + pub RelayChainLocation: Location = Location::parent(); pub AssetHubLocation: Location = Location::new(1, Parachain(kusama_runtime_constants::system_parachain::ASSET_HUB_ID)); pub PeopleLocation: Location = Location::new(1, Parachain(kusama_runtime_constants::system_parachain::PEOPLE_ID)); - - pub GovernanceLocation: Location = Location::parent(); } } diff --git a/system-parachains/coretime/coretime-kusama/src/lib.rs b/system-parachains/coretime/coretime-kusama/src/lib.rs index 597b8dce7b..34d80b2024 100644 --- a/system-parachains/coretime/coretime-kusama/src/lib.rs +++ b/system-parachains/coretime/coretime-kusama/src/lib.rs @@ -42,7 +42,7 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOf, EitherOfDiverse, EverythingBut, InstanceFilter, TransformOrigin, }, weights::{ConstantMultiplier, Weight}, @@ -78,7 +78,7 @@ use system_parachains_constants::{ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use xcm::prelude::*; use xcm_config::{ - FellowshipLocation, GovernanceLocation, KsmRelayLocation, StakingPot, + AssetHubLocation, FellowshipLocation, RelayChainLocation, StakingPot, XcmOriginToTransactDispatchOrigin, }; use xcm_runtime_apis::{ @@ -376,7 +376,7 @@ parameter_types! { // Fellows pluralistic body. pub const FellowsBodyId: BodyId = BodyId::Technical; /// The asset ID for the asset that we use to pay for message delivery fees. - pub FeeAssetId: AssetId = AssetId(KsmRelayLocation::get()); + pub FeeAssetId: AssetId = AssetId(RelayChainLocation::get()); /// The base fee for the message delivery fees. pub const ToSiblingBaseDeliveryFee: u128 = CENTS.saturating_mul(3); pub const ToParentBaseDeliveryFee: u128 = CENTS.saturating_mul(3); @@ -455,7 +455,10 @@ parameter_types! { /// We allow Root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { @@ -719,11 +722,9 @@ mod benches { impl cumulus_pallet_session_benchmarking::Config for Runtime {} - use xcm_config::KsmRelayLocation; - parameter_types! { pub ExistentialDepositAsset: Option = Some(( - KsmRelayLocation::get(), + RelayChainLocation::get(), ExistentialDeposit::get() ).into()); pub const RandomParaId: ParaId = ParaId::new(43211234); @@ -817,7 +818,7 @@ mod benches { fn worst_case_holding(_depositable_count: u32) -> Assets { // just concrete assets according to relay chain. let assets: Vec = vec![Asset { - id: AssetId(KsmRelayLocation::get()), + id: AssetId(RelayChainLocation::get()), fun: Fungible(1_000_000 * UNITS), }]; assets.into() @@ -827,7 +828,7 @@ mod benches { parameter_types! { pub TrustedTeleporter: Option<(Location, Asset)> = Some(( AssetHubLocation::get(), - Asset { fun: Fungible(UNITS), id: AssetId(KsmRelayLocation::get()) }, + Asset { fun: Fungible(UNITS), id: AssetId(RelayChainLocation::get()) }, )); pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None; pub const TrustedReserve: Option<(Location, Asset)> = None; @@ -841,7 +842,7 @@ mod benches { type TrustedReserve = TrustedReserve; fn get_asset() -> Asset { - Asset { id: AssetId(KsmRelayLocation::get()), fun: Fungible(UNITS) } + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(UNITS) } } } @@ -874,14 +875,14 @@ mod benches { fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> { let origin = AssetHubLocation::get(); - let assets: Assets = (AssetId(KsmRelayLocation::get()), 1_000 * UNITS).into(); + let assets: Assets = (AssetId(RelayChainLocation::get()), 1_000 * UNITS).into(); let ticket = Location { parents: 0, interior: Here }; Ok((origin, ticket, assets)) } fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> { Ok(( - Asset { id: AssetId(KsmRelayLocation::get()), fun: Fungible(1_000_000 * UNITS) }, + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(1_000_000 * UNITS) }, Limited(Weight::from_parts(5000, 5000)), )) } @@ -1074,7 +1075,7 @@ impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { - let acceptable_assets = vec![AssetId(xcm_config::KsmRelayLocation::get())]; + let acceptable_assets = vec![AssetId(RelayChainLocation::get())]; PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } diff --git a/system-parachains/coretime/coretime-kusama/src/tests.rs b/system-parachains/coretime/coretime-kusama/src/tests.rs index bc9a6d759f..9d182ac878 100644 --- a/system-parachains/coretime/coretime-kusama/src/tests.rs +++ b/system-parachains/coretime/coretime-kusama/src/tests.rs @@ -16,8 +16,8 @@ use crate::{ coretime::{BrokerPalletId, CoretimeBurnAccount}, - xcm_config::LocationToAccountId, - GovernanceLocation, *, + xcm_config::{AssetHubLocation, LocationToAccountId, RelayChainLocation}, + *, }; use coretime::CoretimeAllocator; use cumulus_pallet_parachain_system::ValidationData; @@ -249,9 +249,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; - - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -259,12 +257,13 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - AssetHub + + // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); @@ -272,9 +271,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs index 5b4a71d812..4a847b7d27 100644 --- a/system-parachains/coretime/coretime-kusama/src/xcm_config.rs +++ b/system-parachains/coretime/coretime-kusama/src/xcm_config.rs @@ -35,7 +35,7 @@ use parachains_common::xcm_config::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::{kusama::locations::AssetHubLocation, TREASURY_PALLET_ID}; +use system_parachains_constants::TREASURY_PALLET_ID; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, @@ -43,19 +43,18 @@ use xcm_builder::{ AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, - NonFungibleAdapter, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, - SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, - SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, - UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + LocationAsSuperuser, NonFungibleAdapter, ParentIsPreset, RelayChainAsNative, + SendXcmFeeToAccount, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::kusama::locations::GovernanceLocation; +pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const RootLocation: Location = Location::here(); - pub const KsmRelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Kusama); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = @@ -64,7 +63,7 @@ parameter_types! { PalletInstance(::index() as u8).into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const FellowshipLocation: Location = Location::parent(); + pub FellowshipLocation: Location = RelayChainLocation::get(); pub StakingPot: AccountId = CollatorSelection::account_id(); } @@ -90,7 +89,7 @@ pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Do a simple punn to convert an `AccountId32` `Location` into a native chain // `AccountId`: LocationToAccountId, @@ -132,9 +131,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, @@ -163,7 +162,11 @@ pub type Barrier = TrailingSetTopicAsId< // allow it. AllowTopLevelPaidExecutionFrom, // Parent and its pluralities (i.e. governance bodies) get free execution. - AllowExplicitUnpaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom<( + ParentOrParentsPlurality, + // For OpenGov on AH + Equals, + )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), @@ -216,7 +219,7 @@ impl xcm_executor::Config for XcmConfig { // where allowed (e.g. with the Relay Chain). type IsReserve = (); /// Only allow teleportation of KSM. - type IsTeleporter = ConcreteAssetFromSystem; + type IsTeleporter = ConcreteAssetFromSystem; type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = WeightInfoBounds< @@ -226,7 +229,7 @@ impl xcm_executor::Config for XcmConfig { >; type Trader = UsingComponents< WeightToFee, - KsmRelayLocation, + RelayChainLocation, AccountId, Balances, ResolveTo, diff --git a/system-parachains/encointer/src/xcm_config.rs b/system-parachains/encointer/src/xcm_config.rs index cf6dc1f74f..808b8d93d6 100644 --- a/system-parachains/encointer/src/xcm_config.rs +++ b/system-parachains/encointer/src/xcm_config.rs @@ -23,7 +23,7 @@ use super::{ use frame_support::{ parameter_types, traits::{ - fungible::HoldConsideration, tokens::imbalance::ResolveTo, Contains, Everything, + fungible::HoldConsideration, tokens::imbalance::ResolveTo, Contains, Equals, Everything, LinearStoragePrice, Nothing, }, }; @@ -35,21 +35,20 @@ use parachains_common::xcm_config::{ use polkadot_parachain_primitives::primitives::Sibling; use sp_core::ConstU32; -use system_parachains_constants::kusama::locations::AssetHubLocation; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeTerminus, EnsureXcmOrigin, FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, - ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + LocationAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, WeightInfoBounds, WithComputedOrigin, }; use xcm_executor::XcmExecutor; -pub use system_parachains_constants::kusama::locations::GovernanceLocation; +pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; parameter_types! { pub const KsmLocation: Location = Location::parent(); @@ -106,9 +105,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognised. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, @@ -145,7 +144,11 @@ pub type Barrier = TrailingSetTopicAsId< AllowTopLevelPaidExecutionFrom, // Parent, its pluralities (i.e. governance bodies), parent's treasury and // sibling bridge hub get free execution. - AllowExplicitUnpaidExecutionFrom<(ParentOrParentsPlurality,)>, + AllowExplicitUnpaidExecutionFrom<( + ParentOrParentsPlurality, + // For OpenGov on AH + Equals, + )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), diff --git a/system-parachains/encointer/tests/tests.rs b/system-parachains/encointer/tests/tests.rs index 098a7ef0ce..4a5666b256 100644 --- a/system-parachains/encointer/tests/tests.rs +++ b/system-parachains/encointer/tests/tests.rs @@ -1,4 +1,7 @@ -use encointer_kusama_runtime::{xcm_config::GovernanceLocation, Runtime, RuntimeOrigin}; +use encointer_kusama_runtime::{ + xcm_config::{AssetHubLocation, RelayChainLocation}, + Runtime, RuntimeOrigin, +}; use frame_support::{assert_err, assert_ok}; use parachains_runtimes_test_utils::GovernanceOrigin; use sp_runtime::Either; @@ -6,8 +9,6 @@ use xcm::prelude::*; #[test] fn governance_authorize_upgrade_works() { - use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; - // no - random para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< @@ -16,12 +17,13 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - AssetHub + + // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); @@ -29,9 +31,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/people/people-kusama/src/lib.rs b/system-parachains/people/people-kusama/src/lib.rs index 7581c76cd1..59b5294a61 100644 --- a/system-parachains/people/people-kusama/src/lib.rs +++ b/system-parachains/people/people-kusama/src/lib.rs @@ -38,8 +38,8 @@ use frame_support::{ genesis_builder_helper::{build_state, get_preset}, parameter_types, traits::{ - tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, - Everything, InstanceFilter, TransformOrigin, + tokens::imbalance::ResolveTo, ConstBool, ConstU32, ConstU64, ConstU8, EitherOf, + EitherOfDiverse, Everything, InstanceFilter, TransformOrigin, }, weights::{ConstantMultiplier, Weight}, PalletId, @@ -90,9 +90,10 @@ use xcm::{ VersionedXcm, }; use xcm_config::{ - FellowshipLocation, GovernanceLocation, PriceForSiblingParachainDelivery, StakingPot, - XcmConfig, XcmOriginToTransactDispatchOrigin, + AssetHubLocation, FellowshipLocation, PriceForSiblingParachainDelivery, RelayChainLocation, + StakingPot, XcmConfig, XcmOriginToTransactDispatchOrigin, }; + use xcm_runtime_apis::{ dry_run::{CallDryRunEffects, Error as XcmDryRunApiError, XcmDryRunEffects}, fees::Error as XcmPaymentApiError, @@ -410,7 +411,10 @@ parameter_types! { /// We allow Root and the `StakingAdmin` to execute privileged collator selection operations. pub type CollatorSelectionUpdateOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_collator_selection::Config for Runtime { @@ -741,11 +745,10 @@ mod benches { } use xcm::latest::prelude::*; - use xcm_config::RelayLocation; parameter_types! { pub ExistentialDepositAsset: Option = Some(( - RelayLocation::get(), + RelayChainLocation::get(), ExistentialDeposit::get() ).into()); } @@ -765,8 +768,10 @@ mod benches { } fn worst_case_holding(_depositable_count: u32) -> Assets { // just concrete assets according to relay chain. - let assets: Vec = - vec![Asset { id: AssetId(RelayLocation::get()), fun: Fungible(1_000_000 * UNITS) }]; + let assets: Vec = vec![Asset { + id: AssetId(RelayChainLocation::get()), + fun: Fungible(1_000_000 * UNITS), + }]; assets.into() } } @@ -774,7 +779,7 @@ mod benches { parameter_types! { pub TrustedTeleporter: Option<(Location, Asset)> = Some(( AssetHubLocation::get(), - Asset { fun: Fungible(UNITS), id: AssetId(RelayLocation::get()) }, + Asset { fun: Fungible(UNITS), id: AssetId(RelayChainLocation::get()) }, )); pub const CheckedAccount: Option<(AccountId, xcm_builder::MintLocation)> = None; pub const TrustedReserve: Option<(Location, Asset)> = None; @@ -788,7 +793,7 @@ mod benches { type TrustedReserve = TrustedReserve; fn get_asset() -> Asset { - Asset { id: AssetId(RelayLocation::get()), fun: Fungible(UNITS) } + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(UNITS) } } } @@ -821,14 +826,14 @@ mod benches { fn claimable_asset() -> Result<(Location, Location, Assets), BenchmarkError> { let origin = AssetHubLocation::get(); - let assets: Assets = (AssetId(RelayLocation::get()), 1_000 * UNITS).into(); + let assets: Assets = (AssetId(RelayChainLocation::get()), 1_000 * UNITS).into(); let ticket = Location::new(0, []); Ok((origin, ticket, assets)) } fn worst_case_for_trader() -> Result<(Asset, WeightLimit), BenchmarkError> { Ok(( - Asset { id: AssetId(RelayLocation::get()), fun: Fungible(1_000_000 * UNITS) }, + Asset { id: AssetId(RelayChainLocation::get()), fun: Fungible(1_000_000 * UNITS) }, Limited(Weight::from_parts(5000, 5000)), )) } @@ -1021,7 +1026,7 @@ impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, XcmPaymentApiError> { - let acceptable_assets = vec![AssetId(xcm_config::RelayLocation::get())]; + let acceptable_assets = vec![AssetId(RelayChainLocation::get())]; PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } diff --git a/system-parachains/people/people-kusama/src/people.rs b/system-parachains/people/people-kusama/src/people.rs index 80bc1f290b..a949f4aafd 100644 --- a/system-parachains/people/people-kusama/src/people.rs +++ b/system-parachains/people/people-kusama/src/people.rs @@ -44,7 +44,10 @@ parameter_types! { pub type IdentityAdminOrigin = EitherOfDiverse< EnsureRoot, - EnsureXcm>, + EitherOf< + EnsureXcm>, + EnsureXcm>, + >, >; impl pallet_identity::Config for Runtime { diff --git a/system-parachains/people/people-kusama/src/tests.rs b/system-parachains/people/people-kusama/src/tests.rs index 9695537365..1af5c1a2f0 100644 --- a/system-parachains/people/people-kusama/src/tests.rs +++ b/system-parachains/people/people-kusama/src/tests.rs @@ -15,7 +15,7 @@ // limitations under the License. use crate::{ - xcm_config::{GovernanceLocation, LocationToAccountId}, + xcm_config::{AssetHubLocation, LocationToAccountId, RelayChainLocation}, Block, Runtime, RuntimeCall, RuntimeOrigin, WeightToFee, }; use polkadot_primitives::AccountId; @@ -142,9 +142,7 @@ fn xcm_payment_api_works() { #[test] fn governance_authorize_upgrade_works() { - use kusama_runtime_constants::system_parachain::ASSET_HUB_ID; - - // no - random para + // no - random non-system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, @@ -152,12 +150,13 @@ fn governance_authorize_upgrade_works() { >(GovernanceOrigin::Location(Location::new(1, Parachain(12334)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); - // no - AssetHub + + // no - random system para assert_err!( parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::new(1, Parachain(ASSET_HUB_ID)))), + >(GovernanceOrigin::Location(Location::new(1, Parachain(1002)))), Either::Right(InstructionError { index: 0, error: XcmError::Barrier }) ); @@ -165,9 +164,11 @@ fn governance_authorize_upgrade_works() { assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(Location::parent()))); + >(GovernanceOrigin::Location(RelayChainLocation::get()))); + + // ok - AssetHub assert_ok!(parachains_runtimes_test_utils::test_cases::can_governance_authorize_upgrade::< Runtime, RuntimeOrigin, - >(GovernanceOrigin::Location(GovernanceLocation::get()))); + >(GovernanceOrigin::Location(AssetHubLocation::get()))); } diff --git a/system-parachains/people/people-kusama/src/xcm_config.rs b/system-parachains/people/people-kusama/src/xcm_config.rs index d257c71d72..d9b187a48b 100644 --- a/system-parachains/people/people-kusama/src/xcm_config.rs +++ b/system-parachains/people/people-kusama/src/xcm_config.rs @@ -37,35 +37,34 @@ use parachains_common::{ }; use polkadot_parachain_primitives::primitives::Sibling; use sp_runtime::traits::AccountIdConversion; -use system_parachains_constants::kusama::locations::AssetHubLocation; +pub use system_parachains_constants::kusama::locations::{AssetHubLocation, RelayChainLocation}; use xcm::latest::prelude::*; use xcm_builder::{ AccountId32Aliases, AliasChildLocation, AliasOriginRootUsingFilter, AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, DenyReserveTransferToRelayChain, DenyThenTry, DescribeAllTerminal, DescribeFamily, DescribeTerminus, EnsureXcmOrigin, - FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, ParentAsSuperuser, - ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, - SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, UsingComponents, - WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, XcmFeeManagerFromComponents, + FrameTransactionalProcessor, FungibleAdapter, HashedDescription, IsConcrete, + LocationAsSuperuser, ParentIsPreset, RelayChainAsNative, SendXcmFeeToAccount, + SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, TrailingSetTopicAsId, + UsingComponents, WeightInfoBounds, WithComputedOrigin, WithUniqueTopic, + XcmFeeManagerFromComponents, }; use xcm_executor::{traits::ConvertLocation, XcmExecutor}; -pub use system_parachains_constants::kusama::locations::GovernanceLocation; - parameter_types! { pub const RootLocation: Location = Location::here(); - pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: Option = Some(NetworkId::Kusama); pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get().unwrap()), Parachain(ParachainInfo::parachain_id().into())].into(); pub const MaxInstructions: u32 = 100; pub const MaxAssetsIntoHolding: u32 = 64; - pub const FellowshipLocation: Location = Location::parent(); + + pub FellowshipLocation: Location = RelayChainLocation::get(); /// The asset ID for the asset that we use to pay for message delivery fees. Just KSM. - pub FeeAssetId: AssetId = AssetId(RelayLocation::get()); + pub FeeAssetId: AssetId = AssetId(RelayChainLocation::get()); /// The base fee for the message delivery fees. pub const BaseDeliveryFee: u128 = CENTS.saturating_mul(3); pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating(); @@ -113,7 +112,7 @@ pub type FungibleTransactor = FungibleAdapter< // Use this currency: Balances, // Use this currency when it is a fungible asset matching the given location or name: - IsConcrete, + IsConcrete, // Convert an XCM `Location` into a local account ID: LocationToAccountId, // Our chain's account ID type (we can't get away without mentioning it explicitly): @@ -137,9 +136,9 @@ pub type XcmOriginToTransactDispatchOrigin = ( // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when // recognized. SiblingParachainAsNative, - // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a - // transaction from the Root origin. - ParentAsSuperuser, + // AssetHub or Relay can execute as root (based on: https://github.com/polkadot-fellows/runtimes/issues/651). + // This will allow them to issue a transaction from the Root origin. + LocationAsSuperuser<(Equals, Equals), RuntimeOrigin>, // Native signed account converter; this just converts an `AccountId32` origin into a normal // `RuntimeOrigin::Signed` origin of the same 32-byte value. SignedAccountId32AsNative, @@ -175,7 +174,11 @@ pub type Barrier = TrailingSetTopicAsId< // allow it. AllowTopLevelPaidExecutionFrom, // Parent and its pluralities (i.e. governance bodies) get free execution. - AllowExplicitUnpaidExecutionFrom, + AllowExplicitUnpaidExecutionFrom<( + ParentOrParentsPlurality, + // For OpenGov on AH + Equals, + )>, // Subscriptions for version tracking are OK. AllowSubscriptionsFrom, ), @@ -219,7 +222,7 @@ impl xcm_executor::Config for XcmConfig { // where allowed (e.g. with the Relay Chain). type IsReserve = (); /// Only allow teleportation of KSM. - type IsTeleporter = ConcreteAssetFromSystem; + type IsTeleporter = ConcreteAssetFromSystem; type UniversalLocation = UniversalLocation; type Barrier = Barrier; type Weigher = WeightInfoBounds< @@ -229,7 +232,7 @@ impl xcm_executor::Config for XcmConfig { >; type Trader = UsingComponents< WeightToFee, - RelayLocation, + RelayChainLocation, AccountId, Balances, ResolveTo,