From bf668392842dea50b388a94e3d785853c6b5612e Mon Sep 17 00:00:00 2001 From: pgherveou Date: Thu, 31 Aug 2023 11:52:07 +0200 Subject: [PATCH] add benchmarks --- polkadot/xcm/pallet-xcm/src/benchmarking.rs | 27 +++++++++++++++++++ polkadot/xcm/pallet-xcm/src/lib.rs | 15 +++++++++++ substrate/frame/contracts/src/wasm/runtime.rs | 11 ++++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/polkadot/xcm/pallet-xcm/src/benchmarking.rs b/polkadot/xcm/pallet-xcm/src/benchmarking.rs index aca4bd1fb3fa..e1a9835ce667 100644 --- a/polkadot/xcm/pallet-xcm/src/benchmarking.rs +++ b/polkadot/xcm/pallet-xcm/src/benchmarking.rs @@ -190,6 +190,33 @@ benchmarks! { Pallet::::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::::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::::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::>().try_into().unwrap(), + (0..xcm::v3::MaxPalletNameLen::get()).map(|_| 97u8).collect::>().try_into().unwrap(), + 1u32, + 0u32, + 0u32, + ).unwrap()).collect::>(); + Pallet::::expect_response(query_id, Response::PalletsInfo(infos.try_into().unwrap())); + + }: { + Pallet::::take_response(query_id); + } + impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext_with_balances(Vec::new()), diff --git a/polkadot/xcm/pallet-xcm/src/lib.rs b/polkadot/xcm/pallet-xcm/src/lib.rs index 9dfb63c2c9c6..b08ec0032e57 100644 --- a/polkadot/xcm/pallet-xcm/src/lib.rs +++ b/polkadot/xcm/pallet-xcm/src/lib.rs @@ -73,6 +73,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 @@ -141,6 +148,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] diff --git a/substrate/frame/contracts/src/wasm/runtime.rs b/substrate/frame/contracts/src/wasm/runtime.rs index 1a5a4bdf0495..37dee861979a 100644 --- a/substrate/frame/contracts/src/wasm/runtime.rs +++ b/substrate/frame/contracts/src/wasm/runtime.rs @@ -2703,12 +2703,16 @@ pub mod env { output_ptr: u32, ) -> Result { use frame_system::pallet_prelude::BlockNumberFor; + use pallet_xcm::WeightInfo; use xcm::VersionedMultiLocation; let timeout: BlockNumberFor = 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 = ::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())?; @@ -2730,12 +2734,15 @@ pub mod env { query_id_ptr: u32, output_ptr: u32, ) -> Result { + use pallet_xcm::WeightInfo; use xcm_executor::traits::QueryHandler; let query_id: as QueryHandler>::QueryId = ctx.read_sandbox_memory_as(memory, query_id_ptr)?; - // TODO benchmark + let weight = ::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)