-
Notifications
You must be signed in to change notification settings - Fork 421
Handle mon update completion actions even with update(s) is blocked #4236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheBlueMatt
wants to merge
1
commit into
lightningdevkit:main
Choose a base branch
from
TheBlueMatt:2025-11-post-update-even-when-blocked
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1296,6 +1296,10 @@ impl MaybeReadable for EventUnblockedChannel { | |
| } | ||
|
|
||
| #[derive(Debug)] | ||
| /// Note that these run after all *non-blocked* [`ChannelMonitorUpdate`]s have been persisted. | ||
| /// Thus, they're primarily useful for (and currently only used for) claims, where the | ||
| /// [`ChannelMonitorUpdate`] we care about is a preimage update, which bypass the monitor update | ||
| /// blocking logic entirely and can never be blocked. | ||
| pub(crate) enum MonitorUpdateCompletionAction { | ||
| /// Indicates that a payment ultimately destined for us was claimed and we should emit an | ||
| /// [`events::Event::PaymentClaimed`] to the user if we haven't yet generated such an event for | ||
|
|
@@ -1580,6 +1584,11 @@ where | |
| /// same `temporary_channel_id` (or final `channel_id` in the case of 0conf channels or prior | ||
| /// to funding appearing on-chain), the downstream `ChannelMonitor` set is required to ensure | ||
| /// duplicates do not occur, so such channels should fail without a monitor update completing. | ||
| /// | ||
| /// Note that these run after all *non-blocked* [`ChannelMonitorUpdate`]s have been persisted. | ||
| /// Thus, they're primarily useful for (and currently only used for) claims, where the | ||
| /// [`ChannelMonitorUpdate`] we care about is a preimage update, which bypass the monitor | ||
| /// update blocking logic entirely and can never be blocked. | ||
| monitor_update_blocked_actions: BTreeMap<ChannelId, Vec<MonitorUpdateCompletionAction>>, | ||
| /// If another channel's [`ChannelMonitorUpdate`] needs to complete before a channel we have | ||
| /// with this peer can complete an RAA [`ChannelMonitorUpdate`] (e.g. because the RAA update | ||
|
|
@@ -3353,78 +3362,90 @@ macro_rules! handle_monitor_update_completion { | |
| let chan_id = $chan.context.channel_id(); | ||
| let outbound_alias = $chan.context().outbound_scid_alias(); | ||
| let cp_node_id = $chan.context.get_counterparty_node_id(); | ||
|
|
||
| #[cfg(debug_assertions)] | ||
| { | ||
| let in_flight_updates = $peer_state.in_flight_monitor_updates.get(&chan_id); | ||
| assert!(in_flight_updates.map(|(_, updates)| updates.is_empty()).unwrap_or(true)); | ||
| assert_eq!($chan.blocked_monitor_updates_pending(), 0); | ||
| assert!($chan.is_awaiting_monitor_update()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment above "Requires that |
||
| } | ||
|
|
||
| let logger = WithChannelContext::from(&$self.logger, &$chan.context, None); | ||
| let updates = $chan.monitor_updating_restored( | ||
| &&logger, | ||
| &$self.node_signer, | ||
| $self.chain_hash, | ||
| &*$self.config.read().unwrap(), | ||
| $self.best_block.read().unwrap().height, | ||
| |htlc_id| { | ||
| $self.path_for_release_held_htlc(htlc_id, outbound_alias, &chan_id, &cp_node_id) | ||
| }, | ||
| ); | ||
| let channel_update = if updates.channel_ready.is_some() | ||
| && $chan.context.is_usable() | ||
| && $peer_state.is_connected | ||
| { | ||
| // We only send a channel_update in the case where we are just now sending a | ||
| // channel_ready and the channel is in a usable state. We may re-send a | ||
| // channel_update later through the announcement_signatures process for public | ||
| // channels, but there's no reason not to just inform our counterparty of our fees | ||
| // now. | ||
| if let Ok((msg, _, _)) = $self.get_channel_update_for_unicast($chan) { | ||
| Some(MessageSendEvent::SendChannelUpdate { node_id: cp_node_id, msg }) | ||
| } else { | ||
| None | ||
| } | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let update_actions = | ||
| $peer_state.monitor_update_blocked_actions.remove(&chan_id).unwrap_or(Vec::new()); | ||
|
|
||
| let (htlc_forwards, decode_update_add_htlcs) = $self.handle_channel_resumption( | ||
| &mut $peer_state.pending_msg_events, | ||
| $chan, | ||
| updates.raa, | ||
| updates.commitment_update, | ||
| updates.commitment_order, | ||
| updates.accepted_htlcs, | ||
| updates.pending_update_adds, | ||
| updates.funding_broadcastable, | ||
| updates.channel_ready, | ||
| updates.announcement_sigs, | ||
| updates.tx_signatures, | ||
| None, | ||
| updates.channel_ready_order, | ||
| ); | ||
| if let Some(upd) = channel_update { | ||
| $peer_state.pending_msg_events.push(upd); | ||
| } | ||
|
|
||
| let unbroadcasted_batch_funding_txid = | ||
| $chan.context.unbroadcasted_batch_funding_txid(&$chan.funding); | ||
| core::mem::drop($peer_state_lock); | ||
| core::mem::drop($per_peer_state_lock); | ||
|
|
||
| $self.post_monitor_update_unlock( | ||
| chan_id, | ||
| cp_node_id, | ||
| unbroadcasted_batch_funding_txid, | ||
| update_actions, | ||
| htlc_forwards, | ||
| decode_update_add_htlcs, | ||
| updates.finalized_claimed_htlcs, | ||
| updates.failed_htlcs, | ||
| ); | ||
| if $chan.blocked_monitor_updates_pending() != 0 { | ||
| mem::drop($peer_state_lock); | ||
| mem::drop($per_peer_state_lock); | ||
|
|
||
| log_debug!(logger, "Channel has blocked monitor updates, completing update actions but leaving channel blocked"); | ||
| $self.handle_monitor_update_completion_actions(update_actions); | ||
| } else { | ||
| log_debug!(logger, "Channel is open and awaiting update, resuming it"); | ||
| let updates = $chan.monitor_updating_restored( | ||
| &&logger, | ||
| &$self.node_signer, | ||
| $self.chain_hash, | ||
| &*$self.config.read().unwrap(), | ||
| $self.best_block.read().unwrap().height, | ||
| |htlc_id| { | ||
| $self.path_for_release_held_htlc(htlc_id, outbound_alias, &chan_id, &cp_node_id) | ||
| }, | ||
| ); | ||
| let channel_update = if updates.channel_ready.is_some() | ||
| && $chan.context.is_usable() | ||
| && $peer_state.is_connected | ||
| { | ||
| // We only send a channel_update in the case where we are just now sending a | ||
| // channel_ready and the channel is in a usable state. We may re-send a | ||
| // channel_update later through the announcement_signatures process for public | ||
| // channels, but there's no reason not to just inform our counterparty of our fees | ||
| // now. | ||
| if let Ok((msg, _, _)) = $self.get_channel_update_for_unicast($chan) { | ||
| Some(MessageSendEvent::SendChannelUpdate { node_id: cp_node_id, msg }) | ||
| } else { | ||
| None | ||
| } | ||
| } else { | ||
| None | ||
| }; | ||
|
|
||
| let (htlc_forwards, decode_update_add_htlcs) = $self.handle_channel_resumption( | ||
| &mut $peer_state.pending_msg_events, | ||
| $chan, | ||
| updates.raa, | ||
| updates.commitment_update, | ||
| updates.commitment_order, | ||
| updates.accepted_htlcs, | ||
| updates.pending_update_adds, | ||
| updates.funding_broadcastable, | ||
| updates.channel_ready, | ||
| updates.announcement_sigs, | ||
| updates.tx_signatures, | ||
| None, | ||
| updates.channel_ready_order, | ||
| ); | ||
| if let Some(upd) = channel_update { | ||
| $peer_state.pending_msg_events.push(upd); | ||
| } | ||
|
|
||
| let unbroadcasted_batch_funding_txid = | ||
| $chan.context.unbroadcasted_batch_funding_txid(&$chan.funding); | ||
| core::mem::drop($peer_state_lock); | ||
| core::mem::drop($per_peer_state_lock); | ||
|
|
||
| $self.post_monitor_update_unlock( | ||
| chan_id, | ||
| cp_node_id, | ||
| unbroadcasted_batch_funding_txid, | ||
| update_actions, | ||
| htlc_forwards, | ||
| decode_update_add_htlcs, | ||
| updates.finalized_claimed_htlcs, | ||
| updates.failed_htlcs, | ||
| ); | ||
| } | ||
| }}; | ||
| } | ||
|
|
||
|
|
@@ -3595,7 +3616,7 @@ macro_rules! handle_new_monitor_update { | |
| $update, | ||
| WithChannelContext::from(&$self.logger, &$chan.context, None), | ||
| ); | ||
| if all_updates_complete && $chan.blocked_monitor_updates_pending() == 0 { | ||
| if all_updates_complete { | ||
| handle_monitor_update_completion!( | ||
| $self, | ||
| $peer_state_lock, | ||
|
|
@@ -9813,12 +9834,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/ | |
| .and_then(Channel::as_funded_mut) | ||
| { | ||
| if chan.is_awaiting_monitor_update() { | ||
| if chan.blocked_monitor_updates_pending() == 0 { | ||
| log_trace!(logger, "Channel is open and awaiting update, resuming it"); | ||
| handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan); | ||
| } else { | ||
| log_trace!(logger, "Channel is open and awaiting update, leaving it blocked due to a blocked monitor update"); | ||
| } | ||
| handle_monitor_update_completion!(self, peer_state_lock, peer_state, per_peer_state, chan); | ||
| } else { | ||
| log_trace!(logger, "Channel is open but not awaiting update"); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/paymnt_hash_1/payment_hash_1