git.delta.rocks / unique-network / refs/commits / ee0e61035d6e

difftreelog

doc: utility benchmarking functions

Daniel Shiposha2022-11-09parent: #e3dab71.patch.diff
in: master

1 file changed

modifiedpallets/scheduler-v2/src/benchmarking.rsdiffbeforeafterboth
74 Ok(())74 Ok(())
75}75}
7676
77/// Generate a name for a scheduled task from an unsigned integer.
77fn u32_to_name(i: u32) -> TaskName {78fn u32_to_name(i: u32) -> TaskName {
78 i.using_encoded(blake2_256)79 i.using_encoded(blake2_256)
79}80}
8081
82/// A utility for creating simple scheduled tasks.
83///
84/// # Arguments
85/// * `periodic` - makes the task periodic.
86/// Sets the task's period and repetition count to `100`.
87/// * `named` - gives a name to the task: `u32_to_name(0)`.
88/// * `signed` - determines the origin of the task.
89/// If true, it will have the Signed origin. Otherwise it will have the Root origin.
90/// See [`make_origin`] for details.
91/// * maybe_lookup_len - sets optional lookup length. It is used to benchmark task fetching from the `Preimages` store.
92/// * priority - the task's priority.
81fn make_task<T: Config>(93fn make_task<T: Config>(
82 periodic: bool,94 periodic: bool,
83 named: bool,95 named: bool,
105 }117 }
106}118}
107119
120/// Creates a `SystemCall::remark` scheduled call with a given `len` in bytes.
121/// Returns `None` if the call is too large to encode.
108fn bounded<T: Config>(len: u32) -> Option<ScheduledCall<T>> {122fn bounded<T: Config>(len: u32) -> Option<ScheduledCall<T>> {
109 let call = <<T as Config>::RuntimeCall>::from(SystemCall::remark {123 let call = <<T as Config>::RuntimeCall>::from(SystemCall::remark {
110 remark: vec![0; len as usize],124 remark: vec![0; len as usize],
111 });125 });
112 ScheduledCall::new(call).ok()126 ScheduledCall::new(call).ok()
113}127}
114128
129/// Creates a scheduled call and maximizes its size.
130///
131/// If the `maybe_lookup_len` is not supplied, the task will create the maximal `Inline` scheduled call.
132///
133/// Otherwise, the function will take the length value from the `maybe_lookup_len`
134/// and find a minimal length value that ensures that the scheduled call will require a Preimage lookup.
115fn make_call<T: Config>(maybe_lookup_len: Option<u32>) -> ScheduledCall<T> {135fn make_call<T: Config>(maybe_lookup_len: Option<u32>) -> ScheduledCall<T> {
116 let bound = EncodedCall::bound() as u32;136 let bound = EncodedCall::bound() as u32;
117 let mut len = match maybe_lookup_len {137 let mut len = match maybe_lookup_len {
145 }165 }
146}166}
147167
168/// Creates an origin for a scheduled call.
169///
170/// If `signed` is true, it creates the Signed origin from a default account `account("origin", 0, SEED)`.
171/// Otherwise, it creates the Root origin.
148fn make_origin<T: Config>(signed: bool) -> <T as Config>::PalletsOrigin {172fn make_origin<T: Config>(signed: bool) -> <T as Config>::PalletsOrigin {
149 match signed {173 match signed {
150 true => frame_system::RawOrigin::Signed(account("origin", 0, SEED)).into(),174 true => frame_system::RawOrigin::Signed(account("origin", 0, SEED)).into(),
151 false => frame_system::RawOrigin::Root.into(),175 false => frame_system::RawOrigin::Root.into(),
152 }176 }
153}177}
154178
179/// Creates a dummy `WeightCounter` with the maximum possible weight limit.
155fn dummy_counter() -> WeightCounter {180fn dummy_counter() -> WeightCounter {
156 WeightCounter {181 WeightCounter {
157 used: Weight::zero(),182 used: Weight::zero(),