Skip to content

Commit

Permalink
add benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Aug 31, 2023
1 parent 4340995 commit 347a958
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
27 changes: 27 additions & 0 deletions polkadot/xcm/pallet-xcm/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ benchmarks! {
Pallet::<T>::check_xcm_version_change(VersionMigrationStage::MigrateAndNotifyOldTargets, Weight::zero());
}

new_query {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
}: {
Pallet::<T>::new_query(responder, timeout, match_querier);
}

take_response {
let responder = MultiLocation::from(Parent);
let timeout = 1u32.into();
let match_querier = MultiLocation::from(Here);
let query_id = Pallet::<T>::new_query(responder, timeout, match_querier);
let infos = (0 .. xcm::v3::MaxPalletsInfo::get()).map(|_| PalletInfo::new(
1u32,
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
(0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::<Vec<_>>().try_into().unwrap(),
1u32,
0u32,
0u32,
).unwrap()).collect::<Vec<_>>();
Pallet::<T>::expect_response(query_id, Response::PalletsInfo(infos.try_into().unwrap()));

}: {
Pallet::<T>::take_response(query_id);
}

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext_with_balances(Vec::new()),
Expand Down
15 changes: 15 additions & 0 deletions polkadot/xcm/pallet-xcm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ pub trait WeightInfo {
fn notify_target_migration_fail() -> Weight;
fn migrate_version_notify_targets() -> Weight;
fn migrate_and_notify_old_targets() -> Weight;
// TODO remove after benchmark are regenerated
fn new_query() -> Weight {
Weight::zero()
}
fn take_response() -> Weight {
Weight::zero()
}
}

/// fallback implementation
Expand Down Expand Up @@ -143,6 +150,14 @@ impl WeightInfo for TestWeightInfo {
fn migrate_and_notify_old_targets() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn new_query() -> Weight {
Weight::from_parts(100_000_000, 0)
}

fn take_response() -> Weight {
Weight::from_parts(100_000_000, 0)
}
}

#[frame_support::pallet]
Expand Down
11 changes: 9 additions & 2 deletions substrate/frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2703,12 +2703,16 @@ pub mod env {
output_ptr: u32,
) -> Result<ReturnCode, TrapReason> {
use frame_system::pallet_prelude::BlockNumberFor;
use pallet_xcm::WeightInfo;
use xcm::VersionedMultiLocation;

let timeout: BlockNumberFor<E::T> = ctx.read_sandbox_memory_as(memory, timeout_ptr)?;
let match_querier: VersionedMultiLocation =
ctx.read_sandbox_memory_as(memory, match_querier_ptr)?;
// TODO benchmark

let weight = <E::T as pallet_xcm::Config>::WeightInfo::new_query();
ctx.charge_gas(RuntimeCosts::CallRuntime(weight))?;

match ctx.ext.xcm_query(timeout, match_querier) {
Ok(query_id) => {
ctx.write_sandbox_memory(memory, output_ptr, &query_id.encode())?;
Expand All @@ -2730,12 +2734,15 @@ pub mod env {
query_id_ptr: u32,
output_ptr: u32,
) -> Result<ReturnCode, TrapReason> {
use pallet_xcm::WeightInfo;
use xcm_executor::traits::QueryHandler;

let query_id: <pallet_xcm::Pallet<E::T> as QueryHandler>::QueryId =
ctx.read_sandbox_memory_as(memory, query_id_ptr)?;

// TODO benchmark
let weight = <E::T as pallet_xcm::Config>::WeightInfo::take_response();
ctx.charge_gas(RuntimeCosts::CallRuntime(weight))?;

let response = ctx.ext.xcm_take_response(query_id);
ctx.write_sandbox_memory(memory, output_ptr, &response.encode())?;
Ok(ReturnCode::Success)
Expand Down

0 comments on commit 347a958

Please sign in to comment.