Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a303dff
xcm-matcher: alias filter for remote account A to local account A
acatangiu Mar 20, 2025
a0207eb
people: add accounts aliasing test
acatangiu Mar 20, 2025
9fc747c
move test to macro for reuse
acatangiu Mar 20, 2025
c7505be
enhance macro, test multiple combinations
acatangiu Mar 21, 2025
76e2e69
implement aliasing rule for coretime and add tests
acatangiu Mar 21, 2025
d0489dd
implement aliasing rule for collectives and add tests
acatangiu Mar 21, 2025
bc42cd9
implement aliasing rule for asset hub and add tests
acatangiu Mar 21, 2025
fcfcd0a
implement aliasing rule for bridge hub and add tests
acatangiu Mar 21, 2025
561f67a
add more tests
acatangiu Mar 21, 2025
c4ba064
Merge branch 'master' of github.com:paritytech/polkadot-sdk into allo…
acatangiu Mar 21, 2025
0cb6362
add alias child locations tests
acatangiu Mar 24, 2025
74d6792
more aliasing tests
acatangiu Mar 24, 2025
97ceeb9
people: set identity for Alice on People using Alice on AH
acatangiu Mar 24, 2025
4d27dfe
Merge branch 'master' of github.com:paritytech/polkadot-sdk into allo…
acatangiu Mar 24, 2025
2bbd410
Update from github-actions[bot] running command 'prdoc --audience run…
github-actions[bot] Mar 25, 2025
4bd4ddb
fix clippy
acatangiu Mar 25, 2025
eed5e19
adjust prdoc
acatangiu Mar 25, 2025
c1115e7
Merge branch 'master' into allow-direct-account-alias-system-chains
acatangiu Mar 25, 2025
eaaac24
fix clippy
acatangiu Mar 25, 2025
55027c4
Apply suggestions from code review
acatangiu Mar 26, 2025
32d8f29
Update from github-actions[bot] running command 'fmt'
github-actions[bot] Mar 26, 2025
2bdf6ad
fix test
acatangiu Mar 26, 2025
311d140
Merge branch 'master' of github.com:paritytech/polkadot-sdk into allo…
acatangiu Mar 26, 2025
9c54d3f
fix merge damage
acatangiu Mar 26, 2025
b57c30e
Merge branch 'master' into allow-direct-account-alias-system-chains
acatangiu Mar 28, 2025
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
1 change: 1 addition & 0 deletions Cargo.lock

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

85 changes: 83 additions & 2 deletions cumulus/parachains/common/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,44 @@ impl Contains<Location> for ParentRelayOrSiblingParachains {
}
}

/// Filter to check if a given `target` location represents the same AccountId32 as `origin`,
/// but coming from another sibling system chain.
///
/// This type should only be used within the context of a parachain, to allow accounts on system
/// chains to Alias to the same accounts on the local chain.
pub struct AliasAccountId32FromSiblingSystemChain;
impl ContainsPair<Location, Location> for AliasAccountId32FromSiblingSystemChain {
fn contains(origin: &Location, target: &Location) -> bool {
let result = match origin.unpack() {
// `origin` is AccountId32 on sibling system parachain
(1, [Parachain(para_id), AccountId32 { network: _, id: origin }])
if ParaId::from(*para_id).is_system() =>
{
match target.unpack() {
// `target` is local AccountId32 and matches `origin` remote account
(0, [AccountId32 { network: _, id: target }]) => target.eq(origin),
_ => false,
}
},
_ => false,
};
log::trace!(
target: "xcm::contains",
"AliasAccountId32FromSiblingSystemChain origin: {:?}, target: {:?}, result {:?}",
origin, target, result,
);
result
}
}

#[cfg(test)]
mod tests {
use frame_support::{parameter_types, traits::Contains};

use super::{
AllSiblingSystemParachains, Asset, ConcreteAssetFromSystem, ContainsPair, GeneralIndex,
Here, Location, PalletInstance, Parachain, Parent,
AliasAccountId32FromSiblingSystemChain, AllSiblingSystemParachains, Asset,
ConcreteAssetFromSystem, ContainsPair, GeneralIndex, Here, Location, PalletInstance,
Parachain, Parent,
};
use polkadot_primitives::LOWEST_PUBLIC_ID;
use xcm::latest::prelude::*;
Expand Down Expand Up @@ -221,4 +252,54 @@ mod tests {
// when used with non-parachain
assert!(!AllSiblingSystemParachains::contains(&Location::new(1, [OnlyChild])));
}

#[test]
fn alias_accountid32_from_sibling_system_parachains() {
let acc_42 = AccountId32 { network: None, id: [42u8; 32] };
let acc_13 = AccountId32 { network: None, id: [13u8; 32] };
// origin acc_42 on sibling system parachain aliases into local acc_42
assert!(AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(0, [acc_42])
));
// if target is not local account, always fails
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(0, [])
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(0, [Parachain(1)])
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(0, [GeneralIndex(42)])
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(1, [acc_42])
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_42]),
&Location::new(2, [acc_42])
));
// origin acc_13 on sibling system parachain CANNOT alias into local acc_42
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(1), acc_13]),
&Location::new(0, [acc_42])
));
// origin acc_42 on sibling non-system parachain CANNOT alias into local acc_42
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(1, [Parachain(LOWEST_PUBLIC_ID.into()), acc_42]),
&Location::new(0, [acc_42])
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(0, [acc_13]),
&Location::new(0, [acc_13]),
));
assert!(!AliasAccountId32FromSiblingSystemChain::contains(
&Location::new(0, [acc_42]),
&Location::new(1, [Parachain(1), acc_42]),
));
}
}
77 changes: 77 additions & 0 deletions cumulus/parachains/integration-tests/emulated/common/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,3 +745,80 @@ macro_rules! test_xcm_fee_querying_apis_work_for_asset_hub {
}
};
}

#[macro_export]
macro_rules! test_cross_chain_alias {
( vec![$( ($sender_para:ty, $receiver_para:ty, $is_teleport:expr, $expected_success:expr) ),+], $origin:expr, $target:expr, $fees:expr ) => {
$crate::macros::paste::paste! {
use xcm::latest::AssetTransferFilter;
$(
{
let para_destination = <$sender_para>::sibling_location_of(<$receiver_para>::para_id());
let account: AccountId = $origin.clone().into();
$sender_para::fund_accounts(vec![(account.clone(), $fees * 10)]);
let total_fees: Asset = (Location::parent(), $fees).into();
let fees: Asset = (Location::parent(), $fees / 2).into();

let remote_fees = if $is_teleport {
Some(AssetTransferFilter::Teleport(fees.clone().into()))
} else {
let source_para_sa = <$receiver_para>::sovereign_account_id_of(
<$receiver_para>::sibling_location_of(<$sender_para>::para_id()),
);
$receiver_para::fund_accounts(vec![(source_para_sa, $fees * 10)]);
Some(AssetTransferFilter::ReserveWithdraw(fees.clone().into()))
};
<$sender_para>::execute_with(|| {
type RuntimeEvent = <$sender_para as $crate::macros::Chain>::RuntimeEvent;
let xcm_message = Xcm::<()>(vec![
WithdrawAsset(total_fees.into()),
PayFees { asset: fees.clone() },
InitiateTransfer {
destination: para_destination,
remote_fees,
preserve_origin: true,
assets: BoundedVec::new(),
remote_xcm: Xcm(vec![
// try to alias into `account`
AliasOrigin($target.clone().into()),
RefundSurplus,
DepositAsset {
assets: Wild(AllCounted(1)),
beneficiary: $target.clone().into(),
},
]),
},
RefundSurplus,
DepositAsset { assets: Wild(AllCounted(1)), beneficiary: account.clone().into() },
]);

let signed_origin = <$sender_para as Chain>::RuntimeOrigin::signed(account.into());
assert_ok!(<$sender_para as [<$sender_para Pallet>]>::PolkadotXcm::execute(
signed_origin,
bx!(xcm::VersionedXcm::from(xcm_message.into())),
Weight::MAX
));
assert_expected_events!(
$sender_para,
vec![
RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Sent { .. }) => {},
]
);
});

<$receiver_para>::execute_with(|| {
type RuntimeEvent = <$receiver_para as $crate::macros::Chain>::RuntimeEvent;
assert_expected_events!(
$receiver_para,
vec![
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed {
success, ..
}) => { success: *success == $expected_success, },
]
);
});
}
)+
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ mod imports {
genesis::{AssetHubWestendAssetOwner, ED as ASSET_HUB_WESTEND_ED},
AssetHubWestendParaPallet as AssetHubWestendPallet,
},
bridge_hub_westend_emulated_chain::bridge_hub_westend_runtime::xcm_config::{
self as bhw_xcm_config,
bridge_hub_westend_emulated_chain::{
bridge_hub_westend_runtime::xcm_config::{self as bhw_xcm_config},
BridgeHubWestendParaPallet as BridgeHubWestendPallet,
},
collectives_westend_emulated_chain::CollectivesWestendParaPallet as CollectivesWestendPallet,
coretime_westend_emulated_chain::CoretimeWestendParaPallet as CoretimeWestendPallet,
penpal_emulated_chain::{
penpal_runtime::xcm_config::{
CustomizableAssetFromSystemAssetHub as PenpalCustomizableAssetFromSystemAssetHub,
Expand All @@ -78,6 +80,7 @@ mod imports {
PenpalAParaPallet as PenpalAPallet, PenpalAssetOwner,
PenpalBParaPallet as PenpalBPallet,
},
people_westend_emulated_chain::PeopleWestendParaPallet as PeopleWestendPallet,
westend_emulated_chain::{
genesis::ED as WESTEND_ED,
westend_runtime::{
Expand All @@ -94,10 +97,12 @@ mod imports {
AssetHubWestendParaSender as AssetHubWestendSender,
BridgeHubWestendPara as BridgeHubWestend,
BridgeHubWestendParaReceiver as BridgeHubWestendReceiver,
CollectivesWestendPara as CollectivesWestend, PenpalAPara as PenpalA,
PenpalAParaReceiver as PenpalAReceiver, PenpalAParaSender as PenpalASender,
PenpalBPara as PenpalB, PenpalBParaReceiver as PenpalBReceiver, WestendRelay as Westend,
WestendRelayReceiver as WestendReceiver, WestendRelaySender as WestendSender,
CollectivesWestendPara as CollectivesWestend, CoretimeWestendPara as CoretimeWestend,
PenpalAPara as PenpalA, PenpalAParaReceiver as PenpalAReceiver,
PenpalAParaSender as PenpalASender, PenpalBPara as PenpalB,
PenpalBParaReceiver as PenpalBReceiver, PeopleWestendPara as PeopleWestend,
WestendRelay as Westend, WestendRelayReceiver as WestendReceiver,
WestendRelaySender as WestendSender,
};

pub const ASSET_ID: u32 = 3;
Expand Down
Loading
Loading