-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ Enable benchmarking project-wide and benchmark
challenge
ex…
…trinsic (#232) * build: 👷 Make build work with `runtime-benchmarks` feature * feat: ✨ Run benchmarkings and set weights for `challenge` transaction
- Loading branch information
Showing
24 changed files
with
166 additions
and
121 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//! Benchmarking setup for pallet-proofs-dealer | ||
use frame_benchmarking::v2::*; | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use frame_support::{assert_ok, traits::fungible::Mutate}; | ||
use frame_system::RawOrigin; | ||
use sp_runtime::traits::Hash; | ||
|
||
use super::*; | ||
use crate::{ | ||
pallet, types::MerkleTrieHashingFor, Call, ChallengesQueue, Config, Event, Pallet, | ||
}; | ||
|
||
#[benchmark] | ||
fn challenge() -> Result<(), BenchmarkError> { | ||
// Setup initial conditions. | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let file_key = MerkleTrieHashingFor::<T>::hash(b"file_key"); | ||
let user_balance = match 1_000_000_000_000_000u128.try_into() { | ||
Ok(balance) => balance, | ||
Err(_) => return Err(BenchmarkError::Stop("Balance conversion failed.")), | ||
}; | ||
assert_ok!(<T as crate::Config>::NativeBalance::mint_into( | ||
&caller, | ||
user_balance, | ||
)); | ||
|
||
// Call some extrinsic. | ||
#[extrinsic_call] | ||
Pallet::challenge(RawOrigin::Signed(caller.clone()), file_key); | ||
|
||
// Verify the challenge event was emitted. | ||
let expected_event = <T as pallet::Config>::RuntimeEvent::from(Event::<T>::NewChallenge { | ||
who: caller, | ||
key_challenged: file_key, | ||
}); | ||
frame_system::Pallet::<T>::assert_last_event(expected_event.into()); | ||
|
||
// Verify that the challenge is in the queue. | ||
let challenges_queue = ChallengesQueue::<T>::get(); | ||
assert_eq!(challenges_queue.len(), 1); | ||
assert_eq!(challenges_queue[0], file_key); | ||
|
||
Ok(()) | ||
} | ||
|
||
impl_benchmark_test_suite! { | ||
Pallet, | ||
crate::mock::new_test_ext(), | ||
crate::mock::Test, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
|
||
//! Autogenerated weights for `pallet_proofs_dealer` | ||
//! | ||
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 43.0.0 | ||
//! DATE: 2024-10-17, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` | ||
//! WORST CASE MAP SIZE: `1000000` | ||
//! HOSTNAME: `Facundos-MacBook-Pro.local`, CPU: `<UNKNOWN>` | ||
//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` | ||
|
||
// Executed Command: | ||
// ./target/release/storage-hub-node | ||
// benchmark | ||
// pallet | ||
// --chain | ||
// dev | ||
// --wasm-execution=compiled | ||
// --pallet | ||
// pallet_proofs_dealer | ||
// --extrinsic | ||
// * | ||
// --steps | ||
// 50 | ||
// --repeat | ||
// 20 | ||
// --output | ||
// pallets/proofs-dealer/src/weights.rs | ||
// --template | ||
// ../polkadot-sdk/substrate/.maintain/frame-weight-template.hbs | ||
|
||
#![cfg_attr(rustfmt, rustfmt_skip)] | ||
#![allow(unused_parens)] | ||
#![allow(unused_imports)] | ||
#![allow(missing_docs)] | ||
|
||
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; | ||
use core::marker::PhantomData; | ||
|
||
/// Weight functions needed for `pallet_proofs_dealer`. | ||
pub trait WeightInfo { | ||
fn challenge() -> Weight; | ||
} | ||
|
||
/// Weights for `pallet_proofs_dealer` using the Substrate node and recommended hardware. | ||
pub struct SubstrateWeight<T>(PhantomData<T>); | ||
impl<T: frame_system::Config> 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: `ProofsDealer::ChallengesQueue` (r:1 w:1) | ||
/// Proof: `ProofsDealer::ChallengesQueue` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`) | ||
fn challenge() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `94` | ||
// Estimated: `4687` | ||
// Minimum execution time: 40_000_000 picoseconds. | ||
Weight::from_parts(43_000_000, 4687) | ||
.saturating_add(T::DbWeight::get().reads(2_u64)) | ||
.saturating_add(T::DbWeight::get().writes(2_u64)) | ||
} | ||
} | ||
|
||
// For backwards compatibility and tests. | ||
impl WeightInfo for () { | ||
/// Storage: `System::Account` (r:1 w:1) | ||
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) | ||
/// Storage: `ProofsDealer::ChallengesQueue` (r:1 w:1) | ||
/// Proof: `ProofsDealer::ChallengesQueue` (`max_values`: Some(1), `max_size`: Some(3202), added: 3697, mode: `MaxEncodedLen`) | ||
fn challenge() -> Weight { | ||
// Proof Size summary in bytes: | ||
// Measured: `94` | ||
// Estimated: `4687` | ||
// Minimum execution time: 40_000_000 picoseconds. | ||
Weight::from_parts(43_000_000, 4687) | ||
.saturating_add(RocksDbWeight::get().reads(2_u64)) | ||
.saturating_add(RocksDbWeight::get().writes(2_u64)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.