Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
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.

2 changes: 2 additions & 0 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "m
pallet-utility = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-vesting = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }
pallet-xcm = { path = "../../xcm/pallet-xcm", default-features = false }
pallet-xcm-benchmarks = { path = "../../xcm/pallet-xcm-benchmarks", default-features = false, optional = true }
frame-election-provider-support = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false }

frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true }
Expand Down Expand Up @@ -220,6 +221,7 @@ runtime-benchmarks = [
"frame-election-provider-support/runtime-benchmarks",
"pallet-bags-list/runtime-benchmarks",
"runtime-parachains/runtime-benchmarks",
"pallet-xcm-benchmarks",
]
try-runtime = [
"frame-executive/try-runtime",
Expand Down
72 changes: 70 additions & 2 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,9 @@ mod benches {
[pallet_treasury, Treasury]
[pallet_utility, Utility]
[pallet_vesting, Vesting]
// XCM
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
[pallet_xcm_benchmarks::generic, pallet_xcm_benchmarks::generic::Pallet::<Runtime>]
);
}

Expand Down Expand Up @@ -1931,19 +1934,85 @@ sp_api::impl_runtime_apis! {
Vec<frame_benchmarking::BenchmarkBatch>,
sp_runtime::RuntimeString,
> {
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey};
use frame_benchmarking::{Benchmarking, BenchmarkBatch, TrackedStorageKey, BenchmarkError};
// Trying to add benchmarks directly to some pallets caused cyclic dependency issues.
// To get around that, we separated the benchmarks into its own crate.
use pallet_session_benchmarking::Pallet as SessionBench;
use pallet_offences_benchmarking::Pallet as OffencesBench;
use frame_system_benchmarking::Pallet as SystemBench;
use frame_benchmarking::baseline::Pallet as Baseline;
use xcm::latest::prelude::*;
use xcm_config::{CheckAccount, KsmLocation, SovereignAccountOf, Statemine, XcmConfig};

impl pallet_session_benchmarking::Config for Runtime {}
impl pallet_offences_benchmarking::Config for Runtime {}
impl frame_system_benchmarking::Config for Runtime {}
impl frame_benchmarking::baseline::Config for Runtime {}

impl pallet_xcm_benchmarks::Config for Runtime {
type XcmConfig = XcmConfig;
type AccountIdConverter = SovereignAccountOf;
fn valid_destination() -> Result<MultiLocation, BenchmarkError> {
Ok(Statemine::get())
}
fn worst_case_holding() -> MultiAssets {
// Kusama only knows about KSM.
vec![MultiAsset{
id: Concrete(KsmLocation::get()),
fun: Fungible(1_000_000 * UNITS),
}].into()
}
}

parameter_types! {
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
));
pub const TrustedReserve: Option<(MultiLocation, MultiAsset)> = Some((
Statemine::get(),
MultiAsset { fun: Fungible(1 * UNITS), id: Concrete(KsmLocation::get()) },
));
}

impl pallet_xcm_benchmarks::fungible::Config for Runtime {
type TransactAsset = Balances;

type CheckedAccount = CheckAccount;
type TrustedTeleporter = TrustedTeleporter;
type TrustedReserve = TrustedReserve;

fn get_multi_asset() -> MultiAsset {
MultiAsset {
id: Concrete(KsmLocation::get()),
fun: Fungible(1 * UNITS),
}
}
}

impl pallet_xcm_benchmarks::generic::Config for Runtime {
type Call = Call;

fn worst_case_response() -> (u64, Response) {
(0u64, Response::Version(Default::default()))
}

fn transact_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(Statemine::get())
}

fn subscribe_origin() -> Result<MultiLocation, BenchmarkError> {
Ok(Statemine::get())
}

fn claimable_asset() -> Result<(MultiLocation, MultiLocation, MultiAssets), BenchmarkError> {
let origin = Statemine::get();
let assets: MultiAssets = (Concrete(KsmLocation::get()), 1_000 * UNITS).into();
let ticket = MultiLocation { parents: 0, interior: Here };
Ok((origin, ticket, assets))
}
}

let whitelist: Vec<TrackedStorageKey> = vec![
// Block Number
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef702a5c1b19ab7a04f536c519aca4983ac").to_vec().into(),
Expand All @@ -1964,7 +2033,6 @@ sp_api::impl_runtime_apis! {

add_benchmarks!(params, batches);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
}
}
Expand Down
1 change: 1 addition & 0 deletions runtime/kusama/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ pub mod runtime_parachains_initializer;
pub mod runtime_parachains_paras;
pub mod runtime_parachains_paras_inherent;
pub mod runtime_parachains_ump;
pub mod xcm;
195 changes: 195 additions & 0 deletions runtime/kusama/src/weights/xcm/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
mod pallet_xcm_benchmarks_fungible;
mod pallet_xcm_benchmarks_generic;

use crate::Runtime;
use frame_support::weights::Weight;
use sp_std::prelude::*;
use xcm::{latest::prelude::*, DoubleEncoded};

use pallet_xcm_benchmarks_fungible::WeightInfo as XcmBalancesWeight;
use pallet_xcm_benchmarks_generic::WeightInfo as XcmGeneric;

/// Types of asset supported by the Kusama runtime.
pub enum AssetTypes {
/// An asset backed by `pallet-balances`.
Balances,
/// Unknown asset.
Unknown,
}

impl From<&MultiAsset> for AssetTypes {
fn from(asset: &MultiAsset) -> Self {
match asset {
MultiAsset { id: Concrete(MultiLocation { parents: 0, interior: Here }), .. } =>
AssetTypes::Balances,
_ => AssetTypes::Unknown,
}
}
}

trait WeighMultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight;
}

// Kusama only knows about one asset, the balances pallet.
const MAX_ASSETS: u32 = 1;

impl WeighMultiAssets for MultiAssetFilter {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
match self {
Self::Definite(assets) => assets
.inner()
.into_iter()
.map(From::from)
.map(|t| match t {
AssetTypes::Balances => balances_weight,
AssetTypes::Unknown => Weight::MAX,
})
.fold(0, |acc, x| acc.saturating_add(x)),
Self::Wild(_) => (MAX_ASSETS as Weight).saturating_mul(balances_weight),
}
}
}

impl WeighMultiAssets for MultiAssets {
fn weigh_multi_assets(&self, balances_weight: Weight) -> Weight {
self.inner()
.into_iter()
.map(|m| <AssetTypes as From<&MultiAsset>>::from(m))
.map(|t| match t {
AssetTypes::Balances => balances_weight,
AssetTypes::Unknown => Weight::MAX,
})
.fold(0, |acc, x| acc.saturating_add(x))
}
}

pub struct KusamaXcmWeight<Call>(core::marker::PhantomData<Call>);
impl<Call> XcmWeightInfo<Call> for KusamaXcmWeight<Call> {
fn withdraw_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::withdraw_asset())
}
fn reserve_asset_deposited(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::reserve_asset_deposited())
}
fn receive_teleported_asset(assets: &MultiAssets) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::receive_teleported_asset())
}
fn query_response(_query_id: &u64, _response: &Response, _max_weight: &u64) -> Weight {
XcmGeneric::<Runtime>::query_response()
}
fn transfer_asset(assets: &MultiAssets, _dest: &MultiLocation) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_asset())
}
fn transfer_reserve_asset(
assets: &MultiAssets,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::transfer_reserve_asset())
}
fn transact(
_origin_type: &OriginKind,
_require_weight_at_most: &u64,
_call: &DoubleEncoded<Call>,
) -> Weight {
XcmGeneric::<Runtime>::transact()
}
fn hrmp_new_channel_open_request(
_sender: &u32,
_max_message_size: &u32,
_max_capacity: &u32,
) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn hrmp_channel_accepted(_recipient: &u32) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn hrmp_channel_closing(_initiator: &u32, _sender: &u32, _recipient: &u32) -> Weight {
// XCM Executor does not currently support HRMP channel operations
Weight::MAX
}
fn clear_origin() -> Weight {
XcmGeneric::<Runtime>::clear_origin()
}
fn descend_origin(_who: &InteriorMultiLocation) -> Weight {
XcmGeneric::<Runtime>::descend_origin()
}
fn report_error(
_query_id: &QueryId,
_dest: &MultiLocation,
_max_response_weight: &u64,
) -> Weight {
XcmGeneric::<Runtime>::report_error()
}

fn deposit_asset(
assets: &MultiAssetFilter,
_max_assets: &u32, // TODO use max assets?
_dest: &MultiLocation,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_asset())
}
fn deposit_reserve_asset(
assets: &MultiAssetFilter,
_max_assets: &u32, // TODO use max assets?
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::deposit_reserve_asset())
}
fn exchange_asset(_give: &MultiAssetFilter, _receive: &MultiAssets) -> Weight {
Weight::MAX // todo fix
}
fn initiate_reserve_withdraw(
assets: &MultiAssetFilter,
_reserve: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmGeneric::<Runtime>::initiate_reserve_withdraw())
}
fn initiate_teleport(
assets: &MultiAssetFilter,
_dest: &MultiLocation,
_xcm: &Xcm<()>,
) -> Weight {
assets.weigh_multi_assets(XcmBalancesWeight::<Runtime>::initiate_teleport())
}
fn query_holding(
_query_id: &u64,
_dest: &MultiLocation,
_assets: &MultiAssetFilter,
_max_response_weight: &u64,
) -> Weight {
XcmGeneric::<Runtime>::query_holding()
}
fn buy_execution(_fees: &MultiAsset, _weight_limit: &WeightLimit) -> Weight {
XcmGeneric::<Runtime>::buy_execution()
}
fn refund_surplus() -> Weight {
XcmGeneric::<Runtime>::refund_surplus()
}
fn set_error_handler(_xcm: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::set_error_handler()
}
fn set_appendix(_xcm: &Xcm<Call>) -> Weight {
XcmGeneric::<Runtime>::set_appendix()
}
fn clear_error() -> Weight {
XcmGeneric::<Runtime>::clear_error()
}
fn claim_asset(_assets: &MultiAssets, _ticket: &MultiLocation) -> Weight {
XcmGeneric::<Runtime>::claim_asset()
}
fn trap(_code: &u64) -> Weight {
XcmGeneric::<Runtime>::trap()
}
fn subscribe_version(_query_id: &QueryId, _max_response_weight: &u64) -> Weight {
XcmGeneric::<Runtime>::subscribe_version()
}
fn unsubscribe_version() -> Weight {
XcmGeneric::<Runtime>::unsubscribe_version()
}
}
Loading