Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Make AssetId and MultiLocation non-Copy; make Instruction 92% smaller #7236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


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

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

2 changes: 1 addition & 1 deletion runtime/common/src/xcm_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<T: configuration::Config + dmp::Config, W: xcm::WrapVersion, P: PriceForPar
msg: &mut Option<Xcm<()>>,
) -> SendResult<(HostConfiguration<T::BlockNumber>, ParaId, Vec<u8>)> {
let d = dest.take().ok_or(MissingArgument)?;
let id = if let MultiLocation { parents: 0, interior: X1(Parachain(id)) } = &d {
let id = if let (0, [Parachain(id)]) = d.unpack() {
*id
} else {
*dest = Some(d);
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ sp_api::impl_runtime_apis! {
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
Expand Down
19 changes: 10 additions & 9 deletions runtime/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
XcmPallet,
};
use frame_support::{
match_types, parameter_types,
parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
Expand Down Expand Up @@ -126,19 +126,20 @@ pub type XcmRouter = (

parameter_types! {
pub const Ksm: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const Statemine: MultiLocation = Parachain(1000).into_location();
pub const Encointer: MultiLocation = Parachain(1001).into_location();
pub const KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get());
pub const KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get());
pub Statemine: MultiLocation = Parachain(1000).into_location();
pub Encointer: MultiLocation = Parachain(1001).into_location();
pub KsmForStatemine: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Statemine::get());
pub KsmForEncointer: (MultiAssetFilter, MultiLocation) = (Ksm::get(), Encointer::get());
pub const MaxAssetsIntoHolding: u32 = 64;
}
pub type TrustedTeleporters =
(xcm_builder::Case<KsmForStatemine>, xcm_builder::Case<KsmForEncointer>);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
pub struct OnlyParachains;
impl Contains<MultiLocation> for OnlyParachains {
fn contains(loc: &MultiLocation) -> bool {
matches!(loc.unpack(), (0, [Parachain(_)]))
}
}

/// The barriers one of which must be passed for an XCM message to be executed.
Expand Down
33 changes: 20 additions & 13 deletions runtime/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use super::{
TransactionByteFee, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
Expand Down Expand Up @@ -56,7 +56,7 @@ parameter_types! {
/// The Polkadot network ID. This is named.
pub const ThisNetwork: NetworkId = NetworkId::Polkadot;
/// Our location in the universe of consensus systems.
pub const UniversalLocation: InteriorMultiLocation = X1(GlobalConsensus(ThisNetwork::get()));
pub UniversalLocation: InteriorMultiLocation = [GlobalConsensus(ThisNetwork::get())].into();
/// The Checking Account, which holds any native assets that have been teleported out and not back in (yet).
pub CheckAccount: AccountId = XcmPallet::check_account();
/// The Checking Account along with the indication that the local chain is able to mint tokens.
Expand Down Expand Up @@ -134,24 +134,31 @@ pub type XcmRouter = (

parameter_types! {
pub const Dot: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const DotForStatemint: (MultiAssetFilter, MultiLocation) = (Dot::get(), Parachain(STATEMINT_ID).into_location());
pub const CollectivesLocation: MultiLocation = Parachain(COLLECTIVES_ID).into_location();
pub const DotForCollectives: (MultiAssetFilter, MultiLocation) = (Dot::get(), CollectivesLocation::get());
pub DotForStatemint: (MultiAssetFilter, MultiLocation) = (Dot::get(), Parachain(STATEMINT_ID).into_location());
pub CollectivesLocation: MultiLocation = Parachain(COLLECTIVES_ID).into_location();
pub DotForCollectives: (MultiAssetFilter, MultiLocation) = (Dot::get(), CollectivesLocation::get());
pub const MaxAssetsIntoHolding: u32 = 64;
}

/// Polkadot Relay recognizes/respects the Statemint chain as a teleporter.
pub type TrustedTeleporters =
(xcm_builder::Case<DotForStatemint>, xcm_builder::Case<DotForCollectives>);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
pub type CollectivesOrFellows: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(COLLECTIVES_ID)) } |
MultiLocation { parents: 0, interior: X2(Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }) }
};
pub struct OnlyParachains;
impl Contains<MultiLocation> for OnlyParachains {
fn contains(loc: &MultiLocation) -> bool {
matches!(loc.unpack(), (0, [Parachain(_)]))
}
}

pub struct CollectivesOrFellows;
impl Contains<MultiLocation> for CollectivesOrFellows {
fn contains(loc: &MultiLocation) -> bool {
matches!(loc.unpack(), |(0, [Parachain(COLLECTIVES_ID)])| (
0,
[Parachain(COLLECTIVES_ID), Plurality { id: BodyId::Technical, .. }]
))
}
Comment on lines +147 to +161
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep the declarative syntax. As a rule, top-level runtime files should not contain procedural code.

}

/// The barriers one of which must be passed for an XCM message to be executed.
Expand Down
4 changes: 2 additions & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2061,11 +2061,11 @@ sp_api::impl_runtime_apis! {
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
Expand Down
39 changes: 20 additions & 19 deletions runtime/rococo/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::{
Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, TransactionByteFee, WeightToFee, XcmPallet,
};
use frame_support::{
match_types, parameter_types,
parameter_types,
traits::{Contains, Everything, Nothing},
weights::Weight,
};
Expand All @@ -45,7 +45,7 @@ use xcm_builder::{
use xcm_executor::{traits::WithOriginFilter, XcmExecutor};

parameter_types! {
pub const TokenLocation: MultiLocation = Here.into_location();
pub TokenLocation: MultiLocation = Here.into_location();
pub const ThisNetwork: NetworkId = NetworkId::Rococo;
pub UniversalLocation: InteriorMultiLocation = ThisNetwork::get().into();
pub CheckAccount: AccountId = XcmPallet::check_account();
Expand Down Expand Up @@ -105,19 +105,19 @@ pub type XcmRouter = (
);

parameter_types! {
pub const Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const Statemine: MultiLocation = Parachain(1000).into_location();
pub const Contracts: MultiLocation = Parachain(1002).into_location();
pub const Encointer: MultiLocation = Parachain(1003).into_location();
pub const Tick: MultiLocation = Parachain(100).into_location();
pub const Trick: MultiLocation = Parachain(110).into_location();
pub const Track: MultiLocation = Parachain(120).into_location();
pub const RocForTick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Tick::get());
pub const RocForTrick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Trick::get());
pub const RocForTrack: (MultiAssetFilter, MultiLocation) = (Roc::get(), Track::get());
pub const RocForStatemine: (MultiAssetFilter, MultiLocation) = (Roc::get(), Statemine::get());
pub const RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get());
pub const RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get());
pub Roc: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub Statemine: MultiLocation = Parachain(1000).into_location();
pub Contracts: MultiLocation = Parachain(1002).into_location();
pub Encointer: MultiLocation = Parachain(1003).into_location();
pub Tick: MultiLocation = Parachain(100).into_location();
pub Trick: MultiLocation = Parachain(110).into_location();
pub Track: MultiLocation = Parachain(120).into_location();
pub RocForTick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Tick::get());
pub RocForTrick: (MultiAssetFilter, MultiLocation) = (Roc::get(), Trick::get());
pub RocForTrack: (MultiAssetFilter, MultiLocation) = (Roc::get(), Track::get());
pub RocForStatemine: (MultiAssetFilter, MultiLocation) = (Roc::get(), Statemine::get());
pub RocForContracts: (MultiAssetFilter, MultiLocation) = (Roc::get(), Contracts::get());
pub RocForEncointer: (MultiAssetFilter, MultiLocation) = (Roc::get(), Encointer::get());
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
}
Expand All @@ -130,10 +130,11 @@ pub type TrustedTeleporters = (
xcm_builder::Case<RocForEncointer>,
);

