@@ -19,7 +19,7 @@ use std::{collections::HashMap, sync::Arc, time::SystemTime};
19
19
use thiserror:: Error ;
20
20
use tokio:: sync:: mpsc:: { channel, Receiver , Sender } ;
21
21
use tokio:: sync:: Mutex ;
22
- use tokio:: { select, time, time:: Duration , time:: Instant } ;
22
+ use tokio:: { select, time, time:: Duration , time:: Instant , time :: Sleep } ;
23
23
use tokio_util:: task:: TaskTracker ;
24
24
use triggered:: { Listener , Trigger } ;
25
25
@@ -1272,8 +1272,7 @@ async fn run_results_logger(
1272
1272
///
1273
1273
/// Note: this producer does not accept a shutdown trigger because it only expects to be dispatched once. In the single
1274
1274
/// producer case exit will drop the only sending channel and the receiving channel provided to the consumer will error
1275
- /// out. In the multiple-producer case, a single producer shutting down does not drop *all* sending channels so the
1276
- /// consumer will not exit and a trigger is required.
1275
+ /// out.
1277
1276
async fn produce_simulation_results (
1278
1277
nodes : HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > ,
1279
1278
mut output_receiver : Receiver < SimulationOutput > ,
@@ -1336,27 +1335,28 @@ async fn track_payment_result(
1336
1335
log:: debug!( "Tracking payment outcome for: {}." , hex:: encode( hash. 0 ) ) ;
1337
1336
1338
1337
// Trigger and listener to stop the implementation specific track payment functions (node.track_payment())
1339
- let ( stop , listen ) = triggered:: trigger ( ) ;
1338
+ let ( track_payment_trigger , track_payment_listener ) = triggered:: trigger ( ) ;
1340
1339
1341
1340
// Timer for waiting after getting the shutdown signal in order for current tracking to complete
1342
- let mut timer: Option < tokio:: time:: Sleep > = None ;
1341
+ let mut timer: Option < Sleep > = None ;
1342
+ let mut timer_started = false ;
1343
1343
1344
1344
loop {
1345
1345
tokio:: select! {
1346
- biased;
1347
1346
// The shutdown listener is triggered and we have not started a timer yet
1348
- _ = async { } , if listener. clone( ) . is_triggered( ) && timer . is_none ( ) => {
1347
+ _ = async { } , if listener. clone( ) . is_triggered( ) && !timer_started => {
1349
1348
log:: debug!( "Shutdown received by track_payment_result, starting timer..." ) ;
1350
1349
timer = Some ( time:: sleep_until( Instant :: now( ) + Duration :: from_secs( 3 ) ) ) ;
1350
+ timer_started = true ;
1351
1351
} ,
1352
1352
// The timer has been started and it expires
1353
1353
Some ( _) = conditional_sleeper( timer) => {
1354
1354
log:: error!( "Track payment failed for {}. The shutdown timer expired." , hex:: encode( hash. 0 ) ) ;
1355
- stop . trigger( ) ;
1355
+ track_payment_trigger . trigger( ) ;
1356
1356
timer = None ;
1357
1357
}
1358
1358
// The payment tracking completes
1359
- res = node. track_payment( & hash, listen . clone( ) ) => {
1359
+ res = node. track_payment( & hash, track_payment_listener . clone( ) ) => {
1360
1360
match res {
1361
1361
Ok ( res) => {
1362
1362
log:: info!(
@@ -1396,7 +1396,7 @@ async fn track_payment_result(
1396
1396
Ok ( ( ) )
1397
1397
}
1398
1398
1399
- async fn conditional_sleeper ( t : Option < tokio :: time :: Sleep > ) -> Option < ( ) > {
1399
+ async fn conditional_sleeper ( t : Option < Sleep > ) -> Option < ( ) > {
1400
1400
match t {
1401
1401
Some ( timer) => {
1402
1402
timer. await ;
0 commit comments