ethereum-consensus
ethereum-consensus copied to clipboard
feat: optimize phase0 attestation processing
Optimize Phase0 Attestation Processing
Summary
Optimizes epoch_processing::get_inclusion_delay_deltas() by restructuring attestation processing flow, reducing epoch boundary block processing time by 88.8%.
Problem
The original implementation iterates through all pending attestations for each validator, creating a significant performance bottleneck in state_transition().
Solution
Restructures attestation processing to perform a single pass through pending attestations:
// Before
for validator in unslashed_validators {
for attestation in pending_attestations {
// Process each attestation for every validator
}
}
// After
for attestation in pending_attestations {
let validator_indices = calculate_validator_indices(attestation);
// Process attestations once, mapping delays to validator indices
}
Performance Impact
Tested at slot 3,200 (20,488 validators, 225 pending attestations):
Processing time: 1.81hrs → 12.2 minutes 8.93x faster
Testing
Verified correctness against reference implementation Benchmarked with mainnet data at slot 3,200
Next steps:
- Similar optimizations planned for Altair, Bellatrix, Capella, and Deneb forks