Learn / Block Execution

Block Execution Timeline

How Substrate processes each block in Subtensor. Understanding this flow helps you know when events fire, when storage updates, and what happens during epochs.

Overview

Roughly every 12 seconds, Subtensor produces a new block . Each block follows a precise execution timeline with four phases. This deterministic order ensures all nodes reach the same state.

1
on_initialize
Block start, epoch checks
2
Execute Extrinsics
Process transactions in order
3
on_finalize
Cleanup, finalize block digest
4
Block Produced
Seal and propagate to network
Block Time

Subtensor targets 12-second block times. A typical block contains around 0-50 extrinsics , though blocks during high activity can contain more.

1 Phase 1: on_initialize

The first code to run in every block. This is where pallets perform per-block housekeeping before any user transactions are processed.

What Happens

  • Aura slot assignment. The block author is determined based on the Aura consensus slot
  • Inherent data. Timestamp and other inherent data are set
  • Epoch check. For each subnet , checks if (block_number + netuid + 1) % (tempo + 1) == 0

2 Phase 2: Execute Extrinsics

User transactions (extrinsics ) are processed in order. Each extrinsic is isolated – one failing doesn't affect others.

Processing Order

  • Inherents first. Unsigned transactions from the block author (timestamp, etc.)
  • Signed transactions. User-submitted calls in FIFO order
  • Transaction pool selection. Block authors include transactions based on priority and fees

3 Phase 3: on_finalize

After all extrinsics are processed, each pallet's on_finalize hook runs. This is for end-of-block cleanup.

What Happens

  • Timestamp finalized. The block's timestamp inherent is locked in
  • Block digest updated. Logs, consensus data, and runtime changes are recorded
  • Authority rotation queued. If the validator set changes, updates are prepared for the next epoch
Minimal Work

Most pallets generally keep on_finalize lightweight. Heavy computation belongs in on_initialize or hooks to avoid blocking finalization.

4 Phase 4: Block Produced

The block author seals the block with a cryptographic proof and propagates it to the network.

What Happens

  • Block hash computed. The header hash uniquely identifies this block
  • Block sealed. The author signs the block using Aura consensus
  • Network propagation. Block is sent to peers via libp2p gossip
  • Finality via GRANDPA . Validators vote to finalize blocks (may lag behind head)

Block Structure

Block #{number}
├── parent_hash: 0x...
├── state_root: 0x...
├── extrinsics_root: 0x...
├── digest: [logs, seal]
└── extrinsics: [inherents, transactions]

Rollback Handling

What happens when a transaction fails? Substrate uses atomic storage changes to maintain consistency.

Atomic Transactions

  • All or nothing. If any part of a call fails, all storage changes are reverted
  • Isolated failures. One failed transaction doesn't affect other transactions in the block
  • Fees still charged. Even if the call fails, transaction fees are deducted
Finding Error Codes

When a call fails, look for System.ExtrinsicFailed event in the block. It contains the error module, index, and message.

Common Failure Scenarios

ScenarioWhat Happens
Insufficient balanceCall reverted, fee still charged
Invalid parametersCall reverted, fee still charged
Out of gas/weightCall reverted, max fee charged
Block weight limitTransaction stays in pool for next block