@@ -21,7 +21,7 @@ use crate::routes::{build_chunk_handler_request, parse_chunk_handler_response};
21
21
22
22
use ic_async_utils:: JoinMap ;
23
23
use ic_base_types:: NodeId ;
24
- use ic_interfaces:: p2p:: state_sync:: { ChunkId , Chunkable , StateSyncArtifactId , StateSyncClient } ;
24
+ use ic_interfaces:: p2p:: state_sync:: { ChunkId , Chunkable , StateSyncArtifactId } ;
25
25
use ic_logger:: { error, info, ReplicaLogger } ;
26
26
use ic_quic_transport:: { Shutdown , Transport } ;
27
27
use rand:: {
@@ -42,7 +42,7 @@ const PARALLEL_CHUNK_DOWNLOADS: usize = 10;
42
42
const ONGOING_STATE_SYNC_CHANNEL_SIZE : usize = 200 ;
43
43
const CHUNK_DOWNLOAD_TIMEOUT : Duration = Duration :: from_secs ( 10 ) ;
44
44
45
- struct OngoingStateSync < T : Send > {
45
+ struct OngoingStateSync {
46
46
log : ReplicaLogger ,
47
47
rt : Handle ,
48
48
artifact_id : StateSyncArtifactId ,
@@ -58,7 +58,6 @@ struct OngoingStateSync<T: Send> {
58
58
// Event tasks
59
59
downloading_chunks : JoinMap < ChunkId , DownloadResult > ,
60
60
// State sync
61
- state_sync : Arc < dyn StateSyncClient < Message = T > > ,
62
61
state_sync_finished : bool ,
63
62
}
64
63
@@ -79,7 +78,6 @@ pub(crate) fn start_ongoing_state_sync<T: Send + 'static>(
79
78
metrics : OngoingStateSyncMetrics ,
80
79
tracker : Arc < Mutex < Box < dyn Chunkable < T > + Send > > > ,
81
80
artifact_id : StateSyncArtifactId ,
82
- state_sync : Arc < dyn StateSyncClient < Message = T > > ,
83
81
transport : Arc < dyn Transport > ,
84
82
) -> OngoingStateSyncHandle {
85
83
let ( new_peers_tx, new_peers_rx) = tokio:: sync:: mpsc:: channel ( ONGOING_STATE_SYNC_CHANNEL_SIZE ) ;
@@ -94,7 +92,6 @@ pub(crate) fn start_ongoing_state_sync<T: Send + 'static>(
94
92
allowed_downloads : 0 ,
95
93
chunks_to_download : Box :: new ( std:: iter:: empty ( ) ) ,
96
94
downloading_chunks : JoinMap :: new ( ) ,
97
- state_sync,
98
95
state_sync_finished : false ,
99
96
} ;
100
97
@@ -110,8 +107,8 @@ pub(crate) fn start_ongoing_state_sync<T: Send + 'static>(
110
107
}
111
108
}
112
109
113
- impl < T : ' static + Send > OngoingStateSync < T > {
114
- pub async fn run (
110
+ impl OngoingStateSync {
111
+ pub async fn run < T : ' static + Send > (
115
112
mut self ,
116
113
cancellation : CancellationToken ,
117
114
tracker : Arc < Mutex < Box < dyn Chunkable < T > + Send > > > ,
@@ -165,15 +162,12 @@ impl<T: 'static + Send> OngoingStateSync<T> {
165
162
self . metrics
166
163
. peers_serving_state
167
164
. set ( self . active_downloads . len ( ) as i64 ) ;
168
- // Conditions on when to exit (in addition to timeout)
169
- if self . state_sync_finished
170
- || self . active_downloads . is_empty ( )
171
- || self . state_sync . should_cancel ( & self . artifact_id )
172
- {
173
- info ! ( self . log, "Stopping ongoing state sync because: finished: {}; no peers: {}; should cancel: {};" ,
165
+ if self . state_sync_finished || self . active_downloads . is_empty ( ) {
166
+ info ! (
167
+ self . log,
168
+ "Stopping ongoing state sync because: finished: {}; no peers: {};" ,
174
169
self . state_sync_finished,
175
170
self . active_downloads. is_empty( ) ,
176
- self . state_sync. should_cancel( & self . artifact_id)
177
171
) ;
178
172
break ;
179
173
}
@@ -182,6 +176,7 @@ impl<T: 'static + Send> OngoingStateSync<T> {
182
176
while let Some ( Ok ( ( finished, _) ) ) = self . downloading_chunks . join_next ( ) . await {
183
177
self . handle_downloaded_chunk_result ( finished) ;
184
178
}
179
+ self . new_peers_rx . close ( ) ;
185
180
}
186
181
187
182
fn handle_downloaded_chunk_result (
@@ -215,7 +210,7 @@ impl<T: 'static + Send> OngoingStateSync<T> {
215
210
}
216
211
}
217
212
218
- fn spawn_chunk_downloads (
213
+ fn spawn_chunk_downloads < T : ' static + Send > (
219
214
& mut self ,
220
215
cancellation : CancellationToken ,
221
216
tracker : Arc < Mutex < Box < dyn Chunkable < T > + Send > > > ,
@@ -286,7 +281,7 @@ impl<T: 'static + Send> OngoingStateSync<T> {
286
281
}
287
282
}
288
283
289
- async fn download_chunk_task (
284
+ async fn download_chunk_task < T : ' static + Send > (
290
285
peer_id : NodeId ,
291
286
client : Arc < dyn Transport > ,
292
287
tracker : Arc < Mutex < Box < dyn Chunkable < T > + Send > > > ,
@@ -374,13 +369,11 @@ pub(crate) enum DownloadChunkError {
374
369
375
370
#[ cfg( test) ]
376
371
mod tests {
377
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
378
-
379
372
use axum:: http:: { Response , StatusCode } ;
380
373
use bytes:: { Bytes , BytesMut } ;
381
374
use ic_interfaces:: p2p:: state_sync:: AddChunkError ;
382
375
use ic_metrics:: MetricsRegistry ;
383
- use ic_p2p_test_utils:: mocks:: { MockChunkable , MockStateSync , MockTransport } ;
376
+ use ic_p2p_test_utils:: mocks:: { MockChunkable , MockTransport } ;
384
377
use ic_test_utilities_logger:: with_test_replica_logger;
385
378
use ic_types:: { crypto:: CryptoHash , Height } ;
386
379
use ic_types_test_utils:: ids:: { NODE_1 , NODE_2 } ;
@@ -403,10 +396,6 @@ mod tests {
403
396
#[ test]
404
397
fn test_should_cancel ( ) {
405
398
with_test_replica_logger ( |log| {
406
- let mut s = MockStateSync :: default ( ) ;
407
- s. expect_should_cancel ( )
408
- . return_once ( |_| false )
409
- . return_const ( true ) ;
410
399
let mut t = MockTransport :: default ( ) ;
411
400
t. expect_rpc ( ) . returning ( |_, _| {
412
401
Ok ( Response :: builder ( )
@@ -428,7 +417,6 @@ mod tests {
428
417
height : Height :: from ( 1 ) ,
429
418
hash : CryptoHash ( vec ! [ ] ) ,
430
419
} ,
431
- Arc :: new ( s) ,
432
420
Arc :: new ( t) ,
433
421
) ;
434
422
@@ -443,8 +431,6 @@ mod tests {
443
431
#[ test]
444
432
fn test_chunk_verification_failed ( ) {
445
433
with_test_replica_logger ( |log| {
446
- let mut s = MockStateSync :: default ( ) ;
447
- s. expect_should_cancel ( ) . return_const ( false ) ;
448
434
let mut t = MockTransport :: default ( ) ;
449
435
t. expect_rpc ( ) . returning ( |_, _| {
450
436
Ok ( Response :: builder ( )
@@ -469,7 +455,6 @@ mod tests {
469
455
height : Height :: from ( 1 ) ,
470
456
hash : CryptoHash ( vec ! [ ] ) ,
471
457
} ,
472
- Arc :: new ( s) ,
473
458
Arc :: new ( t) ,
474
459
) ;
475
460
@@ -486,11 +471,6 @@ mod tests {
486
471
#[ test]
487
472
fn test_add_peer_multiple_times_to_ongoing_state_sync ( ) {
488
473
with_test_replica_logger ( |log| {
489
- let should_cancel = Arc :: new ( AtomicBool :: default ( ) ) ;
490
- let should_cancel_c = should_cancel. clone ( ) ;
491
- let mut s = MockStateSync :: default ( ) ;
492
- s. expect_should_cancel ( )
493
- . returning ( move |_| should_cancel_c. load ( Ordering :: SeqCst ) ) ;
494
474
let mut t = MockTransport :: default ( ) ;
495
475
t. expect_rpc ( ) . returning ( |_, _| {
496
476
Ok ( Response :: builder ( )
@@ -516,14 +496,12 @@ mod tests {
516
496
height : Height :: from ( 1 ) ,
517
497
hash : CryptoHash ( vec ! [ ] ) ,
518
498
} ,
519
- Arc :: new ( s) ,
520
499
Arc :: new ( t) ,
521
500
) ;
522
501
523
502
rt. block_on ( async move {
524
503
ongoing. sender . send ( NODE_1 ) . await . unwrap ( ) ;
525
504
ongoing. sender . send ( NODE_1 ) . await . unwrap ( ) ;
526
- should_cancel. store ( true , Ordering :: SeqCst ) ;
527
505
ongoing. sender . send ( NODE_1 ) . await . unwrap ( ) ;
528
506
// State sync should exit because NODE_1 got removed.
529
507
ongoing. shutdown . shutdown ( ) . await ;
0 commit comments