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
+1 -32
View File
@@ -935,6 +935,7 @@ impl_runtime_apis! {
mod tests {
use super::*;
use frame_system::offchain::{SignAndSubmitTransaction, SubmitSignedTransaction};
use frame_support::traits::OnInitialize;
#[test]
fn validate_transaction_submitter_bounds() {
@@ -958,36 +959,4 @@ mod tests {
is_submit_signed_transaction::<SubmitTransaction>();
is_sign_and_submit_transaction::<SubmitTransaction>();
}
#[test]
fn block_hooks_weight_should_not_exceed_limits() {
use frame_support::weights::WeighBlock;
let check_for_block = |b| {
let block_hooks_weight =
<AllModules as WeighBlock<BlockNumber>>::on_initialize(b) +
<AllModules as WeighBlock<BlockNumber>>::on_finalize(b);
assert_eq!(
block_hooks_weight,
0,
"This test might fail simply because the value being compared to has increased to a \
module declaring a new weight for a hook or call. In this case update the test and \
happily move on.",
);
// Invariant. Always must be like this to have a sane chain.
assert!(block_hooks_weight < MaximumBlockWeight::get());
// Warning.
if block_hooks_weight > MaximumBlockWeight::get() / 2 {
println!(
"block hooks weight is consuming more than a block's capacity. You probably want \
to re-think this. This test will fail now."
);
assert!(false);
}
};
let _ = (0..100_000).for_each(check_for_block);
}
}