@@ -171,6 +171,10 @@ impl PendingOutbound {
171
171
self . last_scheduled = next;
172
172
next
173
173
}
174
+
175
+ fn is_empty ( & self ) -> bool {
176
+ self . messages . is_empty ( )
177
+ }
174
178
}
175
179
176
180
/// Nomos DA broadcast network behaviour.
@@ -274,22 +278,22 @@ where
274
278
peers
275
279
}
276
280
277
- fn replicate_message ( & mut self , waker : & Waker , message : & DaMessage ) {
278
- let message_id = ( message. blob . blob_id . to_vec ( ) , message. subnetwork_id ) ;
279
- if self . seen_message_cache . contains ( & message_id) {
280
- return ;
281
- }
282
- self . seen_message_cache . insert ( message_id) ;
283
- self . send_message_impl ( Some ( waker) , message) ;
284
- }
285
-
286
281
/// Initiate sending a replication message **from outside the behaviour**
287
282
pub fn send_message ( & mut self , message : & DaMessage ) {
288
283
let waker = self . waker . take ( ) ;
289
284
self . send_message_impl ( waker. as_ref ( ) , message) ;
290
285
}
291
286
287
+ /// Send a replication message to all connected peers that are members of
288
+ /// the same subnetwork. If the message has already been seen, it is not
289
+ /// sent again.
292
290
fn send_message_impl ( & mut self , waker : Option < & Waker > , message : & DaMessage ) {
291
+ let message_id = ( message. blob . blob_id . to_vec ( ) , message. subnetwork_id ) ;
292
+ if self . seen_message_cache . contains ( & message_id) {
293
+ return ;
294
+ }
295
+ self . seen_message_cache . insert ( message_id) ;
296
+
293
297
// Push a message in the queue for every single peer connected that is a member
294
298
// of the selected subnetwork_id
295
299
let peers = self . no_loopback_member_peers_of ( message. subnetwork_id ) ;
@@ -368,7 +372,7 @@ where
368
372
Poll :: Ready ( Some ( Ok ( ( peer_id, message, read_half) ) ) ) => {
369
373
// Replicate the message to all connected peers from the same subnet if we
370
374
// haven't seen it yet
371
- self . replicate_message ( cx. waker ( ) , & message) ;
375
+ self . send_message_impl ( Some ( cx. waker ( ) ) , & message) ;
372
376
// Schedule waiting for any next incoming message on the same stream's read half
373
377
self . incoming_tasks
374
378
. push ( Self :: try_read_message ( peer_id, read_half) . boxed ( ) ) ;
@@ -472,6 +476,13 @@ where
472
476
cx. waker ( ) . wake_by_ref ( ) ;
473
477
}
474
478
479
+ // We must ensure that we ge awaken if there are still pending messages in the
480
+ // queue. In some scenarios it may happen that there's no other event that
481
+ // triggers the wake-up.
482
+ if !self . pending_outbound . is_empty ( ) {
483
+ cx. waker ( ) . wake_by_ref ( ) ;
484
+ }
485
+
475
486
Ok ( ( ) )
476
487
}
477
488
0 commit comments