@@ -3737,16 +3737,19 @@ where
37373737 // being fully configured. See the docs for `ChannelManagerReadArgs` for more.
37383738 match source {
37393739 HTLCSource :: OutboundRoute { ref path, ref session_priv, ref payment_id, ref payment_params, .. } => {
3740- self . pending_outbound_payments . fail_htlc ( source, payment_hash, onion_error, path, session_priv, payment_id, payment_params, self . probing_cookie_secret , & self . secp_ctx , & self . pending_events , & self . logger ) ;
3740+ if self . pending_outbound_payments . fail_htlc ( source, payment_hash, onion_error, path,
3741+ session_priv, payment_id, payment_params, self . probing_cookie_secret , & self . secp_ctx ,
3742+ & self . pending_events , & self . logger )
3743+ { self . push_pending_forwards_ev ( ) ; }
37413744 } ,
37423745 HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
37433746 log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with {:?}" , log_bytes!( payment_hash. 0 ) , onion_error) ;
37443747 let err_packet = onion_error. get_encrypted_failure_packet ( incoming_packet_shared_secret, phantom_shared_secret) ;
37453748
3746- let mut forward_event = None ;
3749+ let mut push_forward_ev = false ;
37473750 let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
37483751 if forward_htlcs. is_empty ( ) {
3749- forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
3752+ push_forward_ev = true ;
37503753 }
37513754 match forward_htlcs. entry ( * short_channel_id) {
37523755 hash_map:: Entry :: Occupied ( mut entry) => {
@@ -3757,12 +3760,8 @@ where
37573760 }
37583761 }
37593762 mem:: drop ( forward_htlcs) ;
3763+ if push_forward_ev { self . push_pending_forwards_ev ( ) ; }
37603764 let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
3761- if let Some ( time) = forward_event {
3762- pending_events. push ( events:: Event :: PendingHTLCsForwardable {
3763- time_forwardable : time
3764- } ) ;
3765- }
37663765 pending_events. push ( events:: Event :: HTLCHandlingFailed {
37673766 prev_channel_id : outpoint. to_channel_id ( ) ,
37683767 failed_next_destination : destination,
@@ -4839,7 +4838,7 @@ where
48394838 #[ inline]
48404839 fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
48414840 for & mut ( prev_short_channel_id, prev_funding_outpoint, prev_user_channel_id, ref mut pending_forwards) in per_source_pending_forwards {
4842- let mut forward_event = None ;
4841+ let mut push_forward_event = false ;
48434842 let mut new_intercept_events = Vec :: new ( ) ;
48444843 let mut failed_intercept_forwards = Vec :: new ( ) ;
48454844 if !pending_forwards. is_empty ( ) {
@@ -4897,7 +4896,7 @@ where
48974896 // We don't want to generate a PendingHTLCsForwardable event if only intercepted
48984897 // payments are being processed.
48994898 if forward_htlcs_empty {
4900- forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4899+ push_forward_event = true ;
49014900 }
49024901 entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
49034902 prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id, forward_info } ) ) ) ;
@@ -4915,16 +4914,21 @@ where
49154914 let mut events = self . pending_events . lock ( ) . unwrap ( ) ;
49164915 events. append ( & mut new_intercept_events) ;
49174916 }
4917+ if push_forward_event { self . push_pending_forwards_ev ( ) }
4918+ }
4919+ }
49184920
4919- match forward_event {
4920- Some ( time) => {
4921- let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4922- pending_events. push ( events:: Event :: PendingHTLCsForwardable {
4923- time_forwardable : time
4924- } ) ;
4925- }
4926- None => { } ,
4927- }
4921+ // We only want to push a PendingHTLCsForwardable event if no others are queued.
4922+ fn push_pending_forwards_ev ( & self ) {
4923+ let mut pending_events = self . pending_events . lock ( ) . unwrap ( ) ;
4924+ let forward_ev_exists = pending_events. iter ( )
4925+ . find ( |ev| if let events:: Event :: PendingHTLCsForwardable { .. } = ev { true } else { false } )
4926+ . is_some ( ) ;
4927+ if !forward_ev_exists {
4928+ pending_events. push ( events:: Event :: PendingHTLCsForwardable {
4929+ time_forwardable :
4930+ Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ,
4931+ } ) ;
49284932 }
49294933 }
49304934
0 commit comments