Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
719efe0
Intoduce XCM v2
gavofyork Aug 10, 2021
b2dae98
Minor version cleanup
gavofyork Aug 10, 2021
5ab1b8b
Minor version cleanup
gavofyork Aug 10, 2021
c854e94
Introduce SendError for XcmSend trait to avoid cycles with having Out…
gavofyork Aug 10, 2021
1e287f3
comment
gavofyork Aug 10, 2021
c279e44
Corrent type
gavofyork Aug 10, 2021
632a992
Docs
gavofyork Aug 10, 2021
18ef569
Fix build
gavofyork Aug 10, 2021
ef3bc2e
Fixes
gavofyork Aug 10, 2021
eaea484
Build
gavofyork Aug 10, 2021
9820197
Introduce the basic impl
gavofyork Aug 10, 2021
82a67f7
Docs
gavofyork Aug 12, 2021
ace53dc
Add function
gavofyork Aug 12, 2021
49f1895
Merge remote-tracking branch 'origin/master' into gav-xcm-v2
gavofyork Aug 12, 2021
c6835ae
Basic implementation
gavofyork Aug 12, 2021
19617eb
Weighed responses and on_report
gavofyork Aug 12, 2021
0831192
Make XCM more script-like
gavofyork Aug 14, 2021
62d76b4
Remove BuyExecution::orders
gavofyork Aug 14, 2021
2bf963c
Fixes
gavofyork Aug 15, 2021
d58848f
Fixes
gavofyork Aug 15, 2021
e97f993
Fixes
gavofyork Aug 15, 2021
1a0e0ce
Formatting
gavofyork Aug 15, 2021
89debf5
Merge branch 'gav-rm-buy-orders' into gav-xcm-v2
gavofyork Aug 15, 2021
4516074
Initial draft and make pallet-xcm build
gavofyork Aug 16, 2021
329360f
fix XCM tests
gavofyork Aug 16, 2021
0ca87bd
Formatting
gavofyork Aug 16, 2021
15b9371
Merge remote-tracking branch 'origin/master' into gav-xcm-v2
gavofyork Aug 16, 2021
40efb2e
Fixes
gavofyork Aug 16, 2021
36f7a4e
Formatting
gavofyork Aug 16, 2021
33594b3
spelling
gavofyork Aug 16, 2021
8fd21f2
Fixes
gavofyork Aug 16, 2021
30c225d
Fixes
gavofyork Aug 17, 2021
b0f884e
spelling
gavofyork Aug 17, 2021
732ec50
tests for translation
gavofyork Aug 17, 2021
fbd84e4
extra fields to XCM pallet
gavofyork Aug 17, 2021
236f275
Formatting
gavofyork Aug 17, 2021
0188a9d
Fixes
gavofyork Aug 17, 2021
dcdf01d
spelling
gavofyork Aug 17, 2021
3d20770
first integration test
gavofyork Aug 17, 2021
0b27f43
Another integration test
gavofyork Aug 18, 2021
11b8a80
Formatting
gavofyork Aug 20, 2021
df76b24
Merge remote-tracking branch 'origin/master' into gav-xcm-v2
gavofyork Aug 20, 2021
170a20d
fix tests
gavofyork Aug 20, 2021
26330fa
all tests
gavofyork Aug 21, 2021
5d03978
Fixes
gavofyork Aug 21, 2021
7e7528d
Fixes
gavofyork Aug 22, 2021
b462eae
Formatting
gavofyork Aug 22, 2021
e1f36c4
Fixes
gavofyork Aug 22, 2021
a0db17a
Fixes
gavofyork Aug 22, 2021
653a2a2
Formatting
gavofyork Aug 22, 2021
f1ce4eb
Bump
gavofyork Aug 22, 2021
07ba2d0
Remove unneeded structuring
gavofyork Aug 22, 2021
48baab6
add instruction
gavofyork Aug 22, 2021
f317a64
Fixes
gavofyork Aug 22, 2021
dd80ebc
spelling
gavofyork Aug 22, 2021
de5e76c
Fixes
gavofyork Aug 22, 2021
e798658
Fixes
gavofyork Aug 22, 2021
df8f941
Formatting
gavofyork Aug 22, 2021
e39b1e6
Fixes
gavofyork Aug 22, 2021
bea12fb
Fixes
gavofyork Aug 23, 2021
2b47c3c
Formatting
gavofyork Aug 23, 2021
ca21160
Introduce and use VersionedResponse
gavofyork Aug 23, 2021
a062919
Introduce versioning to dispatchables' params
gavofyork Aug 23, 2021
26ca165
Fixes
gavofyork Aug 23, 2021
aeba4a8
Formatting
gavofyork Aug 23, 2021
1862f69
Merge branch 'gav-versioned-params' into gav-xcm-v2
gavofyork Aug 23, 2021
d92b7a7
Rest of merge
gavofyork Aug 23, 2021
c4c45d5
Merge branch 'gav-xcm-v2' into gav-xcm-trycatch
gavofyork Aug 23, 2021
7d7f2ac
more work
gavofyork Aug 23, 2021
604414c
Formatting
gavofyork Aug 23, 2021
8130a36
Basic logic
gavofyork Aug 23, 2021
fc58298
Fixes
gavofyork Aug 24, 2021
93dc645
Fixes
gavofyork Aug 24, 2021
6b5045f
Merge branch 'gav-xcm-v2' into gav-xcm-trycatch
gavofyork Aug 24, 2021
22fcbf2
Fixes
gavofyork Aug 24, 2021
7f5add7
Add test
gavofyork Aug 24, 2021
8c231a0
Fixes
gavofyork Aug 24, 2021
745835f
Formatting
gavofyork Aug 24, 2021
bb046cc
Fixes
gavofyork Aug 24, 2021
34dae85
Fixes
gavofyork Aug 24, 2021
ffe8513
Fixes
gavofyork Aug 24, 2021
c0f1875
Nits
gavofyork Aug 25, 2021
7b243cc
Simplify
gavofyork Aug 25, 2021
9f7e88c
Spelling
gavofyork Aug 25, 2021
8f07df6
Formatting
gavofyork Aug 25, 2021
41d8435
Return weight of unexecuted instructions in case of error as surplus
gavofyork Aug 25, 2021
53fc8dd
Formatting
gavofyork Aug 25, 2021
944b597
Fixes
gavofyork Aug 25, 2021
bcbacce
Test for instruction count limiting
gavofyork Aug 25, 2021
8c8d434
Formatting
gavofyork Aug 25, 2021
feb79ce
Docs
gavofyork Aug 25, 2021
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
Prev Previous commit
Next Next commit
Fix build
  • Loading branch information
gavofyork committed Aug 10, 2021
commit 18ef5690358857eee78531738a9fa27b1e4f0833
12 changes: 9 additions & 3 deletions xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub mod pallet {
CannotReanchor,
/// Too many assets have been attempted for transfer.
TooManyAssets,
/// Origin is invalid for sending.
InvalidOrigin,
}

#[pallet::hooks]
Expand All @@ -120,7 +122,11 @@ pub mod pallet {
message: Box<Xcm<()>>,
) -> DispatchResult {
let origin_location = T::SendXcmOrigin::ensure_origin(origin)?;
Self::send_xcm(origin_location.clone(), *dest.clone(), *message.clone()).map_err(
let interior = origin_location
.clone()
.try_into()
.map_err(|_| Error::<T>::InvalidOrigin)?;
Self::send_xcm(interior, *dest.clone(), *message.clone()).map_err(
|e| match e {
XcmError::CannotReachDestination(..) => Error::<T>::Unreachable,
_ => Error::<T>::SendFailure,
Expand Down Expand Up @@ -302,11 +308,11 @@ pub mod pallet {
/// Relay an XCM `message` from a given `interior` location in this context to a given `dest`
/// location. A null `dest` is not handled.
pub fn send_xcm(
interior: MultiLocation,
interior: Junctions,
dest: MultiLocation,
message: Xcm<()>,
) -> Result<(), XcmError> {
let message = if interior.is_here() {
let message = if let Junctions::Here = interior {
message
} else {
Xcm::<()>::RelayedFrom { who: interior, message: Box::new(message) }
Expand Down
4 changes: 2 additions & 2 deletions xcm/src/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod multi_asset;
mod multi_location;
mod order;
mod traits;
use super::v1::{Response as Response1, Xcm as Xcm1};
use super::v1::{Response as Response1, Xcm as Xcm1, MultiLocation as MultiLocation1};
pub use junction::{BodyId, BodyPart, Junction, NetworkId};
pub use multi_asset::{AssetInstance, MultiAsset};
pub use multi_location::MultiLocation::{self, *};
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<Call> TryFrom<Xcm1<Call>> for Xcm<Call> {
Xcm1::Transact { origin_type, require_weight_at_most, call } =>
Transact { origin_type, require_weight_at_most, call: call.into() },
Xcm1::RelayedFrom { who, message } => RelayedFrom {
who: who.try_into()?,
who: MultiLocation1 { interior: who, parents: 0 }.try_into()?,
message: alloc::boxed::Box::new((*message).try_into()?),
},
})
Expand Down
2 changes: 1 addition & 1 deletion xcm/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl<Call> TryFrom<Xcm0<Call>> for Xcm<Call> {
Xcm0::Transact { origin_type, require_weight_at_most, call } =>
Transact { origin_type, require_weight_at_most, call: call.into() },
Xcm0::RelayedFrom { who, message } => RelayedFrom {
who: who.try_into()?,
who: MultiLocation::try_from(who)?.try_into()?,
message: alloc::boxed::Box::new((*message).try_into()?),
},
})
Expand Down
106 changes: 51 additions & 55 deletions xcm/src/v1/multilocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,53 +149,33 @@ impl MultiLocation {
(multilocation, last)
}

/// Mutates `self`, suffixing its interior junctions with `new`. Returns `Err` in case of overflow.
pub fn push_interior(&mut self, new: Junction) -> result::Result<(), ()> {
let mut n = Junctions::Here;
mem::swap(&mut self.interior, &mut n);
match n.pushed_with(new) {
Ok(result) => {
self.interior = result;
Ok(())
},
Err(old) => {
self.interior = old;
Err(())
},
}
/// Mutates `self`, suffixing its interior junctions with `new`. Returns `Err` with `new` in
/// case of overflow.
pub fn push_interior(&mut self, new: Junction) -> result::Result<(), Junction> {
self.interior.push(new)
}

/// Mutates `self`, prefixing its interior junctions with `new`. Returns `Err` in case of overflow.
pub fn push_front_interior(&mut self, new: Junction) -> result::Result<(), ()> {
let mut n = Junctions::Here;
mem::swap(&mut self.interior, &mut n);
match n.pushed_front_with(new) {
Ok(result) => {
self.interior = result;
Ok(())
},
Err(old) => {
self.interior = old;
Err(())
},
}
/// Mutates `self`, prefixing its interior junctions with `new`. Returns `Err` with `new` in
/// case of overflow.
pub fn push_front_interior(&mut self, new: Junction) -> result::Result<(), Junction> {
self.interior.push_front(new)
}

/// Consumes `self` and returns a `MultiLocation` suffixed with `new`, or an `Err` with the original value of
/// Consumes `self` and returns a `MultiLocation` suffixed with `new`, or an `Err` with theoriginal value of
/// `self` in case of overflow.
pub fn pushed_with_interior(self, new: Junction) -> result::Result<Self, Self> {
pub fn pushed_with_interior(self, new: Junction) -> result::Result<Self, (Self, Junction)> {
match self.interior.pushed_with(new) {
Ok(i) => Ok(MultiLocation { interior: i, parents: self.parents }),
Err(i) => Err(MultiLocation { interior: i, parents: self.parents }),
Err((i, j)) => Err((MultiLocation { interior: i, parents: self.parents }, j)),
}
}

/// Consumes `self` and returns a `MultiLocation` prefixed with `new`, or an `Err` with the original value of
/// `self` in case of overflow.
pub fn pushed_front_with_interior(self, new: Junction) -> result::Result<Self, Self> {
pub fn pushed_front_with_interior(self, new: Junction) -> result::Result<Self, (Self, Junction)> {
match self.interior.pushed_front_with(new) {
Ok(i) => Ok(MultiLocation { interior: i, parents: self.parents }),
Err(i) => Err(MultiLocation { interior: i, parents: self.parents }),
Err((i, j)) => Err((MultiLocation { interior: i, parents: self.parents }, j)),
}
}

Expand Down Expand Up @@ -259,31 +239,27 @@ impl MultiLocation {
self.interior.match_and_split(&prefix.interior)
}

/// Mutate `self` so that it is suffixed with `suffix`. The correct normalized form is returned,
/// removing any internal [Non-Parent, `Parent`] combinations.
/// Mutate `self` so that it is suffixed with `suffix`.
///
/// Does not modify `self` and returns `Err` with `suffix` in case of overflow.
///
/// # Example
/// ```rust
/// # use xcm::v1::{Junctions::*, Junction::*, MultiLocation};
/// # fn main() {
/// let mut m = MultiLocation::new(1, X2(Parachain(21), OnlyChild));
/// assert_eq!(m.append_with(MultiLocation::new(1, X1(PalletInstance(3)))), Ok(()));
/// let mut m = MultiLocation::new(1, X2(Parachain(21)));
/// assert_eq!(m.append_with(X1(PalletInstance(3))), Ok(()));
/// assert_eq!(m, MultiLocation::new(1, X2(Parachain(21), PalletInstance(3))));
/// # }
/// ```
pub fn append_with(&mut self, suffix: MultiLocation) -> Result<(), MultiLocation> {
let mut prefix = suffix;
core::mem::swap(self, &mut prefix);
match self.prepend_with(prefix) {
Ok(()) => Ok(()),
Err(prefix) => {
let mut suffix = prefix;
core::mem::swap(self, &mut suffix);
Err(suffix)
},
pub fn append_with(&mut self, suffix: Junctions) -> Result<(), Junctions> {
if self.interior.len().saturating_add(suffix.len()) > MAX_JUNCTIONS {
return Err(suffix)
}
for j in suffix.into_iter() {
self.interior.push(j).expect("Already checked the sum of the len()s; qed")
}
Ok(())
}

/// Mutate `self` so that it is prefixed with `prefix`.
Expand Down Expand Up @@ -767,9 +743,29 @@ impl Junctions {
tail
}

/// Consumes `self` and returns a `Junctions` suffixed with `new`, or an `Err` with the original value of
/// `self` in case of overflow.
pub fn pushed_with(self, new: Junction) -> result::Result<Self, Self> {
/// Mutates `self` to be appended with `new` or returns an `Err` with `new` if would overflow.
pub fn push(&mut self, new: Junction) -> result::Result<(), Junction> {
let mut dummy = Junctions::Here;
mem::swap(self, &mut dummy);
match dummy.pushed_with(new) {
Ok(s) => { *self = s; Ok(()) }
Err((s, j)) => { *self = s; Err(j) }
}
}

/// Mutates `self` to be prepended with `new` or returns an `Err` with `new` if would overflow.
pub fn push_front(&mut self, new: Junction) -> result::Result<(), Junction> {
let mut dummy = Junctions::Here;
mem::swap(self, &mut dummy);
match dummy.pushed_front_with(new) {
Ok(s) => { *self = s; Ok(()) }
Err((s, j)) => { *self = s; Err(j) }
}
}

/// Consumes `self` and returns a `Junctions` suffixed with `new`, or an `Err` with the
/// original value of `self` and `new` in case of overflow.
pub fn pushed_with(self, new: Junction) -> result::Result<Self, (Self, Junction)> {
Ok(match self {
Junctions::Here => Junctions::X1(new),
Junctions::X1(a) => Junctions::X2(a, new),
Expand All @@ -779,13 +775,13 @@ impl Junctions {
Junctions::X5(a, b, c, d, e) => Junctions::X6(a, b, c, d, e, new),
Junctions::X6(a, b, c, d, e, f) => Junctions::X7(a, b, c, d, e, f, new),
Junctions::X7(a, b, c, d, e, f, g) => Junctions::X8(a, b, c, d, e, f, g, new),
s => Err(s)?,
s => Err((s, new))?,
})
}

/// Consumes `self` and returns a `Junctions` prefixed with `new`, or an `Err` with the original value of
/// `self` in case of overflow.
pub fn pushed_front_with(self, new: Junction) -> result::Result<Self, Self> {
/// Consumes `self` and returns a `Junctions` prefixed with `new`, or an `Err` with the
/// original value of `self` and `new` in case of overflow.
pub fn pushed_front_with(self, new: Junction) -> result::Result<Self, (Self, Junction)> {
Ok(match self {
Junctions::Here => Junctions::X1(new),
Junctions::X1(a) => Junctions::X2(new, a),
Expand All @@ -795,7 +791,7 @@ impl Junctions {
Junctions::X5(a, b, c, d, e) => Junctions::X6(new, a, b, c, d, e),
Junctions::X6(a, b, c, d, e, f) => Junctions::X7(new, a, b, c, d, e, f),
Junctions::X7(a, b, c, d, e, f, g) => Junctions::X8(new, a, b, c, d, e, f, g),
s => Err(s)?,
s => Err((s, new))?,
})
}

Expand Down
2 changes: 1 addition & 1 deletion xcm/xcm-builder/src/fungibles_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<Prefix: Get<MultiLocation>, AssetId: Clone, ConvertAssetId: Convert<u128, A
fn reverse_ref(what: impl Borrow<AssetId>) -> result::Result<MultiLocation, ()> {
let mut location = Prefix::get();
let id = ConvertAssetId::reverse_ref(what)?;
location.push_interior(Junction::GeneralIndex(id))?;
location.push_interior(Junction::GeneralIndex(id)).map_err(|_| ())?;
Ok(location)
}
}
Expand Down
1 change: 0 additions & 1 deletion xcm/xcm-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ impl<Config: config::Config> XcmExecutor<Config> {
None
},
(origin, Xcm::RelayedFrom { who, message }) => {
ensure!(who.parent_count() == 0, XcmError::EscalationOfPrivilege);
let mut origin = origin;
origin.append_with(who).map_err(|_| XcmError::MultiLocationFull)?;
let surplus = Self::do_execute_xcm(
Expand Down