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
2 changes: 1 addition & 1 deletion xcm/xcm-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ pub use universal_exports::{
};

mod origin_aliases;
pub use origin_aliases::AliasSiblingAccountId32;
pub use origin_aliases::{AliasCase, RemovePrefixAccountId32};
71 changes: 19 additions & 52 deletions xcm/xcm-builder/src/origin_aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,32 @@
// 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 sp_std::marker::PhantomData;
use xcm::latest::prelude::*;

pub struct AliasSiblingAccountId32<ParachainId>(sp_std::marker::PhantomData<ParachainId>);
impl<ParachainId: Get<u32>> ContainsPair<MultiLocation, MultiLocation>
for AliasSiblingAccountId32<ParachainId>
pub struct RemovePrefixAccountId32<Prefix>(PhantomData<Prefix>);
vstam1 marked this conversation as resolved.
Show resolved Hide resolved
impl<Prefix: Get<MultiLocation>> ContainsPair<MultiLocation, MultiLocation>
for RemovePrefixAccountId32<Prefix>
{
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
match origin {
MultiLocation {
parents: 1,
interior:
X2(Parachain(para_id), origin_account @ AccountId32 {network: _, id: _, }),
} if *para_id == ParachainId::get() => match target {
MultiLocation {
parents: 0,
interior: X1(alias_account),
} if origin_account == alias_account => true,
_ => false,
},
_ => false,
if let Ok(appended) = (*target).prepended_with(Prefix::get()) {
vstam1 marked this conversation as resolved.
Show resolved Hide resolved
if appended == *origin {
match appended.last() {
Some(AccountId32 { .. }) => return true,
_ => return false,
}
}
}
false
}
}

pub struct AliasParentAccountId32;
impl ContainsPair<MultiLocation, MultiLocation> for AliasParentAccountId32 {
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
match origin {
MultiLocation {
parents: 1,
interior: X1(origin_account @ AccountId32 {network: _, id: _, })
} => match target {
MultiLocation {
parents: 0,
interior: X1(alias_account)
} if alias_account == origin_account => true,
_ => false,
}
_ => false
}
}
}

pub struct AliasChildAccountId32<ParachainId>(sp_std::marker::PhantomData<ParachainId>);
impl<ParachainId: Get<u32>> ContainsPair<MultiLocation, MultiLocation> for AliasChildAccountId32<ParachainId> {
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
match origin {
MultiLocation {
parents: 0,
interior:
X2(Parachain(para_id), origin_account @ AccountId32 {network: _, id: _, }),
} if *para_id == ParachainId::get() => match target {
MultiLocation {
parents: 0,
interior: X1(alias_account),
} if origin_account == alias_account => true,
_ => false,
},
_ => false,
}
pub struct AliasCase<T>(PhantomData<T>);
impl<T: Get<(MultiLocation, MultiLocation)>> ContainsPair<MultiLocation, MultiLocation>
for AliasCase<T>
{
fn contains(origin: &MultiLocation, target: &MultiLocation) -> bool {
let (o, t) = T::get();
&o == origin && &t == target
}
}
68 changes: 51 additions & 17 deletions xcm/xcm-builder/src/tests/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,54 @@ use super::*;

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

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

assert!(AliasSiblingAccountId32::<ConstU32<1>>::contains(
&(Parent, Parachain(1), AccountId32 { network: None, id: [0;32] }).into(),
&(AccountId32 { network: None, id: [0;32] }).into()
));
}
// 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(
&(Parent, Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

assert!(RemovePrefixAccountId32::<AliasSiblingPrefix>::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(
&(Parachain(1), AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

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

#[test]
fn alias_parent_account_should_work() {
// Accounts Differ
assert!(!RemovePrefixAccountId32::<AliasParentPrefix>::contains(
&(Parent, AccountId32 { network: None, id: [0; 32] }).into(),
&(AccountId32 { network: None, id: [1; 32] }).into()
));

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

use crate::{
barriers::{AllowSubscriptionsFrom, RespectSuspension},
test_utils::*, AliasSiblingAccountId32, origin_aliases::{AliasChildAccountId32, AliasParentAccountId32},
origin_aliases::{AliasChildAccountId32, AliasParentAccountId32},
test_utils::*,
AliasSiblingAccountId32,
};
pub use crate::{
AllowExplicitUnpaidExecutionFrom, AllowKnownQueryResponses, AllowTopLevelPaidExecutionFrom,
Expand All @@ -30,7 +32,7 @@ pub use frame_support::{
},
ensure, parameter_types,
sp_runtime::DispatchErrorWithPostInfo,
traits::{Contains, Get, IsInVec, ConstU32},
traits::{ConstU32, Contains, Get, IsInVec},
};
pub use parity_scale_codec::{Decode, Encode};
pub use sp_io::hashing::blake2_256;
Expand Down Expand Up @@ -642,11 +644,13 @@ impl AssetExchange for TestAssetExchange {
}
}

pub type TestAliases = (
AliasSiblingAccountId32<ConstU32<1>>,
AliasChildAccountId32<ConstU32<1>>,
AliasParentAccountId32,
);
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;
impl Config for TestConfig {
Expand Down