mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 23:21:02 +00:00
on_initialize return weight consumed and default cost to default DispatchInfo instead of zero (#5382)
* frame update * doc * move offchain worker trait also * fix weigh merge * indentation * reorder for better git diff * comment * fix benchmark * remove test
This commit is contained in:
@@ -54,7 +54,10 @@
|
||||
|
||||
use sp_std::{prelude::*, convert::TryInto};
|
||||
use sp_runtime::traits::Hash;
|
||||
use frame_support::{decl_module, decl_storage, traits::Randomness};
|
||||
use frame_support::{
|
||||
decl_module, decl_storage, traits::Randomness,
|
||||
weights::{Weight, SimpleDispatchInfo, WeighData}
|
||||
};
|
||||
use safe_mix::TripletMix;
|
||||
use codec::Encode;
|
||||
use frame_system::Trait;
|
||||
@@ -69,7 +72,7 @@ fn block_number_to_index<T: Trait>(block_number: T::BlockNumber) -> usize {
|
||||
|
||||
decl_module! {
|
||||
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
|
||||
fn on_initialize(block_number: T::BlockNumber) {
|
||||
fn on_initialize(block_number: T::BlockNumber) -> Weight {
|
||||
let parent_hash = <frame_system::Module<T>>::parent_hash();
|
||||
|
||||
<RandomMaterial<T>>::mutate(|ref mut values| if values.len() < RANDOM_MATERIAL_LEN as usize {
|
||||
@@ -78,6 +81,8 @@ decl_module! {
|
||||
let index = block_number_to_index::<T>(block_number);
|
||||
values[index] = parent_hash;
|
||||
});
|
||||
|
||||
SimpleDispatchInfo::default().weigh_data(())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,9 +161,11 @@ mod tests {
|
||||
use sp_runtime::{
|
||||
Perbill,
|
||||
testing::Header,
|
||||
traits::{BlakeTwo256, OnInitialize, Header as _, IdentityLookup},
|
||||
traits::{BlakeTwo256, Header as _, IdentityLookup},
|
||||
};
|
||||
use frame_support::{
|
||||
impl_outer_origin, parameter_types, weights::Weight, traits::{Randomness, OnInitialize},
|
||||
};
|
||||
use frame_support::{impl_outer_origin, parameter_types, weights::Weight, traits::Randomness};
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct Test;
|
||||
|
||||
Reference in New Issue
Block a user