-
Notifications
You must be signed in to change notification settings - Fork 65
apollo_batcher,apollo_consensus_orchestrator: consensus over partial block hash #12451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: ariel/partial_block_hash_definition
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,8 +63,10 @@ use indexmap::{IndexMap, IndexSet}; | |
| #[cfg(test)] | ||
| use mockall::automock; | ||
| use starknet_api::block::{BlockHash, BlockNumber}; | ||
| use starknet_api::block_hash::block_hash_calculator::PartialBlockHashComponents; | ||
| use starknet_api::block_hash::state_diff_hash::calculate_state_diff_hash; | ||
| use starknet_api::block_hash::block_hash_calculator::{ | ||
| PartialBlockHash, | ||
| PartialBlockHashComponents, | ||
| }; | ||
| use starknet_api::consensus_transaction::InternalConsensusTransaction; | ||
| use starknet_api::core::{ContractAddress, GlobalRoot, Nonce}; | ||
| use starknet_api::state::{StateNumber, ThinStateDiff}; | ||
|
|
@@ -823,7 +825,21 @@ impl Batcher { | |
| ); | ||
| trace!("Rejected transactions: {:#?}, State diff: {:#?}.", rejected_tx_hashes, state_diff); | ||
|
|
||
| let state_diff_commitment = calculate_state_diff_hash(&state_diff); | ||
| if let StorageCommitmentBlockHash::Partial(ref components) = &storage_commitment_block_hash | ||
| { | ||
| self.prev_proposal_commitment = Some(( | ||
| height, | ||
| ProposalCommitment { | ||
| partial_block_hash: PartialBlockHash::from_partial_block_hash_components( | ||
| components, | ||
| ) | ||
| .map_err(|e| { | ||
| error!("Failed to compute partial block hash: {}", e); | ||
| BatcherError::InternalError | ||
| })?, | ||
| }, | ||
| )); | ||
| } | ||
|
|
||
| // Commit the proposal to the storage. | ||
| self.storage_writer | ||
|
|
@@ -833,8 +849,6 @@ impl Batcher { | |
| BatcherError::InternalError | ||
| })?; | ||
| info!("Successfully committed proposal for block {} to storage.", height); | ||
| self.prev_proposal_commitment = | ||
| Some((height, ProposalCommitment { state_diff_commitment })); | ||
|
|
||
| // Notify the L1 provider of the new block. | ||
| let rejected_l1_handler_tx_hashes = rejected_tx_hashes | ||
|
|
@@ -1131,25 +1145,30 @@ impl Batcher { | |
| Ok(Some(commitment)) | ||
| } | ||
| None => { | ||
| // Parent proposal commitment is not cached. Compute it from the stored state diff. | ||
| let mut state_diff = self | ||
| // Parent proposal commitment is not cached. Read partial block hash | ||
| // components from storage and compute the partial block hash. | ||
| let (_, components) = self | ||
| .storage_reader | ||
| .get_state_diff(prev_height) | ||
| .get_parent_hash_and_partial_block_hash_components(prev_height) | ||
| .map_err(|err| { | ||
| error!( | ||
| "Failed to read state diff for previous height {prev_height}: {}", | ||
| "Failed to read partial block hash components for previous height \ | ||
| {prev_height}: {}", | ||
| err | ||
| ); | ||
| BatcherError::InternalError | ||
| })? | ||
| .expect("Missing state diff for previous height."); | ||
|
|
||
| // Enforcing no deprecated classes (since v0.14.0). | ||
| // TODO(dafna): Remove once the state sync bug is fixed. | ||
| state_diff.deprecated_declared_classes = Vec::new(); | ||
| })?; | ||
| let components = | ||
| components.expect("Missing partial block hash components for previous height."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Panic on cache miss for ParentHash blocksLow Severity When |
||
|
|
||
| Ok(Some(ProposalCommitment { | ||
| state_diff_commitment: calculate_state_diff_hash(&state_diff), | ||
| partial_block_hash: PartialBlockHash::from_partial_block_hash_components( | ||
| &components, | ||
| ) | ||
| .map_err(|e| { | ||
| error!("Failed to compute partial block hash: {}", e); | ||
| BatcherError::InternalError | ||
| })?, | ||
| })) | ||
| } | ||
| } | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting cache before commit causes panic on retry
Medium Severity
self.prev_proposal_commitmentis now set beforecommit_proposalwrites to storage, whereas the old code set it after. Ifcommit_proposalfails and returns an error,prev_proposal_commitmentalready holdsSome((height, ...))for the uncommitted height. On a retry ofdecision_reachedfor the same height,get_parent_proposal_commitmentfinds this stale entry withh == heightbut needsprev_height == height - 1, triggering theassert_eq!and panicking.Additional Locations (1)
crates/apollo_batcher/src/batcher.rs#L1138-L1142