apollo_consensus_orchestrator: avoid cloning the synced block's state diff to compute accessed keys - #14974
Conversation
PR SummaryLow Risk Overview
The Reviewed by Cursor Bugbot for commit 2b36420. Bugbot is set up for automated code reviews on this repo. Configure here. |
…g accessed keys try_sync cloned the full ThinStateDiff of the synced block just to borrow it as a CommitmentStateDiff for compute_accessed_keys. Move the state diff into the CommitmentStateDiff instead (a cheap field rename) and move it back afterward, since sync_block is later forwarded to add_sync_block by value. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SJn1K1NgLztcwQaKCseg7m
…cross the diff conversion Code review caught that the previous commit's round-trip through CommitmentStateDiff silently dropped ThinStateDiff::deprecated_declared_classes (no counterpart in CommitmentStateDiff), which feeds the state-diff hash and storage. Carry the field across the conversion explicitly, and add test coverage asserting add_sync_block receives the state diff unchanged. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SJn1K1NgLztcwQaKCseg7m
14da353 to
2b36420
Compare
Summary
Follow-up performance optimization on top of #14962 (merged), which added
BlockAccessedKeysData::compute_accessed_keysand wired it intotry_syncinsequencer_consensus_context.rs.In
try_sync, computing the accessed keys for a synced block did:This deep-clones the entire
ThinStateDiffof the synced block — which can hold thousands of storage/nonce/class-hash entries for a full block — purely to obtain an owned value to convert into a borrowedCommitmentStateDiff. The clone exists only becausesync_blockis later moved by value intoself.deps.batcher.add_sync_block(sync_block, accessed_keys), so the original state diff had to be preserved.Since
From<ThinStateDiff> for CommitmentStateDiff(and the reverse) are cheap field-moves (no allocation) inblockifier::state::cached_state, this PR instead moves the state diff into theCommitmentStateDiffviastd::mem::take, computes the accessed keys, and moves it back — avoiding the clone of the block's storage diff on the sync path.One subtlety:
CommitmentStateDiffhas nodeprecated_declared_classesfield (present onThinStateDiff, used by the state-diff hash and by storage), so that field is carried across the conversion explicitly instead of being silently dropped.This runs once per synced block height, on the consensus sync path.
Changes
sequencer_consensus_context.rs: avoid the clone intry_sync, preservingdeprecated_declared_classesacross theThinStateDiff⇄CommitmentStateDiffround-trip.sequencer_consensus_context_test.rs: extendedtry_sync_forwards_accessed_keys_from_centralizedto use a non-empty state diff (includingdeprecated_declared_classes) and assertadd_sync_blockreceives it unchanged.Test plan
cargo build -p apollo_consensus_orchestratorSEED=0 cargo test -p apollo_consensus_orchestrator(203 passed)cargo clippy -p apollo_consensus_orchestrator --all-targets(clean)scripts/rust_fmt.shdeprecated_declared_classes, missing test coverage)Generated by Claude Code