mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 06:47:57 +00:00
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:
@@ -37,9 +37,8 @@
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use serde::{Serialize, Deserialize};
|
||||
use impl_trait_for_tuples::impl_for_tuples;
|
||||
use codec::{Encode, Decode};
|
||||
use sp_arithmetic::traits::{Bounded, Zero};
|
||||
use sp_arithmetic::traits::Bounded;
|
||||
use sp_runtime::{
|
||||
RuntimeDebug,
|
||||
traits::SignedExtension,
|
||||
@@ -67,17 +66,6 @@ pub trait ClassifyDispatch<T> {
|
||||
fn classify_dispatch(&self, target: T) -> DispatchClass;
|
||||
}
|
||||
|
||||
/// Means of determining the weight of a block's life cycle hooks: `on_initialize`, `on_finalize`,
|
||||
/// `on_runtime_upgrade`, and such.
|
||||
pub trait WeighBlock<BlockNumber> {
|
||||
/// Return the weight of the block's on_runtime_upgrade hook.
|
||||
fn on_runtime_upgrade() -> Weight { Zero::zero() }
|
||||
/// Return the weight of the block's on_initialize hook.
|
||||
fn on_initialize(_: BlockNumber) -> Weight { Zero::zero() }
|
||||
/// Return the weight of the block's on_finalize hook.
|
||||
fn on_finalize(_: BlockNumber) -> Weight { Zero::zero() }
|
||||
}
|
||||
|
||||
/// Indicates if dispatch function should pay fees or not.
|
||||
/// If set to false, the block resource limits are applied, yet no fee is deducted.
|
||||
pub trait PaysFee<T> {
|
||||
@@ -86,34 +74,6 @@ pub trait PaysFee<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Maybe I can do something to remove the duplicate code here.
|
||||
#[impl_for_tuples(30)]
|
||||
impl<BlockNumber: Copy> WeighBlock<BlockNumber> for SingleModule {
|
||||
fn on_runtime_upgrade() -> Weight {
|
||||
let mut accumulated_weight: Weight = Zero::zero();
|
||||
for_tuples!(
|
||||
#( accumulated_weight = accumulated_weight.saturating_add(SingleModule::on_runtime_upgrade()); )*
|
||||
);
|
||||
accumulated_weight
|
||||
}
|
||||
|
||||
fn on_initialize(n: BlockNumber) -> Weight {
|
||||
let mut accumulated_weight: Weight = Zero::zero();
|
||||
for_tuples!(
|
||||
#( accumulated_weight = accumulated_weight.saturating_add(SingleModule::on_initialize(n)); )*
|
||||
);
|
||||
accumulated_weight
|
||||
}
|
||||
|
||||
fn on_finalize(n: BlockNumber) -> Weight {
|
||||
let mut accumulated_weight: Weight = Zero::zero();
|
||||
for_tuples!(
|
||||
#( accumulated_weight = accumulated_weight.saturating_add(SingleModule::on_finalize(n)); )*
|
||||
);
|
||||
accumulated_weight
|
||||
}
|
||||
}
|
||||
|
||||
/// A generalized group of dispatch types. This is only distinguishing normal, user-triggered transactions
|
||||
/// (`Normal`) and anything beyond which serves a higher purpose to the system (`Operational`).
|
||||
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
||||
|
||||
Reference in New Issue
Block a user