@@ -429,12 +429,13 @@ impl<
429429 let block = self . get_finalized_block( height) . await ;
430430 result. send( block) . unwrap_or_else( |_| warn!( ?height, "Failed to send block to orchestrator" ) ) ;
431431 }
432- Orchestration :: Processed { height, digest } => {
432+ Orchestration :: Processed { height, digest, commitment } => {
433433 // Update metrics
434434 self . processed_height. set( height as i64 ) ;
435435
436436 // Cancel any outstanding requests (by height and by digest)
437- resolver. cancel( Request :: <B >:: Block ( digest) ) . await ;
437+ resolver. cancel( Request :: <B >:: Block ( commitment) ) . await ;
438+ resolver. cancel( Request :: <B >:: CodingCommitment { height, digest } ) . await ;
438439 resolver. retain( Request :: <B >:: Finalized { height } . predicate( ) ) . await ;
439440
440441 // If finalization exists, prune the archives
@@ -471,9 +472,9 @@ impl<
471472
472473 // Iterate backwards, repairing blocks as we go.
473474 while cursor. height( ) > height {
474- let commitment = cursor. parent( ) ;
475- let Some ( commitment) = shard_layer. get_digest ( & commitment ) . await else {
476- dbg! ( "Missing block digest" ) ;
475+ let digest = cursor. parent( ) ;
476+ let Some ( commitment) = shard_layer. get_commitment ( & digest ) . await else {
477+ resolver . fetch ( Request :: < B > :: CodingCommitment { digest, height : cursor . height ( ) . saturating_sub ( 1 ) } ) . await ;
477478 break ;
478479 } ;
479480
@@ -519,6 +520,14 @@ impl<
519520 } ;
520521 let _ = response. send( block. encode( ) . into( ) ) ;
521522 }
523+ Request :: CodingCommitment { digest, .. } => {
524+ // Check for coding commitment locally
525+ let Some ( commitment) = shard_layer. get_commitment( & digest) . await else {
526+ debug!( ?digest, "coding commitment missing on request" ) ;
527+ continue ;
528+ } ;
529+ let _ = response. send( commitment. encode( ) . into( ) ) ;
530+ }
522531 Request :: Finalized { height } => {
523532 // Get finalization
524533 let Some ( finalization) = self . get_finalization_by_height( height) . await else {
@@ -574,6 +583,24 @@ impl<
574583 debug!( ?commitment, height, "received block" ) ;
575584 let _ = response. send( true ) ;
576585 } ,
586+ Request :: CodingCommitment { digest, height } => {
587+ // Parse block digest and height
588+ let Ok ( commitment) = B :: Commitment :: decode_cfg( value. as_ref( ) , & ( ) ) else {
589+ let _ = response. send( false ) ;
590+ continue ;
591+ } ;
592+
593+ // Persist the commitment.
594+ shard_layer. put_commitment( height, digest, commitment) . await ;
595+
596+ // If we have the block, persist it and its finalization.
597+ if let Some ( block) = self . find_block( & mut shard_layer, commitment) . await {
598+ let finalization = self . cache. get_finalization_for( commitment) . await ;
599+ self . finalize( block. height( ) , commitment, block. clone( ) , finalization, & mut notifier_tx) . await ;
600+ }
601+
602+ let _ = response. send( true ) ;
603+ } ,
577604 Request :: Finalized { height } => {
578605 // Parse finalization
579606 let Ok ( ( finalization, block) ) = <( Finalization <V , B :: Commitment >, B ) >:: decode_cfg( value, & ( ( ) , self . codec_config. clone( ) ) ) else {
0 commit comments