Repository: paritytech/substrate
File: frame/support/src/traits/hooks.rs (Rust)

Code before:
#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))]
#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))]
pub trait IntegrityTest {
	/// See [`Hooks::integrity_test`].
	fn integrity_test() {}
}

/// The pallet hooks trait. This is merely an umbrella trait for:
///
/// - [`OnInitialize`]
/// - [`OnFinalize`]
/// - [`OnRuntimeUpgrade`]
/// - [`OffchainWorker`]
/// - [`OnIdle`]
/// - [`IntegrityTest`]
///
/// ## Ordering
///
/// For all hooks, except [`OnIdle`] the order of execution is derived from how the pallets are
/// ordered in [`crate::construct_runtime`].
///
/// ## Summary
///
/// In short, the following diagram shows the
pub trait Hooks<BlockNumber> {
	/// Block initialization hook. This is called at the very beginning of the block execution
	///
	/// Must return the non-negotiable weight of both itself, and whatever [`on_finalize`] wishes to
	/// consumed.
	///
	/// The weight returned by this is treated as [`DispatchClass::Mandatory`], meaning that it MUST
	/// BE EXECUTED. This implies that this hook should only ever be used if the logic in it must
	/// happen under any circumstance. For all similar use cases where a delay is acceptable, use
	/// [`poll`].
	///
	/// NOTE: This function is called BEFORE ANY extrinsic in a block is applied, including inherent
	/// extrinsics. Hence for instance, if you runtime includes `pallet-timestamp`, the `timestamp`
	/// is not yet up to date at this point.
	fn on_initialize(_n: BlockNumber) -> Weight {
		Weight::zero()
	}

	/// Similar to [`on_initialize`], but:
	///
	/// 1. is called after [`on_initialize`] of all pallets is done executing,
	/// 2. execution on *each block* is not guaranteed
	///
	/// The latter point is usually correlated with the block resources being available, for example
	/// `Weight` leftover.
	fn poll(_n: BlockNumber) -> Weight {
		Weight::zero()

Review comment (suggestion):
```suggestion
	/// Block initialization hook. This is called at the very beginning of block execution.
```

Code after:
#[cfg_attr(all(feature = "tuples-96", not(feature = "tuples-128")), impl_for_tuples(96))]
#[cfg_attr(feature = "tuples-128", impl_for_tuples(128))]
pub trait IntegrityTest {
	/// See [`Hooks::integrity_test`].
	fn integrity_test() {}
}

#[cfg_attr(doc, aquamarine::aquamarine)]
/// The pallet hooks trait. This is merely an umbrella trait for:
///
/// - [`OnInitialize`]
/// - [`OnFinalize`]
/// - [`OnRuntimeUpgrade`]
/// - [`crate::traits::misc::OffchainWorker`]
/// - [`OnIdle`]
/// - [`IntegrityTest`]
///
/// ## Ordering
///
/// For all hooks, except [`OnIdle`] the order of execution is derived from how the pallets are
/// ordered in [`crate::construct_runtime`].
///
/// ## Summary
///
/// In short, the following diagram shows the flow of hooks in a pallet
///
/// ```mermaid
/// graph LR
/// 	Optional --> BeforeExtrinsics
/// 	BeforeExtrinsics --> Extrinsics
/// 	Extrinsics --> AfterExtrinsics
/// 	subgraph Optional
/// 	OnRuntimeUpgrade
/// end
///
/// subgraph BeforeExtrinsics
/// 	OnInitialize
/// end
///
/// subgraph Extrinsics
/// 	direction TB
/// 	Inherent1
/// 	Inherent2
/// 	Extrinsic1
/// 	Extrinsic2
///
/// 	Inherent1 --> Inherent2
/// 	Inherent2 --> Extrinsic1
/// 	Extrinsic1 --> Extrinsic2
/// end
///