Skip to content

Commit 4f29510

Browse files
apollo_batcher: add commitment tasks (#11293)
1 parent 5c8efd1 commit 4f29510

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

crates/apollo_batcher/src/batcher.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,16 +681,29 @@ impl Batcher {
681681
StorageCommitmentBlockHash::ParentHash(block_header_without_hash.parent_hash)
682682
};
683683

684+
let optional_state_diff_commitment = match &storage_commitment_block_hash {
685+
StorageCommitmentBlockHash::ParentHash(_) => None,
686+
StorageCommitmentBlockHash::Partial(PartialBlockHashComponents {
687+
ref header_commitments,
688+
..
689+
}) => Some(header_commitments.state_diff_commitment),
690+
};
691+
684692
self.commit_proposal_and_block(
685693
height,
686-
state_diff,
694+
state_diff.clone(),
687695
address_to_nonce,
688696
l1_transaction_hashes.iter().copied().collect(),
689697
Default::default(),
690698
storage_commitment_block_hash,
691699
)
692700
.await?;
693701

702+
self.commitment_manager
703+
.add_commitment_task(height, state_diff, optional_state_diff_commitment)
704+
.await
705+
.expect("The commitment offset unexpectedly doesn't match the given block height.");
706+
694707
// Write ready commitments to storage.
695708
self.write_commitment_results_to_storage().await?;
696709

@@ -732,7 +745,9 @@ impl Batcher {
732745
)
733746
.expect("Number of reverted transactions should fit in u64");
734747
let partial_block_hash_components =
735-
block_execution_artifacts.partial_block_hash_components().await;
748+
block_execution_artifacts.partial_block_hash_components();
749+
let state_diff_commitment =
750+
partial_block_hash_components.header_commitments.state_diff_commitment;
736751
let block_header_commitments = partial_block_hash_components.header_commitments.clone();
737752
let parent_proposal_commitment = self.get_parent_proposal_commitment(height)?;
738753
self.commit_proposal_and_block(
@@ -745,6 +760,15 @@ impl Batcher {
745760
)
746761
.await?;
747762

763+
self.commitment_manager
764+
.add_commitment_task(
765+
height,
766+
state_diff.clone(), // TODO(Nimrod): Remove the clone here.
767+
Some(state_diff_commitment),
768+
)
769+
.await
770+
.expect("The commitment offset unexpectedly doesn't match the given block height.");
771+
748772
// Write ready commitments to storage.
749773
self.write_commitment_results_to_storage().await?;
750774

@@ -784,8 +808,6 @@ impl Batcher {
784808
})
785809
}
786810

787-
// The `partial_block_hash_components` is optional as it doesn't exist for old blocks coming
788-
// from sync.
789811
async fn commit_proposal_and_block(
790812
&mut self,
791813
height: BlockNumber,

crates/apollo_batcher/src/batcher_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ async fn decision_reached() {
13181318
.with(eq(IndexSet::new()), eq(IndexSet::new()), eq(INITIAL_HEIGHT))
13191319
.returning(|_, _, _| Ok(()));
13201320

1321-
let expected_partial_block_hash = expected_artifacts.partial_block_hash_components().await;
1321+
let expected_partial_block_hash = expected_artifacts.partial_block_hash_components();
13221322
mock_dependencies
13231323
.storage_writer
13241324
.expect_commit_proposal()

crates/apollo_batcher/src/block_builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl BlockExecutionArtifacts {
203203
}
204204

205205
/// Returns the [PartialBlockHashComponents] based on the execution artifacts.
206-
pub async fn partial_block_hash_components(&self) -> PartialBlockHashComponents {
206+
pub fn partial_block_hash_components(&self) -> PartialBlockHashComponents {
207207
self.partial_block_hash_components.clone()
208208
}
209209
}

0 commit comments

Comments
 (0)