Skip to content

Commit

Permalink
Sanitize UniversalLocation witth GlobalConsensus + XCM small nits…
Browse files Browse the repository at this point in the history
… and improvements (#4238)

This PR:
- sanitizes all `UniversalLocation`s with `GlobalConsensus` (when
possible) - addressing
[comment](#4025 (comment))
- adds `DefaultConfig` for `pallet-xcm-benchmarks` for `system`
  • Loading branch information
bkontur authored Apr 22, 2024
1 parent e0202ec commit ff7e2c8
Show file tree
Hide file tree
Showing 19 changed files with 23 additions and 82 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ use xcm_executor::XcmExecutor;

parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub const RelayNetwork: NetworkId = NetworkId::Rococo;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
pub const ExecutiveBody: BodyId = BodyId::Executive;
pub TreasuryAccount: AccountId = TREASURY_PALLET_ID.into_account_truncating();
pub RelayTreasuryLocation: Location = (Parent, PalletInstance(rococo_runtime_constants::TREASURY_PALLET_ID)).into();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use xcm_builder::{

parameter_types! {
pub const WestendLocation: Location = Location::parent();
pub const WestendNetwork: Option<NetworkId> = Some(NetworkId::Westend);
pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into();
pub const WestendNetwork: NetworkId = NetworkId::Westend;
pub UniversalLocation: InteriorLocation = [GlobalConsensus(WestendNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
}

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
4 changes: 2 additions & 2 deletions cumulus/parachains/runtimes/starters/shell/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use xcm_builder::{

parameter_types! {
pub const RococoLocation: Location = Location::parent();
pub const RococoNetwork: Option<NetworkId> = Some(NetworkId::Rococo);
pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into();
pub const RococoNetwork: NetworkId = NetworkId::Rococo;
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RococoNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
}

/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,9 @@ impl cumulus_pallet_aura_ext::Config for Runtime {}

parameter_types! {
pub const RocLocation: Location = Location::parent();
pub const RococoNetwork: Option<NetworkId> = Some(NetworkId::Rococo);
pub const RococoNetwork: NetworkId = NetworkId::Rococo;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
pub UniversalLocation: InteriorLocation = [Parachain(ParachainInfo::parachain_id().into())].into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RococoNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into();
pub CheckingAccount: AccountId = PolkadotXcm::check_account();
}

Expand Down
1 change: 0 additions & 1 deletion polkadot/xcm/pallet-xcm-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ log = { workspace = true, default-features = true }
[dev-dependencies]
pallet-balances = { path = "../../../substrate/frame/balances" }
pallet-assets = { path = "../../../substrate/frame/assets" }
sp-core = { path = "../../../substrate/primitives/core" }
sp-tracing = { path = "../../../substrate/primitives/tracing" }
xcm = { package = "staging-xcm", path = ".." }
# temp
Expand Down
32 changes: 1 addition & 31 deletions polkadot/xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ use crate::{fungible as xcm_balances_benchmark, mock::*};
use frame_benchmarking::BenchmarkError;
use frame_support::{
derive_impl, parameter_types,
traits::{ConstU32, Everything, Nothing},
weights::Weight,
traits::{Everything, Nothing},
};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup};
use xcm::latest::prelude::*;
use xcm_builder::{AllowUnpaidExecutionFrom, FrameTransactionalProcessor, MintLocation};

Expand All @@ -40,37 +37,10 @@ frame_support::construct_runtime!(
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX));
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = ConstU32<16>;
}

parameter_types! {
Expand Down
31 changes: 1 addition & 30 deletions polkadot/xcm/pallet-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ use codec::Decode;
use frame_support::{
derive_impl, parameter_types,
traits::{Contains, Everything, OriginTrait},
weights::Weight,
};
use sp_core::H256;
use sp_runtime::traits::{BlakeTwo256, IdentityLookup, TrailingZeroInput};
use sp_runtime::traits::TrailingZeroInput;
use xcm_builder::{
test_utils::{
AssetsInHolding, TestAssetExchanger, TestAssetLocker, TestAssetTrap,
Expand All @@ -45,37 +43,10 @@ frame_support::construct_runtime!(
}
);

parameter_types! {
pub const BlockHashCount: u64 = 250;
pub BlockWeights: frame_system::limits::BlockWeights =
frame_system::limits::BlockWeights::simple_max(Weight::from_parts(1024, u64::MAX));
}

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
type RuntimeOrigin = RuntimeOrigin;
type Nonce = u64;
type Hash = H256;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
type SS58Prefix = ();
type OnSetCode = ();
type MaxConsumers = frame_support::traits::ConstU32<16>;
}

/// The benchmarks in this pallet should never need an asset transactor to begin with.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm-benchmarks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl xcm_executor::traits::ConvertLocation<u64> for AccountIdConverter {
}

parameter_types! {
pub UniversalLocation: InteriorLocation = Junction::Parachain(101).into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(ByGenesis([1; 32])), Junction::Parachain(101)].into();
pub UnitWeightCost: Weight = Weight::from_parts(10, 10);
pub WeightPrice: (AssetId, u128, u128) = (AssetId(Here.into()), 1_000_000, 1024);
}
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/pallet-xcm/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ parameter_types! {
)),
};
pub const AnyNetwork: Option<NetworkId> = None;
pub UniversalLocation: InteriorLocation = Here;
pub UniversalLocation: InteriorLocation = GlobalConsensus(ByGenesis([0; 32])).into();
pub UnitWeightCost: u64 = 1_000;
pub CheckingAccount: AccountId = XcmPallet::check_account();
}
Expand Down
4 changes: 2 additions & 2 deletions polkadot/xcm/xcm-builder/src/universal_exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn forward_id_for(original_id: &XcmHash) -> XcmHash {
/// end with the `SetTopic` instruction.
///
/// In the case that the message ends with a `SetTopic(T)` (as should be the case if the top-level
/// router is `EnsureUniqueTopic`), then the forwarding message (i.e. the one carrying the
/// router is `WithUniqueTopic`), then the forwarding message (i.e. the one carrying the
/// export instruction *to* the bridge in local consensus) will also end with a `SetTopic` whose
/// inner is `forward_id_for(T)`. If this is not the case then the onward message will not be given
/// the `SetTopic` afterword.
Expand Down Expand Up @@ -254,7 +254,7 @@ impl<Bridges: ExporterFor, Router: SendXcm, UniversalLocation: Get<InteriorLocat
/// end with the `SetTopic` instruction.
///
/// In the case that the message ends with a `SetTopic(T)` (as should be the case if the top-level
/// router is `EnsureUniqueTopic`), then the forwarding message (i.e. the one carrying the
/// router is `WithUniqueTopic`), then the forwarding message (i.e. the one carrying the
/// export instruction *to* the bridge in local consensus) will also end with a `SetTopic` whose
/// inner is `forward_id_for(T)`. If this is not the case then the onward message will not be given
/// the `SetTopic` afterword.
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-builder/tests/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl configuration::Config for Runtime {
parameter_types! {
pub const KsmLocation: Location = Location::here();
pub const KusamaNetwork: NetworkId = NetworkId::Kusama;
pub UniversalLocation: InteriorLocation = Here;
pub UniversalLocation: InteriorLocation = KusamaNetwork::get().into();
pub CheckAccount: (AccountId, MintLocation) = (XcmPallet::check_account(), MintLocation::Local);
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-simulator/example/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ parameter_types! {
parameter_types! {
pub const KsmLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub UniversalLocation: InteriorLocation = Parachain(MsgQueue::parachain_id().into()).into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
}

pub type LocationToAccountId = (
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-simulator/example/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ parameter_types! {
pub const TokenLocation: Location = Here.into_location();
pub RelayNetwork: NetworkId = ByGenesis([0; 32]);
pub const AnyNetwork: Option<NetworkId> = None;
pub UniversalLocation: InteriorLocation = Here;
pub UniversalLocation: InteriorLocation = RelayNetwork::get().into();
pub UnitWeightCost: u64 = 1_000;
}

Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-simulator/fuzzer/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ parameter_types! {
parameter_types! {
pub const KsmLocation: Location = Location::parent();
pub const RelayNetwork: NetworkId = NetworkId::Kusama;
pub UniversalLocation: InteriorLocation = Parachain(MsgQueue::parachain_id().into()).into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
}

pub type LocationToAccountId = (
Expand Down
2 changes: 1 addition & 1 deletion polkadot/xcm/xcm-simulator/fuzzer/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ parameter_types! {
pub const TokenLocation: Location = Here.into_location();
pub const ThisNetwork: NetworkId = NetworkId::ByGenesis([0; 32]);
pub const AnyNetwork: Option<NetworkId> = None;
pub const UniversalLocation: InteriorLocation = Here;
pub UniversalLocation: InteriorLocation = ThisNetwork::get().into();
}

pub type SovereignAccountOf =
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/mock-network/src/parachain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ parameter_types! {
pub const KsmLocation: Location = Location::parent();
pub const TokenLocation: Location = Here.into_location();
pub const RelayNetwork: NetworkId = ByGenesis([0; 32]);
pub UniversalLocation: InteriorLocation = Parachain(MsgQueue::parachain_id().into()).into();
pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into();
}

pub type XcmOriginToCallOrigin = (
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/mock-network/src/relay_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl configuration::Config for Runtime {
parameter_types! {
pub RelayNetwork: NetworkId = ByGenesis([0; 32]);
pub const TokenLocation: Location = Here.into_location();
pub UniversalLocation: InteriorLocation = Here;
pub UniversalLocation: InteriorLocation = RelayNetwork::get().into();
pub UnitWeightCost: u64 = 1_000;
}

Expand Down
2 changes: 2 additions & 0 deletions templates/parachain/runtime/src/configs/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parameter_types! {
pub const RelayLocation: Location = Location::parent();
pub const RelayNetwork: Option<NetworkId> = None;
pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into();
// For the real deployment, it is recommended to set `RelayNetwork` according to the relay chain
// and prepend `UniversalLocation` with `GlobalConsensus(RelayNetwork::get())`.
pub UniversalLocation: InteriorLocation = Parachain(ParachainInfo::parachain_id().into()).into();
}

Expand Down

0 comments on commit ff7e2c8

Please sign in to comment.