Skip to content
Snippets Groups Projects
Unverified Commit 8857e186 authored by bgallois's avatar bgallois
Browse files

benchmark process_refund_queue overhead

parent c2dd6399
No related branches found
No related tags found
No related merge requests found
Pipeline #34237 waiting for manual action
This commit is part of merge request !190. Comments created here will be created in the context of that merge request.
......@@ -108,4 +108,16 @@ assert_has_event::<T>(Event::<T>::RefundFailed ( account ).into());
verify {
assert_has_event::<T>(Event::<T>::RefundFailed ( account ).into());
}
process_refund_queue {
let account: T::AccountId = account("Alice", 1, 1);
let dummy_refund = Refund {
account: account.clone(),
identity: 0u32.into(),
amount: 20u64.into(),
};
// Worst case scenario: the queue is full, and the available weight is maximal.
for i in 0 .. MAX_QUEUED_REFUNDS {
Pallet::<T>::queue_refund(dummy_refund.clone())
}
}: { Pallet::<T>::process_refund_queue(Weight::MAX) }
}
......@@ -308,9 +308,14 @@ pub mod pallet {
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
// process refund queue if space left on block
fn on_idle(_block: T::BlockNumber, remaining_weight: Weight) -> Weight {
Self::process_refund_queue(remaining_weight)
// opti: benchmark process_refund_queue overhead and substract this from weight limit
// .saturating_sub(T::WeightInfo::process_refund_queue())
// The overhead is computed as the worst-case scenario for process_refund_queue (i.e., when the queue is full),
// minus the length of the queue times the actual weight of one refund operation.
let overhead = <T as pallet::Config>::WeightInfo::process_refund_queue()
.saturating_sub(
<T as pallet::Config>::WeightInfo::try_refund()
.saturating_mul(MAX_QUEUED_REFUNDS.into()),
);
Self::process_refund_queue(remaining_weight - overhead)
}
}
}
......
......@@ -7,6 +7,7 @@ pub trait WeightInfo {
fn spend_quota() -> Weight;
fn try_refund() -> Weight;
fn do_refund() -> Weight;
fn process_refund_queue() -> Weight;
}
impl WeightInfo for () {
......@@ -22,4 +23,7 @@ impl WeightInfo for () {
fn do_refund() -> Weight {
Weight::from_parts(999u64, 0)
}
fn process_refund_queue() -> Weight {
Weight::from_parts(999u64, 0)
}
}
......@@ -2,7 +2,7 @@
//! Autogenerated weights for `pallet_quota`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-11-15, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-11-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bgallois-ms7d43`, CPU: `12th Gen Intel(R) Core(TM) i3-12100F`
//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024
......@@ -41,8 +41,8 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `11288`
// Estimated: `12751`
// Minimum execution time: 7_039_000 picoseconds.
Weight::from_parts(7_295_000, 0)
// Minimum execution time: 7_180_000 picoseconds.
Weight::from_parts(7_381_000, 0)
.saturating_add(Weight::from_parts(0, 12751))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
......@@ -53,8 +53,8 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `139`
// Estimated: `3489`
// Minimum execution time: 3_382_000 picoseconds.
Weight::from_parts(3_655_000, 0)
// Minimum execution time: 3_393_000 picoseconds.
Weight::from_parts(3_569_000, 0)
.saturating_add(Weight::from_parts(0, 3489))
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
......@@ -67,8 +67,8 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `139`
// Estimated: `3591`
// Minimum execution time: 11_210_000 picoseconds.
Weight::from_parts(11_612_000, 0)
// Minimum execution time: 10_638_000 picoseconds.
Weight::from_parts(10_976_000, 0)
.saturating_add(Weight::from_parts(0, 3591))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
......@@ -81,10 +81,24 @@ impl<T: frame_system::Config> pallet_quota::WeightInfo for WeightInfo<T> {
// Proof Size summary in bytes:
// Measured: `139`
// Estimated: `3591`
// Minimum execution time: 11_220_000 picoseconds.
Weight::from_parts(11_589_000, 0)
// Minimum execution time: 10_470_000 picoseconds.
Weight::from_parts(11_046_000, 0)
.saturating_add(Weight::from_parts(0, 3591))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Quota RefundQueue (r:1 w:1)
/// Proof: Quota RefundQueue (max_values: Some(1), max_size: Some(11266), added: 11761, mode: MaxEncodedLen)
/// Storage: Quota IdtyQuota (r:1 w:1)
/// Proof: Quota IdtyQuota (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen)
fn process_refund_queue() -> Weight {
// Proof Size summary in bytes:
// Measured: `11428`
// Estimated: `12751`
// Minimum execution time: 259_194_000 picoseconds.
Weight::from_parts(261_006_000, 0)
.saturating_add(Weight::from_parts(0, 12751))
.saturating_add(T::DbWeight::get().reads(2))
.saturating_add(T::DbWeight::get().writes(2))
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment