@@ -5406,11 +5406,9 @@ where
5406
5406
}
5407
5407
};
5408
5408
5409
- let mut push_forward_ev = false ;
5409
+ let mut push_forward_ev = self.decode_update_add_htlcs.lock().unwrap().is_empty() ;
5410
5410
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5411
- if forward_htlcs.is_empty() {
5412
- push_forward_ev = true;
5413
- }
5411
+ push_forward_ev &= forward_htlcs.is_empty();
5414
5412
match forward_htlcs.entry(*short_channel_id) {
5415
5413
hash_map::Entry::Occupied(mut entry) => {
5416
5414
entry.get_mut().push(failure);
@@ -6985,14 +6983,17 @@ where
6985
6983
}
6986
6984
6987
6985
fn decode_update_add_htlcs(&self, update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
6986
+ let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty();
6988
6987
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
6988
+ push_forward_event &= decode_update_add_htlcs.is_empty();
6989
6989
let scid = update_add_htlcs.0;
6990
6990
for update_add_htlc in update_add_htlcs.1 {
6991
6991
match decode_update_add_htlcs.entry(scid) {
6992
6992
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(update_add_htlc); },
6993
6993
hash_map::Entry::Vacant(e) => { e.insert(vec![update_add_htlc]); },
6994
6994
}
6995
6995
}
6996
+ if push_forward_event { self.push_pending_forwards_ev(); }
6996
6997
}
6997
6998
6998
6999
#[inline]
@@ -7011,6 +7012,7 @@ where
7011
7012
// Pull this now to avoid introducing a lock order with `forward_htlcs`.
7012
7013
let is_our_scid = self.short_to_chan_info.read().unwrap().contains_key(&scid);
7013
7014
7015
+ let decode_update_add_htlcs_empty = self.decode_update_add_htlcs.lock().unwrap().is_empty();
7014
7016
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
7015
7017
let forward_htlcs_empty = forward_htlcs.is_empty();
7016
7018
match forward_htlcs.entry(scid) {
@@ -7059,7 +7061,7 @@ where
7059
7061
} else {
7060
7062
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7061
7063
// payments are being processed.
7062
- if forward_htlcs_empty {
7064
+ if forward_htlcs_empty && decode_update_add_htlcs_empty {
7063
7065
push_forward_event = true;
7064
7066
}
7065
7067
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -10827,7 +10829,7 @@ where
10827
10829
(13, claimable_htlc_onion_fields, optional_vec),
10828
10830
(14, decode_update_add_htlcs, option),
10829
10831
});
10830
- let decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or(new_hash_map());
10832
+ let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or(new_hash_map());
10831
10833
if fake_scid_rand_bytes.is_none() {
10832
10834
fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
10833
10835
}
@@ -11047,6 +11049,18 @@ where
11047
11049
// still have an entry for this HTLC in `forward_htlcs` or
11048
11050
// `pending_intercepted_htlcs`, we were apparently not persisted after
11049
11051
// the monitor was when forwarding the payment.
11052
+ decode_update_add_htlcs.retain(|scid, update_add_htlcs| {
11053
+ update_add_htlcs.retain(|update_add_htlc| {
11054
+ let matches = *scid == prev_hop_data.short_channel_id &&
11055
+ update_add_htlc.htlc_id == prev_hop_data.htlc_id;
11056
+ if matches {
11057
+ log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel {}",
11058
+ &htlc.payment_hash, &monitor.channel_id());
11059
+ }
11060
+ !matches
11061
+ });
11062
+ !update_add_htlcs.is_empty()
11063
+ });
11050
11064
forward_htlcs.retain(|_, forwards| {
11051
11065
forwards.retain(|forward| {
11052
11066
if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
@@ -11128,7 +11142,7 @@ where
11128
11142
}
11129
11143
}
11130
11144
11131
- if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11145
+ if !forward_htlcs.is_empty() || !decode_update_add_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11132
11146
// If we have pending HTLCs to forward, assume we either dropped a
11133
11147
// `PendingHTLCsForwardable` or the user received it but never processed it as they
11134
11148
// shut down before the timer hit. Either way, set the time_forwardable to a small
0 commit comments