Block processing happens whenever a new block is received. This includes validation, state transition, block index update, state storage, etc.
State Map - maps block hashes to the state after processing them
Block Database - database mapping block hashes to full blocks
Block Index - in-memory representation of the blockchain including all blocks
- Block
- full block including attestations/exits/deposits/slashings
- State
- full state of blockchain (equivalent to UTXO set in BTC)
- Block Node
- Block hash
- Block height
- Slot
- Parent
- Children
Side note: block height != slot
because slots progress even if blocks aren't proposed.
Slot | Height |
---|---|
0 | 0 |
1 | n/a |
2 | n/a |
3 | 1 |
4 | 2 |
- Database
- Blocks
- Finalized/Justified Blocks
- Block Index
- Latest Attestations from each Validator
- Genesis Time
- Map of block hash to update state
- State Map
- Map of block hash to updated state
- Block Index
- Finalized block node and state
- Justified block node and state
- Tip block node
- Map of block hash to block node
State transitions are done in 3 phases.
- Slot Transition
- happen every single slot regardless of whether a block was proposed
- Block Transition
- happen after the slot transition for
block.slot
- only happen if a block was proposed
- Epoch Transition
- happen regardless of whether a block was proposed
- run at the end of
state.slot
ifstate.slot % epochLength == 0
- Validation
a. Make sure the block isn't processed too soon. A block can only be created on or after
genesisTime + slotNumber * seconds per slot
. b. Ensure the block has a parent block in the block index. c. Ensure we haven't already processed a block with this hash. - Calculate block state and add to state map. (
blockchain.StateManager.AddBlockToStateMap
) a. State update phase i. Run slot transitions untilstate.slot == block.slot
ii. Run block transition iii. Ifslot % epochLength == 0
, run epoch transition b. Set the block hash in the database to the updated state c. Set the block hash in the memory state map to the updated state - Store block in database (
blockchain.StoreBlock
) - Add block to block index (
blockchain.addBlockNodeToIndex
) - Update database block index
- Update latest attestations for each validator
- Update chain tip
- Update the finalized and justified nodes and corresponding states.
- Delete any states that have
slot < finalizedNode.slot