Skip to content

Commit

Permalink
Merge pull request #2992 from autonomys/add-set_pot_slot_iterations-b…
Browse files Browse the repository at this point in the history
…enchmark

Add benchmark for the `set_pot_slot_iterations` extrinsic
  • Loading branch information
NingLin-P committed Aug 29, 2024
2 parents ecaee78 + 3ca9a79 commit 66600e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions crates/pallet-subspace/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use frame_benchmarking::v2::*;
mod benchmarks {
use crate::{
AllowAuthoringByAnyone, Call, Config, CurrentSlot, EnableRewards, EnableRewardsAt,
NextSolutionRangeOverride, Pallet, SegmentCommitment, ShouldAdjustSolutionRange,
SolutionRanges,
NextSolutionRangeOverride, Pallet, PotSlotIterations, PotSlotIterationsUpdate,
PotSlotIterationsUpdateValue, SegmentCommitment, ShouldAdjustSolutionRange, SolutionRanges,
};
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
Expand All @@ -24,9 +24,10 @@ mod benchmarks {
use sp_core::Get;
use sp_runtime::traits::{Block, Header};
use sp_std::boxed::Box;
use sp_std::num::NonZeroU32;
use subspace_core_primitives::{
ArchivedBlockProgress, Blake3Hash, LastArchivedBlock, PotOutput, SegmentHeader,
SegmentIndex, Solution, SolutionRange,
ArchivedBlockProgress, Blake3Hash, LastArchivedBlock, PotCheckpoints, PotOutput,
SegmentHeader, SegmentIndex, Solution, SolutionRange,
};

const SEED: u32 = 0;
Expand Down Expand Up @@ -147,6 +148,28 @@ mod benchmarks {
assert!(Pallet::<T>::root_plot_public_key().is_none());
}

#[benchmark]
fn set_pot_slot_iterations() {
let slot_iterations = NonZeroU32::new(PotCheckpoints::NUM_CHECKPOINTS.get() as u32 * 2)
.expect("NUM_CHECKPOINTS is non-zero");
let next_slot_iterations = slot_iterations
.checked_mul(NonZeroU32::new(2).expect("2 is non-zero"))
.expect("Not overflow");

PotSlotIterations::<T>::set(Some(slot_iterations));

#[extrinsic_call]
_(RawOrigin::Root, next_slot_iterations);

assert_eq!(
PotSlotIterationsUpdate::<T>::get(),
Some(PotSlotIterationsUpdateValue {
target_slot: None,
slot_iterations: next_slot_iterations,
})
);
}

// Create a dummy segment header
fn create_segment_header(segment_index: SegmentIndex) -> SegmentHeader {
SegmentHeader::V0 {
Expand Down
2 changes: 1 addition & 1 deletion crates/pallet-subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pub mod pallet {
pub(super) entropy: Blake3Hash,
}

#[derive(Debug, Copy, Clone, Encode, Decode, TypeInfo)]
#[derive(Debug, Copy, Clone, Encode, Decode, TypeInfo, PartialEq)]
pub(super) struct PotSlotIterationsUpdateValue {
/// Target slot at which entropy should be injected (when known)
pub(super) target_slot: Option<Slot>,
Expand Down

0 comments on commit 66600e7

Please sign in to comment.