diff --git a/.gitignore b/.gitignore index 92d9fef54..748bf2f0f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ # Spec/Wasm build directory /build/ - # RustRover - related -**/.idea \ No newline at end of file +**/.idea + +# Temporary files +**/tmp +raw.json \ No newline at end of file diff --git a/chains/orchestrator-relays/runtime/dancelight/src/lib.rs b/chains/orchestrator-relays/runtime/dancelight/src/lib.rs index 805c15f90..ac27ba7eb 100644 --- a/chains/orchestrator-relays/runtime/dancelight/src/lib.rs +++ b/chains/orchestrator-relays/runtime/dancelight/src/lib.rs @@ -1577,7 +1577,7 @@ impl pallet_data_preservers::AssignmentPayment 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( @@ -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; type ProfileId = u64; type ProfileDeposit = tp_traits::BytesDeposit; @@ -1975,7 +1975,7 @@ impl RegistrarHandler where RegistrarManager: RegistrarInterface, RegistrarWeightInfo: paras_registrar::WeightInfo, - Runtime: pallet_registrar::Config, + Runtime: pallet_registrar::Config + paras_registrar::Config, sp_runtime::AccountId32: From, { fn register( @@ -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::::put(id); + assert_eq!(paras_registrar::NextFreeParaId::::get(), id); + assert_ok!(Registrar::reserve(RuntimeOrigin::signed(who.into()))); + } } impl pallet_registrar::Config for Runtime { @@ -2072,8 +2079,13 @@ impl pallet_registrar::Config for Runtime { type DepositAmount = DepositAmount; type RegistrarHooks = DancelightRegistrarHooks; type RuntimeHoldReason = RuntimeHoldReason; - type InnerRegistrar = - InnerDancelightRegistrar; + + type InnerRegistrar = InnerDancelightRegistrar< + Runtime, + AccountId, + Registrar, + weights::runtime_common_paras_registrar::SubstrateWeight, + >; type WeightInfo = weights::pallet_registrar::SubstrateWeight; } @@ -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::] [pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::] diff --git a/chains/orchestrator-relays/runtime/dancelight/src/weights/mod.rs b/chains/orchestrator-relays/runtime/dancelight/src/weights/mod.rs index 46cb008b3..7cf05dadf 100644 --- a/chains/orchestrator-relays/runtime/dancelight/src/weights/mod.rs +++ b/chains/orchestrator-relays/runtime/dancelight/src/weights/mod.rs @@ -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; diff --git a/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_data_preservers.rs b/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_data_preservers.rs new file mode 100644 index 000000000..53aeaf149 --- /dev/null +++ b/chains/orchestrator-relays/runtime/dancelight/src/weights/pallet_data_preservers.rs @@ -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 + + +//! 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: `` +//! 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(PhantomData); +impl pallet_data_preservers::WeightInfo for SubstrateWeight { + /// 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)) + } +} \ No newline at end of file diff --git a/pallets/data-preservers/src/benchmarks.rs b/pallets/data-preservers/src/benchmarks.rs index 95560050f..b83dc0aab 100644 --- a/pallets/data-preservers/src/benchmarks.rs +++ b/pallets/data-preservers/src/benchmarks.rs @@ -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, @@ -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, diff --git a/pallets/registrar/src/benchmarks.rs b/pallets/registrar/src/benchmarks.rs index 918e377a1..7840e0c1d 100644 --- a/pallets/registrar/src/benchmarks.rs +++ b/pallets/registrar/src/benchmarks.rs @@ -37,6 +37,12 @@ use { tp_traits::{ParaId, RegistrarHandler, RelayStorageRootProvider, SlotFrequency}, }; +// !!! (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 +const BASE_PARA_ID: u32 = 2010; + /// Create a funded user. /// Used for generating the necessary amount for registering fn create_funded_user( @@ -144,17 +150,21 @@ mod benchmarks { let (caller, _deposit_amount) = create_funded_user::("caller", 0, T::DepositAmount::get()); + let para_id = ParaId::from(BASE_PARA_ID); + + T::InnerRegistrar::prepare_chain_registration(para_id, caller.clone()); + #[extrinsic_call] Pallet::::register( RawOrigin::Signed(caller), - Default::default(), + para_id, storage, T::InnerRegistrar::bench_head_data(), ); // verification code assert_eq!(pending_verification_len::(), 1usize); - assert!(Pallet::::registrar_deposit(ParaId::default()).is_some()); + assert!(Pallet::::registrar_deposit(para_id).is_some()); } #[benchmark] @@ -216,9 +226,11 @@ mod benchmarks { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + let current_para_id = ParaId::from(2010 + i); + T::InnerRegistrar::prepare_chain_registration(current_para_id, caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), - i.into(), + current_para_id, storage.clone(), T::InnerRegistrar::bench_head_data(), ) @@ -228,14 +240,14 @@ mod benchmarks { // We should have registered y assert_eq!(pending_verification_len::(), y as usize); - assert!(Pallet::::registrar_deposit(ParaId::from(y - 1)).is_some()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID + y - 1)).is_some()); #[extrinsic_call] - Pallet::::deregister(RawOrigin::Root, (y - 1).into()); + Pallet::::deregister(RawOrigin::Root, (BASE_PARA_ID + y - 1).into()); // We should have y-1 assert_eq!(pending_verification_len::(), (y - 1) as usize); - assert!(Pallet::::registrar_deposit(ParaId::from(y - 1)).is_none()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID + y - 1)).is_none()); } #[benchmark] @@ -250,10 +262,11 @@ mod benchmarks { Pallet::::deregister(RawOrigin::Root.into(), para_id).unwrap(); } - for i in 0..y { + for i in BASE_PARA_ID..(BASE_PARA_ID + y) { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(i.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -269,9 +282,10 @@ mod benchmarks { T::InnerRegistrar::registrar_new_session(2); T::InnerRegistrar::registrar_new_session(3); - for i in 0..y { + for i in BASE_PARA_ID..(BASE_PARA_ID + y) { // Call mark_valid_for_collating to ensure that the deregister call // does not execute the cleanup hooks immediately + Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), i.into()).unwrap(); } @@ -279,17 +293,17 @@ mod benchmarks { Pallet::::initializer_on_new_session(&(T::SessionDelay::get() + 3u32.into())); // We should have registered y assert_eq!(Pallet::::registered_para_ids().len(), y as usize); - assert!(Pallet::::registrar_deposit(ParaId::from(y - 1)).is_some()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID + y - 1)).is_some()); #[extrinsic_call] - Pallet::::deregister(RawOrigin::Root, (y - 1).into()); + Pallet::::deregister(RawOrigin::Root, (BASE_PARA_ID + y - 1).into()); // We now have y - 1 but the deposit has not been removed yet assert_eq!( Pallet::::pending_registered_para_ids()[0].1.len(), (y - 1) as usize ); - assert!(Pallet::::registrar_deposit(ParaId::from(y - 1)).is_some()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID + y - 1)).is_some()); // Start a new session Pallet::::initializer_on_new_session( @@ -298,7 +312,7 @@ mod benchmarks { // Now it has been removed assert_eq!(Pallet::::registered_para_ids().len(), (y - 1) as usize); - assert!(Pallet::::registrar_deposit(ParaId::from(y - 1)).is_none()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID + y - 1)).is_none()); } #[benchmark] @@ -314,6 +328,7 @@ mod benchmarks { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + Pallet::::register( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -433,7 +448,7 @@ mod benchmarks { #[benchmark] fn mark_valid_for_collating() { let x = T::MaxGenesisDataSize::get(); - let y = T::MaxLengthParaIds::get(); + let y = T::MaxLengthParaIds::get() + BASE_PARA_ID; let storage = max_size_genesis_data(1, x); let code = get_code(&storage); @@ -444,10 +459,13 @@ mod benchmarks { // Worst case: when RegisteredParaIds and PendingVerification are both full // First loop to fill PendingVerification to its maximum - for i in 0..y { + for i in BASE_PARA_ID..y { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + + T::InnerRegistrar::prepare_chain_registration(i.into(), caller.clone()); + Pallet::::register( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -458,10 +476,11 @@ mod benchmarks { } // Second loop to fill RegisteredParaIds to its maximum, minus 1 space for the benchmark call - for k in 1000..(1000 + y - 1) { + for k in (BASE_PARA_ID + 1000)..(1000 + y - 1) { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", k, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(k.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), k.into(), @@ -477,7 +496,7 @@ mod benchmarks { T::InnerRegistrar::registrar_new_session(2); T::InnerRegistrar::registrar_new_session(3); - for k in 1000..(1000 + y - 1) { + for k in (BASE_PARA_ID + 1000)..(1000 + y - 1) { // Call mark_valid_for_collating to ensure that the deregister call // does not execute the cleanup hooks immediately Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), k.into()).unwrap(); @@ -487,20 +506,23 @@ mod benchmarks { Pallet::::initializer_on_new_session(&(T::SessionDelay::get() + 3u32.into())); // We should have registered y - assert_eq!(pending_verification_len::(), y as usize); + assert_eq!(pending_verification_len::(), (y - BASE_PARA_ID) as usize); T::RegistrarHooks::benchmarks_ensure_valid_for_collating((y - 1).into()); #[extrinsic_call] Pallet::::mark_valid_for_collating(RawOrigin::Root, (y - 1).into()); // We should have y-1 - assert_eq!(pending_verification_len::(), (y - 1) as usize); + assert_eq!( + pending_verification_len::(), + (y - BASE_PARA_ID - 1) as usize + ); } #[benchmark] fn pause_container_chain() { let x = T::MaxGenesisDataSize::get(); - let y = T::MaxLengthParaIds::get(); + let y = T::MaxLengthParaIds::get() + BASE_PARA_ID; let storage = max_size_genesis_data(1, x); let code = get_code(&storage); // Deregister all the existing chains to avoid conflicts with the new ones @@ -510,9 +532,10 @@ mod benchmarks { // Worst case: when RegisteredParaIds and Paused are both full // Second loop to fill Paused to its maximum, minus 1 space for the benchmark call - for k in 1000..(1000 + y - 1) { + for k in (BASE_PARA_ID + 1000)..(1000 + y - 1) { let (caller, _deposit_amount) = create_funded_user::("caller", k, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(k.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), k.into(), @@ -525,10 +548,11 @@ mod benchmarks { } // First loop to fill RegisteredParaIds to its maximum - for i in 0..y { + for i in BASE_PARA_ID..y { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(i.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -544,16 +568,19 @@ mod benchmarks { T::InnerRegistrar::registrar_new_session(2); T::InnerRegistrar::registrar_new_session(3); - for k in 1000..(1000 + y - 1) { + for k in (BASE_PARA_ID + 1000)..(1000 + y - 1) { Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), k.into()).unwrap(); Pallet::::pause_container_chain(RawOrigin::Root.into(), k.into()).unwrap(); } - for i in 0..y { + for i in BASE_PARA_ID..y { Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), i.into()).unwrap(); } // Check PendingPaused has a length of y - 1 - assert_eq!(Pallet::::pending_paused()[0].1.len(), y as usize - 1); + assert_eq!( + Pallet::::pending_paused()[0].1.len(), + (y - BASE_PARA_ID) as usize - 1 + ); // Check y-1 is not in PendingPaused assert!(!Pallet::::pending_paused()[0] .1 @@ -578,7 +605,7 @@ mod benchmarks { #[benchmark] fn unpause_container_chain() { let x = T::MaxGenesisDataSize::get(); - let y = T::MaxLengthParaIds::get(); + let y = T::MaxLengthParaIds::get() + BASE_PARA_ID; let storage = max_size_genesis_data(1, x); let code = get_code(&storage); // Deregister all the existing chains to avoid conflicts with the new ones @@ -588,9 +615,10 @@ mod benchmarks { // Worst case: when RegisteredParaIds and Paused are both full // Second loop to fill Paused to its maximum - for k in 1000..(1000 + y) { + for k in (BASE_PARA_ID + 1000)..(1000 + y) { let (caller, _deposit_amount) = create_funded_user::("caller", k, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(k.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), k.into(), @@ -603,10 +631,11 @@ mod benchmarks { } // First loop to fill RegisteredParaIds to its maximum, minus 1 space for the benchmark call - for i in 0..(y - 1) { + for i in BASE_PARA_ID..(y - 1) { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(i.into(), caller.clone()); Pallet::::register( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -622,35 +651,38 @@ mod benchmarks { T::InnerRegistrar::registrar_new_session(2); T::InnerRegistrar::registrar_new_session(3); - for k in 1000..(1000 + y) { + for k in (BASE_PARA_ID + 1000)..(1000 + y) { Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), k.into()).unwrap(); Pallet::::pause_container_chain(RawOrigin::Root.into(), k.into()).unwrap(); } - for i in 0..(y - 1) { + for i in BASE_PARA_ID..(y - 1) { Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), i.into()).unwrap(); } // Check PendingPaused has a length of y - assert_eq!(Pallet::::pending_paused()[0].1.len(), y as usize); + assert_eq!( + Pallet::::pending_paused()[0].1.len(), + (y - BASE_PARA_ID) as usize + ); // Check 1000 is in PendingPaused assert!(Pallet::::pending_paused()[0] .1 - .contains(&ParaId::from(1000))); + .contains(&ParaId::from(1000 + BASE_PARA_ID))); // Check 1000 is not in pending_registered_para_ids assert!(!Pallet::::pending_registered_para_ids()[0] .1 - .contains(&ParaId::from(1000))); + .contains(&ParaId::from(1000 + BASE_PARA_ID))); #[extrinsic_call] - Pallet::::unpause_container_chain(RawOrigin::Root, 1000u32.into()); + Pallet::::unpause_container_chain(RawOrigin::Root, (1000 + BASE_PARA_ID).into()); // Start a new session Pallet::::initializer_on_new_session(&(T::SessionDelay::get() + 3u32.into())); // Check 1000 is not in Paused - assert!(!Pallet::::paused().contains(&ParaId::from(1000))); + assert!(!Pallet::::paused().contains(&ParaId::from(1000 + BASE_PARA_ID))); // Check 1000 is in registered_para_ids - assert!(Pallet::::registered_para_ids().contains(&ParaId::from(1000))); + assert!(Pallet::::registered_para_ids().contains(&ParaId::from(1000 + BASE_PARA_ID))); } #[benchmark] @@ -661,10 +693,12 @@ mod benchmarks { let (caller, _deposit_amount) = create_funded_user::("caller", 0, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(BASE_PARA_ID.into(), caller.clone()); + #[extrinsic_call] Pallet::::register_parathread( RawOrigin::Signed(caller), - Default::default(), + BASE_PARA_ID.into(), slot_frequency, storage, T::InnerRegistrar::bench_head_data(), @@ -672,13 +706,13 @@ mod benchmarks { // verification code assert_eq!(pending_verification_len::(), 1usize); - assert!(Pallet::::registrar_deposit(ParaId::default()).is_some()); + assert!(Pallet::::registrar_deposit(ParaId::from(BASE_PARA_ID)).is_some()); } #[benchmark] fn set_parathread_params() { let x = T::MaxGenesisDataSize::get(); - let y = T::MaxLengthParaIds::get(); + let y = T::MaxLengthParaIds::get() + BASE_PARA_ID; let storage = max_size_genesis_data(1, x); let slot_frequency = SlotFrequency::default(); @@ -687,10 +721,11 @@ mod benchmarks { Pallet::::deregister(RawOrigin::Root.into(), para_id).unwrap(); } - for i in 0..y { + for i in BASE_PARA_ID..y { // Twice the deposit just in case let (caller, _deposit_amount) = create_funded_user::("caller", i, T::DepositAmount::get()); + T::InnerRegistrar::prepare_chain_registration(i.into(), caller.clone()); Pallet::::register_parathread( RawOrigin::Signed(caller.clone()).into(), i.into(), @@ -706,7 +741,7 @@ mod benchmarks { T::InnerRegistrar::registrar_new_session(2); T::InnerRegistrar::registrar_new_session(3); - for i in 0..y { + for i in BASE_PARA_ID..y { Pallet::::mark_valid_for_collating(RawOrigin::Root.into(), i.into()).unwrap(); } @@ -731,7 +766,7 @@ mod benchmarks { #[benchmark] fn set_para_manager() { - let para_id = 1001u32.into(); + let para_id = 2010u32.into(); let origin = EnsureSignedByManager::::try_successful_origin(¶_id) .expect("failed to create ManagerOrigin"); diff --git a/pallets/registrar/src/lib.rs b/pallets/registrar/src/lib.rs index 64a4c5be9..1613c91d4 100644 --- a/pallets/registrar/src/lib.rs +++ b/pallets/registrar/src/lib.rs @@ -800,6 +800,7 @@ pub mod pallet { let new_balance = T::Currency::minimum_balance() * 10_000_000u32.into() + T::DepositAmount::get(); let account = create_funded_user::("caller", 1000, new_balance).0; + T::InnerRegistrar::prepare_chain_registration(*para_id, account.clone()); let origin = RawOrigin::Signed(account); let mut storage = vec![]; storage.push((b":code".to_vec(), vec![1; 10]).into()); diff --git a/primitives/traits/src/lib.rs b/primitives/traits/src/lib.rs index d0c8315dd..4e0522cf2 100644 --- a/primitives/traits/src/lib.rs +++ b/primitives/traits/src/lib.rs @@ -428,6 +428,8 @@ pub trait RegistrarHandler { fn add_trusted_validation_code(_code: Vec) {} #[cfg(feature = "runtime-benchmarks")] fn registrar_new_session(_session: u32) {} + #[cfg(feature = "runtime-benchmarks")] + fn prepare_chain_registration(_id: ParaId, _who: AccountId) {} } impl RegistrarHandler for () { diff --git a/tools/dev-benchmark-pallet.sh b/tools/dev-benchmark-pallet.sh index dbf0bd1d5..2d9a895c4 100755 --- a/tools/dev-benchmark-pallet.sh +++ b/tools/dev-benchmark-pallet.sh @@ -22,7 +22,7 @@ set -e cd "$(dirname "$0")/.." # mkdir just in case as the benchmarking fails if they don't exist -mkdir -p tmp/dancebox_weights tmp/flashbox_weights tmp/simple_template_weights tmp/frontier_template_weights +mkdir -p tmp/dancebox_weights tmp/flashbox_weights tmp/simple_template_weights tmp/frontier_template_weights tmp/dancelight_weights # Empty directories rm -rf tmp/*_weights/* @@ -70,14 +70,23 @@ fi TEMPLATE_PATH=benchmarking/frame-weight-runtime-template.hbs \ OUTPUT_PATH=tmp/dancebox_weights \ tools/benchmarking.sh "$PALLET" "*" --check -cp -v tmp/dancebox_weights/$PALLET.rs runtime/dancebox/src/weights/$PALLET.rs +cp -v tmp/dancebox_weights/$PALLET.rs chains/orchestrator-paras/runtime/dancebox/src/weights/$PALLET.rs # Flashbox weights TEMPLATE_PATH=benchmarking/frame-weight-runtime-template.hbs \ CHAIN=flashbox_dev \ OUTPUT_PATH=tmp/flashbox_weights \ tools/benchmarking.sh "$PALLET" "*" --check -cp -v tmp/flashbox_weights/$PALLET.rs runtime/flashbox/src/weights/$PALLET.rs +cp -v tmp/flashbox_weights/$PALLET.rs chains/orchestrator-paras/runtime/flashbox/src/weights/$PALLET.rs + +# Dancelight weights +BINARY=target/release/tanssi-relay \ + TEMPLATE_PATH=benchmarking/frame-weight-runtime-template.hbs \ + CHAIN=dancelight-dev \ + OUTPUT_PATH=tmp/dancelight_weights \ + tools/benchmarking.sh "$PALLET" "*" --check +cp -v tmp/dancelight_weights/$PALLET.rs chains/orchestrator-relays/runtime/dancelight/src/weights/$PALLET.rs + # Probably don't need to add weights to templates, change false to true if the pallet is also included in the templates if false; then