Skip to content
21 changes: 21 additions & 0 deletions substrate/frame/broker/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,27 @@ mod benches {
}
}

#[benchmark]
fn do_tick_base() -> Result<(), BenchmarkError> {
setup_and_start_sale::<T>()?;

advance_to::<T>(5);

let mut status = Status::<T>::get().unwrap();
status.last_committed_timeslice = 3;
Status::<T>::put(&status);

#[block]
{
Broker::<T>::do_tick();
}

let updated_status = Status::<T>::get().unwrap();
assert_eq!(status, updated_status);

Ok(())
}

// Implements a test for each benchmark. Execute with:
// `cargo test -p pallet-broker --features runtime-benchmarks`.
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
Expand Down
7 changes: 4 additions & 3 deletions substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ impl<T: Config> Pallet<T> {
/// - Request revenue information for a previous timeslice
/// - Initialize an instantaneous core pool historical revenue record
pub(crate) fn do_tick() -> Weight {
let mut meter = WeightMeter::new();
meter.consume(T::WeightInfo::do_tick_base());

let (mut status, config) = match (Status::<T>::get(), Configuration::<T>::get()) {
(Some(s), Some(c)) => (s, c),
_ => return Weight::zero(),
_ => return meter.consumed(),
};

let mut meter = WeightMeter::new();

if Self::process_core_count(&mut status) {
meter.consume(T::WeightInfo::process_core_count(status.core_count.into()));
}
Expand Down
Loading