Erigon synchronizes via ordered stages. Each stage processes blocks independently and can unwind during reorgs.
- Snapshots - Download/verify immutable historical data
- Headers - Download and validate block headers
- BlockHashes - Index blockHash → blockNumber
- Bodies - Download block bodies and transactions
- Senders - Recover transaction senders from signatures
- Execution - Execute blocks and compute state
- TxLookup - Index txHash → blockNumber
- Finish - Update RPC-visible head block
sync.go-Syncstruct orchestrates stage execution, tracks unwind pointsstageloop/stageloop.go-StageLoop()runs continuous sync cycledefault_stages.go- Stage factory functions and ordering (DefaultStages(),DefaultForwardOrder,DefaultUnwindOrder)stages/stages.go-SyncStageconstants and progress tracking
Each stage implements:
type Stage struct {
ID stages.SyncStage
Forward ExecFunc // Execute stage forward
Unwind UnwindFunc // Handle reorgs
Prune PruneFunc // Remove old data
}Each stage has a config struct (e.g., HeadersCfg, ExecuteBlockCfg) containing:
- Database handles
- P2P handlers
- Chain config
- Batch sizes and tuning parameters
UnwindTo()called with target block and reason- Stages unwind in reverse order (
DefaultUnwindOrder) - State rolled back via domain writers
- Execution resumes from unwind point
| File | Stage | Purpose |
|---|---|---|
stage_snapshots.go |
Snapshots | Download segment files |
stage_headers.go |
Headers | P2P header download |
stage_blockhashes.go |
BlockHashes | blockHash→blockNum index |
stage_bodies.go |
Bodies | P2P body download |
stage_senders.go |
Senders | Signature recovery |
stage_execute.go |
Execution | Block execution, state changes |
stage_txlookup.go |
TxLookup | txHash→blockNum index |
stage_finish.go |
Finish | Update head for RPC |
headerdownload/- Header P2P download algorithmsbodydownload/- Body P2P download algorithms