Per-transaction weight for srml (#2799)

* debug checkpoint.

* new

* Worked.

* Worked and weight propagated to executive.

* Works with some tests.

* Cleanup debug prints.

* More cleanup.

* Undo more logs.

* Undo a few more.

* Fix build.

* Allow len to be used in weight calculation.

* Remove noop function from dispath.

* Cleanup.

* Unify traits.

* Update docs and nits.

* line width

* Update core/sr-primitives/src/weights.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/sr-primitives/src/weights.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/sr-primitives/src/weights.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Update core/sr-primitives/src/weights.rs

Co-Authored-By: Amar Singh <asinghchrony@protonmail.com>

* Update srml/example/src/lib.rs

Co-Authored-By: Bastian Köcher <bkchr@users.noreply.github.com>

* Final cleanup.

* Fix build.
This commit is contained in:
Kian Peymani
2019-06-12 14:38:30 +02:00
committed by GitHub
parent e53e9e9bda
commit 3496f11404
15 changed files with 288 additions and 54 deletions
+8 -8
View File
@@ -315,8 +315,8 @@ decl_storage! {
pub AccountNonce get(account_nonce): map T::AccountId => T::Index;
/// Total extrinsics count for the current block.
ExtrinsicCount: Option<u32>;
/// Total length in bytes for all extrinsics put together, for the current block.
AllExtrinsicsLen: Option<u32>;
/// Total weight for all extrinsics put together, for the current block.
AllExtrinsicsWeight: Option<u32>;
/// Map of block numbers to block hashes.
pub BlockHash get(block_hash) build(|_| vec![(T::BlockNumber::zero(), hash69())]): map T::BlockNumber => T::Hash;
/// Extrinsics data for the current block (maps an extrinsic's index to its data).
@@ -530,9 +530,9 @@ impl<T: Trait> Module<T> {
<ExtrinsicCount<T>>::get().unwrap_or_default()
}
/// Gets a total length of all executed extrinsics.
pub fn all_extrinsics_len() -> u32 {
<AllExtrinsicsLen<T>>::get().unwrap_or_default()
/// Gets a total weight of all executed extrinsics.
pub fn all_extrinsics_weight() -> u32 {
<AllExtrinsicsWeight<T>>::get().unwrap_or_default()
}
/// Start the execution of a particular block.
@@ -563,7 +563,7 @@ impl<T: Trait> Module<T> {
/// Remove temporary "environment" entries in storage.
pub fn finalize() -> T::Header {
<ExtrinsicCount<T>>::kill();
<AllExtrinsicsLen<T>>::kill();
<AllExtrinsicsWeight<T>>::kill();
let number = <Number<T>>::take();
let parent_hash = <ParentHash<T>>::take();
@@ -714,10 +714,10 @@ impl<T: Trait> Module<T> {
}.into());
let next_extrinsic_index = Self::extrinsic_index().unwrap_or_default() + 1u32;
let total_length = encoded_len.saturating_add(Self::all_extrinsics_len());
let total_length = encoded_len.saturating_add(Self::all_extrinsics_weight());
storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &next_extrinsic_index);
<AllExtrinsicsLen<T>>::put(&total_length);
<AllExtrinsicsWeight<T>>::put(&total_length);
}
/// To be called immediately after `note_applied_extrinsic` of the last extrinsic of the block