You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: prune finalized blocks and attestations (#83)
Implements automatic pruning of finalized data to prevent unbounded
storage growth. Adds a LiveChain index table to optimize fork choice
operations while enabling efficient cleanup of finalized blocks,
attestations, and signatures.
## Summary
When slots become finalized, they no longer participate in fork choice.
This PR:
1. Adds a LiveChain index for fast fork choice (avoids Block
deserialization)
2. Automatically prunes finalized data when checkpoints advance
3. Moves signature-related types to storage module for proper
encapsulation
## Key Changes
### LiveChain Index
- New `LiveChain` table: `(slot, root) -> parent_root` mappings (40
bytes per block)
- Big-endian slot encoding enables efficient range scans and early
termination
- Refactored `compute_lmd_ghost_head` to use `HashMap<H256, (u64,
H256)>` instead of full `Block`
- Automatic pruning removes finalized entries while preserving Blocks
table for historical queries
### Automatic Pruning
- `update_checkpoints()` triggers pruning when finalization advances
- **LiveChain**: Prunes index entries for slots < finalized_slot (keeps
finalized block itself)
- **GossipSignatures**: Removes signatures for finalized attestations
(no longer needed for block building)
- **AggregatedPayloads**: Removes aggregated proofs for finalized
attestations
## Implementation Details
**Why pruning on finalization?**
- Finalized attestations can't contribute to future fork choice
decisions
- Gossip signatures are only needed for building new blocks on live
forks
- Aggregated payloads from finalized blocks won't be reused
## Testing
Ran a validator node for 1 hour with these changes. Storage reached ~1GB
with a downward slope (actively pruning) compared to ~5GB before pruning
was implemented.
Also tested via existing spec tests:
- `forkchoice_spectests.rs`: Fork choice with LiveChain index
- `signature_spectests.rs`: Block building with new signature types
- `stf_spectests.rs`: State transition with pruned storage
0 commit comments