@@ -418,13 +418,17 @@ async fn wait_for_validator_height<H: TestHarness>(
418418async fn assert_validator_matches_canonical < H : TestHarness > (
419419 validator : & HailstormValidator < H > ,
420420 canonical : & [ CanonicalEntry < H > ] ,
421+ num_participants : u16 ,
421422 label : & str ,
422423) {
424+ let genesis_digest = H :: digest ( & H :: genesis_block ( num_participants) ) ;
423425 let delivered = validator. application . blocks ( ) ;
424426 for ( height, block) in delivered {
425- let ( _ , expected_digest, _ ) = canonical
427+ let expected_digest = canonical
426428 . iter ( )
427429 . find ( |( expected_height, _, _) | * expected_height == height)
430+ . map ( |( _, digest, _) | * digest)
431+ . or_else ( || ( height == Height :: zero ( ) ) . then_some ( genesis_digest) )
428432 . unwrap_or_else ( || {
429433 panic ! (
430434 "{label}: unexpected delivered block at height {}" ,
@@ -433,25 +437,27 @@ async fn assert_validator_matches_canonical<H: TestHarness>(
433437 } ) ;
434438 assert_eq ! (
435439 block. digest( ) ,
436- * expected_digest,
440+ expected_digest,
437441 "{label}: application delivered wrong digest at height {}" ,
438442 height. get( )
439443 ) ;
440444 }
441445
442446 if let Some ( ( height, digest) ) = validator. application . tip ( ) {
443- let ( _, expected_digest, _) = canonical
444- . iter ( )
445- . find ( |( expected_height, _, _) | * expected_height == height)
446- . unwrap_or_else ( || {
447- panic ! (
448- "{label}: unexpected delivered tip at height {}" ,
449- height. get( )
450- )
451- } ) ;
447+ let ( expected_height, expected_digest) =
448+ if let Some ( ( expected_height, expected_digest, _) ) = canonical. last ( ) {
449+ ( * expected_height, * expected_digest)
450+ } else {
451+ ( Height :: zero ( ) , genesis_digest)
452+ } ;
453+ assert_eq ! (
454+ height,
455+ expected_height,
456+ "{label}: application reported wrong tip height" ,
457+ ) ;
452458 assert_eq ! (
453459 digest,
454- * expected_digest,
460+ expected_digest,
455461 "{label}: application reported wrong tip digest at height {}" ,
456462 height. get( )
457463 ) ;
@@ -508,12 +514,19 @@ async fn assert_validator_matches_canonical<H: TestHarness>(
508514async fn assert_active_validators_match_canonical < H : TestHarness > (
509515 validators : & [ Option < HailstormValidator < H > > ] ,
510516 canonical : & [ CanonicalEntry < H > ] ,
517+ num_participants : u16 ,
511518) {
512519 for idx in active_validator_indices ( validators) {
513520 let validator = validators[ idx]
514521 . as_ref ( )
515522 . expect ( "active validator should be present" ) ;
516- assert_validator_matches_canonical ( validator, canonical, & format ! ( "validator_{idx}" ) ) . await ;
523+ assert_validator_matches_canonical (
524+ validator,
525+ canonical,
526+ num_participants,
527+ & format ! ( "validator_{idx}" ) ,
528+ )
529+ . await ;
517530 }
518531}
519532
@@ -650,7 +663,12 @@ async fn advance_hailstorm_to<H: TestHarness>(
650663 finalize_hailstorm_height ( pending, context, state) . await ;
651664 }
652665
653- assert_active_validators_match_canonical ( state. validators , state. canonical ) . await ;
666+ assert_active_validators_match_canonical (
667+ state. validators ,
668+ state. canonical ,
669+ state. participants . len ( ) as u16 ,
670+ )
671+ . await ;
654672}
655673
656674/// Stress marshal with repeated validator crashes and recoveries while a
@@ -857,7 +875,12 @@ pub fn hailstorm<H: TestHarness>(
857875 . await ;
858876 }
859877 }
860- assert_active_validators_match_canonical ( & validators, & canonical) . await ;
878+ assert_active_validators_match_canonical (
879+ & validators,
880+ & canonical,
881+ participants. len ( ) as u16 ,
882+ )
883+ . await ;
861884 info ! (
862885 seed,
863886 shutdown_idx,
0 commit comments