match_types! {
pub type OnlyParachains: impl Contains<MultiLocation> = {
MultiLocation { parents: 0, interior: X1(Parachain(_)) }
};
pub struct OnlyParachains;
impl Contains<MultiLocation> for OnlyParachains {
fn contains(loc: &MultiLocation) -> bool {
matches!(loc.unpack(), (0, [Parachain(_)]))
}
}

/// The barriers one of which must be passed for an XCM message to be executed.
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ sp_api::impl_runtime_apis! {
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Westmint::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(TokenLocation::get()) },
));
Expand Down
8 changes: 4 additions & 4 deletions runtime/westend/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ pub type XcmRouter = (
);

parameter_types! {
pub const Westmint: MultiLocation = Parachain(1000).into_location();
pub const Collectives: MultiLocation = Parachain(1001).into_location();
pub Westmint: MultiLocation = Parachain(1000).into_location();
pub Collectives: MultiLocation = Parachain(1001).into_location();
pub const Wnd: MultiAssetFilter = Wild(AllOf { fun: WildFungible, id: Concrete(TokenLocation::get()) });
pub const WndForWestmint: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Westmint::get());
pub const WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get());
pub WndForWestmint: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Westmint::get());
pub WndForCollectives: (MultiAssetFilter, MultiLocation) = (Wnd::get(), Collectives::get());
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsIntoHolding: u32 = 64;
}
Expand Down
2 changes: 1 addition & 1 deletion xcm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ log = { version = "0.4.17", default-features = false }
parity-scale-codec = { version = "3.4.0", default-features = false, features = [ "derive", "max-encoded-len" ] }
scale-info = { version = "2.5.0", default-features = false, features = ["derive"] }
sp-weights = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
serde = { version = "1.0.136", optional = true, features = ["derive"] }
serde = { version = "1.0.136", optional = true, features = ["derive", "rc"] }
gilescope marked this conversation as resolved.
Show resolved Hide resolved
xcm-procedural = { path = "procedural" }

