Weight annotation for block hooks. (#4058)

* Initial version that works with proper tests.

* get rid of todos and grumbles and such.

* Cleanup and fix line-width

* fix test runtime test
This commit is contained in:
Kian Paimani
2019-11-12 14:42:38 +01:00
committed by Gavin Wood
parent ab1b98fee5
commit efedac734d
10 changed files with 339 additions and 15 deletions
+23
View File
@@ -606,6 +606,29 @@ impl<T: Trait> Module<T> {
AllExtrinsicsLen::get().unwrap_or_default()
}
/// Inform the system module of some additional weight that should be accounted for, in the
/// current block.
///
/// NOTE: use with extra care; this function is made public only be used for certain modules
/// that need it. A runtime that does not have dynamic calls should never need this and should
/// stick to static weights. A typical use case for this is inner calls or smart contract calls.
/// Furthermore, it only makes sense to use this when it is presumably _cheap_ to provide the
/// argument `weight`; In other words, if this function is to be used to account for some
/// unknown, user provided call's weight, it would only make sense to use it if you are sure you
/// can rapidly compute the weight of the inner call.
///
/// Even more dangerous is to note that this function does NOT take any action, if the new sum
/// of block weight is more than the block weight limit. This is what the _unchecked_.
///
/// Another potential use-case could be for the `on_initialise` and `on_finalize` hooks.
///
/// If no previous weight exists, the function initializes the weight to zero.
pub fn register_extra_weight_unchecked(weight: Weight) {
let current_weight = AllExtrinsicsWeight::get().unwrap_or_default();
let next_weight = current_weight.saturating_add(weight).min(T::MaximumBlockWeight::get());
AllExtrinsicsWeight::put(next_weight);
}
/// Start the execution of a particular block.
pub fn initialize(
number: &T::BlockNumber,