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 48 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 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
40fcc27
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Jan 13, 2025
5bde333
fix conflicts
acatangiu Jan 13, 2025
4ed6e22
fix bugs, add tests
acatangiu Jan 14, 2025
8600075
remove alias auto-prune
acatangiu Jan 14, 2025
795e63e
define runtime APIs for authorized aliases
acatangiu Jan 14, 2025
4f35647
add events
acatangiu Jan 14, 2025
875c9ab
tweak prdoc
acatangiu Jan 14, 2025
327a2e1
remove debug prints
acatangiu Jan 14, 2025
af6abe8
fix import
acatangiu Jan 14, 2025
356c8f2
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Jan 14, 2025
29b0c0d
configure runtimes
acatangiu Jan 14, 2025
9792913
better configure runtimes
acatangiu Jan 16, 2025
31b5feb
implement runtime APIs
acatangiu Jan 16, 2025
825a4b4
fix test runtimes
acatangiu Jan 16, 2025
f2869b2
make runtime APIs truly versioned
acatangiu Jan 16, 2025
1d17ef4
fix tests
acatangiu Jan 16, 2025
bdd0f7b
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Jan 16, 2025
91e283a
fix clippy
acatangiu Jan 17, 2025
7056188
fix more test runtimes
acatangiu Jan 17, 2025
0a705ca
fix clippy
acatangiu Jan 17, 2025
caff17b
fix toml
acatangiu Jan 17, 2025
28b6989
fix benchmarks
acatangiu Jan 17, 2025
f434f45
fix prdoc
acatangiu Jan 17, 2025
ab80b6e
Merge branch 'master' of github.com:paritytech/polkadot-sdk into auth…
acatangiu Jan 17, 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.

15 changes: 15 additions & 0 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,21 @@ impl_runtime_apis! {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}

impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
fn authorized_aliasers(target: VersionedLocation) -> Result<
Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
xcm_runtime_apis::authorized_aliases::Error
> {
PolkadotXcm::authorized_aliasers(target)
}
fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
bool,
xcm_runtime_apis::authorized_aliases::Error
> {
PolkadotXcm::is_authorized_alias(origin, target)
}
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -16,9 +16,9 @@
use super::{
AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee,
CollatorSelection, FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo,
ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ToWestendXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, Uniques, WeightToFee,
XcmpQueue,
ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent,
RuntimeHoldReason, RuntimeOrigin, ToWestendXcmRouter, TransactionByteFee,
TrustBackedAssetsInstance, Uniques, WeightToFee, XcmpQueue,
};
use assets_common::{
matching::{FromNetwork, FromSiblingParachain, IsForeignConcreteAsset, ParentLocation},
Expand All @@ -27,12 +27,13 @@ use assets_common::{
use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration,
tokens::imbalance::{ResolveAssetTo, ResolveTo},
ConstU32, Contains, Equals, Everything, PalletInfoAccess,
ConstU32, Contains, Equals, Everything, LinearStoragePrice, PalletInfoAccess,
},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
use parachains_common::{
xcm_config::{
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
Expand Down Expand Up @@ -334,6 +335,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 @@ -448,16 +455,16 @@ impl xcm_executor::Config for XcmConfig {
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;
}

/// 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 All @@ -483,6 +490,12 @@ pub type XcmRouter = WithUniqueTopic<(
SovereignPaidRemoteExporter<bridging::EthereumNetworkExportTable, XcmpQueue, UniversalLocation>,
)>;

parameter_types! {
pub const DepositPerItem: Balance = crate::deposit(1, 0);
pub const DepositPerByte: Balance = crate::deposit(0, 1);
pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand Down Expand Up @@ -513,6 +526,13 @@ impl pallet_xcm::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
// xcm_executor::Config::Aliasers also uses pallet_xcm::AuthorizedAliasers.
type AuthorizedAliasConsideration = HoldConsideration<
AccountId,
Balances,
AuthorizeAliasHoldReason,
LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
33 changes: 24 additions & 9 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,6 +1715,30 @@ impl_runtime_apis! {
}
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}

impl xcm_runtime_apis::authorized_aliases::AuthorizedAliasersApi<Block> for Runtime {
fn authorized_aliasers(target: VersionedLocation) -> Result<
Vec<xcm_runtime_apis::authorized_aliases::OriginAliaser>,
xcm_runtime_apis::authorized_aliases::Error
> {
PolkadotXcm::authorized_aliasers(target)
}
fn is_authorized_alias(origin: VersionedLocation, target: VersionedLocation) -> Result<
bool,
xcm_runtime_apis::authorized_aliases::Error
> {
PolkadotXcm::is_authorized_alias(origin, target)
}
}

impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentCallApi<Block, Balance, RuntimeCall>
for Runtime
{
Expand Down Expand Up @@ -2175,15 +2199,6 @@ impl_runtime_apis! {
}
}

impl xcm_runtime_apis::trusted_query::TrustedQueryApi<Block> for Runtime {
fn is_trusted_reserve(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_reserve(asset, location)
}
fn is_trusted_teleporter(asset: VersionedAsset, location: VersionedLocation) -> xcm_runtime_apis::trusted_query::XcmTrustedQueryResult {
PolkadotXcm::is_trusted_teleporter(asset, location)
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
{
fn balance(address: H160) -> U256 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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 @@ -15,10 +15,10 @@

use super::{
AccountId, AllPalletsWithSystem, Assets, Authorship, Balance, Balances, BaseDeliveryFee,
CollatorSelection, FeeAssetId, ForeignAssets, ForeignAssetsInstance, ParachainInfo,
ParachainSystem, PolkadotXcm, PoolAssets, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin,
ToRococoXcmRouter, TransactionByteFee, TrustBackedAssetsInstance, Uniques, WeightToFee,
XcmpQueue,
CollatorSelection, DepositPerByte, DepositPerItem, FeeAssetId, ForeignAssets,
ForeignAssetsInstance, ParachainInfo, ParachainSystem, PolkadotXcm, PoolAssets, Runtime,
RuntimeCall, RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, ToRococoXcmRouter,
TransactionByteFee, TrustBackedAssetsInstance, Uniques, WeightToFee, XcmpQueue,
};
use assets_common::{
matching::{FromSiblingParachain, IsForeignConcreteAsset, ParentLocation},
Expand All @@ -27,12 +27,13 @@ use assets_common::{
use frame_support::{
parameter_types,
traits::{
fungible::HoldConsideration,
tokens::imbalance::{ResolveAssetTo, ResolveTo},
ConstU32, Contains, Equals, Everything, PalletInfoAccess,
ConstU32, Contains, Equals, Everything, LinearStoragePrice, PalletInfoAccess,
},
};
use frame_system::EnsureRoot;
use pallet_xcm::XcmPassthrough;
use pallet_xcm::{AuthorizedAliasers, XcmPassthrough};
use parachains_common::{
xcm_config::{
AllSiblingSystemParachains, AssetFeeAsExistentialDepositMultiplier,
Expand Down Expand Up @@ -354,6 +355,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 @@ -466,16 +473,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 Expand Up @@ -505,6 +512,10 @@ pub type XcmRouter = WithUniqueTopic<(
>,
)>;

parameter_types! {
pub const AuthorizeAliasHoldReason: RuntimeHoldReason = RuntimeHoldReason::PolkadotXcm(pallet_xcm::HoldReason::AuthorizeAlias);
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
Expand Down Expand Up @@ -533,6 +544,13 @@ impl pallet_xcm::Config for Runtime {
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
// xcm_executor::Config::Aliasers also uses pallet_xcm::AuthorizedAliasers.
type AuthorizedAliasConsideration = HoldConsideration<
AccountId,
Balances,
AuthorizeAliasHoldReason,
LinearStoragePrice<DepositPerItem, DepositPerByte, Balance>,
>;
}

impl cumulus_pallet_xcm::Config for Runtime {
Expand Down
Loading
Loading