Skip to content

[Splicing] Tx negotiation during splicing #3736

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

Conversation

optout21
Copy link
Contributor

@optout21 optout21 commented Apr 15, 2025

Implementation of transaction negotiation during splicing.
Builds on 3407 and 3443.

  • No new phase, Funded(FundedChannel) is used throughout splicing
  • Both FundedChannel and PendingV2Channel can act as a transaction constructor
  • PendingV2Channel logic is put behind a trait -- FundingTxConstructorV2
  • A RenegotiatingScope is used to store extra state during splicing
  • FundingChannel can act as a FundingTxConstructorV2, using the state from RenegotiatingScope (if present)
  • Since both FundedChannel and FundingTxConstructor has context(), context accessors are extracted into a common base trait, ChannelContextProvider (it is also shared by InitialRemoteCommitmentReceiver).

(Also relevant: #3444)

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Apr 15, 2025

👋 Thanks for assigning @wpaulino 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 @wpaulino! 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 @jkczyz @wpaulino! 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 @wpaulino! 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

🔔 2nd Reminder

Hey @jkczyz @wpaulino! 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 @wpaulino! 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

🔔 3rd Reminder

Hey @jkczyz @wpaulino! 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 @wpaulino! 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

🔔 4th Reminder

Hey @jkczyz @wpaulino! 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 @wpaulino! 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

🔔 5th Reminder

Hey @jkczyz @wpaulino! 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

🔔 6th Reminder

Hey @jkczyz @wpaulino! 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

🔔 6th Reminder

Hey @jkczyz @wpaulino! 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.

Copy link
Contributor

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

Sorry about the late review. We were traveling to an off site last week. Just a high-level pass on the first four commits. Will need to take a closer look at the last one.

Copy link

codecov bot commented Apr 30, 2025

Codecov Report

Attention: Patch coverage is 56.30252% with 52 lines in your changes missing coverage. Please review.

Project coverage is 90.28%. Comparing base (8aae34e) to head (f1c280d).
Report is 15 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 55.23% 46 Missing and 1 partial ⚠️
lightning/src/ln/channelmanager.rs 64.28% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3736      +/-   ##
==========================================
+ Coverage   89.73%   90.28%   +0.55%     
==========================================
  Files         159      160       +1     
  Lines      128910   132032    +3122     
  Branches   128910   132032    +3122     
==========================================
+ Hits       115676   119207    +3531     
+ Misses      10536    10172     -364     
+ Partials     2698     2653      -45     

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

@optout21 optout21 force-pushed the splice-dual-tx4 branch 3 times, most recently from 88d2e83 to 866368d Compare May 5, 2025 11:59
@optout21
Copy link
Contributor Author

optout21 commented May 6, 2025

Ready for a new round of review. I have addressed the comments, applied most of them. There is still one to-do (update channel reserve values), that I will do, but the rest is ready for review.
I did the changes in separate 'fix' commits.

@optout21
Copy link
Contributor Author

Ready for a new round of review. All pending and newly raised comments addressed.

@ldk-reviews-bot
Copy link

🔔 1st Reminder

Hey @wpaulino! 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.

@optout21
Copy link
Contributor Author

optout21 commented Jun 5, 2025

We had some discussion on #3741 (comment) and on the spec PR (lightning/bolts#1160 (comment)) about this. Turns out we need to make TxAddInput::prevtx optional or possible an enum with TxAddInput::shared_input_txid. We'll avoid storing the funding transaction.

Getting closer :) As I see the changes needed:

  • make TxAddInput::prevtx Optional
  • Enhance InteractiveConstructor to differentiate non-shared and shared inputs. For shared inputs set shared_input_txid (only the initiator). The acceptor should check if shared input was added.
  • To begin_interactive_... we should supply the prev_funding_txo, in both inititator&acceptor case. Both would add it to InteractiveConstructor as shared input.

In this PR or another one? Probably best would be to include these into this PR (causing some further processing time).

@jkczyz
Copy link
Contributor

jkczyz commented Jun 5, 2025

In this PR or another one? Probably best would be to include these into this PR (causing some further processing time).

Yeah, I think we need to do it in this PR.

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

When using fixup commits, please keep each one grouped under the relevant commit it should be applied to. You already have the context as to what commit the fix belongs to, and you won't have to reload that context when it's time to squash them (it also makes review easier).

@optout21
Copy link
Contributor Author

I'm working on shared input support, can be seen in draft PR #3842 . WIP.

