Skip to content

Broadcast holder commitment for currently confirmed funding #3939

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wpaulino
Copy link
Contributor

@wpaulino wpaulino commented Jul 17, 2025

A splice's FundingScope can only be promoted once a ChannelMonitorUpdateStep::RenegotiatedFundingLocked is applied, or if the monitor is no longer accepting updates, once the splice transaction is no longer under reorg risk. Because of this, our current FundingScope may not reflect the latest confirmed state in the chain. Before making a holder commitment broadcast, we must check which FundingScope is currently confirmed to ensure that it can propagate throughout the network.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jul 17, 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.

@wpaulino wpaulino removed the request for review from joostjager July 17, 2025 21:00
@wpaulino wpaulino force-pushed the splice-funding-commitment-broadcast branch from a783444 to a8ae4b7 Compare July 18, 2025 22:23
@wpaulino wpaulino requested a review from TheBlueMatt July 18, 2025 22:23
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

Attention: Patch coverage is 43.34471% with 166 lines in your changes missing coverage. Please review.

Project coverage is 88.66%. Comparing base (e36abb7) to head (60d97d0).
Report is 29 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 40.21% 146 Missing and 19 partials ⚠️
lightning/src/chain/onchaintx.rs 94.11% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3939      +/-   ##
==========================================
- Coverage   89.02%   88.66%   -0.37%     
==========================================
  Files         168      167       -1     
  Lines      121831   122072     +241     
  Branches   121831   122072     +241     
==========================================
- Hits       108457   108232     -225     
- Misses      10970    11497     +527     
+ Partials     2404     2343      -61     
Flag Coverage Δ
fuzzing ?
tests 88.66% <43.34%> (-0.19%) ⬇️

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.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @TheBlueMatt! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

@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.

@wpaulino wpaulino force-pushed the splice-funding-commitment-broadcast branch from a8ae4b7 to 86b53fa Compare July 22, 2025 16:39
@wpaulino wpaulino requested a review from TheBlueMatt July 22, 2025 16:40
@wpaulino wpaulino force-pushed the splice-funding-commitment-broadcast branch from 86b53fa to 48629c7 Compare July 22, 2025 23:15
@jkczyz jkczyz self-requested a review July 23, 2025 18:18
wpaulino added 3 commits July 23, 2025 17:08
Whether it's a splice, or a dual-funded RBF, we need to know which
funding transaction out of all of the negotiated ones is currently
confirmed in case we need to broadcast the holder commitment.
A `FundingScope` can only be promoted once a
`ChannelMonitorUpdateStep::RenegotiatedFundingLocked` is applied, or if
the monitor is no longer accepting updates, once the renegotiated
funding transaction is no longer under reorg risk. Because of this, our
current `FundingScope` may not reflect the latest confirmed state in the
chain. Before making a holder commitment broadcast, we must check which
`FundingScope` is currently confirmed to ensure that it can propogate
throughout the network.
If we don't, it's possible that an alternative funding transaction
confirms instead of the one that was locked and we're not able to
broadcast a holder commitment to recover our funds.

Note that if another funding transaction confirms other than the latest
zero conf negotiated one, then we must force close the channel, as
commitment updates are only made for the latest zero conf negotiated
funding transaction as it's considered "locked"
@wpaulino wpaulino force-pushed the splice-funding-commitment-broadcast branch from 48629c7 to 60d97d0 Compare July 24, 2025 00:10
@wpaulino wpaulino requested a review from TheBlueMatt July 24, 2025 00:11

mem::swap(&mut self.funding, &mut new_funding);
mem::swap(&mut self.funding, new_funding);
Copy link
Contributor

Choose a reason for hiding this comment

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

The mem::swap function requires two mutable references, but new_funding is being passed by value here. This will cause a compilation error. The correct syntax should be:

mem::swap(&mut self.funding, &mut *new_funding);

Since new_funding is an Option<&mut FundingScope>, you need to dereference it first with * and then take a mutable reference to the dereferenced value.

Suggested change
mem::swap(&mut self.funding, new_funding);
mem::swap(&mut self.funding, &mut *new_funding);

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

OnchainEvent::AlternativeFundingConfirmation {} => {
// An alternative funding transaction has irrevocably confirmed and we're no
// longer allowing monitor updates, so promote the `FundingScope` now.
debug_assert!(self.no_further_updates_allowed());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm confused, we push an OnchainEvent::AlternativeFundingConfirmation without checking this, so I don't think this is universally true? Were you intending to only push one if the channel is closed (in which case how do we keep track of a splice that has one confirmation?) or not (in which case we need to remove this assertion and, I think, track the alternative funding confirmation forever in a new field (or set the expiry of an AlternativeFundingConfirmation to never, which we can do as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused, we push an OnchainEvent::AlternativeFundingConfirmation without checking this, so I don't think this is universally true?

It's done in the following commit, I just applied the fixup to the wrong commit when I added this.

Were you intending to only push one if the channel is closed (in which case how do we keep track of a splice that has one confirmation?) or not (in which case we need to remove this assertion and, I think, track the alternative funding confirmation forever in a new field (or set the expiry of an AlternativeFundingConfirmation to never, which we can do as well).

There's a new variable alternative_funding_confirmed that tracks the confirmed funding txid. The AlternativeFundingConfirmation is just an event used to promote the confirmed scope once the monitor isn't allowing updates anymore, otherwise we rely on the RenegotiatedFundingLocked monitor update.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @jkczyz! This PR has been waiting for your review.
Please take a look when you have a chance. If you're unable to review, please let us know so we can find another reviewer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants