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

Implement AliasOrigin processing in XCVM #7245

Merged
merged 32 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
43044fc
Implement AliasOrigin processing in XCVM
KiChjang May 17, 2023
59b6056
add builder types and first test
vstam1 May 22, 2023
cb0ff78
switch to more general builder types
vstam1 May 22, 2023
7efcc39
clone target for RemovePrefixAccountId32
vstam1 May 22, 2023
c1c41f6
change builder types
vstam1 May 23, 2023
97f1f31
change AliasForeignAccountId32 and add test for AliasCase
vstam1 May 24, 2023
d984c95
add Aliasers type to xcm configs
vstam1 May 24, 2023
19e3123
add benchmark
vstam1 May 24, 2023
312461d
merge master
vstam1 May 24, 2023
f115cca
benchmark fix
vstam1 May 24, 2023
c7c3473
add benchmark function for runtimes
vstam1 May 24, 2023
39743b6
fix alias_origin result types
vstam1 May 24, 2023
de583b6
fix benchmark test
vstam1 May 24, 2023
7530772
add runtime-benchmarks feature in pallet-xcm-benchmarks
vstam1 May 24, 2023
f29f111
fmt
vstam1 May 24, 2023
56c7e03
remove AliasCase, add test and fmt
vstam1 May 25, 2023
e3f71ed
Merge branch 'master' into kckyeung/xcm-alias-origin
vstam1 May 25, 2023
a325ee9
address feedback
vstam1 May 30, 2023
31c12fd
merge master
vstam1 May 30, 2023
9b74bfb
Merge branch 'master' into kckyeung/xcm-alias-origin
vstam1 May 31, 2023
e2c2da2
".git/.scripts/commands/bench/bench.sh" xcm kusama pallet_xcm_benchma…
May 31, 2023
0f9bba5
".git/.scripts/commands/bench/bench.sh" xcm westend pallet_xcm_benchm…
May 31, 2023
cb82d9b
".git/.scripts/commands/bench/bench.sh" xcm rococo pallet_xcm_benchma…
May 31, 2023
26f2062
address feedback
vstam1 Jun 1, 2023
e5c910b
lock
vstam1 Jun 2, 2023
f3e4342
merge master
vstam1 Jun 2, 2023
da0c6d4
".git/.scripts/commands/bench/bench.sh" xcm kusama pallet_xcm_benchma…
Jun 2, 2023
c34c201
".git/.scripts/commands/bench/bench.sh" xcm westend pallet_xcm_benchm…
Jun 2, 2023
046c7d1
".git/.scripts/commands/bench/bench.sh" xcm rococo pallet_xcm_benchma…
Jun 2, 2023
e7d8749
Merge branch 'master' into kckyeung/xcm-alias-origin
vstam1 Jun 5, 2023
a6350e1
change doc
vstam1 Jun 5, 2023
2f2c80c
fmt
vstam1 Jun 5, 2023
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
5 changes: 4 additions & 1 deletion xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,7 @@ pub use universal_exports::{
};

mod origin_aliases;
pub use origin_aliases::{AliasCase, RemovePrefixAccountId32};
pub use origin_aliases::{
AliasCase, AliasForeignAccountId32, ChildPrefix, IsNativeAccountId32, ParentPrefix,
SiblingPrefix,
};
74 changes: 56 additions & 18 deletions xcm/xcm-builder/src/origin_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,71 @@
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
vstam1 marked this conversation as resolved.
Show resolved Hide resolved

use frame_support::traits::{ContainsPair, Get};
use frame_support::traits::{Contains, ContainsPair};
use sp_std::marker::PhantomData;
use xcm::latest::prelude::*;

pub struct RemovePrefixAccountId32<Prefix>(PhantomData<Prefix>);
impl<Prefix: Get<MultiLocation>> ContainsPair<MultiLocation, MultiLocation>
for RemovePrefixAccountId32<Prefix>
pub struct AliasCase<Origin, Target>(PhantomData<(Origin, Target)>);
impl<Origin, Target> ContainsPair<MultiLocation, MultiLocation> for AliasCase<Origin, Target>
where
Origin: Contains<MultiLocation>,
Target: Contains<MultiLocation>,
{
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
if let Ok(appended) = (*target).clone().prepended_with(Prefix::get()) {
if appended == *origin {
match appended.last() {
Some(AccountId32 { .. }) => return true,
_ => return false,
}
}
}
false
Origin::contains(origin) && Target::contains(target)
}
}

pub struct AliasCase<T>(PhantomData<T>);
impl<T: Get<(MultiLocation, MultiLocation)>> ContainsPair<MultiLocation, MultiLocation>
for AliasCase<T>
pub struct AliasForeignAccountId32<Prefix, Target>(PhantomData<(Prefix, Target)>);
impl<Prefix: Contains<MultiLocation>, Target: Contains<MultiLocation>>
ContainsPair<MultiLocation, MultiLocation> for AliasForeignAccountId32<Prefix, Target>
{
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
let (o, t) = T::get();
&o == origin && &t == target
if let (prefix, Some(account_id @ AccountId32 { .. })) = origin.split_last_interior() {
return Prefix::contains(&prefix) &&
Target::contains(target) &&
vstam1 marked this conversation as resolved.
Show resolved Hide resolved
Some(&account_id) == target.last()
}
false
}
}

pub struct SiblingPrefix;
impl Contains<MultiLocation> for SiblingPrefix {
fn contains(t: &MultiLocation) -> bool {
match *t {
MultiLocation { parents: 1, interior: X1(Parachain(_)) } => true,
_ => false,
}
}
}

pub struct ParentPrefix;
impl Contains<MultiLocation> for ParentPrefix {
fn contains(t: &MultiLocation) -> bool {
match *t {
MultiLocation { parents: 1, interior: Here } => true,
_ => false,
}
}
}

pub struct ChildPrefix;
impl Contains<MultiLocation> for ChildPrefix {
fn contains(t: &MultiLocation) -> bool {
match *t {
MultiLocation { parents: 0, interior: X1(Parachain(_)) } => true,
_ => false,
}
}
}

pub struct IsNativeAccountId32;
vstam1 marked this conversation as resolved.
Show resolved Hide resolved
impl Contains<MultiLocation> for IsNativeAccountId32 {
fn contains(t: &MultiLocation) -> bool {
match *t {
MultiLocation { parents: 0, interior: X1(AccountId32 { .. }) } => true,
_ => false,
}
}
}
24 changes: 6 additions & 18 deletions xcm/xcm-builder/src/tests/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,27 @@ use super::*;

#[test]
fn alias_sibling_account_should_work() {
// Wrong parachain
assert!(!RemovePrefixAccountId32::<AliasSiblingPrefix>::contains(
&(Parent, Parachain(2), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [0; 32] }).into()
));

// Accounts Differ
assert!(!RemovePrefixAccountId32::<AliasSiblingPrefix>::contains(
assert!(!AliasForeignAccountId32::<SiblingPrefix, IsNativeAccountId32>::contains(
&(Parent, Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

assert!(RemovePrefixAccountId32::<AliasSiblingPrefix>::contains(
assert!(AliasForeignAccountId32::<SiblingPrefix, IsNativeAccountId32>::contains(
&(Parent, Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [0; 32] }).into()
));
}

#[test]
fn alias_child_account_should_work() {
// Wrong parachain
assert!(!RemovePrefixAccountId32::<AliasChildPrefix>::contains(
&(Parachain(2), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [0; 32] }).into()
));

// Accounts Differ
assert!(!RemovePrefixAccountId32::<AliasChildPrefix>::contains(
assert!(!AliasForeignAccountId32::<ChildPrefix, IsNativeAccountId32>::contains(
&(Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

assert!(RemovePrefixAccountId32::<AliasChildPrefix>::contains(
assert!(AliasForeignAccountId32::<ChildPrefix, IsNativeAccountId32>::contains(
&(Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [0; 32] }).into()
));
Expand All @@ -59,12 +47,12 @@ fn alias_child_account_should_work() {
#[test]
fn alias_parent_account_should_work() {
// Accounts Differ
assert!(!RemovePrefixAccountId32::<AliasParentPrefix>::contains(
assert!(!AliasForeignAccountId32::<ParentPrefix, IsNativeAccountId32>::contains(
&(Parent, AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

assert!(RemovePrefixAccountId32::<AliasParentPrefix>::contains(
assert!(AliasForeignAccountId32::<ParentPrefix, IsNativeAccountId32>::contains(
&(Parent, AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [0; 32] }).into()
));
Expand Down
8 changes: 0 additions & 8 deletions xcm/xcm-builder/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

use crate::{
barriers::{AllowSubscriptionsFrom, RespectSuspension},
origin_aliases::{AliasChildAccountId32, AliasParentAccountId32},
test_utils::*,
AliasSiblingAccountId32,
};
pub use crate::{
AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowTopLevelPaidExecutionFrom,
Expand Down Expand Up @@ -644,12 +642,6 @@ impl AssetExchange for TestAssetExchange {
}
}

parameter_types! {
pub static AliasSiblingPrefix: MultiLocation = (Parent, Parachain(1)).into();
pub static AliasChildPrefix: MultiLocation = (Parachain(1)).into();
pub static AliasParentPrefix: MultiLocation = (Parent).into();
}

pub type TestAliases = ();

pub struct TestConfig;
Expand Down