@@ -5402,11 +5402,9 @@ where
5402
5402
}
5403
5403
};
5404
5404
5405
- let mut push_forward_ev = false ;
5405
+ let mut push_forward_ev = self.decode_update_add_htlcs.lock().unwrap().is_empty() ;
5406
5406
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5407
- if forward_htlcs.is_empty() {
5408
- push_forward_ev = true;
5409
- }
5407
+ push_forward_ev &= forward_htlcs.is_empty();
5410
5408
match forward_htlcs.entry(*short_channel_id) {
5411
5409
hash_map::Entry::Occupied(mut entry) => {
5412
5410
entry.get_mut().push(failure);
@@ -6981,14 +6979,17 @@ where
6981
6979
}
6982
6980
6983
6981
fn decode_update_add_htlcs(&self, update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
6982
+ let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty();
6984
6983
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
6984
+ push_forward_event &= decode_update_add_htlcs.is_empty();
6985
6985
let scid = update_add_htlcs.0;
6986
6986
for update_add_htlc in update_add_htlcs.1 {
6987
6987
match decode_update_add_htlcs.entry(scid) {
6988
6988
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(update_add_htlc); },
6989
6989
hash_map::Entry::Vacant(e) => { e.insert(vec![update_add_htlc]); },
6990
6990
}
6991
6991
}
6992
+ if push_forward_event { self.push_pending_forwards_ev(); }
6992
6993
}
6993
6994
6994
6995
#[inline]
@@ -7007,6 +7008,7 @@ where
7007
7008
// Pull this now to avoid introducing a lock order with `forward_htlcs`.
7008
7009
let is_our_scid = self.short_to_chan_info.read().unwrap().contains_key(&scid);
7009
7010
7011
+ let decode_update_add_htlcs_empty = self.decode_update_add_htlcs.lock().unwrap().is_empty();
7010
7012
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
7011
7013
let forward_htlcs_empty = forward_htlcs.is_empty();
7012
7014
match forward_htlcs.entry(scid) {
@@ -7055,7 +7057,7 @@ where
7055
7057
} else {
7056
7058
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7057
7059
// payments are being processed.
7058
- if forward_htlcs_empty {
7060
+ if forward_htlcs_empty && decode_update_add_htlcs_empty {
7059
7061
push_forward_event = true;
7060
7062
}
7061
7063
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -10823,7 +10825,7 @@ where
10823
10825
(13, claimable_htlc_onion_fields, optional_vec),
10824
10826
(14, decode_update_add_htlcs, option),
10825
10827
});
10826
- let decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or(new_hash_map());
10828
+ let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or(new_hash_map());
10827
10829
if fake_scid_rand_bytes.is_none() {
10828
10830
fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
10829
10831
}
@@ -11043,6 +11045,18 @@ where
11043
11045
// still have an entry for this HTLC in `forward_htlcs` or
11044
11046
// `pending_intercepted_htlcs`, we were apparently not persisted after
11045
11047
// the monitor was when forwarding the payment.
11048
+ decode_update_add_htlcs.retain(|scid, update_add_htlcs| {
11049
+ update_add_htlcs.retain(|update_add_htlc| {
11050
+ let matches = *scid == prev_hop_data.short_channel_id &&
11051
+ update_add_htlc.htlc_id == prev_hop_data.htlc_id;
11052
+ if matches {
11053
+ log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel {}",
11054
+ &htlc.payment_hash, &monitor.channel_id());
11055
+ }
11056
+ !matches
11057
+ });
11058
+ !update_add_htlcs.is_empty()
11059
+ });
11046
11060
forward_htlcs.retain(|_, forwards| {
11047
11061
forwards.retain(|forward| {
11048
11062
if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
@@ -11124,7 +11138,7 @@ where
11124
11138
}
11125
11139
}
11126
11140
11127
- if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11141
+ if !forward_htlcs.is_empty() || !decode_update_add_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11128
11142
// If we have pending HTLCs to forward, assume we either dropped a
11129
11143
// `PendingHTLCsForwardable` or the user received it but never processed it as they
11130
11144
// shut down before the timer hit. Either way, set the time_forwardable to a small
0 commit comments