@@ -43,7 +43,11 @@ use types::{
4343
4444const D : Duration = Duration :: new ( 0 , 0 ) ;
4545
46- /// Instruct the testing rig how to complete requests for _by_range requests
46+ /// Configuration for how the test rig should respond to sync requests.
47+ ///
48+ /// Controls simulated peer behavior during lookup tests, including RPC errors,
49+ /// invalid responses, and custom block processing results. Use builder methods
50+ /// to configure specific failure scenarios.
4751#[ derive( Default , Educe ) ]
4852#[ educe( Debug ) ]
4953pub struct CompleteStrategy {
@@ -118,15 +122,15 @@ impl CompleteStrategy {
118122 self
119123 }
120124
121- fn process_result < F > ( mut self , f : F ) -> Self
125+ fn with_process_result < F > ( mut self , f : F ) -> Self
122126 where
123127 F : Fn ( ) -> BlockProcessingResult + Send + Sync + ' static ,
124128 {
125129 self . process_result_conditional = Some ( Box :: new ( move |_| Some ( f ( ) ) ) ) ;
126130 self
127131 }
128132
129- fn block_imported_while_processing ( mut self , block_root : Hash256 ) -> Self {
133+ fn with_block_imported_while_processing ( mut self , block_root : Hash256 ) -> Self {
130134 self . block_imported_while_processing = Some ( block_root) ;
131135 self
132136 }
@@ -264,8 +268,11 @@ impl TestRig {
264268 } )
265269 }
266270
267- // Network / external peers simulated behaviour
268-
271+ /// Runs the sync simulation until all event queues are empty.
272+ ///
273+ /// Processes events from network, beacon processor, and sync queues in random order
274+ /// to test for race conditions. The `complete_strategy` controls how the simulated
275+ /// peers respond to requests (e.g., returning errors, wrong data, or valid responses).
269276 async fn simulate ( & mut self , complete_strategy : CompleteStrategy ) {
270277 self . complete_strategy = complete_strategy;
271278 self . log ( & format ! (
@@ -289,10 +296,10 @@ impl TestRig {
289296 let lookup = self . seen_lookups . entry ( id) . or_insert ( SeenLookup {
290297 id,
291298 block_root,
292- max_seen_peers : <_ >:: default ( ) ,
299+ seen_peers : <_ >:: default ( ) ,
293300 } ) ;
294301 for peer in peers {
295- lookup. max_seen_peers . insert ( peer) ;
302+ lookup. seen_peers . insert ( peer) ;
296303 }
297304 }
298305
@@ -1019,38 +1026,38 @@ impl TestRig {
10191026
10201027 fn assert_peers_at_lookup_of_slot ( & self , slot : u64 , expected_peers : usize ) {
10211028 let lookup = self . lookup_at_slot ( slot) ;
1022- if lookup. max_seen_peers . len ( ) != expected_peers {
1029+ if lookup. seen_peers . len ( ) != expected_peers {
10231030 panic ! (
10241031 "Expected lookup of slot {slot} to have {expected_peers} peers but had {:?}" ,
1025- lookup. max_seen_peers
1032+ lookup. seen_peers
10261033 )
10271034 }
10281035 }
10291036
10301037 /// Total count of unique lookups created
10311038 fn created_lookups ( & self ) -> usize {
1032- // Substract initial value to allow resetting metrics mid test
1039+ // Subtract initial value to allow resetting metrics mid test
10331040 self . sync_manager . block_lookups ( ) . metrics ( ) . created_lookups
10341041 - self . initial_block_lookups_metrics . created_lookups
10351042 }
10361043
10371044 /// Total count of lookups completed or dropped
10381045 fn dropped_lookups ( & self ) -> usize {
1039- // Substract initial value to allow resetting metrics mid test
1046+ // Subtract initial value to allow resetting metrics mid test
10401047 self . sync_manager . block_lookups ( ) . metrics ( ) . dropped_lookups
10411048 - self . initial_block_lookups_metrics . dropped_lookups
10421049 }
10431050
10441051 fn completed_lookups ( & self ) -> usize {
1045- // Substract initial value to allow resetting metrics mid test
1052+ // Subtract initial value to allow resetting metrics mid test
10461053 self . sync_manager
10471054 . block_lookups ( )
10481055 . metrics ( )
10491056 . completed_lookups
10501057 - self . initial_block_lookups_metrics . completed_lookups
10511058 }
10521059
1053- fn reset_metrics ( & mut self ) {
1060+ fn capture_metrics_baseline ( & mut self ) {
10541061 self . initial_block_lookups_metrics = self . sync_manager . block_lookups ( ) . metrics ( ) . clone ( )
10551062 }
10561063
@@ -1636,7 +1643,7 @@ async fn happy_path_unknown_block_parent(depth: usize) {
16361643 }
16371644}
16381645
1639- /// Assert that sync completes from a GossipUnknownParentBlob / UknownDataColumnParent
1646+ /// Assert that sync completes from a GossipUnknownParentBlob / UnknownDataColumnParent
16401647async fn happy_path_unknown_data_parent ( depth : usize ) {
16411648 let Some ( mut r) = TestRig :: new_after_deneb ( ) else {
16421649 return ;
@@ -1767,7 +1774,7 @@ async fn too_many_download_failures(depth: usize) {
17671774
17681775 // Trigger sync again for same block, and complete successfully.
17691776 // Asserts that the lookup is not on a blacklist
1770- r. reset_metrics ( ) ;
1777+ r. capture_metrics_baseline ( ) ;
17711778 r. trigger_with_last_block ( ) ;
17721779 r. simulate ( CompleteStrategy :: happy_path ( ) ) . await ;
17731780 r. assert_successful_lookup_sync ( ) ;
@@ -1780,7 +1787,7 @@ async fn too_many_processing_failures(depth: usize) {
17801787 // Simulate that a peer always returns empty
17811788 r. simulate (
17821789 CompleteStrategy :: new ( )
1783- . process_result ( || BlockProcessingResult :: Err ( BlockError :: BlockSlotLimitReached ) ) ,
1790+ . with_process_result ( || BlockProcessingResult :: Err ( BlockError :: BlockSlotLimitReached ) ) ,
17841791 )
17851792 . await ;
17861793 // We register multiple penalties, the lookup fails and sync does not progress
@@ -1789,7 +1796,7 @@ async fn too_many_processing_failures(depth: usize) {
17891796
17901797 // Trigger sync again for same block, and complete successfully.
17911798 // Asserts that the lookup is not on a blacklist
1792- r. reset_metrics ( ) ;
1799+ r. capture_metrics_baseline ( ) ;
17931800 r. trigger_with_last_block ( ) ;
17941801 r. simulate ( CompleteStrategy :: happy_path ( ) ) . await ;
17951802 r. assert_successful_lookup_sync ( ) ;
@@ -1833,7 +1840,7 @@ async fn test_single_block_lookup_ignored_response() {
18331840 let mut r = TestRig :: default ( ) ;
18341841 r. build_chain_and_trigger_last_block ( 1 ) . await ;
18351842 // Send an Ignored response, the request should be dropped
1836- r. simulate ( CompleteStrategy :: new ( ) . process_result ( || BlockProcessingResult :: Ignored ) )
1843+ r. simulate ( CompleteStrategy :: new ( ) . with_process_result ( || BlockProcessingResult :: Ignored ) )
18371844 . await ;
18381845 // The block was not actually imported
18391846 r. assert_head_slot ( 0 ) ;
@@ -1848,7 +1855,7 @@ async fn test_single_block_lookup_duplicate_response() {
18481855 let mut r = TestRig :: default ( ) ;
18491856 r. build_chain_and_trigger_last_block ( 1 ) . await ;
18501857 // Send an Ignored response, the request should be dropped
1851- r. simulate ( CompleteStrategy :: new ( ) . process_result ( || {
1858+ r. simulate ( CompleteStrategy :: new ( ) . with_process_result ( || {
18521859 BlockProcessingResult :: Err ( BlockError :: DuplicateFullyImported ( Hash256 :: ZERO ) )
18531860 } ) )
18541861 . await ;
@@ -1898,7 +1905,7 @@ async fn lookups_form_chain() {
18981905 for slot in 1 ..=( depth as u64 ) {
18991906 let lookup = r. lookup_by_root ( r. block_root_at_slot ( slot) ) ;
19001907 assert_eq ! (
1901- lookup. max_seen_peers . len( ) ,
1908+ lookup. seen_peers . len( ) ,
19021909 1 + depth - slot as usize ,
19031910 "Unexpected peer count for lookup at slot {slot}"
19041911 ) ;
@@ -2033,7 +2040,7 @@ async fn test_same_chain_race_condition() {
20332040 r. trigger_with_last_block ( ) ;
20342041
20352042 let block_root_to_skip = r. block_root_at_slot ( 3 ) ;
2036- r. simulate ( CompleteStrategy :: new ( ) . block_imported_while_processing ( block_root_to_skip) )
2043+ r. simulate ( CompleteStrategy :: new ( ) . with_block_imported_while_processing ( block_root_to_skip) )
20372044 . await ;
20382045
20392046 // Try to get this block again while the chain is being processed. We should not request it again.
0 commit comments