@@ -421,7 +421,7 @@ fn finalization_waits_for_durable_block_before_advancing_finalized() {
421421}
422422
423423#[ test_traced]
424- fn syncing_block_forkchoice_retries_before_acknowledging ( ) {
424+ fn syncing_certificate_head_falls_back_to_block_anchor_before_acknowledging ( ) {
425425 deterministic:: Runner :: default ( ) . start ( |context| async move {
426426 let provider = StubExecutionProvider :: default ( ) ;
427427 let release_head_forkchoice = provider. pause_next_forkchoice ( ) ;
@@ -443,6 +443,7 @@ fn syncing_block_forkchoice_retries_before_acknowledging() {
443443 mailbox. finalization ( round ( 2 ) , future_head) ;
444444 wait_until ( & context, || provider. forkchoices ( ) . len ( ) == 1 ) . await ;
445445
446+ provider. set_syncing_forkchoice_head ( future_head. 0 ) ;
446447 provider. set_forkchoices_syncing ( true ) ;
447448 let block = make_block_at_round ( 1 , B256 :: ZERO , round ( 1 ) ) ;
448449 let finalized = block. block_hash ( ) ;
@@ -452,25 +453,70 @@ fn syncing_block_forkchoice_retries_before_acknowledging() {
452453 release_head_forkchoice
453454 . send ( ( ) )
454455 . expect ( "the head FCU should still be waiting" ) ;
455- wait_until ( & context, || provider. forkchoices ( ) . len ( ) == 2 ) . await ;
456+ wait_until ( & context, || provider. forkchoices ( ) . len ( ) == 3 ) . await ;
456457
457458 let mut waiter = Box :: pin ( waiter) ;
458459 tokio:: select! {
459- result = & mut waiter => panic!( "syncing FCU acknowledged the block: {result:?}" ) ,
460+ result = & mut waiter => panic!( "syncing block anchor acknowledged the block: {result:?}" ) ,
460461 _ = context. sleep( Duration :: from_millis( 100 ) ) => { }
461462 }
462463
463464 provider. set_forkchoices_syncing ( false ) ;
464465 waiter
465466 . await
466- . expect ( "valid retry should acknowledge the durable block" ) ;
467+ . expect ( "valid block anchor should acknowledge the durable block" ) ;
468+
469+ wait_until ( & context, || provider. forkchoices ( ) . len ( ) == 5 ) . await ;
467470
468471 let forkchoices = provider. forkchoices ( ) ;
469- assert_eq ! ( forkchoices. len( ) , 3 ) ;
470- assert_eq ! ( forkchoices[ 1 ] , forkchoices[ 2 ] ) ;
471- assert_eq ! ( forkchoices[ 2 ] . head_block_hash, future_head. 0 ) ;
472- assert_eq ! ( forkchoices[ 2 ] . safe_block_hash, finalized) ;
473- assert_eq ! ( forkchoices[ 2 ] . finalized_block_hash, finalized) ;
472+ assert_eq ! ( forkchoices[ 1 ] . head_block_hash, future_head. 0 ) ;
473+ assert_eq ! ( forkchoices[ 1 ] . safe_block_hash, finalized) ;
474+ assert_eq ! ( forkchoices[ 1 ] . finalized_block_hash, finalized) ;
475+
476+ assert_eq ! ( forkchoices[ 2 ] , forkchoices[ 3 ] ) ;
477+ assert_eq ! ( forkchoices[ 3 ] . head_block_hash, finalized) ;
478+ assert_eq ! ( forkchoices[ 3 ] . safe_block_hash, finalized) ;
479+ assert_eq ! ( forkchoices[ 3 ] . finalized_block_hash, finalized) ;
480+
481+ assert_eq ! ( forkchoices[ 4 ] , forkchoices[ 1 ] ) ;
482+ } ) ;
483+ }
484+
485+ #[ test_traced]
486+ fn known_certificate_head_finalizes_delivered_block_without_anchor ( ) {
487+ deterministic:: Runner :: default ( ) . start ( |context| async move {
488+ let provider = StubExecutionProvider :: default ( ) ;
489+
490+ let ( actor, mut mailbox) = init (
491+ context. child ( "follower_executor" ) ,
492+ Config {
493+ execution_provider : provider. clone ( ) ,
494+ execution_engine : provider. clone ( ) ,
495+ marshal : StubMarshal :: default ( ) ,
496+ epoch_strategy : FixedEpocher :: new ( EPOCH_LENGTH ) ,
497+ floor : Height :: zero ( ) ,
498+ fcu_heartbeat_interval : Duration :: from_secs ( 60 ) ,
499+ } ,
500+ ) ;
501+ actor. start ( ) ;
502+
503+ let future_head = digest ( 9 ) ;
504+ mailbox. finalization ( round ( 2 ) , future_head) ;
505+ wait_until ( & context, || provider. forkchoices ( ) . len ( ) == 1 ) . await ;
506+
507+ let block = make_block_at_round ( 1 , B256 :: ZERO , round ( 1 ) ) ;
508+ let finalized = block. block_hash ( ) ;
509+ let ( ack, waiter) = Exact :: handle ( ) ;
510+ assert ! ( mailbox. report( Update :: Block ( block. into( ) , ack) ) . accepted( ) ) ;
511+ waiter
512+ . await
513+ . expect ( "known certificate head should finalize the delivered block" ) ;
514+
515+ let forkchoices = provider. forkchoices ( ) ;
516+ assert_eq ! ( forkchoices. len( ) , 2 ) ;
517+ assert_eq ! ( forkchoices[ 1 ] . head_block_hash, future_head. 0 ) ;
518+ assert_eq ! ( forkchoices[ 1 ] . safe_block_hash, finalized) ;
519+ assert_eq ! ( forkchoices[ 1 ] . finalized_block_hash, finalized) ;
474520 } ) ;
475521}
476522
0 commit comments