Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-xcm: add support to authorize aliases #6336

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
31f7879
make docs for LocalOriginToLocation uniform across codebase
acatangiu Nov 1, 2024
7a0af10
pallet-xcm: add support for authorizing aliases
acatangiu Nov 1, 2024
879d48b
add stub weights
acatangiu Nov 6, 2024
9103e27
add benchmark code
acatangiu Nov 6, 2024
c29fc5d
add migration for authorized aliases
acatangiu Nov 6, 2024
e84293f
fix pallet-xcm authorized aliases
acatangiu Nov 6, 2024
0332aca
asset hub westend: add support for authorized aliases
acatangiu Nov 6, 2024
9447da4
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Nov 7, 2024
4611498
address comments and fix tests after rebase
acatangiu Nov 7, 2024
709cf3e
add prdoc
acatangiu Nov 7, 2024
200ccee
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Nov 7, 2024
35b4859
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=we…
Nov 7, 2024
79bfce2
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=ro…
Nov 7, 2024
673c3f6
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Nov 7, 2024
ac5d4a6
".git/.scripts/commands/bench/bench.sh" --subcommand=xcm --runtime=as…
Nov 7, 2024
70694dd
fix benchmarks
acatangiu Nov 7, 2024
61c8224
Update polkadot/xcm/pallet-xcm/src/benchmarking.rs
franciscoaguirre Nov 7, 2024
9d59105
Update polkadot/xcm/pallet-xcm/src/lib.rs
franciscoaguirre Nov 7, 2024
1b647db
Update polkadot/xcm/pallet-xcm/src/lib.rs
franciscoaguirre Nov 7, 2024
7b58df8
chore: change new_version to XCM_VERSION
franciscoaguirre Nov 7, 2024
8764367
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Nov 11, 2024
c239f8d
rename vars
acatangiu Nov 11, 2024
a606607
pallet-xcm: add expiry to authorized aliases
acatangiu Nov 12, 2024
b7ef64c
pallet-xcm: add storage deposit for authorized aliases
acatangiu Nov 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ use core::marker::PhantomData;
/// Weight functions for `pallet_xcm`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `498`
// Estimated: `3963`
// Minimum execution time: 19_789_000 picoseconds.
Weight::from_parts(20_317_000, 3963)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `537`
// Estimated: `4002`
// Minimum execution time: 20_805_000 picoseconds.
Weight::from_parts(21_481_000, 4002)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0)
/// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ impl xcm_executor::Config for XcmConfig {
type XcmRecorder = PolkadotXcm;
}

/// Converts a local signed origin into an XCM location.
/// Forms the basis for local origins sending/executing XCMs.
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

