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 7 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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.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 @@ -448,8 +448,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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.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 @@ -28,11 +28,11 @@ use frame_support::{
parameter_types,
traits::{
tokens::imbalance::{ResolveAssetTo, ResolveTo},
ConstU32, Contains, Equals, Everything, Nothing, PalletInfoAccess,
ConstU32, Contains, Equals, Everything, PalletInfoAccess,
},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use pallet_xcm::{AuthorizedAliases, XcmPassthrough};
use parachains_common::{
xcm_config::{
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
Expand Down Expand Up @@ -462,15 +462,16 @@ impl xcm_executor::Config for XcmConfig {
(bridging::to_rococo::UniversalAliases, bridging::to_ethereum::UniversalAliases);
type CallDispatcher = RuntimeCall;
type SafeCallFilter = Everything;
type Aliasers = Nothing;
type Aliasers = AuthorizedAliases<Runtime>;
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 Down Expand Up @@ -133,6 +134,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 @@ -191,6 +193,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 @@ -300,6 +303,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 @@ -410,6 +414,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 @@ -488,6 +493,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 @@ -569,6 +575,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 @@ -648,6 +655,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 @@ -700,6 +708,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 @@ -764,6 +773,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 @@ -825,6 +835,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 @@ -939,6 +950,87 @@ 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(Westend), 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())
));

// `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())
));
// 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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.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 @@ -237,8 +237,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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.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 @@ -231,8 +231,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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.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 @@ -235,8 +235,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 @@ -208,8 +208,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,20 @@ 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> {
fn add_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn remove_authorized_alias() -> Weight {
// TODO: benchmark
Weight::from_parts(3_724_000, 0)
.saturating_add(Weight::from_parts(0, 1517))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0)
/// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1)
Expand Down
Loading
Loading