@@ -5414,11 +5414,9 @@ where
5414
5414
}
5415
5415
};
5416
5416
5417
- let mut push_forward_ev = false ;
5417
+ let mut push_forward_ev = self.decode_update_add_htlcs.lock().unwrap().is_empty() ;
5418
5418
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
5419
- if forward_htlcs.is_empty() {
5420
- push_forward_ev = true;
5421
- }
5419
+ push_forward_ev &= forward_htlcs.is_empty();
5422
5420
match forward_htlcs.entry(*short_channel_id) {
5423
5421
hash_map::Entry::Occupied(mut entry) => {
5424
5422
entry.get_mut().push(failure);
@@ -7005,14 +7003,17 @@ where
7005
7003
}
7006
7004
7007
7005
fn decode_update_add_htlcs(&self, update_add_htlcs: (u64, Vec<msgs::UpdateAddHTLC>)) {
7006
+ let mut push_forward_event = self.forward_htlcs.lock().unwrap().is_empty();
7008
7007
let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
7008
+ push_forward_event &= decode_update_add_htlcs.is_empty();
7009
7009
let scid = update_add_htlcs.0;
7010
7010
for update_add_htlc in update_add_htlcs.1 {
7011
7011
match decode_update_add_htlcs.entry(scid) {
7012
7012
hash_map::Entry::Occupied(mut e) => { e.get_mut().push(update_add_htlc); },
7013
7013
hash_map::Entry::Vacant(e) => { e.insert(vec![update_add_htlc]); },
7014
7014
}
7015
7015
}
7016
+ if push_forward_event { self.push_pending_forwards_ev(); }
7016
7017
}
7017
7018
7018
7019
#[inline]
@@ -7031,6 +7032,7 @@ where
7031
7032
// Pull this now to avoid introducing a lock order with `forward_htlcs`.
7032
7033
let is_our_scid = self.short_to_chan_info.read().unwrap().contains_key(&scid);
7033
7034
7035
+ let decode_update_add_htlcs_empty = self.decode_update_add_htlcs.lock().unwrap().is_empty();
7034
7036
let mut forward_htlcs = self.forward_htlcs.lock().unwrap();
7035
7037
let forward_htlcs_empty = forward_htlcs.is_empty();
7036
7038
match forward_htlcs.entry(scid) {
@@ -7079,7 +7081,7 @@ where
7079
7081
} else {
7080
7082
// We don't want to generate a PendingHTLCsForwardable event if only intercepted
7081
7083
// payments are being processed.
7082
- if forward_htlcs_empty {
7084
+ if forward_htlcs_empty && decode_update_add_htlcs_empty {
7083
7085
push_forward_event = true;
7084
7086
}
7085
7087
entry.insert(vec!(HTLCForwardInfo::AddHTLC(PendingAddHTLCInfo {
@@ -10875,7 +10877,7 @@ where
10875
10877
(13, claimable_htlc_onion_fields, optional_vec),
10876
10878
(14, decode_update_add_htlcs, option),
10877
10879
});
10878
- let decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
10880
+ let mut decode_update_add_htlcs = decode_update_add_htlcs.unwrap_or_else(|| new_hash_map());
10879
10881
if fake_scid_rand_bytes.is_none() {
10880
10882
fake_scid_rand_bytes = Some(args.entropy_source.get_secure_random_bytes());
10881
10883
}
@@ -11095,6 +11097,18 @@ where
11095
11097
// still have an entry for this HTLC in `forward_htlcs` or
11096
11098
// `pending_intercepted_htlcs`, we were apparently not persisted after
11097
11099
// the monitor was when forwarding the payment.
11100
+ decode_update_add_htlcs.retain(|scid, update_add_htlcs| {
11101
+ update_add_htlcs.retain(|update_add_htlc| {
11102
+ let matches = *scid == prev_hop_data.short_channel_id &&
11103
+ update_add_htlc.htlc_id == prev_hop_data.htlc_id;
11104
+ if matches {
11105
+ log_info!(logger, "Removing pending to-decode HTLC with hash {} as it was forwarded to the closed channel {}",
11106
+ &htlc.payment_hash, &monitor.channel_id());
11107
+ }
11108
+ !matches
11109
+ });
11110
+ !update_add_htlcs.is_empty()
11111
+ });
11098
11112
forward_htlcs.retain(|_, forwards| {
11099
11113
forwards.retain(|forward| {
11100
11114
if let HTLCForwardInfo::AddHTLC(htlc_info) = forward {
@@ -11176,7 +11190,7 @@ where
11176
11190
}
11177
11191
}
11178
11192
11179
- if !forward_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11193
+ if !forward_htlcs.is_empty() || !decode_update_add_htlcs.is_empty() || pending_outbounds.needs_abandon() {
11180
11194
// If we have pending HTLCs to forward, assume we either dropped a
11181
11195
// `PendingHTLCsForwardable` or the user received it but never processed it as they
11182
11196
// shut down before the timer hit. Either way, set the time_forwardable to a small
0 commit comments