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.
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.
2 Phase 2: Execute Extrinsics
User transactions (extrinsics ) are processed in order. Each extrinsic is isolated – one failing doesn't affect others.
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
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.
Block Structure
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
When a call fails, look for System.ExtrinsicFailed event in the block. It contains the error module, index, and message.
Common Failure Scenarios
| Scenario | What Happens |
|---|---|
| Insufficient balance | Call reverted, fee still charged |
| Invalid parameters | Call reverted, fee still charged |
| Out of gas/weight | Call reverted, max fee charged |
| Block weight limit | Transaction stays in pool for next block |