@optout21 optout21 force-pushed the splice-dual-tx4 branch 4 times, most recently from de1b796 to 367593b Compare June 11, 2025 20:27
@optout21
Copy link
Contributor Author

Comments addressed, summary of pending changes:

@wpaulino
Copy link
Contributor

Let us know when this is ready for another round, no need to wait on #3842 to get more review on this.

@optout21
Copy link
Contributor Author

Let us know when this is ready for another round, no need to wait on #3842 to get more review on this.

I was busy with #3842, but I agree that this PR should be treated independently of 3842.
I will squash the fixups, and this should be ready for a new round of review.

This is a simple rename, DualFundingContext to FundingNegotiationContext,
to suggest that this is use not only in dual-funded channel open.
Also rename the field dual_funding_context to funding_negotiation_context.
@optout21
Copy link
Contributor Author

Commits squashed, rebased (post #3741), fmt. Ready for a new round of review.

@optout21 optout21 force-pushed the splice-dual-tx4 branch 2 times, most recently from be09f9a to 59e9b23 Compare June 17, 2025 08:11
optout21 added 4 commits June 17, 2025 11:00
The begin_interactive_funding_tx_construction() method is extended with
`is_initiator` parameter (splice initiator), and
`prev_funding_input` optional parameter, containing the previous funding
transaction, which will be added to the negotiation as an input by the
initiator.
Introduce struct NegotiatingChannelView to perform transaction negotiation
logic, on top of either PendingV2Channel (dual-funded channel open) or
FundedChannel (splicing).
Fill the logic for including transaction negotiation during splicing,
implement the functions:
splice_channel, splice_init, splice_ack, funding_tx_constructed.
Also extend the test case test_v1_splice_in with the steps for
funding negotiation during splicing.
@optout21 optout21 requested review from jkczyz and wpaulino June 17, 2025 09:10
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

There are a handful of comments from my last review that still need to be addressed

fn begin_interactive_funding_tx_construction<ES: Deref>(
&mut self, signer_provider: &SP, entropy_source: &ES, holder_node_id: PublicKey,
change_destination_opt: Option<ScriptBuf>,
is_initiator: bool, change_destination_opt: Option<ScriptBuf>,
prev_funding_input: Option<(TxIn, TransactionU16LenLimited)>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we just drop this commit and revisit once #3842 lands? Or we can just drop the prev_funding_input part for now.

let logger = WithChannelContext::from(logger, &chan.context, None);
chan.funding_tx_constructed(signing_session, &&logger)
let logger = WithChannelContext::from(logger, self.context(), None);
if let Ok(mut negotiating_channel) = self.as_negotiating_channel() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: looks like we don't need the else branch since as_negotiating_channel already returns a similar error

/// Can be produced by:
/// - [`PendingV2Channel`], at V2 channel open, and
/// - [`FundedChannel`], when splicing.
pub struct NegotiatingChannelView<'a, SP: Deref>
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be pub(crate/super)

@@ -8884,7 +8884,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
}

#[rustfmt::skip]
fn internal_tx_msg<HandleTxMsgFn: Fn(&mut Channel<SP>) -> Result<MessageSendEvent, &'static str>>(
fn internal_tx_msg<HandleTxMsgFn: Fn(&mut Channel<SP>) -> Result<MessageSendEvent, ChannelError>>(
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't look like HandleTxMsgFn needs to return a result at all, just the MessageSendEvent

Comment on lines +2172 to +2174
let post_value_to_self_msat_signed = (prev_funding.value_to_self_msat as i64)
.saturating_add(our_funding_contribution_sats * 1000);
if post_value_to_self_msat_signed < 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should already have been validated in splice_init/splice_ack when we check we still meet the reserve post-splice, right?

Comment on lines +2184 to +2187
let prev_funding_txid = prev_funding
.channel_transaction_parameters
.funding_outpoint
.map(|outpoint| outpoint.txid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use prev_funding.funding_txid()

Comment on lines +2196 to +2198
holder_selected_contest_delay: prev_funding
.channel_transaction_parameters
.holder_selected_contest_delay,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could define an intermediate variable channel_parameters to make these fit into a single line

Comment on lines +10059 to +10062
funded_channel.splice_init(
msg, our_funding_contribution, &self.signer_provider, &self.entropy_source,
&self.get_our_node_id(), &self.logger
), chan_entry);
Copy link
Contributor

Choose a reason for hiding this comment

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

Extract the splice_init (and splice_ack below) function call to its own variable

interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
is_splice: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Still don't think we should track this again and should just rely on splice_parent_funding_txid

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