@@ -3737,16 +3737,19 @@ where
3737
3737
// being fully configured. See the docs for `ChannelManagerReadArgs` for more.
3738
3738
match source {
3739
3739
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 ( ) ; }
3741
3744
} ,
3742
3745
HTLCSource :: PreviousHopData ( HTLCPreviousHopData { ref short_channel_id, ref htlc_id, ref incoming_packet_shared_secret, ref phantom_shared_secret, ref outpoint } ) => {
3743
3746
log_trace ! ( self . logger, "Failing HTLC with payment_hash {} backwards from us with {:?}" , log_bytes!( payment_hash. 0 ) , onion_error) ;
3744
3747
let err_packet = onion_error. get_encrypted_failure_packet ( incoming_packet_shared_secret, phantom_shared_secret) ;
3745
3748
3746
- let mut forward_event = None ;
3749
+ let mut push_forward_ev = false ;
3747
3750
let mut forward_htlcs = self . forward_htlcs . lock ( ) . unwrap ( ) ;
3748
3751
if forward_htlcs. is_empty ( ) {
3749
- forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
3752
+ push_forward_ev = true ;
3750
3753
}
3751
3754
match forward_htlcs. entry ( * short_channel_id) {
3752
3755
hash_map:: Entry :: Occupied ( mut entry) => {
@@ -3757,12 +3760,8 @@ where
3757
3760
}
3758
3761
}
3759
3762
mem:: drop ( forward_htlcs) ;
3763
+ if push_forward_ev { self . push_pending_forwards_ev ( ) ; }
3760
3764
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
- }
3766
3765
pending_events. push ( events:: Event :: HTLCHandlingFailed {
3767
3766
prev_channel_id : outpoint. to_channel_id ( ) ,
3768
3767
failed_next_destination : destination,
@@ -4839,7 +4838,7 @@ where
4839
4838
#[ inline]
4840
4839
fn forward_htlcs ( & self , per_source_pending_forwards : & mut [ ( u64 , OutPoint , u128 , Vec < ( PendingHTLCInfo , u64 ) > ) ] ) {
4841
4840
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 ;
4843
4842
let mut new_intercept_events = Vec :: new ( ) ;
4844
4843
let mut failed_intercept_forwards = Vec :: new ( ) ;
4845
4844
if !pending_forwards. is_empty ( ) {
@@ -4897,7 +4896,7 @@ where
4897
4896
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
4898
4897
// payments are being processed.
4899
4898
if forward_htlcs_empty {
4900
- forward_event = Some ( Duration :: from_millis ( MIN_HTLC_RELAY_HOLDING_CELL_MILLIS ) ) ;
4899
+ push_forward_event = true ;
4901
4900
}
4902
4901
entry. insert ( vec ! ( HTLCForwardInfo :: AddHTLC ( PendingAddHTLCInfo {
4903
4902
prev_short_channel_id, prev_funding_outpoint, prev_htlc_id, prev_user_channel_id, forward_info } ) ) ) ;
@@ -4915,16 +4914,21 @@ where
4915
4914
let mut events = self . pending_events . lock ( ) . unwrap ( ) ;
4916
4915
events. append ( & mut new_intercept_events) ;
4917
4916
}
4917
+ if push_forward_event { self . push_pending_forwards_ev ( ) }
4918
+ }
4919
+ }
4918
4920
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
+ } ) ;
4928
4932
}
4929
4933
}
4930
4934
0 commit comments