Skip to content

Commit

Permalink
Fix: benchmarking for pallet-data-preservers and pallet-registrar on …
Browse files Browse the repository at this point in the history
…Dancelight (#783)

* chore: added dancelight to dev-benchmark-pallet.sh script

* feat: added pallet_data_preservers to dancelight's benchmarks runtime config

* fix: disable InnerRegistrar for benchmarking so all pallet_data_preservers benchmarks work

* feat: added weights for pallet_data_preservers on Dancelight

* feat: using weights::runtime_common_paras_registrar for InnerDancelightRegistrar

* chore: added tmp folder and raw.json to .gitignore

* feat: added benchmark helper for pallet_data_preservers

* feat: added initial implementation of benchmark helper for pallet_data_preservers

* feat: added reserving of para_id to DataPreserversBenchmarkHelper

* fix: pallet_data_preservers benchmarking for Dancelight works correctly

* style: fixed formatting

* chore: moved DataPreserversBenchmarkHelper-related imports inside the implementation

* refactor: moved reserving ParaId for benchmarking to InnerDancelightRegistrar and removed DataPreserversBenchmarkHelper

* chore: updated dev-benchmark-pallet.sh output folders

* chore: removed unused imports

* fix: cargo-clippy errors

* fix: fixed pallet-registrar benchmarking for Dancelight

* chore: remove unused ArgumentFactory

* chore: removed unused imports

---------

Co-authored-by: Aleksandar Brayanov <[email protected]>
  • Loading branch information
chexware and Aleksandar Brayanov authored Jan 8, 2025
1 parent 9530640 commit c76b692
Show file tree
Hide file tree
Showing 9 changed files with 338 additions and 53 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
# Spec/Wasm build directory
/build/


# RustRover - related
**/.idea
**/.idea

# Temporary files
**/tmp
raw.json
24 changes: 19 additions & 5 deletions chains/orchestrator-relays/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,7 @@ impl pallet_data_preservers::AssignmentPayment<AccountId> for PreserversAssignme
type ProviderRequest = PreserversAssignmentPaymentRequest;
/// Extra parameter the assigner provides.
type AssignerParameter = PreserversAssignmentPaymentExtra;
/// Represents the succesful outcome of the assignment.
/// Represents the successful outcome of the assignment.
type AssignmentWitness = PreserversAssignmentPaymentWitness;

fn try_start_assignment(
Expand Down Expand Up @@ -1641,7 +1641,7 @@ impl pallet_data_preservers::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
type Currency = Balances;
type WeightInfo = ();
type WeightInfo = weights::pallet_data_preservers::SubstrateWeight<Runtime>;

type ProfileId = u64;
type ProfileDeposit = tp_traits::BytesDeposit<ProfileDepositBaseFee, ProfileDepositByteFee>;
Expand Down Expand Up @@ -1975,7 +1975,7 @@ impl<Runtime, AccountId, RegistrarManager, RegistrarWeightInfo> RegistrarHandler
where
RegistrarManager: RegistrarInterface<AccountId = AccountId>,
RegistrarWeightInfo: paras_registrar::WeightInfo,
Runtime: pallet_registrar::Config,
Runtime: pallet_registrar::Config + paras_registrar::Config,
sp_runtime::AccountId32: From<AccountId>,
{
fn register(
Expand Down Expand Up @@ -2055,6 +2055,13 @@ where
fn registrar_new_session(session: u32) {
benchmark_helpers::run_to_session(session)
}
#[cfg(feature = "runtime-benchmarks")]
fn prepare_chain_registration(id: ParaId, who: AccountId) {
use frame_support::assert_ok;
paras_registrar::NextFreeParaId::<Runtime>::put(id);
assert_eq!(paras_registrar::NextFreeParaId::<Runtime>::get(), id);
assert_ok!(Registrar::reserve(RuntimeOrigin::signed(who.into())));
}
}

impl pallet_registrar::Config for Runtime {
Expand All @@ -2072,8 +2079,13 @@ impl pallet_registrar::Config for Runtime {
type DepositAmount = DepositAmount;
type RegistrarHooks = DancelightRegistrarHooks;
type RuntimeHoldReason = RuntimeHoldReason;
type InnerRegistrar =
InnerDancelightRegistrar<Runtime, AccountId, Registrar, paras_registrar::TestWeightInfo>;

type InnerRegistrar = InnerDancelightRegistrar<
Runtime,
AccountId,
Registrar,
weights::runtime_common_paras_registrar::SubstrateWeight<Runtime>,
>;
type WeightInfo = weights::pallet_registrar::SubstrateWeight<Runtime>;
}

Expand Down Expand Up @@ -2225,7 +2237,9 @@ mod benches {
[pallet_external_validators_rewards, ExternalValidatorsRewards]
[pallet_external_validator_slashes, ExternalValidatorSlashes]
[pallet_invulnerables, TanssiInvulnerables]
[pallet_data_preservers, DataPreservers]
[pallet_pooled_staking, PooledStaking]

// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod pallet_author_noting;
pub mod pallet_balances;
pub mod pallet_collator_assignment;
pub mod pallet_conviction_voting;
pub mod pallet_data_preservers;
pub mod pallet_external_validator_slashes;
pub mod pallet_external_validators;
pub mod pallet_external_validators_rewards;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
// Copyright (C) Moondance Labs Ltd.
// This file is part of Tanssi.

// Tanssi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Tanssi is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Tanssi. If not, see <http://www.gnu.org/licenses/>


//! Autogenerated weights for pallet_data_preservers
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0
//! DATE: 2025-01-06, STEPS: `16`, REPEAT: `1`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `192.168.1.114`, CPU: `<UNKNOWN>`
//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dancelight-dev"), DB CACHE: 1024
// Executed Command:
// target/release/tanssi-relay
// benchmark
// pallet
// --execution=wasm
// --wasm-execution=compiled
// --pallet
// pallet_data_preservers
// --extrinsic
// *
// --chain=dancelight-dev
// --steps
// 16
// --repeat
// 1
// --template=benchmarking/frame-weight-runtime-template.hbs
// --json-file
// raw.json
// --output
// tmp/dancelight_weights/pallet_data_preservers.rs

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;

/// Weights for pallet_data_preservers using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_data_preservers::WeightInfo for SubstrateWeight<T> {
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::NextProfileId` (r:1 w:1)
/// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 200]`.
/// The range of component `y` is `[1, 10]`.
fn create_profile(x: u32, y: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `216`
// Estimated: `4151`
// Minimum execution time: 35_000_000 picoseconds.
Weight::from_parts(36_514_351, 4151)
// Standard Error: 27_613
.saturating_add(Weight::from_parts(10_213, 0).saturating_mul(x.into()))
// Standard Error: 582_475
.saturating_add(Weight::from_parts(295_482, 0).saturating_mul(y.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(4_u64))
}
/// Storage: `DataPreservers::NextProfileId` (r:1 w:1)
/// Proof: `DataPreservers::NextProfileId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 200]`.
/// The range of component `y` is `[1, 10]`.
fn force_create_profile(x: u32, y: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `76`
// Estimated: `4151`
// Minimum execution time: 8_000_000 picoseconds.
Weight::from_parts(8_354_610, 4151)
// Standard Error: 2_602
.saturating_add(Weight::from_parts(202, 0).saturating_mul(x.into()))
// Standard Error: 54_890
.saturating_add(Weight::from_parts(44_132, 0).saturating_mul(y.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 200]`.
/// The range of component `y` is `[1, 10]`.
fn update_profile(x: u32, y: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `423`
// Estimated: `4151`
// Minimum execution time: 37_000_000 picoseconds.
Weight::from_parts(36_611_720, 4151)
// Standard Error: 4_570
.saturating_add(Weight::from_parts(4_865, 0).saturating_mul(x.into()))
// Standard Error: 96_417
.saturating_add(Weight::from_parts(215_140, 0).saturating_mul(y.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 200]`.
/// The range of component `y` is `[1, 10]`.
fn force_update_profile(x: u32, _y: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `423`
// Estimated: `4151`
// Minimum execution time: 31_000_000 picoseconds.
Weight::from_parts(36_034_836, 4151)
// Standard Error: 18_909
.saturating_add(Weight::from_parts(1_191, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
fn delete_profile() -> Weight {
// Proof Size summary in bytes:
// Measured: `423`
// Estimated: `4151`
// Minimum execution time: 31_000_000 picoseconds.
Weight::from_parts(31_000_000, 4151)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:1 w:1)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(121), added: 2596, mode: `MaxEncodedLen`)
fn force_delete_profile() -> Weight {
// Proof Size summary in bytes:
// Measured: `423`
// Estimated: `4151`
// Minimum execution time: 31_000_000 picoseconds.
Weight::from_parts(31_000_000, 4151)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(3_u64))
}
/// Storage: `ContainerRegistrar::ParaManager` (r:1 w:0)
/// Proof: `ContainerRegistrar::ParaManager` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Assignments` (r:1 w:1)
/// Proof: `DataPreservers::Assignments` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`)
fn start_assignment() -> Weight {
// Proof Size summary in bytes:
// Measured: `511`
// Estimated: `4151`
// Minimum execution time: 16_000_000 picoseconds.
Weight::from_parts(16_000_000, 4151)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `ContainerRegistrar::ParaManager` (r:1 w:0)
/// Proof: `ContainerRegistrar::ParaManager` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Assignments` (r:1 w:1)
/// Proof: `DataPreservers::Assignments` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`)
fn stop_assignment() -> Weight {
// Proof Size summary in bytes:
// Measured: `568`
// Estimated: `4151`
// Minimum execution time: 18_000_000 picoseconds.
Weight::from_parts(18_000_000, 4151)
.saturating_add(T::DbWeight::get().reads(3_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
/// Storage: `DataPreservers::Profiles` (r:1 w:1)
/// Proof: `DataPreservers::Profiles` (`max_values`: None, `max_size`: Some(686), added: 3161, mode: `MaxEncodedLen`)
/// Storage: `DataPreservers::Assignments` (r:1 w:1)
/// Proof: `DataPreservers::Assignments` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`)
fn force_start_assignment() -> Weight {
// Proof Size summary in bytes:
// Measured: `224`
// Estimated: `4151`
// Minimum execution time: 12_000_000 picoseconds.
Weight::from_parts(12_000_000, 4151)
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(2_u64))
}
}
12 changes: 10 additions & 2 deletions pallets/data-preservers/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,11 @@ mod benchmarks {
#[benchmark]
fn start_assignment() {
let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap();
let para_id = ParaId::from(42);
// !!! (Applicable for Dancelight only)
// The specified ParaId needs to be larger than LOWEST_PUBLIC_ID value in Polkadot SDK.
// Currently, this value is 2000. We should also avoid setting the value to one of
// the container chains reserved by root
let para_id = ParaId::from(2042);

let profile = Profile {
url,
Expand Down Expand Up @@ -352,7 +356,11 @@ mod benchmarks {
#[benchmark]
fn stop_assignment() {
let url = BoundedVec::try_from(vec![b'A'; 10]).unwrap();
let para_id = ParaId::from(42);
// !!! (Applicable for Dancelight only)
// The specified ParaId needs to be larger than LOWEST_PUBLIC_ID value in Polkadot SDK.
// Currently, this value is 2000. We should also avoid setting the value to one of
// the container chains reserved by root
let para_id = ParaId::from(2042);

let profile = Profile {
url,
Expand Down
Loading

0 comments on commit c76b692

Please sign in to comment.