Attribute Macro frame_support::pallet_macros::inherent

source ·
Expand description

The #[pallet::inherent] attribute allows the pallet to provide inherents.

An inherent is some piece of data that is inserted by a block authoring node at block creation time and can either be accepted or rejected by validators based on whether the data falls within an acceptable range.

The most common inherent is the timestamp that is inserted into every block. Since there is no way to validate timestamps, validators simply check that the timestamp reported by the block authoring node falls within an acceptable range.

Example usage:

mod pallet {
	// Example inherent identifier
	pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"timstap0";

	pub struct Pallet<T>(_);

	impl<T: Config> ProvideInherent for Pallet<T> {
		type Call = Call<T>;
		type Error = InherentError;

		fn create_inherent(data: &InherentData) -> Option<Self::Call> {

		fn check_inherent(
			call: &Self::Call,
			data: &InherentData,
		) -> result::Result<(), Self::Error> {

		fn is_inherent(call: &Self::Call) -> bool {

I.e. a trait implementation with bound T: Config, of trait ProvideInherent for type Pallet<T>, and some optional where clause.

§Macro expansion

The macro currently makes no use of this information, but it might use this information in the future to give information directly to construct_runtime.

Documentation for this macro can be found at frame_support::pallet_macros::inherent.