From 3b94aadfc5862a40ad3302a3e0ebf5bba8115d27 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 25 Dec 2024 13:28:27 +0800 Subject: [PATCH] Companion of paritytech/polkadot-sdk#4634 --- runtime/crab/src/lib.rs | 27 ++++--- runtime/crab/src/pallets/polkadot_xcm.rs | 1 + runtime/darwinia/src/lib.rs | 27 ++++--- runtime/darwinia/src/pallets/polkadot_xcm.rs | 1 + .../src/weights/pallet_asset_manager.rs | 76 ++----------------- runtime/koi/src/lib.rs | 27 ++++--- runtime/koi/src/pallets/polkadot_xcm.rs | 1 + runtime/koi/src/pallets/xcmp_queue.rs | 2 +- .../koi/src/weights/pallet_asset_manager.rs | 6 +- 9 files changed, 54 insertions(+), 114 deletions(-) diff --git a/runtime/crab/src/lib.rs b/runtime/crab/src/lib.rs index 8cfee1d31..d6559e23a 100644 --- a/runtime/crab/src/lib.rs +++ b/runtime/crab/src/lib.rs @@ -427,28 +427,17 @@ sp_api::impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, xcm_runtime_apis::fees::Error> { - // polkadot-sdk - use xcm::IntoVersion; - - let acceptable = vec![ - // Native token. - xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get())) - ]; + let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())]; - Ok(acceptable - .into_iter() - .filter_map(|asset| asset.into_version(xcm_version).ok()) - .collect()) + PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result { // polkadot-sdk use frame_support::weights::WeightToFee; - use xcm::IntoVersion; match asset.try_as::() { - Ok(asset_id) if asset_id.0 == SelfReserve::get() => { - // Native token. + Ok(asset_id) if asset_id.0 == RelayLocation::get() => { Ok(WeightToFee::weight_to_fee(&weight)) }, Ok(asset_id) => { @@ -473,6 +462,16 @@ sp_api::impl_runtime_apis! { } } + impl xcm_runtime_apis::dry_run::DryRunApi for Runtime { + fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_call::(origin, call) + } + + fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_xcm::(origin_location, xcm) + } + } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { <::ChainId as sp_core::Get>::get() diff --git a/runtime/crab/src/pallets/polkadot_xcm.rs b/runtime/crab/src/pallets/polkadot_xcm.rs index 22a0815a4..cdb82ea41 100644 --- a/runtime/crab/src/pallets/polkadot_xcm.rs +++ b/runtime/crab/src/pallets/polkadot_xcm.rs @@ -22,6 +22,7 @@ use crate::*; use xcm::latest::prelude::*; frame_support::parameter_types! { + pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; pub const MaxAssetsIntoHolding: u32 = 64; pub const MaxInstructions: u32 = 100; diff --git a/runtime/darwinia/src/lib.rs b/runtime/darwinia/src/lib.rs index 35844c4c9..59456e794 100644 --- a/runtime/darwinia/src/lib.rs +++ b/runtime/darwinia/src/lib.rs @@ -436,28 +436,17 @@ sp_api::impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, xcm_runtime_apis::fees::Error> { - // polkadot-sdk - use xcm::IntoVersion; - - let acceptable = vec![ - // Native token. - xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get())) - ]; + let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())]; - Ok(acceptable - .into_iter() - .filter_map(|asset| asset.into_version(xcm_version).ok()) - .collect()) + PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result { // polkadot-sdk use frame_support::weights::WeightToFee; - use xcm::IntoVersion; match asset.try_as::() { - Ok(asset_id) if asset_id.0 == SelfReserve::get() => { - // Native token. + Ok(asset_id) if asset_id.0 == RelayLocation::get() => { Ok(WeightToFee::weight_to_fee(&weight)) }, Ok(asset_id) => { @@ -482,6 +471,16 @@ sp_api::impl_runtime_apis! { } } + impl xcm_runtime_apis::dry_run::DryRunApi for Runtime { + fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_call::(origin, call) + } + + fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_xcm::(origin_location, xcm) + } + } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { <::ChainId as sp_core::Get>::get() diff --git a/runtime/darwinia/src/pallets/polkadot_xcm.rs b/runtime/darwinia/src/pallets/polkadot_xcm.rs index fe1da78de..8132334be 100644 --- a/runtime/darwinia/src/pallets/polkadot_xcm.rs +++ b/runtime/darwinia/src/pallets/polkadot_xcm.rs @@ -22,6 +22,7 @@ use crate::{AssetId, Assets, *}; use xcm::latest::prelude::*; frame_support::parameter_types! { + pub const RelayLocation: Location = Location::parent(); pub const RelayNetwork: NetworkId = NetworkId::Polkadot; pub const MaxAssetsIntoHolding: u32 = 64; pub const MaxInstructions: u32 = 100; diff --git a/runtime/darwinia/src/weights/pallet_asset_manager.rs b/runtime/darwinia/src/weights/pallet_asset_manager.rs index c3a769726..fb7baf2e4 100644 --- a/runtime/darwinia/src/weights/pallet_asset_manager.rs +++ b/runtime/darwinia/src/weights/pallet_asset_manager.rs @@ -67,32 +67,12 @@ impl pallet_asset_manager::WeightInfo for WeightInfo // Proof Size summary in bytes: // Measured: `276` // Estimated: `3741` - // Minimum execution time: 27_000_000 picoseconds. - Weight::from_parts(28_000_000, 0) + // Minimum execution time: 26_000_000 picoseconds. + Weight::from_parts(27_000_000, 0) .saturating_add(Weight::from_parts(0, 3741)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) } - /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) - /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) - /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `x` is `[5, 100]`. - fn set_asset_units_per_second(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `595 + x * (9 ±0)` - // Estimated: `3983 + x * (10 ±0)` - // Minimum execution time: 14_000_000 picoseconds. - Weight::from_parts(15_745_769, 0) - .saturating_add(Weight::from_parts(0, 3983)) - // Standard Error: 1_882 - .saturating_add(Weight::from_parts(311_730, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) - } /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `AssetManager::AssetIdType` (r:1 w:1) @@ -102,57 +82,17 @@ impl pallet_asset_manager::WeightInfo for WeightInfo /// Storage: `AssetManager::AssetTypeId` (r:0 w:2) /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `x` is `[5, 100]`. - fn change_existing_asset_type(x: u32, ) -> Weight { + fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `968 + x * (13 ±0)` // Estimated: `4303 + x * (14 ±0)` - // Minimum execution time: 23_000_000 picoseconds. - Weight::from_parts(23_950_644, 0) + // Minimum execution time: 20_000_000 picoseconds. + Weight::from_parts(23_199_447, 0) .saturating_add(Weight::from_parts(0, 4303)) - // Standard Error: 2_239 - .saturating_add(Weight::from_parts(313_174, 0).saturating_mul(x.into())) + // Standard Error: 2_109 + .saturating_add(Weight::from_parts(301_010, 0)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(6)) - .saturating_add(Weight::from_parts(0, 14).saturating_mul(x.into())) - } - /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) - /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `x` is `[5, 100]`. - fn remove_supported_asset(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `196 + x * (5 ±0)` - // Estimated: `1678 + x * (5 ±0)` - // Minimum execution time: 11_000_000 picoseconds. - Weight::from_parts(9_848_583, 0) - .saturating_add(Weight::from_parts(0, 1678)) - // Standard Error: 1_357 - .saturating_add(Weight::from_parts(271_961, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 5).saturating_mul(x.into())) - } - /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) - /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetIdType` (r:1 w:1) - /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `AssetManager::AssetTypeId` (r:0 w:1) - /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `x` is `[5, 100]`. - fn remove_existing_asset_type(x: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `486 + x * (10 ±0)` - // Estimated: `3949 + x * (10 ±0)` - // Minimum execution time: 16_000_000 picoseconds. - Weight::from_parts(17_547_073, 0) - .saturating_add(Weight::from_parts(0, 3949)) - // Standard Error: 2_092 - .saturating_add(Weight::from_parts(267_953, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(4)) - .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 14)) } } diff --git a/runtime/koi/src/lib.rs b/runtime/koi/src/lib.rs index 1a693c3a8..75232e3ad 100644 --- a/runtime/koi/src/lib.rs +++ b/runtime/koi/src/lib.rs @@ -352,28 +352,17 @@ sp_api::impl_runtime_apis! { impl xcm_runtime_apis::fees::XcmPaymentApi for Runtime { fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result, xcm_runtime_apis::fees::Error> { - // polkadot-sdk - use xcm::IntoVersion; - - let acceptable = vec![ - // Native token. - xcm::VersionedAssetId::from(xcm::latest::AssetId(SelfReserve::get())) - ]; + let acceptable_assets = vec![xcn::latest::AssetId(RelayLocation::get())]; - Ok(acceptable - .into_iter() - .filter_map(|asset| asset.into_version(xcm_version).ok()) - .collect()) + PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets) } fn query_weight_to_asset_fee(weight: frame_support::weights::Weight, asset: xcm::VersionedAssetId) -> Result { // polkadot-sdk use frame_support::weights::WeightToFee; - use xcm::IntoVersion; match asset.try_as::() { - Ok(asset_id) if asset_id.0 == SelfReserve::get() => { - // Native token. + Ok(asset_id) if asset_id.0 == RelayLocation::get() => { Ok(WeightToFee::weight_to_fee(&weight)) }, Ok(asset_id) => { @@ -398,6 +387,16 @@ sp_api::impl_runtime_apis! { } } + impl xcm_runtime_apis::dry_run::DryRunApi for Runtime { + fn dry_run_call(origin: OriginCaller, call: RuntimeCall) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_call::(origin, call) + } + + fn dry_run_xcm(origin_location: xcm::VersionedLocation, xcm: xcm::VersionedXcm) -> Result, xcm_runtime_apis::dry_run::Error> { + PolkadotXcm::dry_run_xcm::(origin_location, xcm) + } + } + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { <::ChainId as sp_core::Get>::get() diff --git a/runtime/koi/src/pallets/polkadot_xcm.rs b/runtime/koi/src/pallets/polkadot_xcm.rs index 861b941c6..82bbac043 100644 --- a/runtime/koi/src/pallets/polkadot_xcm.rs +++ b/runtime/koi/src/pallets/polkadot_xcm.rs @@ -22,6 +22,7 @@ use crate::{AssetId, Assets, *}; use xcm::latest::prelude::*; frame_support::parameter_types! { + pub const RelayLocation: Location = Location::parent(); // TODO: Paseo. pub const RelayNetwork: NetworkId = NetworkId::Rococo; pub const MaxAssetsIntoHolding: u32 = 64; diff --git a/runtime/koi/src/pallets/xcmp_queue.rs b/runtime/koi/src/pallets/xcmp_queue.rs index 7e1f51ff2..8efdd93a0 100644 --- a/runtime/koi/src/pallets/xcmp_queue.rs +++ b/runtime/koi/src/pallets/xcmp_queue.rs @@ -21,7 +21,7 @@ use crate::*; impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; - type ControllerOrigin = RootOr; + type ControllerOrigin = Root; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; type MaxActiveOutboundChannels = ConstU32<128>; type MaxInboundSuspended = sp_core::ConstU32<1_000>; diff --git a/runtime/koi/src/weights/pallet_asset_manager.rs b/runtime/koi/src/weights/pallet_asset_manager.rs index 4c8db696b..75a06dc78 100644 --- a/runtime/koi/src/weights/pallet_asset_manager.rs +++ b/runtime/koi/src/weights/pallet_asset_manager.rs @@ -82,7 +82,7 @@ impl pallet_asset_manager::WeightInfo for WeightInfo /// Storage: `AssetManager::AssetTypeId` (r:0 w:2) /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `x` is `[5, 100]`. - fn change_existing_asset_type(x: u32, ) -> Weight { + fn change_existing_asset_type() -> Weight { // Proof Size summary in bytes: // Measured: `968 + x * (13 ±0)` // Estimated: `4303 + x * (14 ±0)` @@ -90,9 +90,9 @@ impl pallet_asset_manager::WeightInfo for WeightInfo Weight::from_parts(23_199_447, 0) .saturating_add(Weight::from_parts(0, 4303)) // Standard Error: 2_109 - .saturating_add(Weight::from_parts(301_010, 0).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(301_010, 0)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(6)) - .saturating_add(Weight::from_parts(0, 14).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 14)) } }