Skip to content

Commit

Permalink
Fix invulnerables benchmark for dancelight (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpolaczyk authored Nov 22, 2024
1 parent 0504b86 commit 464a1eb
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 27 deletions.
28 changes: 15 additions & 13 deletions pallets/external-validators/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use {
frame_support::traits::{Currency, EnsureOrigin, Get},
frame_system::{EventRecord, RawOrigin},
pallet_session::{self as session, SessionManager},
sp_runtime::traits::Convert,
rand::{RngCore, SeedableRng},
sp_runtime::{codec, traits::Convert},
sp_std::prelude::*,
};
const SEED: u32 = 0;
Expand All @@ -52,21 +53,22 @@ fn create_funded_user<T: Config + pallet_balances::Config>(
user
}

fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};

let keys = {
let mut keys = [0u8; 256];
struct InputFromRng<'a, T>(&'a mut T);
impl<'a, T: RngCore> codec::Input for InputFromRng<'a, T> {
fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
Ok(None)
}

if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));
rng.fill_bytes(&mut keys);
}
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
self.0.fill_bytes(into);
Ok(())
}
}

keys
};
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));

Decode::decode(&mut &keys[..]).unwrap()
Decode::decode(&mut InputFromRng(&mut rng)).unwrap()
}

fn invulnerable<T: Config + session::Config + pallet_balances::Config>(
Expand Down
28 changes: 15 additions & 13 deletions pallets/invulnerables/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use {
},
frame_system::{EventRecord, RawOrigin},
pallet_session::{self as session, SessionManager},
sp_runtime::traits::AtLeast32BitUnsigned,
rand::{RngCore, SeedableRng},
sp_runtime::{codec, traits::AtLeast32BitUnsigned},
sp_std::prelude::*,
tp_traits::DistributeRewards,
};
Expand Down Expand Up @@ -56,21 +57,22 @@ fn create_funded_user<T: Config + pallet_balances::Config>(
user
}

fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};

let keys = {
let mut keys = [0u8; 128];
struct InputFromRng<'a, T>(&'a mut T);
impl<'a, T: RngCore> codec::Input for InputFromRng<'a, T> {
fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> {
Ok(None)
}

if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));
rng.fill_bytes(&mut keys);
}
fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> {
self.0.fill_bytes(into);
Ok(())
}
}

keys
};
fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::from(c));

Decode::decode(&mut &keys[..]).unwrap()
Decode::decode(&mut InputFromRng(&mut rng)).unwrap()
}

fn invulnerable<T: Config + session::Config + pallet_balances::Config>(
Expand Down
3 changes: 2 additions & 1 deletion solo-chains/runtime/dancelight/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ impl pallet_invulnerables::Config for Runtime {
type CollatorId = <Self as frame_system::Config>::AccountId;
type CollatorIdOf = ConvertInto;
type CollatorRegistration = Session;
type WeightInfo = ();
type WeightInfo = weights::pallet_invulnerables::SubstrateWeight<Runtime>;
#[cfg(feature = "runtime-benchmarks")]
type Currency = Balances;
}
Expand Down Expand Up @@ -1976,6 +1976,7 @@ mod benches {
[pallet_collator_assignment, TanssiCollatorAssignment]
[pallet_external_validators, ExternalValidators]
[pallet_external_validator_slashes, ExternalValidatorSlashes]
[pallet_invulnerables, TanssiInvulnerables]
// XCM
[pallet_xcm, PalletXcmExtrinsicsBenchmark::<Runtime>]
[pallet_xcm_benchmarks::fungible, pallet_xcm_benchmarks::fungible::Pallet::<Runtime>]
Expand Down
1 change: 1 addition & 0 deletions solo-chains/runtime/dancelight/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub mod pallet_conviction_voting;
pub mod pallet_external_validator_slashes;
pub mod pallet_external_validators;
pub mod pallet_identity;
pub mod pallet_invulnerables;
pub mod pallet_message_queue;
pub mod pallet_multisig;
pub mod pallet_parameters;
Expand Down
117 changes: 117 additions & 0 deletions solo-chains/runtime/dancelight/src/weights/pallet_invulnerables.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// 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_invulnerables
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 42.0.0
//! DATE: 2024-11-20, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `tomasz-XPS-15-9520`, CPU: `12th Gen Intel(R) Core(TM) i7-12700H`
//! 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_invulnerables
// --extrinsic
// *
// --chain=dancelight-dev
// --steps
// 50
// --repeat
// 20
// --template=benchmarking/frame-weight-runtime-template.hbs
// --json-file
// raw.json
// --output
// tmp/dancelight_weights/pallet_invulnerables.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_invulnerables using the Substrate node and recommended hardware.
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_invulnerables::WeightInfo for SubstrateWeight<T> {
/// Storage: `Session::NextKeys` (r:1 w:0)
/// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`)
/// Storage: `TanssiInvulnerables::Invulnerables` (r:1 w:1)
/// Proof: `TanssiInvulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// The range of component `b` is `[1, 99]`.
fn add_invulnerable(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `845 + b * (36 ±0)`
// Estimated: `4687 + b * (37 ±0)`
// Minimum execution time: 12_566_000 picoseconds.
Weight::from_parts(17_476_246, 4687)
// Standard Error: 1_484
.saturating_add(Weight::from_parts(64_539, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
.saturating_add(Weight::from_parts(0, 37).saturating_mul(b.into()))
}
/// Storage: `TanssiInvulnerables::Invulnerables` (r:1 w:1)
/// Proof: `TanssiInvulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// The range of component `b` is `[1, 100]`.
fn remove_invulnerable(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `137 + b * (32 ±0)`
// Estimated: `4687`
// Minimum execution time: 6_954_000 picoseconds.
Weight::from_parts(9_208_806, 4687)
// Standard Error: 654
.saturating_add(Weight::from_parts(35_463, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
/// Storage: `TanssiInvulnerables::Invulnerables` (r:1 w:0)
/// Proof: `TanssiInvulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// The range of component `r` is `[1, 100]`.
fn new_session(r: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `137 + r * (32 ±0)`
// Estimated: `4687`
// Minimum execution time: 6_255_000 picoseconds.
Weight::from_parts(9_361_395, 4687)
// Standard Error: 1_732
.saturating_add(Weight::from_parts(28_444, 0).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(1_u64))
}
/// Storage: `TanssiInvulnerables::Invulnerables` (r:1 w:0)
/// Proof: `TanssiInvulnerables::Invulnerables` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:1 w:1)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// The range of component `b` is `[1, 100]`.
fn reward_invulnerable(b: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `285 + b * (33 ±0)`
// Estimated: `4687`
// Minimum execution time: 15_199_000 picoseconds.
Weight::from_parts(17_573_236, 4687)
// Standard Error: 801
.saturating_add(Weight::from_parts(45_127, 0).saturating_mul(b.into()))
.saturating_add(T::DbWeight::get().reads(2_u64))
.saturating_add(T::DbWeight::get().writes(1_u64))
}
}

0 comments on commit 464a1eb

Please sign in to comment.