@@ -3513,6 +3513,7 @@ macro_rules! emit_initial_channel_ready_event {
35133513macro_rules! handle_monitor_update_completion {
35143514 ($self: ident, $peer_state_lock: expr, $peer_state: expr, $per_peer_state_lock: expr, $chan: expr) => { {
35153515 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());
35163517 let counterparty_node_id = $chan.context.get_counterparty_node_id();
35173518 #[cfg(debug_assertions)]
35183519 {
@@ -3525,7 +3526,7 @@ macro_rules! handle_monitor_update_completion {
35253526 let mut updates = $chan.monitor_updating_restored(&&logger,
35263527 &$self.node_signer, $self.chain_hash, &*$self.config.read().unwrap(),
35273528 $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));
35293530 let channel_update = if updates.channel_ready.is_some()
35303531 && $chan.context.is_usable()
35313532 && $peer_state.is_connected
@@ -5627,11 +5628,17 @@ where
56275628 /// [`HeldHtlcAvailable`] onion message, so the recipient's [`ReleaseHeldHtlc`] response will be
56285629 /// received to our node.
56295630 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,
56315633 ) -> BlindedMessagePath {
56325634 let intercept_id =
56335635 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+ )
56355642 }
56365643
56375644 /// 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/
1130111308 // disconnect, so Channel's reestablish will never hand us any holding cell
1130211309 // freed HTLCs to fail backwards. If in the future we no longer drop pending
1130311310 // 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());
1130411312 let res = chan.channel_reestablish(
1130511313 msg,
1130611314 &&logger,
1130711315 &self.node_signer,
1130811316 self.chain_hash,
1130911317 &self.config.read().unwrap(),
1131011318 &*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)
1131211320 );
1131311321 let responses = try_channel_entry!(self, peer_state, res, chan_entry);
1131411322 let mut channel_update = None;
@@ -11785,11 +11793,12 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1178511793 // Returns whether we should remove this channel as it's just been closed.
1178611794 let unblock_chan = |chan: &mut Channel<SP>, pending_msg_events: &mut Vec<MessageSendEvent>| -> Option<ShutdownResult> {
1178711795 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());
1178811797 let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
1178911798 let node_id = chan.context().get_counterparty_node_id();
1179011799 if let Some(msgs) = chan.signer_maybe_unblocked(
1179111800 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)
1179311802 ) {
1179411803 if chan.context().is_connected() {
1179511804 if let Some(msg) = msgs.open_channel {
@@ -15028,7 +15037,30 @@ where
1502815037 );
1502915038 }
1503015039 },
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+
1503215064 let mut htlc = {
1503315065 let mut pending_intercept_htlcs =
1503415066 self.pending_intercepted_htlcs.lock().unwrap();
0 commit comments