Skip to content

Detect commitment transaction confirmation in ChannelMonitor instead #4013

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

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Aug 14, 2025

Previously, the ChannelManager would assume a Channel was closed the moment it saw a spend for its funding input. With splicing, this will no longer be the case. Since the ChannelMonitor is already responsible for reliably tracking each onchain transaction relevant to a channel, we now produce a MonitorEvent::CommitmentTxConfirmed event to inform the ChannelManager the channel can be considered closed and removed.

As a result of this change, many tests failed now that we rely on handling the MonitorEvent::CommitmentTxConfirmed first before seeing the ChannelMonitorUpdateStep::ChannelForceClosed go out.

@wpaulino wpaulino requested a review from TheBlueMatt August 14, 2025 18:41
@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Aug 14, 2025

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@TheBlueMatt
Copy link
Collaborator

Note that this now makes it possible for a Channel to have an update while the event has yet to be processed by the ChannelManager

This was already the case, at least if you connected the block to the monitor first, probably worth updating the commit message.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is unhappy but otherwise happy to land this.

@ldk-reviews-bot
Copy link

👋 The first review has been submitted!

Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer.

Previously, the `ChannelManager` would assume a `Channel` was closed the
moment it saw a spend for its funding input. With splicing, this will no
longer be the case. Since the `ChannelMonitor` is already responsible
for reliably tracking each onchain transaction relevant to a channel, we
now produce a `MonitorEvent::CommitmentTxConfirmed` event to inform the
`ChannelManager` the channel can be considered closed and removed.

As a result of this change, many tests failed now that we rely on
handling the `MonitorEvent::CommitmentTxConfirmed` first before seeing
the `ChannelMonitorUpdateStep::ChannelForceClosed` go out.
@wpaulino wpaulino force-pushed the commitment-tx-confirmed-from-monitor branch from da958b0 to 68cd71c Compare August 15, 2025 19:09
@wpaulino wpaulino requested a review from TheBlueMatt August 15, 2025 19:10
Copy link

codecov bot commented Aug 15, 2025

Codecov Report

❌ Patch coverage is 92.80576% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.84%. Comparing base (ac8f897) to head (68cd71c).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/functional_tests.rs 90.14% 6 Missing and 1 partial ⚠️
lightning/src/ln/channelmanager.rs 84.61% 1 Missing and 1 partial ⚠️
lightning/src/chain/channelmonitor.rs 94.73% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4013      +/-   ##
==========================================
- Coverage   88.85%   88.84%   -0.02%     
==========================================
  Files         175      175              
  Lines      127710   127723      +13     
  Branches   127710   127723      +13     
==========================================
- Hits       113478   113476       -2     
- Misses      11675    11686      +11     
- Partials     2557     2561       +4     
Flag Coverage Δ
fuzzing 21.76% <75.00%> (-0.10%) ⬇️
tests 88.67% <92.80%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna go ahead and land this. Its really trivial code-change, and while its a bit of a change logic-wise, we already have to support basically this - someone can connect a block to the ChannelMonitor and then sit around for a minute before connecting the block to the ChannelManager, so any behavior that relied on the Channel being closed directly would have been buggy anyway.

It does mean we will sometimes send a channel_ready and then close later if a channel is closed in the same block it was opened, but who cares.

let err = ChannelError::Close((reason.to_string(), reason));
let mut chan = chan_entry.remove();
let (_, e) = convert_channel_err!(self, peer_state, err, &mut chan);
failed_channels.push((Err(e), counterparty_node_id));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We always generate a ChannelMonitorUpdate to tell the ChannelMonitor that this channel is closed...which the monitor just told us about. The only thing it really does is set lockdown_from_offchain in the ChannelMonitor which adds panics if we later provide a ChannelMonitorUpdate for the channel, but those are just sanity checks and definitely aren't something to protect for an extra monitor update.

Isn't required here cause its not new, but we should drop the ChannelMonitorUpdate in a followup.

@TheBlueMatt TheBlueMatt merged commit 633cb49 into lightningdevkit:main Aug 17, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants