@@ -8,14 +8,19 @@ use std::{
8
8
use axum:: http:: Request ;
9
9
use backoff:: backoff:: Backoff ;
10
10
use bytes:: Bytes ;
11
- use ic_async_utils:: JoinMap ;
12
11
use ic_interfaces:: { artifact_manager:: ArtifactProcessorEvent , artifact_pool:: ValidatedPoolReader } ;
13
12
use ic_logger:: { warn, ReplicaLogger } ;
14
13
use ic_quic_transport:: { ConnId , Transport } ;
15
14
use ic_types:: artifact:: { Advert , ArtifactKind } ;
16
15
use ic_types:: NodeId ;
17
16
use serde:: { Deserialize , Serialize } ;
18
- use tokio:: { runtime:: Handle , select, sync:: mpsc:: Receiver , task:: JoinHandle , time} ;
17
+ use tokio:: {
18
+ runtime:: Handle ,
19
+ select,
20
+ sync:: mpsc:: Receiver ,
21
+ task:: { JoinHandle , JoinSet } ,
22
+ time,
23
+ } ;
19
24
20
25
use crate :: { metrics:: ConsensusManagerMetrics , AdvertUpdate , CommitId , Data , SlotNumber } ;
21
26
@@ -210,9 +215,9 @@ where
210
215
. expect ( "Serializing advert update" )
211
216
. into ( ) ;
212
217
213
- let mut in_progress_transmissions = JoinMap :: new ( ) ;
218
+ let mut in_progress_transmissions = JoinSet :: new ( ) ;
214
219
// stores the connection ID of the last successful transmission to a peer.
215
- let mut completed_transmissions : HashMap < NodeId , ConnId > = HashMap :: new ( ) ;
220
+ let mut initiated_transmissions : HashMap < NodeId , ConnId > = HashMap :: new ( ) ;
216
221
let mut periodic_check_interval = time:: interval ( Duration :: from_secs ( 5 ) ) ;
217
222
218
223
loop {
@@ -222,20 +227,20 @@ where
222
227
// spawn task for peers with higher conn id or not in completed transmissions.
223
228
// add task to join map
224
229
for ( peer, connection_id) in transport. peers( ) {
225
- let is_completed = completed_transmissions . get( & peer) . is_some_and( |c| * c == connection_id) ;
230
+ let is_initiated = initiated_transmissions . get( & peer) . is_some_and( |c| * c == connection_id) ;
226
231
227
- if !is_completed {
232
+ if !is_initiated {
228
233
metrics. send_view_send_to_peer_total. inc( ) ;
229
- let task = send_advert_to_peer( transport. clone( ) , connection_id, body. clone( ) , peer, Artifact :: TAG . into( ) ) ;
230
- in_progress_transmissions. spawn_on( peer, task, & rt_handle) ;
234
+ let task = send_advert_to_peer( transport. clone( ) , body. clone( ) , peer, Artifact :: TAG . into( ) ) ;
235
+ in_progress_transmissions. spawn_on( task, & rt_handle) ;
236
+ initiated_transmissions. insert( peer, connection_id) ;
231
237
}
232
238
}
233
239
}
234
240
Some ( result) = in_progress_transmissions. join_next( ) => {
235
241
match result {
236
- Ok ( ( connection_id , peer ) ) => {
242
+ Ok ( _ ) => {
237
243
metrics. send_view_send_to_peer_delivered_total. inc( ) ;
238
- completed_transmissions. insert( peer, connection_id) ;
239
244
} ,
240
245
Err ( err) => {
241
246
// Cancelling tasks is ok. Panicking tasks are not.
@@ -254,11 +259,10 @@ where
254
259
/// If the peer is not reachable, it will retry with an exponential backoff.
255
260
async fn send_advert_to_peer (
256
261
transport : Arc < dyn Transport > ,
257
- connection_id : ConnId ,
258
262
message : Bytes ,
259
263
peer : NodeId ,
260
264
uri_prefix : & str ,
261
- ) -> ConnId {
265
+ ) {
262
266
let mut backoff = get_backoff_policy ( ) ;
263
267
264
268
loop {
@@ -268,7 +272,7 @@ async fn send_advert_to_peer(
268
272
. expect ( "Building from typed values" ) ;
269
273
270
274
if let Ok ( ( ) ) = transport. push ( & peer, request) . await {
271
- return connection_id ;
275
+ return ;
272
276
}
273
277
274
278
let backoff_duration = backoff. next_backoff ( ) . unwrap_or ( MAX_ELAPSED_TIME ) ;
0 commit comments