Skip to content

Commit

Permalink
[pallet_xcm] adapt paritytech/polkadot-sdk#1672 (new `reserve_transfe…
Browse files Browse the repository at this point in the history
…r_assets`)
  • Loading branch information
bkontur authored and claravanstaden committed Feb 5, 2024
1 parent e60088e commit 70f49b1
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 59 deletions.
29 changes: 28 additions & 1 deletion relay/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ mod benches {
[pallet_whitelist, Whitelist]
[pallet_asset_rate, AssetRate]
// XCM
[pallet_xcm, XcmPallet]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
[pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::<Runtime>]
);
Expand Down Expand Up @@ -2279,6 +2279,7 @@ sp_api::impl_runtime_apis! {
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use frame_system_benchmarking::Pallet as SystemBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use frame_benchmarking::baseline::Pallet as Baseline;
Expand Down Expand Up @@ -2327,6 +2328,32 @@ sp_api::impl_runtime_apis! {
impl pallet_nomination_pools_benchmarking::Config for Runtime {}
impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {}

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
Some(crate::xcm_config::AssetHubLocation::get())
}

fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay/native token can be teleported to/from AH.
Some((
MultiAsset { fun: Fungible(EXISTENTIAL_DEPOSIT), id: Concrete(Here.into()) },
crate::xcm_config::AssetHubLocation::get(),
))
}

fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay can reserve transfer native token to some random parachain.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Here.into())
},
crate::Junction::Parachain(43211234).into(),
))
}
}

parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
TokenLocation::get(),
Expand Down
7 changes: 0 additions & 7 deletions relay/kusama/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ parameter_types! {
pub const FellowsBodyId: BodyId = BodyId::Technical;
}

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parachain(1000).into());
}

/// Type to convert an `Origin` type value into a `MultiLocation` value which represents an interior
/// location of this chain.
pub type LocalOriginToLocation = (
Expand Down Expand Up @@ -286,8 +281,6 @@ impl pallet_xcm::Config for Runtime {
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}

Expand Down
35 changes: 31 additions & 4 deletions relay/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ mod benches {
[pallet_whitelist, Whitelist]
[pallet_asset_rate, AssetRate]
// XCM
[pallet_xcm, XcmPallet]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
[pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::<Runtime>]
);
Expand Down Expand Up @@ -2291,6 +2291,7 @@ sp_api::impl_runtime_apis! {
use pallet_offences_benchmarking::Pallet as OffencesBench;
use pallet_election_provider_support_benchmarking::Pallet as ElectionProviderBench;
use pallet_nomination_pools_benchmarking::Pallet as NominationPoolsBench;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_benchmarking::baseline::Pallet as Baseline;

Expand Down Expand Up @@ -2329,9 +2330,31 @@ sp_api::impl_runtime_apis! {
impl pallet_nomination_pools_benchmarking::Config for Runtime {}
impl runtime_parachains::disputes::slashing::benchmarking::Config for Runtime {}

let mut whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
let treasury_key = frame_system::Account::<Runtime>::hashed_key_for(Treasury::account_id());
whitelist.push(treasury_key.to_vec().into());
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
Some(crate::xcm_config::AssetHubLocation::get())
}

fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay/native token can be teleported to/from AH.
Some((
MultiAsset { fun: Fungible(EXISTENTIAL_DEPOSIT), id: Concrete(Here.into()) },
crate::xcm_config::AssetHubLocation::get(),
))
}

fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay can reserve transfer native token to some random parachain.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Here.into())
},
crate::Junction::Parachain(43211234).into(),
))
}
}

parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
Expand Down Expand Up @@ -2440,6 +2463,10 @@ sp_api::impl_runtime_apis! {
}
}

let mut whitelist: Vec<TrackedStorageKey> = AllPalletsWithSystem::whitelisted_storage_keys();
let treasury_key = frame_system::Account::<Runtime>::hashed_key_for(Treasury::account_id());
whitelist.push(treasury_key.to_vec().into());

let mut batches = Vec::<BenchmarkBatch>::new();
let params = (&config, &whitelist);

Expand Down
7 changes: 0 additions & 7 deletions relay/polkadot/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ parameter_types! {
pub const TreasurerBodyId: BodyId = BodyId::Index(TREASURER_INDEX);
}

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parachain(1000).into());
}

/// Type to convert the `GeneralAdmin` origin to a Plurality `MultiLocation` value.
pub type GeneralAdminToPlurality =
OriginToPluralityVoice<RuntimeOrigin, GeneralAdmin, GeneralAdminBodyId>;
Expand Down Expand Up @@ -313,7 +308,5 @@ impl pallet_xcm::Config for Runtime {
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
}
36 changes: 35 additions & 1 deletion system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// XCM
[pallet_xcm, PolkadotXcm]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// Bridges
[pallet_xcm_bridge_hub_router, ToPolkadot]
// NOTE: Make sure you point to the individual modules below.
Expand Down Expand Up @@ -1224,6 +1224,7 @@ impl_runtime_apis! {
) {
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
use pallet_xcm_bridge_hub_router::benchmarking::Pallet as XcmBridgeHubRouterBench;
Expand Down Expand Up @@ -1276,6 +1277,39 @@ impl_runtime_apis! {
use xcm_config::{KsmLocation, MaxAssetsIntoHolding};
use pallet_xcm_benchmarks::asset_instance_from;

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
Some(Parent.into())
}

fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay/native token can be teleported between AH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Parent.into())
},
Parent.into(),
))
}

fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// AH can reserve transfer native token to some random parachain.
let random_para_id = 43211234;
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
random_para_id.into()
);
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Parent.into())
},
ParentThen(Parachain(random_para_id).into()).into(),
))
}
}

parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
KsmLocation::get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,6 @@ pub type XcmRouter = WithUniqueTopic<(
SovereignPaidRemoteExporter<bridging::EthereumNetworkExportTable, XcmpQueue, UniversalLocation>,
)>;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand Down Expand Up @@ -688,8 +683,6 @@ impl pallet_xcm::Config for Runtime {
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down
36 changes: 35 additions & 1 deletion system-parachains/asset-hubs/asset-hub-polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// XCM
[pallet_xcm, PolkadotXcm]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// Bridges
[pallet_xcm_bridge_hub_router, ToKusama]
// NOTE: Make sure you point to the individual modules below.
Expand Down Expand Up @@ -1117,6 +1117,7 @@ impl_runtime_apis! {
) {
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
use pallet_xcm_bridge_hub_router::benchmarking::Pallet as XcmBridgeHubRouterBench;
Expand Down Expand Up @@ -1168,6 +1169,39 @@ impl_runtime_apis! {
use xcm_config::{DotLocation, MaxAssetsIntoHolding};
use pallet_xcm_benchmarks::asset_instance_from;

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
Some(Parent.into())
}

fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay/native token can be teleported between AH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Parent.into())
},
Parent.into(),
))
}

fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// AH can reserve transfer native token to some random parachain.
let random_para_id = 43211234;
ParachainSystem::open_outbound_hrmp_channel_for_benchmarks_or_tests(
random_para_id.into()
);
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Parent.into())
},
ParentThen(Parachain(random_para_id).into()).into(),
))
}
}

parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
DotLocation::get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,6 @@ pub type XcmRouter = WithUniqueTopic<(
SovereignPaidRemoteExporter<bridging::EthereumNetworkExportTable, XcmpQueue, UniversalLocation>,
)>;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand Down Expand Up @@ -613,8 +608,6 @@ impl pallet_xcm::Config for Runtime {
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down
26 changes: 25 additions & 1 deletion system-parachains/bridge-hubs/bridge-hub-kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ mod benches {
[pallet_collator_selection, CollatorSelection]
[cumulus_pallet_xcmp_queue, XcmpQueue]
// XCM
[pallet_xcm, PolkadotXcm]
[pallet_xcm, PalletXcmExtrinsiscsBenchmark::<Runtime>]
// NOTE: Make sure you point to the individual modules below.
[pallet_xcm_benchmarks::fungible, XcmBalances]
[pallet_xcm_benchmarks::generic, XcmGeneric]
Expand Down Expand Up @@ -929,6 +929,7 @@ impl_runtime_apis! {
) {
use frame_benchmarking::{Benchmarking, BenchmarkList};
use frame_support::traits::StorageInfoTrait;
use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
use frame_system_benchmarking::Pallet as SystemBench;
use cumulus_pallet_session_benchmarking::Pallet as SessionBench;

Expand Down Expand Up @@ -974,6 +975,29 @@ impl_runtime_apis! {
use xcm::latest::prelude::*;
use xcm_config::KsmRelayLocation;

use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark;
impl pallet_xcm::benchmarking::Config for Runtime {
fn reachable_dest() -> Option<MultiLocation> {
Some(Parent.into())
}

fn teleportable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Relay/native token can be teleported between BH and Relay.
Some((
MultiAsset {
fun: Fungible(EXISTENTIAL_DEPOSIT),
id: Concrete(Parent.into())
},
Parent.into(),
))
}

fn reserve_transferable_asset_and_dest() -> Option<(MultiAsset, MultiLocation)> {
// Reserve transfers are disabled on BH.
None
}
}

parameter_types! {
pub ExistentialDepositMultiAsset: Option<MultiAsset> = Some((
KsmRelayLocation::get(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,6 @@ pub type XcmRouter = WithUniqueTopic<(
XcmpQueue,
)>;

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub ReachableDest: Option<MultiLocation> = Some(Parent.into());
}

impl pallet_xcm::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We want to disallow users sending (arbitrary) XCMs from this chain.
Expand Down Expand Up @@ -361,8 +356,6 @@ impl pallet_xcm::Config for Runtime {
type SovereignAccountOf = LocationToAccountId;
type MaxLockers = ConstU32<8>;
type WeightInfo = crate::weights::pallet_xcm::WeightInfo<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type ReachableDest = ReachableDest;
type AdminOrigin = EnsureRoot<AccountId>;
type MaxRemoteLockConsumers = ConstU32<0>;
type RemoteLockConsumerIdentifier = ();
Expand Down
Loading

0 comments on commit 70f49b1

Please sign in to comment.