Skip to content

Commit 79fa8fb

Browse files
XCMv4 (#1230)
# Note for reviewer Most changes are just syntax changes necessary for the new version. Most important files should be the ones under the `xcm` folder. # Description Added XCMv4. ## Removed `Multi` prefix The following types have been renamed: - MultiLocation -> Location - MultiAsset -> Asset - MultiAssets -> Assets - InteriorMultiLocation -> InteriorLocation - MultiAssetFilter -> AssetFilter - VersionedMultiAsset -> VersionedAsset - WildMultiAsset -> WildAsset - VersionedMultiLocation -> VersionedLocation In order to fix a name conflict, the `Assets` in `xcm-executor` were renamed to `HoldingAssets`, as they represent assets in holding. ## Removed `Abstract` asset id It was not being used anywhere and this simplifies the code. Now assets are just constructed as follows: ```rust let asset: Asset = (AssetId(Location::new(1, Here)), 100u128).into(); ``` No need for specifying `Concrete` anymore. ## Outcome is now a named fields struct Instead of ```rust pub enum Outcome { Complete(Weight), Incomplete(Weight, Error), Error(Error), } ``` we now have ```rust pub enum Outcome { Complete { used: Weight }, Incomplete { used: Weight, error: Error }, Error { error: Error }, } ``` ## Added Reanchorable trait Now both locations and assets implement this trait, making it easier to reanchor both. ## New syntax for building locations and junctions Now junctions are built using the following methods: ```rust let location = Location { parents: 1, interior: [Parachain(1000), PalletInstance(50), GeneralIndex(1984)].into() }; ``` or ```rust let location = Location::new(1, [Parachain(1000), PalletInstance(50), GeneralIndex(1984)]); ``` And they are matched like so: ```rust match location.unpack() { (1, [Parachain(id)]) => ... (0, Here) => ..., (1, [_]) => ..., } ``` This syntax is mandatory in v4, and has been also implemented for v2 and v3 for easier migration. This was needed to make all sizes smaller. # TODO - [x] Scaffold v4 - [x] Port github.com/paritytech/polkadot/pull/7236 - [x] Remove `Multi` prefix - [x] Remove `Abstract` asset id --------- Co-authored-by: command-bot <> Co-authored-by: Keith Yeung <[email protected]>
1 parent 25db393 commit 79fa8fb

File tree

105 files changed

+9065
-3420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+9065
-3420
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ log = { version = "0.4.17", default-features = false }
1818
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] }
1919
scale-info = { version = "2.10.0", default-features = false, features = ["derive", "serde"] }
2020
sp-weights = { path = "../../substrate/primitives/weights", default-features = false, features = ["serde"] }
21-
serde = { version = "1.0.195", default-features = false, features = ["alloc", "derive"] }
21+
serde = { version = "1.0.195", default-features = false, features = ["alloc", "derive", "rc"] }
2222
schemars = { version = "0.8.13", default-features = true, optional = true }
2323
xcm-procedural = { path = "procedural" }
2424
environmental = { version = "1.1.4", default-features = false }

pallet-xcm-benchmarks/src/fungible/benchmarking.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use frame_support::{
2424
};
2525
use sp_runtime::traits::{Bounded, Zero};
2626
use sp_std::{prelude::*, vec};
27-
use xcm::latest::{prelude::*, MAX_ITEMS_IN_MULTIASSETS};
27+
use xcm::latest::{prelude::*, MAX_ITEMS_IN_ASSETS};
2828
use xcm_executor::traits::{ConvertLocation, FeeReason, TransactAsset};
2929

