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