Skip to content

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Jul 31, 2025

Splice-in support was added in #3736. This PR expands ChannelManager::splice_channel to support splice-out (i.e., removing funds from a channel). This is accomplished by adding a FundingTxContributions enum to cover both use cases.

Depends on #3736.

@ldk-reviews-bot
Copy link

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

@jkczyz jkczyz requested a review from wpaulino July 31, 2025 16:11
@jkczyz jkczyz marked this pull request as draft July 31, 2025 16:11
@jkczyz jkczyz self-assigned this Jul 31, 2025
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 74.21053% with 49 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.76%. Comparing base (6d47f0a) to head (ce203f2).
⚠️ Report is 94 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/msgs.rs 29.41% 15 Missing and 9 partials ⚠️
lightning/src/ln/funding.rs 45.71% 18 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs 91.93% 1 Missing and 4 partials ⚠️
lightning/src/ln/interactivetxs.rs 97.91% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3979      +/-   ##
==========================================
+ Coverage   88.74%   88.76%   +0.01%     
==========================================
  Files         173      176       +3     
  Lines      124899   127944    +3045     
  Branches   124899   127944    +3045     
==========================================
+ Hits       110841   113564    +2723     
- Misses      11631    11808     +177     
- Partials     2427     2572     +145     
Flag Coverage Δ
fuzzing 21.69% <2.34%> (?)
tests 88.59% <73.15%> (-0.16%) ⬇️

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.

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch 3 times, most recently from 2d39059 to 381fba6 Compare August 1, 2025 00:23
@jkczyz jkczyz marked this pull request as ready for review August 1, 2025 00:23
@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.

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

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch 2 times, most recently from 396948e to 59fbd7e Compare August 7, 2025 23:38
@jkczyz jkczyz requested a review from wpaulino August 8, 2025 13:42
@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.

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from fde2f61 to f12c993 Compare August 11, 2025 16:39
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 11, 2025

Rebased to resolve merge conflicts.

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from f12c993 to 806220e Compare August 11, 2025 22:22
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 11, 2025

Squashed as requested.

funding_feerate.to_sat_per_kwu() as u32,
));

if channel_balance > contribution_amount.unsigned_abs() + estimated_fee {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't enough, we need to make sure the balance is still above the reserve and has enough to pay for fees on the commitment transaction if they're the channel initiator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the reserve check will be at the call site as a separate check. I hadn't considered the fees for the commitment transaction. For the splice-in case, is it assumed it is sufficient because it was sufficient with the previous funding contributions?

Copy link
Contributor

Choose a reason for hiding this comment

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

For the splice-in case, is it assumed it is sufficient because it was sufficient with the previous funding contributions?

Most likely yeah, but it's better to be safe than sorry. We already need to always check it for the counterparty and for our splice-outs, so might as well always do it for splice-ins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this for @tankyleo.

Copy link
Contributor

Choose a reason for hiding this comment

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

See other comments.

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from 806220e to 9c2f266 Compare August 13, 2025 23:58
@jkczyz jkczyz requested a review from wpaulino August 13, 2025 23:58
@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from 9c2f266 to ef1aee7 Compare August 14, 2025 22:19
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 14, 2025

Squashed as requested.

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.

We should also make sure a FundingTransactionReadyForSigning event gets pushed when doing splice outs

/// When funds are added to a channel.
SpliceIn {
/// The amount to contribute to the splice.
value: Amount,
Copy link
Contributor

Choose a reason for hiding this comment

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

Another variant could be to consume the full input set, but we can revisit that later

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 was thinking we could have a constructor that took inputs and gave back a SpliceContribution::SpliceIn with amount. However, we'd need to provide information about the balance in order to compute that. So maybe best to use a dedicated variant as you said.

@wpaulino wpaulino requested a review from tankyleo August 14, 2025 23:24
jkczyz added 2 commits August 20, 2025 14:37
TransactionU16LenLimited was used to limit Transaction serialization
size to u16::MAX. This was because messages can not be longer than
u16::MAX bytes when serialized for the transport layer. However, this
limit doesn't take into account other fields in a message containing a
Transaction, including the length of the transaction itself.

Remove TransactionU16LenLimited and instead check any user supplied
transactions in the context of the enclosing message (e.g. TxAddInput).
ChannelManager::splice_channel takes witness weights with the funding
inputs. Storing these in FundingNegotiationContext allows us to use them
when calculating the change output and include them in a common struct
used for initiating a splice-in.

In preparation for having ChannelManager::splice_channel take
FundingTxContributions, add a weight to the
FundingTxContributions::InputsOnly, which supports the splice-in use
case.
@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from 7a38617 to 29c61bd Compare August 20, 2025 19:37
Copy link
Contributor Author

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

Fixed CI and squashed commits as requested.

@jkczyz jkczyz requested a review from tankyleo August 20, 2025 19:38
@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from 29c61bd to f2aa7fe Compare August 20, 2025 21:57
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 20, 2025

Pushed a fix for CI.

When splicing a channel, the previous funding output is spent and fees
for it are paid by the splice initiator. However, the witness weight was
not including EMPTY_SCRIPT_SIG_WEIGHT. Fix this and update the variable
name to make clear the weight needed is the input satisfaction.
@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from f2aa7fe to 8a596fb Compare August 21, 2025 16:05
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 21, 2025

Sorry, early CI failures were masking another one. Think it should be fixed in latest push. Also, pulled out the EMPTY_SCRIPT_SIG_WEIGHT into a separate commit.


impl FundingTxInput {
fn new<F: FnOnce(&bitcoin::Script) -> bool>(
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: sequence could be made optional with a default value of ENABLE_RBF_NO_LOCKTIME

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think about always setting it to ENABLE_RBF_NO_LOCKTIME and providing a mutator to override it? Would be nice to avoid passing an Option here if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure, let's link to it in the FundingTxInput::new docs though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's private, so will need to link each of the four public functions.

@jkczyz jkczyz force-pushed the 2025-07-splice-out branch 2 times, most recently from 567442d to ef24de4 Compare August 22, 2025 21:06
@jkczyz jkczyz requested a review from wpaulino August 22, 2025 21:07
@ldk-reviews-bot
Copy link

🔔 1st Reminder

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

@wpaulino
Copy link
Contributor

Feel free to squash on your next push

jkczyz added 4 commits August 25, 2025 12:20
The funding inputs used for splicing and v2 channel establishment are
passed as a tuple of txin, prevtx, and witness weight. Add a struct so
that the items included can be better documented.
ChannelManager::splice_channel takes individual parameters to support
splice-in. Change these to an enum such that it can be used for
splice-out as well.
Update SpliceContribution with a variant used to support splice-out
(i.e., removing funds from a channel). The TxOut values must not exceed
the users channel balance after accounting for fees and the reserve
requirement.
When a counterparty sends splice_init with a negative contribution, they
are requesting to remove funds from a channel. Remove conditions
guarding against this and check that they have enough channel balance to
cover the removed funds.
@jkczyz jkczyz force-pushed the 2025-07-splice-out branch from ef24de4 to ce203f2 Compare August 25, 2025 17:32
@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 25, 2025

Feel free to squash on your next push

Done. PTAL

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.

Three small nits we can take care of in followups

funding_negotiation_context.our_funding_contribution_satoshis;
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
let our_funding_contribution = funding_negotiation_context.our_funding_contribution;
debug_assert!(our_funding_contribution <= SignedAmount::MAX_MONEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

Check that the abs is smaller than MAX_MONEY ?

Comment on lines +37 to +38
/// The outputs to include in the splice's funding transaction. The total value of all
/// outputs will be the amount that is removed.
Copy link
Contributor

Choose a reason for hiding this comment

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

"We will remove the total value of the outputs plus the transaction fees" ?

/// The amount to contribute to the splice.
value: Amount,

/// The inputs included in the splice's funding transaction to meet the contributed amount.
Copy link
Contributor

Choose a reason for hiding this comment

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

"to meet the contributed amount plus the fees" ?

@wpaulino wpaulino merged commit 5f73b70 into lightningdevkit:main Aug 25, 2025
24 of 25 checks passed
@jkczyz jkczyz mentioned this pull request Aug 25, 2025
jkczyz added a commit that referenced this pull request Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants