-
Notifications
You must be signed in to change notification settings - Fork 443
Check in-flight monitor updates in force_shutdown for LocalAnnounced HTLCs #4434
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
joostjager
wants to merge
1
commit into
lightningdevkit:main
Choose a base branch
from
joostjager:fix-force-close-in-progress-monitor-drops-htlc
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.
+52
−25
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
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 |
|---|---|---|
|
|
@@ -2326,9 +2326,12 @@ where | |
| }) | ||
| } | ||
|
|
||
| pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult { | ||
| pub fn force_shutdown( | ||
| &mut self, closure_reason: ClosureReason, | ||
| in_flight_monitor_updates: &[ChannelMonitorUpdate], | ||
| ) -> ShutdownResult { | ||
| let (funding, context) = self.funding_and_context_mut(); | ||
| context.force_shutdown(funding, closure_reason) | ||
| context.force_shutdown(funding, closure_reason, in_flight_monitor_updates) | ||
| } | ||
|
|
||
| #[rustfmt::skip] | ||
|
|
@@ -5891,6 +5894,7 @@ impl<SP: SignerProvider> ChannelContext<SP> { | |
| /// those explicitly stated to be alowed after shutdown, e.g. some simple getters). | ||
| fn force_shutdown( | ||
| &mut self, funding: &FundingScope, mut closure_reason: ClosureReason, | ||
| in_flight_monitor_updates: &[ChannelMonitorUpdate], | ||
| ) -> ShutdownResult { | ||
| // Note that we MUST only generate a monitor update that indicates force-closure - we're | ||
| // called during initialization prior to the chain_monitor in the encompassing ChannelManager | ||
|
|
@@ -5919,14 +5923,16 @@ impl<SP: SignerProvider> ChannelContext<SP> { | |
| } | ||
|
|
||
| // Once we're closed, the `ChannelMonitor` is responsible for resolving any remaining | ||
| // HTLCs. However, in the specific case of us pushing new HTLC(s) to the counterparty in | ||
| // the latest commitment transaction that we haven't actually sent due to a block | ||
| // `ChannelMonitorUpdate`, we may have some HTLCs that the `ChannelMonitor` won't know | ||
| // about and thus really need to be included in `dropped_outbound_htlcs`. | ||
| // HTLCs. However, if we have HTLCs in `LocalAnnounced` state whose corresponding | ||
| // `ChannelMonitorUpdate` is either blocked (in `blocked_monitor_updates`) or dispatched | ||
| // but not yet persisted (in `in_flight_monitor_updates`), the `ChannelMonitor` may not | ||
| // know about them and they need to be included in `dropped_outbound_htlcs`. | ||
| 'htlc_iter: for htlc in self.pending_outbound_htlcs.iter() { | ||
| if let OutboundHTLCState::LocalAnnounced(_) = htlc.state { | ||
| for update in self.blocked_monitor_updates.iter() { | ||
| for update in update.update.updates.iter() { | ||
| let blocked_iter = self.blocked_monitor_updates.iter().map(|u| &u.update); | ||
|
Contributor
Author
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. I do wonder if it is also possible for outbound htlcs to have already progressed to the |
||
| let in_flight_iter = in_flight_monitor_updates.iter(); | ||
| for update in blocked_iter.chain(in_flight_iter) { | ||
| for update in update.updates.iter() { | ||
| let have_htlc = match update { | ||
| ChannelMonitorUpdateStep::LatestCounterpartyCommitment { | ||
| htlc_data, | ||
|
|
@@ -6730,10 +6736,14 @@ where | |
| &self.context | ||
| } | ||
|
|
||
| pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult { | ||
| pub fn force_shutdown( | ||
| &mut self, closure_reason: ClosureReason, | ||
| in_flight_monitor_updates: &[ChannelMonitorUpdate], | ||
| ) -> ShutdownResult { | ||
| let splice_funding_failed = self.maybe_fail_splice_negotiation(); | ||
|
|
||
| let mut shutdown_result = self.context.force_shutdown(&self.funding, closure_reason); | ||
| let mut shutdown_result = | ||
| self.context.force_shutdown(&self.funding, closure_reason, in_flight_monitor_updates); | ||
| shutdown_result.splice_funding_failed = splice_funding_failed; | ||
| shutdown_result | ||
| } | ||
|
|
@@ -9528,7 +9538,7 @@ where | |
| (closing_signed, signed_tx, shutdown_result) | ||
| } | ||
| Err(err) => { | ||
| let shutdown = self.context.force_shutdown(&self.funding, ClosureReason::ProcessingError {err: err.to_string()}); | ||
| let shutdown = self.context.force_shutdown(&self.funding, ClosureReason::ProcessingError {err: err.to_string()}, &[]); | ||
| (None, None, Some(shutdown)) | ||
| } | ||
| } | ||
|
|
@@ -13365,7 +13375,7 @@ pub(super) struct OutboundV1Channel<SP: SignerProvider> { | |
|
|
||
| impl<SP: SignerProvider> OutboundV1Channel<SP> { | ||
| pub fn abandon_unfunded_chan(&mut self, closure_reason: ClosureReason) -> ShutdownResult { | ||
| self.context.force_shutdown(&self.funding, closure_reason) | ||
| self.context.force_shutdown(&self.funding, closure_reason, &[]) | ||
| } | ||
|
|
||
| #[allow(dead_code)] // TODO(dual_funding): Remove once opending V2 channels is enabled. | ||
|
|
||
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
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.
This now no longer needs to wait for the force close to confirm.