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:
thiolliere
2020-03-24 19:51:04 +01:00
committed by GitHub
parent 2e558908e6
commit 8a41ac664b
32 changed files with 331 additions and 365 deletions
@@ -87,8 +87,9 @@ use sp_runtime::{
print, DispatchResult, DispatchError, Perbill, traits::{Zero, StaticLookup, Convert},
};
use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error, weights::SimpleDispatchInfo,
storage::{StorageMap, IterableStorageMap}, traits::{
decl_storage, decl_event, ensure, decl_module, decl_error,
weights::{SimpleDispatchInfo, Weight, WeighData}, storage::{StorageMap, IterableStorageMap},
traits::{
Currency, Get, LockableCurrency, LockIdentifier, ReservableCurrency, WithdrawReasons,
ChangeMembers, OnUnbalanced, WithdrawReason, Contains, BalanceStatus
}
@@ -223,8 +224,10 @@ decl_module! {
fn deposit_event() = default;
fn on_runtime_upgrade() {
fn on_runtime_upgrade() -> Weight {
migration::migrate::<T>();
SimpleDispatchInfo::default().weigh_data(())
}
const CandidacyBond: BalanceOf<T> = T::CandidacyBond::get();
@@ -461,11 +464,13 @@ decl_module! {
}
/// What to do at the end of each block. Checks if an election needs to happen or not.
fn on_initialize(n: T::BlockNumber) {
fn on_initialize(n: T::BlockNumber) -> Weight {
if let Err(e) = Self::end_block(n) {
print("Guru meditation");
print(e);
}
SimpleDispatchInfo::default().weigh_data(())
}
}
}