Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix XCM Teleport Benchmark (backport) #4148

Merged
merged 2 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 1 addition & 3 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ use authority_discovery_primitives::AuthorityId as AuthorityDiscoveryId;
use beefy_primitives::crypto::AuthorityId as BeefyId;
use frame_support::{
construct_runtime, parameter_types,
traits::{
Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing,
},
traits::{Contains, Everything, InstanceFilter, KeyOwnerProofSystem, LockIdentifier, Nothing},
weights::Weight,
PalletId, RuntimeDebug,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ impl<T: frame_system::Config> WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(4 as Weight))
}
// Storage: Benchmark Override (r:0 w:0)
// Storage: System Account (r:1 w:1)
pub(crate) fn receive_teleported_asset() -> Weight {
(2_000_000_000_000 as Weight)
(38_670_000 as Weight)
.saturating_add(T::DbWeight::get().reads(1 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
// Storage: System Account (r:1 w:1)
pub(crate) fn deposit_asset() -> Weight {
Expand Down
25 changes: 18 additions & 7 deletions xcm/pallet-xcm-benchmarks/src/fungible/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
use super::*;
use crate::{account_and_location, new_executor, worst_case_holding, AssetTransactorOf, XcmCallOf};
use frame_benchmarking::{benchmarks_instance_pallet, BenchmarkError, BenchmarkResult};
use frame_support::{pallet_prelude::Get, traits::fungible::Inspect};
use sp_runtime::traits::Zero;
use frame_support::{
pallet_prelude::Get,
traits::fungible::{Inspect, Mutate},
};
use sp_runtime::traits::{Bounded, Zero};
use sp_std::{convert::TryInto, prelude::*, vec};
use xcm::latest::prelude::*;
use xcm_executor::traits::{Convert, TransactAsset};
Expand Down Expand Up @@ -106,11 +109,19 @@ benchmarks_instance_pallet! {

receive_teleported_asset {
// If there is no trusted teleporter, then we skip this benchmark.
let (trusted_teleporter, teleportable_asset) = T::TrustedTeleporter::get().ok_or(
BenchmarkError::Override(
BenchmarkResult::from_weight(T::BlockWeights::get().max_block)
)
)?;
let (trusted_teleporter, teleportable_asset) = T::TrustedTeleporter::get()
.ok_or(BenchmarkError::Skip)?;

if let Some(checked_account) = T::CheckedAccount::get() {
T::TransactAsset::mint_into(
&checked_account,
<
T::TransactAsset
as
Inspect<T::AccountId>
>::Balance::max_value() / 2u32.into(),
)?;
}

let assets: MultiAssets = vec![ teleportable_asset ].into();

Expand Down
9 changes: 7 additions & 2 deletions xcm/pallet-xcm-benchmarks/src/fungible/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl xcm_executor::Config for XcmConfig {
type AssetTransactor = AssetTransactor;
type OriginConverter = ();
type IsReserve = ();
type IsTeleporter = ();
type IsTeleporter = TrustedTeleporters;
type LocationInverter = xcm_builder::LocationInverter<Ancestry>;
type Barrier = AllowUnpaidExecutionFrom<Everything>;
type Weigher = xcm_builder::FixedWeightBounds<UnitWeightCost, Call, MaxInstructions>;
Expand All @@ -153,12 +153,17 @@ impl crate::Config for Test {
}
}

pub type TrustedTeleporters = (xcm_builder::Case<TeleConcreteFung>,);

parameter_types! {
pub const CheckedAccount: Option<u64> = Some(100);
pub const ChildTeleporter: MultiLocation = Parachain(1000).into();
pub const TrustedTeleporter: Option<(MultiLocation, MultiAsset)> = Some((
X1(OnlyChild).into(),
ChildTeleporter::get(),
MultiAsset { id: Concrete(Here.into()), fun: Fungible(100) },
));
pub const TeleConcreteFung: (MultiAssetFilter, MultiLocation) =
(Wild(AllOf { fun: WildFungible, id: Concrete(Here.into()) }), ChildTeleporter::get());
}

impl xcm_balances_benchmark::Config for Test {
Expand Down