@@ -3513,6 +3513,7 @@ macro_rules! emit_initial_channel_ready_event {
3513
3513
macro_rules! handle_monitor_update_completion {
3514
3514
($self: ident, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
3515
3515
let channel_id = $chan.context.channel_id();
3516
+ let short_channel_id = $chan.funding.get_short_channel_id().unwrap_or($chan.context().outbound_scid_alias());
3516
3517
let counterparty_node_id = $chan.context.get_counterparty_node_id();
3517
3518
#[cfg(debug_assertions)]
3518
3519
{
@@ -3525,7 +3526,7 @@ macro_rules! handle_monitor_update_completion {
3525
3526
let mut updates = $chan.monitor_updating_restored(&&logger,
3526
3527
&$self.node_signer, $self.chain_hash, &*$self.config.read().unwrap(),
3527
3528
$self.best_block.read().unwrap().height,
3528
- |htlc_id| $self.path_for_release_held_htlc(htlc_id, &channel_id, &counterparty_node_id));
3529
+ |htlc_id| $self.path_for_release_held_htlc(htlc_id, short_channel_id, &channel_id, &counterparty_node_id));
3529
3530
let channel_update = if updates.channel_ready.is_some()
3530
3531
&& $chan.context.is_usable()
3531
3532
&& $peer_state.is_connected
@@ -5627,11 +5628,17 @@ where
5627
5628
/// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be
5628
5629
/// received to our node.
5629
5630
fn path_for_release_held_htlc(
5630
- &self, htlc_id: u64, channel_id: &ChannelId, counterparty_node_id: &PublicKey,
5631
+ &self, htlc_id: u64, short_channel_id: u64, channel_id: &ChannelId,
5632
+ counterparty_node_id: &PublicKey,
5631
5633
) -> BlindedMessagePath {
5632
5634
let intercept_id =
5633
5635
InterceptId::from_htlc_id_and_chan_id(htlc_id, channel_id, counterparty_node_id);
5634
- self.flow.path_for_release_held_htlc(intercept_id, &*self.entropy_source)
5636
+ self.flow.path_for_release_held_htlc(
5637
+ intercept_id,
5638
+ short_channel_id,
5639
+ htlc_id,
5640
+ &*self.entropy_source,
5641
+ )
5635
5642
}
5636
5643
5637
5644
/// Signals that no further attempts for the given payment should occur. Useful if you have a
@@ -11301,14 +11308,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11301
11308
// disconnect, so Channel's reestablish will never hand us any holding cell
11302
11309
// freed HTLCs to fail backwards. If in the future we no longer drop pending
11303
11310
// add-HTLCs on disconnect, we may be handed HTLCs to fail backwards here.
11311
+ let short_channel_id = chan.funding.get_short_channel_id().unwrap_or(chan.context.outbound_scid_alias());
11304
11312
let res = chan.channel_reestablish(
11305
11313
msg,
11306
11314
&&logger,
11307
11315
&self.node_signer,
11308
11316
self.chain_hash,
11309
11317
&self.config.read().unwrap(),
11310
11318
&*self.best_block.read().unwrap(),
11311
- |htlc_id| self.path_for_release_held_htlc(htlc_id, &msg.channel_id, counterparty_node_id)
11319
+ |htlc_id| self.path_for_release_held_htlc(htlc_id, short_channel_id, &msg.channel_id, counterparty_node_id)
11312
11320
);
11313
11321
let responses = try_channel_entry!(self, peer_state, res, chan_entry);
11314
11322
let mut channel_update = None;
@@ -11785,11 +11793,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
11785
11793
// Returns whether we should remove this channel as it's just been closed.
11786
11794
let unblock_chan = |chan: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
11787
11795
let channel_id = chan.context().channel_id();
11796
+ let short_channel_id = chan.as_funded().and_then(|c| c.funding.get_short_channel_id()).unwrap_or(chan.context().outbound_scid_alias());
11788
11797
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11789
11798
let node_id = chan.context().get_counterparty_node_id();
11790
11799
if let Some(msgs) = chan.signer_maybe_unblocked(
11791
11800
self.chain_hash, &&logger,
11792
- |htlc_id| self.path_for_release_held_htlc(htlc_id, &channel_id, &node_id)
11801
+ |htlc_id| self.path_for_release_held_htlc(htlc_id, short_channel_id, &channel_id, &node_id)
11793
11802
) {
11794
11803
if chan.context().is_connected() {
11795
11804
if let Some(msg) = msgs.open_channel {
@@ -15028,7 +15037,30 @@ where
15028
15037
);
15029
15038
}
15030
15039
},
15031
- AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id } => {
15040
+ AsyncPaymentsContext::ReleaseHeldHtlc { intercept_id, short_channel_id, htlc_id } => {
15041
+ // It's possible the release_held_htlc message raced ahead of us transitioning the pending
15042
+ // update_add to `Self::pending_intercept_htlcs`. If that's the case, update the pending
15043
+ // update_add to indicate that the HTLC should be released immediately.
15044
+ //
15045
+ // Check for the HTLC here before checking `pending_intercept_htlcs` to avoid a different
15046
+ // race where the HTLC gets transitioned to `pending_intercept_htlcs` after we drop that
15047
+ // map's lock but before acquiring the `decode_update_add_htlcs` lock.
15048
+ let mut decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
15049
+ if let Some(htlcs) = decode_update_add_htlcs.get_mut(&short_channel_id) {
15050
+ for update_add in htlcs.iter_mut() {
15051
+ if update_add.htlc_id == htlc_id {
15052
+ log_trace!(
15053
+ self.logger,
15054
+ "Marking held htlc with intercept_id {} as ready to release",
15055
+ intercept_id
15056
+ );
15057
+ update_add.hold_htlc.take();
15058
+ return;
15059
+ }
15060
+ }
15061
+ }
15062
+ core::mem::drop(decode_update_add_htlcs);
15063
+
15032
15064
let mut htlc = {
15033
15065
let mut pending_intercept_htlcs =
15034
15066
self.pending_intercepted_htlcs.lock().unwrap();
0 commit comments