@@ -21,7 +21,7 @@ use std::{collections::HashMap, sync::Arc, time::SystemTime};
2121use thiserror:: Error ;
2222use tokio:: sync:: mpsc:: { channel, Receiver , Sender } ;
2323use tokio:: sync:: Mutex ;
24- use tokio:: { select, time, time:: Duration , time:: Instant } ;
24+ use tokio:: { select, time, time:: Duration , time:: Instant , time :: Sleep } ;
2525use tokio_util:: task:: TaskTracker ;
2626use triggered:: { Listener , Trigger } ;
2727
@@ -1345,8 +1345,7 @@ async fn run_results_logger(
13451345///
13461346/// Note: this producer does not accept a shutdown trigger because it only expects to be dispatched once. In the single
13471347/// producer case exit will drop the only sending channel and the receiving channel provided to the consumer will error
1348- /// out. In the multiple-producer case, a single producer shutting down does not drop *all* sending channels so the
1349- /// consumer will not exit and a trigger is required.
1348+ /// out.
13501349async fn produce_simulation_results (
13511350 nodes : HashMap < PublicKey , Arc < Mutex < dyn LightningNode > > > ,
13521351 mut output_receiver : Receiver < SimulationOutput > ,
@@ -1409,27 +1408,28 @@ async fn track_payment_result(
14091408 log:: debug!( "Tracking payment outcome for: {}." , hex:: encode( hash. 0 ) ) ;
14101409
14111410 // Trigger and listener to stop the implementation specific track payment functions (node.track_payment())
1412- let ( stop , listen ) = triggered:: trigger ( ) ;
1411+ let ( track_payment_trigger , track_payment_listener ) = triggered:: trigger ( ) ;
14131412
14141413 // Timer for waiting after getting the shutdown signal in order for current tracking to complete
1415- let mut timer: Option < tokio:: time:: Sleep > = None ;
1414+ let mut timer: Option < Sleep > = None ;
1415+ let mut timer_started = false ;
14161416
14171417 loop {
14181418 tokio:: select! {
1419- biased;
14201419 // The shutdown listener is triggered and we have not started a timer yet
1421- _ = async { } , if listener. clone( ) . is_triggered( ) && timer . is_none ( ) => {
1420+ _ = async { } , if listener. clone( ) . is_triggered( ) && !timer_started => {
14221421 log:: debug!( "Shutdown received by track_payment_result, starting timer..." ) ;
14231422 timer = Some ( time:: sleep_until( Instant :: now( ) + Duration :: from_secs( 3 ) ) ) ;
1423+ timer_started = true ;
14241424 } ,
14251425 // The timer has been started and it expires
14261426 Some ( _) = conditional_sleeper( timer) => {
14271427 log:: error!( "Track payment failed for {}. The shutdown timer expired." , hex:: encode( hash. 0 ) ) ;
1428- stop . trigger( ) ;
1428+ track_payment_trigger . trigger( ) ;
14291429 timer = None ;
14301430 }
14311431 // The payment tracking completes
1432- res = node. track_payment( & hash, listen . clone( ) ) => {
1432+ res = node. track_payment( & hash, track_payment_listener . clone( ) ) => {
14331433 match res {
14341434 Ok ( res) => {
14351435 log:: info!(
@@ -1469,7 +1469,7 @@ async fn track_payment_result(
14691469 Ok ( ( ) )
14701470}
14711471
1472- async fn conditional_sleeper ( t : Option < tokio :: time :: Sleep > ) -> Option < ( ) > {
1472+ async fn conditional_sleeper ( t : Option < Sleep > ) -> Option < ( ) > {
14731473 match t {
14741474 Some ( timer) => {
14751475 timer. await ;
0 commit comments