frame-executive 2.0.0-rc4

FRAME executives engine
Documentation

Executive Module

The Executive module acts as the orchestration layer for the runtime. It dispatches incoming extrinsic calls to the respective modules in the runtime.

Overview

The executive module is not a typical pallet providing functionality around a specific feature. It is a cross-cutting framework component for the FRAME. It works in conjunction with the FRAME System module to perform these cross-cutting functions.

The Executive module provides functions to:

  • Check transaction validity.
  • Initialize a block.
  • Apply extrinsics.
  • Execute a block.
  • Finalize a block.
  • Start an off-chain worker.

Implementations

The Executive module provides the following implementations:

  • ExecuteBlock: Trait that can be used to execute a block.
  • Executive: Type that can be used to make the FRAME available from the runtime.

Usage

The default Substrate node template declares the Executive type in its library.

Example

Executive type declaration from the node template.

# use sp_runtime::generic;
# use frame_executive as executive;
# pub struct UncheckedExtrinsic {};
# pub struct Header {};
# type Context = frame_system::ChainContext<Runtime>;
# pub type Block = generic::Block<Header, UncheckedExtrinsic>;
# pub type Balances = u64;
# pub type AllModules = u64;
# pub enum Runtime {};
# use sp_runtime::transaction_validity::{
#    TransactionValidity, UnknownTransaction, TransactionSource,
# };
# use sp_runtime::traits::ValidateUnsigned;
# impl ValidateUnsigned for Runtime {
#     type Call = ();
#
#     fn validate_unsigned(_source: TransactionSource, _call: &Self::Call) -> TransactionValidity {
#         UnknownTransaction::NoUnsignedValidator.into()
#     }
# }
/// Executive: handles dispatch to the various modules.
pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllModules>;

Custom OnRuntimeUpgrade logic

You can add custom logic that should be called in your runtime on a runtime upgrade. This is done by setting an optional generic parameter. The custom logic will be called before the on runtime upgrade logic of all modules is called.

# use sp_runtime::generic;
# use frame_executive as executive;
# pub struct UncheckedExtrinsic {};
# pub struct Header {};
# type Context = frame_system::ChainContext<Runtime>;
# pub type Block = generic::Block<Header, UncheckedExtrinsic>;
# pub type Balances = u64;
# pub type AllModules = u64;
# pub enum Runtime {};
# use sp_runtime::transaction_validity::{
#    TransactionValidity, UnknownTransaction, TransactionSource,
# };
# use sp_runtime::traits::ValidateUnsigned;
# impl ValidateUnsigned for Runtime {
#     type Call = ();
#
#     fn validate_unsigned(_source: TransactionSource, _call: &Self::Call) -> TransactionValidity {
#         UnknownTransaction::NoUnsignedValidator.into()
#     }
# }
struct CustomOnRuntimeUpgrade;
impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
// Do whatever you want.
0
}
}

pub type Executive = executive::Executive<Runtime, Block, Context, Runtime, AllModules, CustomOnRuntimeUpgrade>;