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 1 commit 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 @jkczyz 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.

@@ -12470,6 +12493,31 @@ where
}
}

#[cfg(splicing)]
for (counterparty_node_id, channel_id, monitor_update) in monitor_updates {
let per_peer_state = self.per_peer_state.read().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Could take this lock once outside the loop. Or move this into the previous scope given we already have taken the read lock there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The lock is dropped on every call to handle_new_monitor_update below

@@ -10371,25 +10402,47 @@ where
.iter_mut()
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
{
// TODO: Do we need to do any of this after the channel is resumed?
Copy link
Contributor

Choose a reason for hiding this comment

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

Resumed meaning from being paused pending a ChannelMonitor persistence completing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was a stale TODO though

Comment on lines 9678 to 9711
self.context.latest_monitor_update_id += 1;
let monitor_update = ChannelMonitorUpdate {
update_id: self.context.latest_monitor_update_id,
updates: vec![ChannelMonitorUpdateStep::RenegotiatedFundingLocked {
funding_txid: funding_txo.unwrap().txid,
}],
channel_id: Some(self.context.channel_id()),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't have a strong opinion, but to DRY this up should we do this as part of maybe_promote_splice_funding, returning Option<ChannelMonitorUpdate>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cleaned it up a bit, let me know if this is what you had in mind

// If an RBF happens and it confirms, this will no longer be accurate, so update it now
// if we know the RBF doesn't belong to a splice.
if !has_pending_splice
&& self.first_confirmed_funding_txo == self.funding.funding_outpoint()
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this second part of the condition necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this is how we know that first_confirmed_funding_txo hasn't been updated yet.

@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 from cf88d1f to 00e8bb3 Compare July 9, 2025 23:23
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.
@wpaulino wpaulino force-pushed the renegotiated-funding-locked-monitor-update branch 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 54.43038% with 36 lines in your changes missing coverage. Please review.

Project coverage is 88.78%. Comparing base (c48e0a8) to head (c1ead6a).
Report is 79 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 14.70% 29 Missing ⚠️
lightning/src/chain/onchaintx.rs 0.00% 6 Missing ⚠️
lightning/src/ln/channel.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3894      +/-   ##
==========================================
- Coverage   89.65%   88.78%   -0.88%     
==========================================
  Files         164      166       +2     
  Lines      134658   119528   -15130     
  Branches   134658   119528   -15130     
==========================================
- Hits       120734   106120   -14614     
+ Misses      11246    11075     -171     
+ Partials     2678     2333     -345     

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

Comment on lines +9871 to +9874
let funding_promoted = chain_node_signer
.and_then(|(chain_hash, node_signer, user_config)| {
self.maybe_promote_splice_funding(node_signer, chain_hash, user_config, height, logger)
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we'll never promote when unconfirming, so this should be fine.

Comment on lines +9580 to +9587
{
let funding = self
.pending_funding
.iter_mut()
.find(|funding| funding.get_funding_txid() == Some(splice_txid))
.unwrap();
promote_splice_funding!(self, funding);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use a scope here?

Comment on lines +10228 to +10231
let funding_txo = chan
.funding
.get_funding_txo()
.expect("Splice FundingScope should always have a funding_txo");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we were trying to avoid accessing funding from ChannelManager. Should we continue to return the funding_txo? Then maybe we can avoid the boilerplate here? Possibly similarly in maybe_promote_splice_funding using a struct for the return type to avoid similar boilerplate at its call sites.

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