Skip to content

Introduce RenegotiatedFunding monitor update variant #3822

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

@wpaulino wpaulino commented Jun 2, 2025

This is a new ChannelMonitorUpdateStep variant intended to be used whenever a new funding transaction for the channel has been negotiated via the InteractiveTxConstructor. This commit primarily focuses on its use for splices, but future work will expand where needed to support RBFs (both for the initial dual funding transaction, and splice transactions).

To draw a parallel to channel open, we generally want to have the commitment transactions negotiated for the funding transaction and committed to the respective ChannelMonitor before attempting to sign the funding transaction itself. This monitor update fulfills this need for a newly negotiated splice; it includes both the new holder and counterparty commitment transactions, and the new set of applicable ChannelTransactionParameters. Once the monitor update has been applied to the monitor and persisted, we allow the release of our tx_signatures for the splice transaction to wait for its confirmation.

Note: This currently doesn't build without some of the work done in #3736.

Depends on #3774.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jun 2, 2025

👋 Thanks for assigning @tankyleo 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 requested a review from jkczyz June 2, 2025 23:53
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

Attention: Patch coverage is 22.72727% with 136 lines in your changes missing coverage. Please review.

Project coverage is 89.75%. Comparing base (0848e7a) to head (ac8c8c5).

Files with missing lines Patch % Lines
lightning/src/chain/channelmonitor.rs 7.04% 132 Missing ⚠️
lightning/src/chain/chainmonitor.rs 42.85% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3822      +/-   ##
==========================================
- Coverage   89.87%   89.75%   -0.12%     
==========================================
  Files         160      160              
  Lines      129654   129825     +171     
  Branches   129654   129825     +171     
==========================================
+ Hits       116523   116529       +6     
- Misses      10434    10592     +158     
- Partials     2697     2704       +7     

☔ 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

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

This is a new `ChannelMonitorUpdateStep` variant intended to be used
whenever a new funding transaction for the channel has been negotiated
via the `InteractiveTxConstructor`. This commit primarily focuses on its
use for splices, but future work will expand where needed to support
RBFs (both for the initial dual funding transaction, and splice
transactions).

To draw a parallel to channel open, we generally want to have the
commitment transactions negotiated for the funding transaction and
committed to the respective `ChannelMonitor` before attempting to sign
the funding transaction itself. This monitor update fulfills this need
for a newly negotiated splice; it includes both the new holder
and counterparty commitment transactions, and the new set of applicable
`ChannelTransactionParameters`. Once the monitor update has been applied
to the monitor and persisted, we allow the release of our
`tx_signatures` for the splice transaction to wait for its confirmation.
@wpaulino wpaulino force-pushed the renegotiated-funding-monitor-update branch from 6c78591 to ac8c8c5 Compare June 9, 2025 00:35
@wpaulino wpaulino requested a review from jkczyz June 9, 2025 00:35
@tankyleo tankyleo self-requested a review June 9, 2025 19:55
Copy link
Contributor

@tankyleo tankyleo left a comment

Choose a reason for hiding this comment

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

First pass in channel monitor

let mut alternative_htlcs = alternative_counterparty_commitment_tx.nondust_htlcs().iter();
while let Some(alternative_htlc) = alternative_htlcs.next() {
if alternative_htlc.transaction_output_index.is_none() {
continue;
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 can stop iterating entirely here ?

Comment on lines +3479 to +3482
.filter(|htlc_with_source| {
htlc_with_source.0.transaction_output_index.is_some()
&& alternative_htlc.is_data_equal(&htlc_with_source.0)
})
Copy link
Contributor

@tankyleo tankyleo Jun 9, 2025

Choose a reason for hiding this comment

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

I think we can use take_while here to stop iterating as soon as the closure returns false on some element; all elements after the first false will return false.

Sorry I suggested using take_while here, but took a second look and realized this iterator starts from the very beginning of htlcs_with_sources, so this won't work.

};
let mut htlcs_with_sources = current_counterparty_commitment_htlcs.clone();
let mut alternative_htlcs = alternative_counterparty_commitment_tx.nondust_htlcs().iter();
while let Some(alternative_htlc) = alternative_htlcs.next() {
Copy link
Contributor

@tankyleo tankyleo Jun 9, 2025

Choose a reason for hiding this comment

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

Would be simpler if we zipped alternative_htlcs and htlcs_with_sources, and just assigned the index from the alternative_htlcs element into the htlcs_with_sources element on each iteration ? I realize I may be missing something here.

return Err(());
}

if let Some(parent_funding_txid) = channel_parameters.splice_parent_funding_txid.as_ref() {
Copy link
Contributor

Choose a reason for hiding this comment

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

For now this always matches right ? It will not match for RBFs of the very first dual funding transaction ?

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.

4 participants