[dev-dependencies]
Expand Down
10 changes: 5 additions & 5 deletions xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl crate::Config for Test {
type AccountIdConverter = AccountIdConverter;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
let valid_destination: MultiLocation =
X1(AccountId32 { network: None, id: [0u8; 32] }).into();
[AccountId32 { network: None, id: [0u8; 32] }].into();

Ok(valid_destination)
}
Expand All @@ -183,14 +183,14 @@ pub type TrustedTeleporters = (xcm_builder::Case<TeleportConcreteFungible>,);

parameter_types! {
pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local));
pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location();
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
pub ChildTeleporter: MultiLocation = Parachain(1000).into_location();
pub TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
));
pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) =
pub TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) =
pub ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
}

Expand Down
4 changes: 2 additions & 2 deletions xcm/pallet-xcm-benchmarks/src/generic/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ benchmarks! {

descend_origin {
let mut executor = new_executor::<T>(Default::default());
let who = X2(OnlyChild, OnlyChild);
let who = Junctions::from([OnlyChild, OnlyChild]);
let instruction = Instruction::DescendOrigin(who.clone());
let xcm = Xcm(vec![instruction]);
} : {
Expand Down Expand Up @@ -493,7 +493,7 @@ benchmarks! {
} verify {
use frame_support::traits::Get;
let universal_location = <T::XcmConfig as xcm_executor::Config>::UniversalLocation::get();
assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location)));
assert_eq!(executor.origin(), &Some(Junctions::from([alias]).relative_to(&universal_location)));
}

export_message {
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm-benchmarks/src/generic/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl generic::Config for Test {

fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let assets: MultiAssets = (Concrete(Here.into()), 100).into();
let ticket = MultiLocation { parents: 0, interior: X1(GeneralIndex(0)) };
let ticket = MultiLocation { parents: 0, interior: [GeneralIndex(0)].into() };
Ok((Default::default(), ticket, assets))
}

Expand Down
4 changes: 2 additions & 2 deletions xcm/pallet-xcm-benchmarks/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl xcm_executor::traits::OnResponse for DevNull {
pub struct AccountIdConverter;
impl xcm_executor::traits::Convert<MultiLocation, u64> for AccountIdConverter {
fn convert(ml: MultiLocation) -> Result<u64, MultiLocation> {
match ml {
MultiLocation { parents: 0, interior: X1(Junction::AccountId32 { id, .. }) } =>
match ml.unpack() {
(0, [Junction::AccountId32 { id, .. }]) =>
Ok(<u64 as codec::Decode>::decode(&mut &*id.to_vec()).unwrap()),
_ => Err(ml),
}
Expand Down
2 changes: 1 addition & 1 deletion xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ benchmarks! {
let loc = T::ReachableDest::get().ok_or(
BenchmarkError::Override(BenchmarkResult::from_weight(Weight::MAX)),
)?;
let versioned_loc: VersionedMultiLocation = loc.into();
let versioned_loc: VersionedMultiLocation = loc.clone().into();
let _ = Pallet::<T>::request_version_notify(loc);
}: _(RawOrigin::Root, Box::new(versioned_loc))

Expand Down
Loading