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
+2 -2
View File
@@ -310,12 +310,12 @@ impl<T: Trait, D: AsRef<[u8]>> frame_support::traits::KeyOwnerProofSystem<(KeyTy
mod tests {
use super::*;
use sp_core::crypto::key_types::DUMMY;
use sp_runtime::{traits::OnInitialize, testing::UintAuthorityId};
use sp_runtime::testing::UintAuthorityId;
use crate::mock::{
NEXT_VALIDATORS, force_new_session,
set_next_validators, Test, System, Session,
};
use frame_support::traits::KeyOwnerProofSystem;
use frame_support::traits::{KeyOwnerProofSystem, OnInitialize};
type Historical = Module<Test>;
+9 -5
View File
@@ -102,12 +102,14 @@
use sp_std::{prelude::*, marker::PhantomData, ops::{Sub, Rem}};
use codec::Decode;
use sp_runtime::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPublic};
use frame_support::weights::SimpleDispatchInfo;
use sp_runtime::traits::{Convert, Zero, Member, OpaqueKeys};
use sp_staking::SessionIndex;
use frame_support::{ensure, decl_module, decl_event, decl_storage, decl_error, ConsensusEngineId};
use frame_support::{traits::{Get, FindAuthor, ValidatorRegistration}, Parameter};
use frame_support::dispatch::{self, DispatchResult, DispatchError};
use frame_support::{
ensure, decl_module, decl_event, decl_storage, decl_error, ConsensusEngineId, Parameter,
weights::{Weight, SimpleDispatchInfo, WeighData},
traits::{Get, FindAuthor, ValidatorRegistration},
dispatch::{self, DispatchResult, DispatchError},
};
use frame_system::{self as system, ensure_signed};
#[cfg(test)]
@@ -495,10 +497,12 @@ decl_module! {
/// Called when a block is initialized. Will rotate session if it is the last
/// block of the current session.
fn on_initialize(n: T::BlockNumber) {
fn on_initialize(n: T::BlockNumber) -> Weight {
if T::ShouldEndSession::should_end_session(n) {
Self::rotate_session();
}
SimpleDispatchInfo::default().weigh_data(())
}
}
}
+2 -2
View File
@@ -17,9 +17,9 @@
// Tests for the Session Pallet
use super::*;
use frame_support::assert_ok;
use frame_support::{traits::OnInitialize, assert_ok};
use sp_core::crypto::key_types::DUMMY;
use sp_runtime::{traits::OnInitialize, testing::UintAuthorityId};
use sp_runtime::testing::UintAuthorityId;
use mock::{
NEXT_VALIDATORS, SESSION_CHANGED, TEST_SESSION_CHANGED, authorities, force_new_session,
set_next_validators, set_session_length, session_changed, Test, Origin, System, Session,