Skip unnecessary payload deserialization, batch attestation inserts, unify validator_indices, and clean up time constants#174
Conversation
… data inserts, unify validator_indices, and derive MILLISECONDS_PER_SLOT Four cleanup items from reviewing the devnet 3 merge: 1. update_safe_target was deserializing full StoredAggregatedPayload vectors (containing multi-KB proof data) from both attestation pools only to immediately discard the values and keep the keys. Added key-only iterators (iter_known_aggregated_payload_keys, iter_new_aggregated_payload_keys) that skip value deserialization entirely. 2. on_block_core called insert_attestation_data_by_root once per block body attestation plus once for the proposer, each opening a separate write batch and committing. Added insert_attestation_data_by_root_batch and collected all entries into a single commit. 3. aggregation_bits_to_validator_indices in store.rs duplicated the logic in AggregatedSignatureProof::participant_indices. Extracted a shared validator_indices() function in ethlambda_types::attestation and made both call it. 4. SECONDS_PER_SLOT was only used by two test files and was redundant with MILLISECONDS_PER_SLOT. Removed it and derived MILLISECONDS_PER_SLOT from MILLISECONDS_PER_INTERVAL * INTERVALS_PER_SLOT to prevent consistency drift. Updated test callers to match production arithmetic.
🤖 Kimi Code ReviewReview SummaryThis PR introduces several improvements to the ethlambda consensus client, focusing on performance optimizations and code cleanup. The changes are generally positive, but there are a few areas that need attention. Issues Found1. Critical: Potential Overflow in
|
🤖 Codex Code ReviewNo blocking findings in this PR. I checked the touched paths for fork-choice impact, attestation handling, signature/bitfield semantics, and storage consistency. The behavioral changes look correct:
One non-blocking review note:
Residual risk:
Automated review by OpenAI Codex · custom prompt |
🤖 Claude Code ReviewNow I have all the context needed. Let me write the review. PR #174 Review: Skip payload deserialization, batch attestation inserts, unify
|
Greptile SummaryThis PR delivers four targeted performance optimizations and code cleanup changes to the blockchain fork choice implementation, with no behavior changes:
All changes preserve existing behavior and pass the full test suite (102 tests). Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| crates/blockchain/src/lib.rs | Removed redundant SECONDS_PER_SLOT constant and derived MILLISECONDS_PER_SLOT from base constants to prevent inconsistency |
| crates/storage/src/store.rs | Added key-only iterators for aggregated payloads and batch insert method for attestation data to optimize hot-path operations |
| crates/blockchain/src/store.rs | Replaced full payload deserialization with key-only iterators in update_safe_target, batched attestation inserts, unified validator indices extraction |
Last reviewed commit: e083b8b
Summary
Follow-up cleanup from reviewing the devnet 3 merge (#107). Four targeted optimizations and deduplication fixes — no behavior changes.
update_safe_target(runs every slot)insert_attestation_data_by_rootcommits inon_block_core(runs every block)aggregation_bits_to_validator_indicesinto sharedvalidator_indices()MILLISECONDS_PER_SLOTfrom base constants, remove redundantSECONDS_PER_SLOTChanges in detail
1. Key-only iterators for
update_safe_target(crates/storage/src/store.rs,crates/blockchain/src/store.rs)update_safe_targetcallsiter_known_aggregated_payloads()anditer_new_aggregated_payloads(), which deserializeVec<StoredAggregatedPayload>per entry (each containing multi-KBAggregatedSignatureProofobjects). It then immediately discards the values and passes only the keys toextract_latest_attestations.Fix: Added
iter_known_aggregated_payload_keys()anditer_new_aggregated_payload_keys()backed by a sharediter_aggregated_payload_keys(table)helper that decodes only the key bytes, skipping value deserialization entirely.update_safe_targetnow uses these through aHashSetfor deduplication.This runs every slot (every 4 seconds) and scales with validator count.
2. Batch attestation data inserts in
on_block_core(crates/storage/src/store.rs,crates/blockchain/src/store.rs)on_block_corecalledinsert_attestation_data_by_rootonce per block body attestation plus once for the proposer attestation. Each call opened a separate write batch and committed — N+1 round-trips per block.Fix: Added
insert_attestation_data_by_root_batchthat writes all entries in a single batch-commit.on_block_corenow collects all attestation data entries (body + proposer) and inserts them in one go. The existinginsert_attestation_data_by_rootis kept for the single-entry callers (on_gossip_attestation,on_gossip_aggregated_attestation).3. Unify
aggregation_bits_to_validator_indices(crates/common/types/src/attestation.rs,crates/common/types/src/block.rs,crates/blockchain/src/store.rs)store.rshad a free functionaggregation_bits_to_validator_indices(&AggregationBits) -> Vec<u64>that was structurally identical toAggregatedSignatureProof::participant_indices()inblock.rs. Both iterate a bitfield and collect set-bit indices.Fix: Added
validator_indices(&AggregationBits) -> impl Iterator<Item = u64>inethlambda_types::attestation(whereAggregationBitsis defined).participant_indices()now delegates to it. The local function instore.rsis removed; all 5 call sites use the shared function.4. Derive
MILLISECONDS_PER_SLOTand removeSECONDS_PER_SLOT(crates/blockchain/src/lib.rs, test files)Three independent time constants were defined:
SECONDS_PER_SLOTwas only used in two test files and was redundant.MILLISECONDS_PER_SLOTwas independently defined rather than derived, creating a consistency risk if either base constant changes.Fix: Removed
SECONDS_PER_SLOT. MadeMILLISECONDS_PER_SLOT = MILLISECONDS_PER_INTERVAL * INTERVALS_PER_SLOT. Updated test callers (forkchoice_spectests.rs,signature_spectests.rs) to usegenesis_time * 1000 + slot * MILLISECONDS_PER_SLOT, matching the production arithmetic inget_proposal_head.How to test
All existing tests cover these changes — no new behavior was introduced.
cargo test --workspace --release cargo clippy --workspace --tests -- -D warnings cargo fmt --all -- --checkAll 102 tests pass.