@@ -50,9 +50,12 @@ impl From<&StatusMessage> for ChainId {
5050}
5151
5252const BATCHES_PER_PEER : usize = 1 ;
53- const EPOCHS_PER_REQUEST : u64 = 2 ; // max 32
54- const GREEDY_MODE_BATCH_MULTIPLIER : usize = 3 ;
55- const GREEDY_MODE_PEER_LIMIT : usize = 2 ;
53+ const EPOCHS_PER_REQUEST : u64 = if cfg ! ( test) {
54+ 2
55+ } else {
56+ // max 32
57+ 1
58+ } ;
5659const MAX_SYNC_DISTANCE_IN_SLOTS : u64 = 10000 ;
5760const NOT_ENOUGH_PEERS_MESSAGE_COOLDOWN : Duration = Duration :: from_secs ( 10 ) ;
5861const PEER_UPDATE_COOLDOWN_IN_SECONDS : u64 = 12 ;
@@ -731,14 +734,8 @@ impl SyncManager {
731734 }
732735
733736 fn peer_sync_batch_assignments ( peers : & [ PeerId ] ) -> impl Iterator < Item = PeerId > + ' _ {
734- let batches_per_peer = if peers. len ( ) <= GREEDY_MODE_PEER_LIMIT {
735- BATCHES_PER_PEER * GREEDY_MODE_BATCH_MULTIPLIER
736- } else {
737- BATCHES_PER_PEER
738- } ;
739-
740737 core:: iter:: repeat ( peers)
741- . take ( batches_per_peer )
738+ . take ( BATCHES_PER_PEER )
742739 . flatten ( )
743740 . copied ( )
744741 }
@@ -956,6 +953,7 @@ mod tests {
956953 let current_slot = 20_001 ;
957954 let local_head_slot = 3000 ;
958955 let local_finalized_slot = 1000 ;
956+ let slots_per_request = EPOCHS_PER_REQUEST * <Mainnet as Preset >:: SlotsPerEpoch :: U64 ;
959957
960958 let peer_status = StatusMessage {
961959 fork_digest : H32 :: default ( ) ,
@@ -977,8 +975,8 @@ mod tests {
977975 local_finalized_slot,
978976 ) ?;
979977
980- let sync_range_from = local_head_slot + 64 * 3 * i + 1 ;
981- let sync_range_to = sync_range_from + 64 * 3 - 1 ;
978+ let sync_range_from = local_head_slot + slots_per_request * i + 1 ;
979+ let sync_range_to = sync_range_from + slots_per_request - 1 ;
982980
983981 assert_eq ! ( sync_manager. last_sync_range, sync_range_from..sync_range_to) ;
984982
@@ -991,11 +989,7 @@ mod tests {
991989 batches
992990 . into_iter ( )
993991 . map ( |batch| ( batch. start_slot , batch. count ) ) ,
994- [
995- ( sync_range_from, 64 ) ,
996- ( sync_range_from + 64 , 64 ) ,
997- ( sync_range_from + 64 * 2 , 64 ) ,
998- ] ,
992+ [ ( sync_range_from, slots_per_request) ] ,
999993 ) ;
1000994 }
1001995
@@ -1008,6 +1002,7 @@ mod tests {
10081002 let current_slot = 20_001 ;
10091003 let local_head_slot = 3000 ;
10101004 let local_finalized_slot = 1000 ;
1005+ let slots_per_request = EPOCHS_PER_REQUEST * <Mainnet as Preset >:: SlotsPerEpoch :: U64 ;
10111006
10121007 let peer_status = StatusMessage {
10131008 fork_digest : H32 :: default ( ) ,
@@ -1029,7 +1024,7 @@ mod tests {
10291024 ) ?;
10301025
10311026 let sync_range_from = local_head_slot + 1 ;
1032- let sync_range_to = sync_range_from + 64 * 3 - 1 ;
1027+ let sync_range_to = sync_range_from + slots_per_request - 1 ;
10331028
10341029 assert_eq ! ( sync_manager. last_sync_range, sync_range_from..sync_range_to) ;
10351030
@@ -1044,7 +1039,7 @@ mod tests {
10441039 ) ?;
10451040
10461041 let sync_range_from = local_head_slot - 32 + 1 ;
1047- let sync_range_to = sync_range_from + 64 * 3 - 1 ;
1042+ let sync_range_to = sync_range_from + slots_per_request - 1 ;
10481043
10491044 assert_eq ! ( sync_manager. last_sync_range, sync_range_from..sync_range_to) ;
10501045 }
@@ -1062,8 +1057,8 @@ mod tests {
10621057 local_finalized_slot,
10631058 ) ?;
10641059
1065- let sync_range_from = local_finalized_slot + 64 * 3 * i + 1 ;
1066- sync_range_to = sync_range_from + 64 * 3 - 1 ;
1060+ let sync_range_from = local_finalized_slot + slots_per_request * i + 1 ;
1061+ sync_range_to = sync_range_from + slots_per_request - 1 ;
10671062
10681063 assert_eq ! ( sync_manager. last_sync_range, sync_range_from..sync_range_to) ;
10691064
@@ -1080,7 +1075,7 @@ mod tests {
10801075 ) ?;
10811076
10821077 let sync_range_from = local_head_slot - 32 + 1 ;
1083- let sync_range_to = sync_range_from + 64 * 3 - 1 ;
1078+ let sync_range_to = sync_range_from + slots_per_request - 1 ;
10841079
10851080 assert_eq ! ( sync_manager. last_sync_range, sync_range_from..sync_range_to) ;
10861081
0 commit comments