@@ -26,7 +26,9 @@ use apollo_batcher_types::batcher_types::{
2626use apollo_batcher_types:: errors:: BatcherError ;
2727use apollo_class_manager_types:: transaction_converter:: TransactionConverter ;
2828use apollo_class_manager_types:: SharedClassManagerClient ;
29- use apollo_committer_types:: communication:: SharedCommitterClient ;
29+ use apollo_committer_types:: committer_types:: { CommitBlockResponse , RevertBlockResponse } ;
30+ use apollo_committer_types:: communication:: { CommitterClientResponse , SharedCommitterClient } ;
31+ use apollo_committer_types:: errors:: CommitterClientResult ;
3032use apollo_infra:: component_definitions:: { default_component_start_fn, ComponentStarter } ;
3133use apollo_l1_provider_types:: errors:: { L1ProviderClientError , L1ProviderError } ;
3234use apollo_l1_provider_types:: { SessionState , SharedL1ProviderClient } ;
@@ -705,7 +707,7 @@ impl Batcher {
705707 . expect ( "The commitment offset unexpectedly doesn't match the given block height." ) ;
706708
707709 // Write ready commitments to storage.
708- self . write_commitment_results_to_storage ( ) . await ?;
710+ self . handle_committer_results ( ) . await ?;
709711
710712 LAST_SYNCED_BLOCK_HEIGHT . set_lossy ( block_number. 0 ) ;
711713 SYNCED_TRANSACTIONS . increment (
@@ -770,7 +772,7 @@ impl Batcher {
770772 . expect ( "The commitment offset unexpectedly doesn't match the given block height." ) ;
771773
772774 // Write ready commitments to storage.
773- self . write_commitment_results_to_storage ( ) . await ?;
775+ self . handle_committer_results ( ) . await ?;
774776
775777 let execution_infos = block_execution_artifacts
776778 . execution_data
@@ -1152,66 +1154,95 @@ impl Batcher {
11521154 }
11531155
11541156 /// Writes the ready commitment results to storage.
1155- async fn write_commitment_results_to_storage ( & mut self ) -> BatcherResult < ( ) > {
1157+ async fn handle_committer_results ( & mut self ) -> BatcherResult < ( ) > {
11561158 let commitment_results = self . commitment_manager . get_commitment_results ( ) . await ;
11571159 for commitment_task_output in commitment_results. into_iter ( ) {
1158- let height = commitment_task_output. height ;
1159-
1160- // Decide whether to finalize the block hash based on the config.
1161- let should_finalize_block_hash =
1162- match self . config . first_block_with_partial_block_hash . as_ref ( ) {
1163- Some ( FirstBlockWithPartialBlockHash { block_number, .. } ) => {
1164- height >= * block_number
1165- }
1166- None => true ,
1167- } ;
1168-
1169- // Get the final commitment.
1170- let FinalBlockCommitment { height, block_hash, global_root } =
1171- ApolloCommitmentManager :: final_commitment_output (
1172- self . storage_reader . clone ( ) ,
1173- commitment_task_output,
1174- should_finalize_block_hash,
1175- )
1176- . map_err ( |err| {
1177- error ! ( "Failed to get the final commitment output for height {height}: {err}" ) ;
1178- BatcherError :: InternalError
1179- } ) ?;
1180-
1181- // Verify the first new block hash matches the configured block hash.
1182- if let Some ( FirstBlockWithPartialBlockHash {
1183- block_number,
1184- block_hash : expected_block_hash,
1185- ..
1186- } ) = self . config . first_block_with_partial_block_hash . as_ref ( )
1187- {
1188- if height == * block_number {
1189- assert_eq ! (
1190- * expected_block_hash,
1191- block_hash. expect(
1192- "The block hash of the first new block should be finalized and \
1193- therefore set."
1194- ) ,
1195- "The calculated block hash of the first new block ({block_hash:?}) does \
1196- not match the configured block hash ({expected_block_hash:?})"
1197- ) ;
1160+ match commitment_task_output. committer_response {
1161+ CommitterClientResponse :: CommitBlock ( commit_response) => {
1162+ self . write_commitment_result_to_storage (
1163+ commitment_task_output. height ,
1164+ commit_response,
1165+ )
1166+ . await ?;
1167+ }
1168+ CommitterClientResponse :: RevertBlock ( revert_response) => {
1169+ self . handle_revert_result ( commitment_task_output. height , revert_response)
1170+ . await ?;
11981171 }
11991172 }
1173+ }
1174+ Ok ( ( ) )
1175+ }
12001176
1201- // Write the block hash and global root to storage.
1202- self . storage_writer
1203- . set_global_root_and_block_hash ( height, global_root, block_hash)
1204- . map_err ( |err| {
1205- error ! (
1206- "Failed to set global root and block hash in storage for {height}: {err}"
1207- ) ;
1208- BatcherError :: InternalError
1209- } ) ?;
1177+ async fn write_commitment_result_to_storage (
1178+ & mut self ,
1179+ height : BlockNumber ,
1180+ commit_response_result : CommitterClientResult < CommitBlockResponse > ,
1181+ ) -> BatcherResult < ( ) > {
1182+ // TODO: Handle commit block error.
1183+ let commit_response = commit_response_result. expect ( "Commit block error." ) ;
1184+
1185+ // Decide whether to finalize the block hash based on the config.
1186+ let should_finalize_block_hash =
1187+ match self . config . first_block_with_partial_block_hash . as_ref ( ) {
1188+ Some ( FirstBlockWithPartialBlockHash { block_number, .. } ) => {
1189+ height >= * block_number
1190+ }
1191+ None => true ,
1192+ } ;
1193+
1194+ // Get the final commitment.
1195+ let FinalBlockCommitment { height, block_hash, global_root } =
1196+ ApolloCommitmentManager :: final_commitment_output (
1197+ self . storage_reader . clone ( ) ,
1198+ commit_response,
1199+ height,
1200+ should_finalize_block_hash,
1201+ )
1202+ . map_err ( |err| {
1203+ error ! ( "Failed to get the final commitment output for height {height}: {err}" ) ;
1204+ BatcherError :: InternalError
1205+ } ) ?;
1206+
1207+ // Verify the first new block hash matches the configured block hash.
1208+ if let Some ( FirstBlockWithPartialBlockHash {
1209+ block_number,
1210+ block_hash : expected_block_hash,
1211+ ..
1212+ } ) = self . config . first_block_with_partial_block_hash . as_ref ( )
1213+ {
1214+ if height == * block_number {
1215+ assert_eq ! (
1216+ * expected_block_hash,
1217+ block_hash. expect(
1218+ "The block hash of the first new block should be finalized and therefore \
1219+ set."
1220+ ) ,
1221+ "The calculated block hash of the first new block ({block_hash:?}) does not \
1222+ match the configured block hash ({expected_block_hash:?})"
1223+ ) ;
1224+ }
12101225 }
12111226
1227+ // Write the block hash and global root to storage.
1228+ self . storage_writer
1229+ . set_global_root_and_block_hash ( height, global_root, block_hash)
1230+ . map_err ( |err| {
1231+ error ! ( "Failed to set global root and block hash in storage for {height}: {err}" ) ;
1232+ BatcherError :: InternalError
1233+ } ) ?;
1234+
12121235 Ok ( ( ) )
12131236 }
12141237
1238+ async fn handle_revert_result (
1239+ & mut self ,
1240+ _height : BlockNumber ,
1241+ _revert_response : CommitterClientResult < RevertBlockResponse > ,
1242+ ) -> BatcherResult < ( ) > {
1243+ unimplemented ! ( )
1244+ }
1245+
12151246 pub fn get_block_hash ( & self , block_number : BlockNumber ) -> BatcherResult < BlockHash > {
12161247 self . storage_reader
12171248 . get_block_hash ( block_number)
0 commit comments