Skip to content

Introduce RenegotiatedFundingLocked monitor update variant #3894

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 2 commits into
base: main
Choose a base branch
from

Conversation

wpaulino
Copy link
Contributor

This is a new ChannelMonitorUpdateStep variant intended to be used whenever a new funding transaction that was negotiated and applied via the RenegotiatedFunding update reaches its intended confirmation depth and both sides of the channel exchange channel_ready/splice_locked. This commit primarily focuses on its use for splices, but future work will expand where needed to support RBFs for a dual funded channel.

This monitor update ensures that the monitor can safely drop all prior commitment data since it is now considered invalid/unnecessary. Once the update is applied, only state for the new funding transaction is tracked going forward, until the monitor receives another RenegotiatedFunding update.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jun 26, 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.

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

@ldk-reviews-bot
Copy link

🔔 2nd 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.

@ldk-reviews-bot
Copy link

🔔 3rd 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.

@ldk-reviews-bot
Copy link

🔔 4th 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.

@ldk-reviews-bot
Copy link

🔔 5th 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.

@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 renegotiated-funding-locked-monitor-update branch 2 times, most recently from 00e8bb3 to c1ead6a Compare July 9, 2025 23:25
@wpaulino wpaulino requested a review from jkczyz July 9, 2025 23:26
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 75.33333% with 37 lines in your changes missing coverage. Please review.

Project coverage is 88.96%. Comparing base (c48e0a8) to head (6c43f5d).
Report is 139 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 14.28% 24 Missing ⚠️
lightning/src/ln/channel.rs 82.00% 9 Missing ⚠️
lightning/src/ln/channelmanager.rs 95.45% 2 Missing and 1 partial ⚠️
lightning/src/chain/onchaintx.rs 83.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3894      +/-   ##
==========================================
- Coverage   89.65%   88.96%   -0.70%     
==========================================
  Files         164      166       +2     
  Lines      134658   121410   -13248     
  Branches   134658   121410   -13248     
==========================================
- Hits       120734   108012   -12722     
+ Misses      11246    10988     -258     
+ Partials     2678     2410     -268     
Flag Coverage Δ
fuzz 22.56% <54.00%> (?)

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.

@wpaulino wpaulino force-pushed the renegotiated-funding-locked-monitor-update branch from c1ead6a to a6d4b1e Compare July 14, 2025 18:33
@wpaulino wpaulino requested review from jkczyz and TheBlueMatt July 14, 2025 18:33
jkczyz
jkczyz previously approved these changes Jul 14, 2025
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.

Note that rustfmt/MSRV are failing.

// if we know the RBF doesn't belong to a splice.
if !is_pending_splice && self.first_confirmed_funding_txo == self.funding.funding_outpoint()
{
self.first_confirmed_funding_txo = new_funding.funding_outpoint();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Given this is only used to check if this channel is v1 or v2, and its "set at init", calling it first_confirmed_funding_txo seems like a misnomer. Its often set to a funding txo pre-first-confirmation, and is used pre-first-confirmation as well. It should probably be renamed and maybe we should decide what we actually want to use it for (should it be first-funding-txo or first-build-funding-txo?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a commit renaming it to first_negotiated_funding_txo

.and_then(Channel::as_funded_mut)
{
let funding_txo = channel.funding.get_funding_txo().unwrap();
handle_new_monitor_update!(
Copy link
Collaborator

Choose a reason for hiding this comment

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

monitor updates have to be handled in the same mutex where the channel generated them, otherwise they can end up getting applied out-of-order which isn't allowed. You can handle the post-update actions (which may need an unlock) later, though, see REMAIN_LOCKED_UPDATE_ACTIONS_PROCESSED_LATER and the logic in finish_close_channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah TIL, thanks

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 16, 2025
@wpaulino wpaulino dismissed stale reviews from coderabbitai[bot] and jkczyz via 3bdf268 July 16, 2025 00:31
@wpaulino wpaulino force-pushed the renegotiated-funding-locked-monitor-update branch from a6d4b1e to 3bdf268 Compare July 16, 2025 00:31
wpaulino added 2 commits July 17, 2025 10:35
This is a new `ChannelMonitorUpdateStep` variant intended to be used
whenever a new funding transaction that was negotiated and applied via
the `RenegotiatedFunding` update reaches its intended confirmation depth
and both sides of the channel exchange `channel_ready`/`splice_locked`.
This commit primarily focuses on its use for splices, but future work
will expand where needed to support RBFs for a dual funded channel.

This monitor update ensures that the monitor can safely drop all prior
commitment data since it is now considered invalid/unnecessary. Once the
update is applied, only state for the new funding transaction is tracked
going forward, until the monitor receives another `RenegotiatedFunding`
update.
It's only intended to be set during initialization and used to check if
the channel is v1 or v2. We rename it to `first_negotiated_funding_txo`
to better reflect its purpose.
@wpaulino wpaulino force-pushed the renegotiated-funding-locked-monitor-update branch from 3bdf268 to 6c43f5d Compare July 17, 2025 17:35
@wpaulino wpaulino requested a review from jkczyz July 18, 2025 22:17
@wpaulino wpaulino requested a review from TheBlueMatt July 18, 2025 22:17
@ldk-reviews-bot
Copy link

🔔 1st Reminder

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

1 similar comment
@ldk-reviews-bot
Copy link

🔔 1st Reminder

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

);

// The swap above places the previous `FundingScope` into `pending_funding`.
for funding in self.pending_funding.drain(..) {
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 a bit hesitant to accept that we should totally discard other funding scopes and never claim from them. If a user accepts 0conf splices, that's great, but if a commitment tx on the previous funding ends up getting confirmed, completely ignoring it and not trying to claim any of the value on it does seem a bit weird. I get that under our security model we shouldn't need to (eg if the user accepts 0conf funding we'd ignore it too) but it does seem worth fixing....

We don't need to fix it now, but opening an issue and addressing it eventually would be nice, IMO.

.unwrap_or_else(|| Vec::new());
mem::drop(peer_state);
mem::drop(per_peer_state);
self.handle_monitor_update_completion_actions(update_actions);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs to call the handle_monitor_update_completion macro (e.g. to call Channel::monitor_updating_restored), not this directly. Calling handle_monitor_update_completion_actions directly is only for closed channels.

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.

4 participants