pub type PriceForParentDelivery =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ use core::marker::PhantomData;
/// Weight functions for `pallet_xcm`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `498`
// Estimated: `3963`
// Minimum execution time: 19_789_000 picoseconds.
Weight::from_parts(20_317_000, 3963)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `537`
// Estimated: `4002`
// Minimum execution time: 20_805_000 picoseconds.
Weight::from_parts(21_481_000, 4002)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0)
/// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use frame_support::{
},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
use parachains_common::{
xcm_config::{
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
Expand Down Expand Up @@ -353,6 +353,12 @@ pub type TrustedTeleporters = (
IsForeignConcreteAsset<FromSiblingParachain<parachain_info::Pallet<Runtime>>>,
);

/// Defines origin aliasing rules for this chain.
///
/// - Allow any origin to alias into a child sub-location (equivalent to DescendOrigin),
/// - Allow origins explicitly authorized by the alias target location.
pub type TrustedAliasers = (AliasChildLocation, AuthorizedAliasers<Runtime>);

/// Asset converter for pool assets.
/// Used to convert one asset to another, when there is a pool available between the two.
/// This type thus allows paying fees with any asset as long as there is a pool between said
Expand Down Expand Up @@ -465,16 +471,16 @@ impl xcm_executor::Config for XcmConfig {
(bridging::to_rococo::UniversalAliases, bridging::to_ethereum::UniversalAliases);
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
// We allow any origin to alias into a child sub-location (equivalent to DescendOrigin).
type Aliasers = AliasChildLocation;
type Aliasers = TrustedAliasers;
type TransactionalProcessor = FrameTransactionalProcessor;
type HrmpNewChannelOpenRequestHandler = ();
type HrmpChannelAcceptedHandler = ();
type HrmpChannelClosingHandler = ();
type XcmRecorder = PolkadotXcm;
}

/// Local origins on this chain are allowed to dispatch XCM sends/executions.
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

pub type PriceForParentDelivery =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use frame_support::{
fungibles::{
Create, Inspect as FungiblesInspect, InspectEnumerable, Mutate as FungiblesMutate,
},
ContainsPair,
},
weights::{Weight, WeightToFee as WeightToFeeT},
};
Expand All @@ -54,7 +55,7 @@ use std::{convert::Into, ops::Mul};
use testnet_parachains_constants::westend::{consensus::*, currency::UNITS, fee::WeightToFee};
use xcm::latest::{
prelude::{Assets as XcmAssets, *},
ROCOCO_GENESIS_HASH,
ROCOCO_GENESIS_HASH, WESTEND_GENESIS_HASH,
};
use xcm_builder::WithLatestLocationConverter;
use xcm_executor::traits::{ConvertLocation, JustTry, WeightTrader};
Expand Down Expand Up @@ -136,6 +137,7 @@ fn setup_pool_for_paying_fees_with_foreign_assets(
#[test]
fn test_buy_and_refund_weight_in_native() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -194,6 +196,7 @@ fn test_buy_and_refund_weight_in_native() {
#[test]
fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -303,6 +306,7 @@ fn test_buy_and_refund_weight_with_swap_local_asset_xcm_trader() {
#[test]
fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -413,6 +417,7 @@ fn test_buy_and_refund_weight_with_swap_foreign_asset_xcm_trader() {
#[test]
fn test_asset_xcm_take_first_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -491,6 +496,7 @@ fn test_asset_xcm_take_first_trader() {
#[test]
fn test_foreign_asset_xcm_take_first_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -572,6 +578,7 @@ fn test_foreign_asset_xcm_take_first_trader() {
#[test]
fn test_asset_xcm_take_first_trader_with_refund() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -651,6 +658,7 @@ fn test_asset_xcm_take_first_trader_with_refund() {
#[test]
fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_ed() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -703,6 +711,7 @@ fn test_asset_xcm_take_first_trader_refund_not_possible_since_amount_less_than_e
#[test]
fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -767,6 +776,7 @@ fn test_that_buying_ed_refund_does_not_refund_for_take_first_trader() {
#[test]
fn test_asset_xcm_take_first_trader_not_possible_for_non_sufficient_assets() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -828,6 +838,7 @@ fn test_assets_balances_api_works() {
use assets_common::runtime_api::runtime_decl_for_fungibles_api::FungiblesApi;

ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
Expand Down Expand Up @@ -942,6 +953,92 @@ fn test_assets_balances_api_works() {
});
}

#[test]
fn authorized_aliases_work() {
ExtBuilder::<Runtime>::default()
.with_tracing()
.with_collators(vec![AccountId::from(ALICE)])
.with_session_keys(vec![(
AccountId::from(ALICE),
AccountId::from(ALICE),
SessionKeys { aura: AuraId::from(sp_core::sr25519::Public::from_raw(ALICE)) },
)])
.build()
.execute_with(|| {
let alice: AccountId = ALICE.into();
let local_alice = Location::new(
0,
AccountId32 { network: Some(ByGenesis(WESTEND_GENESIS_HASH)), id: ALICE },
);
let alice_on_sibling_para =
Location::new(1, [Parachain(42), AccountId32 { network: None, id: ALICE }]);
let alice_on_relay = Location::new(1, AccountId32 { network: None, id: ALICE });
let bob_on_relay = Location::new(1, AccountId32 { network: None, id: [42_u8; 32] });

// neither `alice_on_sibling_para`, `alice_on_relay`, `bob_on_relay` are allowed to
// alias into `local_alice`
for aliaser in [&alice_on_sibling_para, &alice_on_relay, &bob_on_relay] {
assert!(!<XcmConfig as xcm_executor::Config>::Aliasers::contains(
aliaser,
&local_alice
));
}

// Alice explicitly authorizes `alice_on_sibling_para` to alias her local account
assert_ok!(PolkadotXcm::add_authorized_alias(
RuntimeHelper::origin_of(alice.clone()),
Box::new(alice_on_sibling_para.clone().into()),
None
));

// `alice_on_sibling_para` now explicitly allowed to alias into `local_alice`
assert!(<XcmConfig as xcm_executor::Config>::Aliasers::contains(
&alice_on_sibling_para,
bkontur marked this conversation as resolved.
Show resolved Hide resolved
&local_alice
));
// as expected, `alice_on_relay` and `bob_on_relay` still can't alias into `local_alice`
for aliaser in [&alice_on_relay, &bob_on_relay] {
assert!(!<XcmConfig as xcm_executor::Config>::Aliasers::contains(
aliaser,
&local_alice
));
}

// Alice explicitly authorizes `alice_on_relay` to alias her local account
assert_ok!(PolkadotXcm::add_authorized_alias(
RuntimeHelper::origin_of(alice.clone()),
Box::new(alice_on_relay.clone().into()),
None
));
// Now both `alice_on_relay` and `alice_on_sibling_para` can alias into her local
// account
for aliaser in [&alice_on_relay, &alice_on_sibling_para] {
assert!(<XcmConfig as xcm_executor::Config>::Aliasers::contains(
aliaser,
&local_alice
));
}

// Alice removes authorization for `alice_on_relay` to alias her local account
assert_ok!(PolkadotXcm::remove_authorized_alias(
RuntimeHelper::origin_of(alice.clone()),
Box::new(alice_on_relay.clone().into())
));

// `alice_on_relay` no longer allowed to alias into `local_alice`
assert!(!<XcmConfig as xcm_executor::Config>::Aliasers::contains(
&alice_on_relay,
&local_alice
));

// `alice_on_sibling_para` still allowed to alias into `local_alice`
assert!(<XcmConfig as xcm_executor::Config>::Aliasers::contains(
&alice_on_sibling_para,
&local_alice
));
})
}

asset_test_utils::include_teleports_for_native_asset_works!(
Runtime,
AllPalletsWithoutSystem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ use core::marker::PhantomData;
/// Weight functions for `pallet_xcm`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `498`
// Estimated: `3963`
// Minimum execution time: 19_789_000 picoseconds.
Weight::from_parts(20_317_000, 3963)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `537`
// Estimated: `4002`
// Minimum execution time: 20_805_000 picoseconds.
Weight::from_parts(21_481_000, 4002)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0)
/// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ impl xcm_executor::Config for XcmConfig {
pub type PriceForParentDelivery =
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;

/// Converts a local signed origin into an XCM location.
/// Forms the basis for local origins sending/executing XCMs.
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

/// The means for routing XCM messages which are not for local execution into the right message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ use core::marker::PhantomData;
/// Weight functions for `pallet_xcm`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn add_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `498`
// Estimated: `3963`
// Minimum execution time: 19_789_000 picoseconds.
Weight::from_parts(20_317_000, 3963)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `PolkadotXcm::AuthorizedAliases` (r:1 w:1)
/// Proof: `PolkadotXcm::AuthorizedAliases` (`max_values`: None, `max_size`: None, mode: `Measured`)
fn remove_authorized_alias() -> Weight {
// Proof Size summary in bytes:
// Measured: `537`
// Estimated: `4002`
// Minimum execution time: 20_805_000 picoseconds.
Weight::from_parts(21_481_000, 4002)
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0)
/// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ impl xcm_executor::Config for XcmConfig {
pub type PriceForParentDelivery =
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, ParachainSystem>;

/// Converts a local signed origin into an XCM location.
/// Forms the basis for local origins sending/executing XCMs.
/// Converts a local signed origin into an XCM location. Forms the basis for local origins
/// sending/executing XCMs.
pub type LocalOriginToLocation = SignedToAccountId32<RuntimeOrigin, AccountId, RelayNetwork>;

/// The means for routing XCM messages which are not for local execution into the right message
Expand Down
Loading
Loading