-
Notifications
You must be signed in to change notification settings - Fork 418
Add splice-out support #3979
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
Add splice-out support #3979
Conversation
👋 Thanks for assigning @wpaulino as a reviewer! |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2d39059
to
381fba6
Compare
🔔 1st Reminder Hey @wpaulino! This PR has been waiting for your review. |
👋 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. |
396948e
to
59fbd7e
Compare
🔔 1st Reminder Hey @wpaulino! This PR has been waiting for your review. |
fde2f61
to
f12c993
Compare
Rebased to resolve merge conflicts. |
f12c993
to
806220e
Compare
Squashed as requested. |
lightning/src/ln/channel.rs
Outdated
funding_feerate.to_sat_per_kwu() as u32, | ||
)); | ||
|
||
if channel_balance > contribution_amount.unsigned_abs() + estimated_fee { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving this for @tankyleo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comments.
806220e
to
9c2f266
Compare
9c2f266
to
ef1aee7
Compare
Squashed as requested. |
There was a problem hiding this 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
lightning/src/ln/channelmanager.rs
Outdated
/// When funds are added to a channel. | ||
SpliceIn { | ||
/// The amount to contribute to the splice. | ||
value: Amount, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.
7a38617
to
29c61bd
Compare
There was a problem hiding this 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.
29c61bd
to
f2aa7fe
Compare
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.
f2aa7fe
to
8a596fb
Compare
Sorry, early CI failures were masking another one. Think it should be fixed in latest push. Also, pulled out the |
lightning/src/ln/funding.rs
Outdated
|
||
impl FundingTxInput { | ||
fn new<F: FnOnce(&bitcoin::Script) -> bool>( | ||
prevtx: Transaction, vout: u32, sequence: Sequence, witness_weight: Weight, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
567442d
to
ef24de4
Compare
1 similar comment
Feel free to squash on your next push |
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.
ef24de4
to
ce203f2
Compare
Done. PTAL |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
?
/// The outputs to include in the splice's funding transaction. The total value of all | ||
/// outputs will be the amount that is removed. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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" ?
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 aFundingTxContributions
enum to cover both use cases.Depends on #3736.