3030
benchmarks_instance_pallet! {
@@ -43,7 +43,7 @@ benchmarks_instance_pallet! {
4343
withdraw_asset {
4444
let (sender_account, sender_location) = account_and_location::<T>(1);
4545
let worst_case_holding = T::worst_case_holding(0);
46-
let asset = T::get_multi_asset();
46+
let asset = T::get_asset();
4747

4848
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
4949
// check the assets of origin.
@@ -63,8 +63,8 @@ benchmarks_instance_pallet! {
6363

6464
transfer_asset {
6565
let (sender_account, sender_location) = account_and_location::<T>(1);
66-
let asset = T::get_multi_asset();
67-
let assets: MultiAssets = vec![ asset.clone() ].into();
66+
let asset = T::get_asset();
67+
let assets: Assets = vec![ asset.clone() ].into();
6868
// this xcm doesn't use holding
6969

7070
let dest_location = T::valid_destination()?;
@@ -95,10 +95,10 @@ benchmarks_instance_pallet! {
9595
);
9696
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
9797

98-
let asset = T::get_multi_asset();
98+
let asset = T::get_asset();
9999
<AssetTransactorOf<T>>::deposit_asset(&asset, &sender_location, None).unwrap();
100100
assert!(T::TransactAsset::balance(&sender_account) > sender_account_balance_before);
101-
let assets: MultiAssets = vec![ asset ].into();
101+
let assets: Assets = vec![asset].into();
102102
assert!(T::TransactAsset::balance(&dest_account).is_zero());
103103

104104
let mut executor = new_executor::<T>(sender_location);
@@ -129,7 +129,7 @@ benchmarks_instance_pallet! {
129129
BenchmarkResult::from_weight(Weight::MAX)
130130
))?;
131131

132-
let assets: MultiAssets = vec![ transferable_reserve_asset ].into();
132+
let assets: Assets = vec![ transferable_reserve_asset ].into();
133133

134134
let mut executor = new_executor::<T>(trusted_reserve);
135135
let instruction = Instruction::ReserveAssetDeposited(assets.clone());
@@ -143,7 +143,7 @@ benchmarks_instance_pallet! {
143143
initiate_reserve_withdraw {
144144
let (sender_account, sender_location) = account_and_location::<T>(1);
145145
let holding = T::worst_case_holding(1);
146-
let assets_filter = MultiAssetFilter::Definite(holding.clone().into_inner().into_iter().take(MAX_ITEMS_IN_MULTIASSETS).collect::<Vec<_>>().into());
146+
let assets_filter = AssetFilter::Definite(holding.clone().into_inner().into_iter().take(MAX_ITEMS_IN_ASSETS).collect::<Vec<_>>().into());
147147
let reserve = T::valid_destination().map_err(|_| BenchmarkError::Skip)?;
148148

149149
let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery(
@@ -188,7 +188,7 @@ benchmarks_instance_pallet! {
188188
)?;
189189
}
190190

191-
let assets: MultiAssets = vec![ teleportable_asset ].into();
191+
let assets: Assets = vec![ teleportable_asset ].into();
192192

193193
let mut executor = new_executor::<T>(trusted_teleporter);
194194
let instruction = Instruction::ReceiveTeleportedAsset(assets.clone());
@@ -204,7 +204,7 @@ benchmarks_instance_pallet! {
204204
}
205205

206206
deposit_asset {
207-
let asset = T::get_multi_asset();
207+
let asset = T::get_asset();
208208
let mut holding = T::worst_case_holding(1);
209209

210210
// Add our asset to the holding.
@@ -230,7 +230,7 @@ benchmarks_instance_pallet! {
230230
}
231231

232232
deposit_reserve_asset {
233-
let asset = T::get_multi_asset();
233+
let asset = T::get_asset();
234234
let mut holding = T::worst_case_holding(1);
235235

236236
// Add our asset to the holding.
@@ -257,7 +257,7 @@ benchmarks_instance_pallet! {
257257
}
258258

259259
initiate_teleport {
260-
let asset = T::get_multi_asset();
260+
let asset = T::get_asset();
261261
let mut holding = T::worst_case_holding(0);
262262

263263
// Add our asset to the holding.

pallet-xcm-benchmarks/src/fungible/mock.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ parameter_types! {
9393

9494
pub struct MatchAnyFungible;
9595
impl xcm_executor::traits::MatchesFungible<u64> for MatchAnyFungible {
96-
fn matches_fungible(m: &MultiAsset) -> Option<u64> {
96+
fn matches_fungible(m: &Asset) -> Option<u64> {
9797
use sp_runtime::traits::SaturatedConversion;
9898
match m {
99-
MultiAsset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
99+
Asset { fun: Fungible(amount), .. } => Some((*amount).saturated_into::<u64>()),
100100
_ => None,
101101
}
102102
}
@@ -151,13 +151,12 @@ impl crate::Config for Test {
151151
type XcmConfig = XcmConfig;
152152
type AccountIdConverter = AccountIdConverter;
153153
type DeliveryHelper = ();
154-
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
155-
let valid_destination: MultiLocation =
156-
X1(AccountId32 { network: None, id: [0u8; 32] }).into();
154+
fn valid_destination() -> Result<Location, BenchmarkError> {
155+
let valid_destination: Location = [AccountId32 { network: None, id: [0u8; 32] }].into();
157156

158157
Ok(valid_destination)
159158
}
160-
fn worst_case_holding(depositable_count: u32) -> MultiAssets {
159+
fn worst_case_holding(depositable_count: u32) -> Assets {
161160
crate::mock_worst_case_holding(
162161
depositable_count,
163162
<XcmConfig as xcm_executor::Config>::MaxAssetsIntoHolding::get(),
@@ -170,19 +169,19 @@ pub type TrustedReserves = xcm_builder::Case<ReserveConcreteFungible>;
170169

171170
parameter_types! {
172171
pub const CheckingAccount: Option<(u64, MintLocation)> = Some((100, MintLocation::Local));
173-
pub const ChildTeleporter: MultiLocation = Parachain(1000).into_location();
174-
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
172+
pub ChildTeleporter: Location = Parachain(1000).into_location();
173+
pub TrustedTeleporter: Option<(Location, Asset)> = Some((
175174
ChildTeleporter::get(),
176-
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
175+
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
177176
));
178-
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
177+
pub TrustedReserve: Option<(Location, Asset)> = Some((
179178
ChildTeleporter::get(),
180-
MultiAsset { id: Concrete(Here.into_location()), fun: Fungible(100) },
179+
Asset { id: AssetId(Here.into_location()), fun: Fungible(100) },
181180
));
182-
pub const TeleportConcreteFungible: (MultiAssetFilter, MultiLocation) =
183-
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
184-
pub const ReserveConcreteFungible: (MultiAssetFilter, MultiLocation) =
185-
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into_location()) }), ChildTeleporter::get());
181+
pub TeleportConcreteFungible: (AssetFilter, Location) =
182+
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
183+
pub ReserveConcreteFungible: (AssetFilter, Location) =
184+
(Wild(AllOf { fun: WildFungible, id: AssetId(Here.into_location()) }), ChildTeleporter::get());
186185
}
187186

188187
impl xcm_balances_benchmark::Config for Test {
@@ -191,10 +190,10 @@ impl xcm_balances_benchmark::Config for Test {
191190
type TrustedTeleporter = TrustedTeleporter;
192191
type TrustedReserve = TrustedReserve;
193192

194-
fn get_multi_asset() -> MultiAsset {
193+
fn get_asset() -> Asset {
195194
let amount =
196195
<Balances as frame_support::traits::fungible::Inspect<u64>>::minimum_balance() as u128;
197-
MultiAsset { id: Concrete(Here.into()), fun: Fungible(amount) }
196+
Asset { id: AssetId(Here.into()), fun: Fungible(amount) }
198197
}
199198
}
200199

pallet-xcm-benchmarks/src/fungible/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ pub mod pallet {
3737
type CheckedAccount: Get<Option<(Self::AccountId, xcm_builder::MintLocation)>>;
3838

3939
/// A trusted location which we allow teleports from, and the asset we allow to teleport.
40-
type TrustedTeleporter: Get<Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>>;
40+
type TrustedTeleporter: Get<Option<(xcm::latest::Location, xcm::latest::Asset)>>;
4141

4242
/// A trusted location where reserve assets are stored, and the asset we allow to be
4343
/// reserves.
44-
type TrustedReserve: Get<Option<(xcm::latest::MultiLocation, xcm::latest::MultiAsset)>>;
44+
type TrustedReserve: Get<Option<(xcm::latest::Location, xcm::latest::Asset)>>;
4545

4646
/// Give me a fungible asset that your asset transactor is going to accept.
47-
fn get_multi_asset() -> xcm::latest::MultiAsset;
47+
fn get_asset() -> xcm::latest::Asset;
4848
}
4949

5050
#[pallet::pallet]

pallet-xcm-benchmarks/src/generic/benchmarking.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ benchmarks! {
7777
let mut executor = new_executor::<T>(Default::default());
7878
executor.set_holding(holding);
7979

80-
let fee_asset = Concrete(Here.into());
80+
let fee_asset = AssetId(Here.into());
8181

8282
let instruction = Instruction::<XcmCallOf<T>>::BuyExecution {
8383
fees: (fee_asset, 100_000_000u128).into(), // should be something inside of holding
@@ -95,7 +95,7 @@ benchmarks! {
9595
let mut executor = new_executor::<T>(Default::default());
9696
let (query_id, response) = T::worst_case_response();
9797
let max_weight = Weight::MAX;
98-
let querier: Option<MultiLocation> = Some(Here.into());
98+
let querier: Option<Location> = Some(Here.into());
9999
let instruction = Instruction::QueryResponse { query_id, response, max_weight, querier };
100100
let xcm = Xcm(vec![instruction]);
101101
}: {
@@ -174,15 +174,15 @@ benchmarks! {
174174

175175
descend_origin {
176176
let mut executor = new_executor::<T>(Default::default());
177-
let who = X2(OnlyChild, OnlyChild);
178-
let instruction = Instruction::DescendOrigin(who);
177+
let who = Junctions::from([OnlyChild, OnlyChild]);
178+
let instruction = Instruction::DescendOrigin(who.clone());
179179
let xcm = Xcm(vec![instruction]);
180180
} : {
181181
executor.bench_process(xcm)?;
182182
} verify {
183183
assert_eq!(
184184
executor.origin(),
185-
&Some(MultiLocation {
185+
&Some(Location {
186186
parents: 0,
187187
interior: who,
188188
}),
@@ -242,7 +242,7 @@ benchmarks! {
242242
&origin,
243243
assets.clone().into(),
244244
&XcmContext {
245-
origin: Some(origin),
245+
origin: Some(origin.clone()),
246246
message_id: [0; 32],
247247
topic: None,
248248
},
@@ -279,7 +279,7 @@ benchmarks! {
279279
let origin = T::subscribe_origin()?;
280280
let query_id = Default::default();
281281
let max_response_weight = Default::default();
282-
let mut executor = new_executor::<T>(origin);
282+
let mut executor = new_executor::<T>(origin.clone());
283283
let instruction = Instruction::SubscribeVersion { query_id, max_response_weight };
284284
let xcm = Xcm(vec![instruction]);
285285
} : {
@@ -299,14 +299,14 @@ benchmarks! {
299299
query_id,
300300
max_response_weight,
301301
&XcmContext {
302-
origin: Some(origin),
302+
origin: Some(origin.clone()),
303303
message_id: [0; 32],
304304
topic: None,
305305
},
306306
).map_err(|_| "Could not start subscription")?;
307307
assert!(<T::XcmConfig as xcm_executor::Config>::SubscriptionService::is_subscribed(&origin));
308308

309-
let mut executor = new_executor::<T>(origin);
309+
let mut executor = new_executor::<T>(origin.clone());
310310
let instruction = Instruction::UnsubscribeVersion;
311311
let xcm = Xcm(vec![instruction]);
312312
} : {
@@ -545,7 +545,7 @@ benchmarks! {
545545
} verify {
546546
use frame_support::traits::Get;
547547
let universal_location = <T::XcmConfig as xcm_executor::Config>::UniversalLocation::get();
548-
assert_eq!(executor.origin(), &Some(X1(alias).relative_to(&universal_location)));
548+
assert_eq!(executor.origin(), &Some(Junctions::from([alias]).relative_to(&universal_location)));
549549
}
550550

551551
export_message {
@@ -561,8 +561,8 @@ benchmarks! {
561561

562562
let (expected_fees_mode, expected_assets_in_holding) = T::DeliveryHelper::ensure_successful_delivery(
563563
&origin,
564-
&destination.into(),
565-
FeeReason::Export { network, destination },
564+
&destination.clone().into(),
565+
FeeReason::Export { network, destination: destination.clone() },
566566
);
567567
let sender_account = T::AccountIdConverter::convert_location(&origin).unwrap();
568568
let sender_account_balance_before = T::TransactAsset::balance(&sender_account);
@@ -575,7 +575,7 @@ benchmarks! {
575575
executor.set_holding(expected_assets_in_holding.into());
576576
}
577577
let xcm = Xcm(vec![ExportMessage {
578-
network, destination, xcm: inner_xcm,
578+
network, destination: destination.clone(), xcm: inner_xcm,
579579
}]);
580580
}: {
581581
executor.bench_process(xcm)?;
@@ -632,13 +632,13 @@ benchmarks! {
632632

633633
let (unlocker, owner, asset) = T::unlockable_asset()?;
634634

635-
let mut executor = new_executor::<T>(unlocker);
635+
let mut executor = new_executor::<T>(unlocker.clone());
636636

637637
// We first place the asset in lock first...
638638
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
639639
unlocker,
640640
asset.clone(),
641-
owner,
641+
owner.clone(),
642642
)
643643
.map_err(|_| BenchmarkError::Skip)?
644644
.enact()
@@ -658,13 +658,13 @@ benchmarks! {
658658

659659
let (unlocker, owner, asset) = T::unlockable_asset()?;
660660

661-
let mut executor = new_executor::<T>(unlocker);
661+
let mut executor = new_executor::<T>(unlocker.clone());
662662

663663
// We first place the asset in lock first...
664664
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
665665
unlocker,
666666
asset.clone(),
667-
owner,
667+
owner.clone(),
668668
)
669669
.map_err(|_| BenchmarkError::Skip)?
670670
.enact()
@@ -686,9 +686,9 @@ benchmarks! {
686686

687687
// We first place the asset in lock first...
688688
<T::XcmConfig as xcm_executor::Config>::AssetLocker::prepare_lock(
689-
locker,
689+
locker.clone(),
690690
asset.clone(),
691-
owner,
691+
owner.clone(),
692692
)
693693
.map_err(|_| BenchmarkError::Skip)?
694694
.enact()
@@ -739,7 +739,7 @@ benchmarks! {
739739

740740
let mut executor = new_executor::<T>(origin);
741741

742-
let instruction = Instruction::AliasOrigin(target);
742+
let instruction = Instruction::AliasOrigin(target.clone());
743743
let xcm = Xcm(vec![instruction]);
744744
}: {
745745
executor.bench_process(xcm)?;

0 commit comments

Comments
 (0)