-
Notifications
You must be signed in to change notification settings - Fork 417
Refactor PendingSplice
#3911
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
base: main
Are you sure you want to change the base?
Refactor PendingSplice
#3911
Conversation
👋 Thanks for assigning @TheBlueMatt as a reviewer! |
@@ -12616,7 +12616,6 @@ where | |||
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122 | |||
(51, is_manual_broadcast, option), // Added in 0.0.124 | |||
(53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124 | |||
(54, self.pending_funding, optional_vec), // Added in 0.2 |
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 still have the opportunity to reuse 54 for negotiated_candidates
when we persist that, right?
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 think the more important question is whether PendingSplice
(or PendingFunding
) should be persisted, because currently it isn't.
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'll persist PendingFunding
entirely. Wasn't sure about doing it in this PR or waiting for the additions in #3736.
🔔 1st Reminder Hey @wpaulino! This PR has been waiting for your review. |
🔔 2nd Reminder Hey @wpaulino! This PR has been waiting for your review. |
d8da168
to
12cc782
Compare
Rebased. |
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.
LGTM, CI is failing though
75850ff
to
db9149c
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.
Good to squash
db9149c
to
6dabb81
Compare
Squashed. Hopefully CI will be happy. |
Looks like this stalled long enough that it needs rebase :/ |
Yeah, plan is to get it in after #3886 to avoid merge needing to rebase that for merge conflicts. |
6dabb81
to
d5a7051
Compare
Attempted a rebase on main using Claude Code with mixed success. Looks like there's another conflict though. 😭 |
FundedChannel::pending_funding is to be moved to PendingSplice. As such, it will be persisted with PendingSplice once persistence is added for the latter.
FundedChannel::pending_funding and FundedChannel::pending_splice were developed independently, but the former will only contain values when the latter is set.
An upcoming commit will rename PendingSplice to PendingFunding. Thus, rename the similarly named field to something more meaningful. It includes FundingScopes that have been negotiated but have not reached enough confirmations by both parties to have exchanged splice_locked.
While PendingSplice is only used for splicing a FundedChannel, it will be useful when supporting RBF for V2 channel establishment.
Now that PendingFunding directly contains the negotiated candidates, some unnecessary checks can be removed.
d5a7051
to
d0780f7
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3911 +/- ##
==========================================
- Coverage 88.39% 88.32% -0.07%
==========================================
Files 177 177
Lines 131314 131495 +181
Branches 131314 131495 +181
==========================================
+ Hits 116069 116146 +77
- Misses 12596 12688 +92
- Partials 2649 2661 +12
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:
|
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.
Needs to add persistence to PendingFunding
as discussed offline
To use impl_writeable_tlv_based_enum_upgradable with unread_variants, currently tuple syntax can't be used enum variants. Update FundingNegotiation to use this syntax so that it can be used with that macro.
let prev_funding_txid = self.funding.get_funding_txid(); | ||
|
||
if let Some(scid) = self.funding.short_channel_id { | ||
self.context.historical_scids.push(scid); | ||
} | ||
|
||
core::mem::swap(&mut self.funding, funding); | ||
|
||
// The swap above places the previous `FundingScope` into `pending_funding`. | ||
pending_splice | ||
.negotiated_candidates | ||
.drain(..) | ||
.filter(|funding| funding.get_funding_txid() != prev_funding_txid) | ||
.map(|mut funding| { | ||
funding | ||
.funding_transaction | ||
.take() | ||
.map(|tx| FundingInfo::Tx { transaction: tx }) | ||
.unwrap_or_else(|| FundingInfo::OutPoint { | ||
outpoint: funding | ||
.get_funding_txo() | ||
.expect("Negotiated splices must have a known funding outpoint"), | ||
}) | ||
}) | ||
.collect::<Vec<_>>() |
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.
The code separates the funding swap logic from the cleanup operations that happen at lines 10742-10745. This creates a potential issue where if any code between these two sections throws an exception, the channel could be left in an inconsistent state.
The original macro ensured these operations happened atomically. Consider moving the cleanup operations (setting interactive_tx_signing_session
, pending_splice
, etc. to None
) inside this block before returning the discarded funding information to maintain atomicity and prevent inconsistent state in error cases.
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
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.
There isn't any possibility of failure. Having it inside the same scope doesn't make any difference.
lightning/src/ln/channel.rs
Outdated
@@ -2576,6 +2583,13 @@ enum FundingNegotiation { | |||
}, | |||
} | |||
|
|||
impl_writeable_tlv_based_enum_upgradable!(FundingNegotiation, | |||
(0, AwaitingSignatures) => { | |||
(0, funding, required), |
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 can be odd, right?
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.
Yeah
Once a splice funding transaction has been constructed, the corresponding state must be persisted so that the process can be continued across restarts. This includes exchanging signatures, waiting for enough confirmations, and RBF'ing.
1d7f24f
to
5350932
Compare
FundedChannel::pending_funding
andFundedChannel::pending_splice
were developed independently, but the former will only contain values when the latter is set. This PR moves the former intoPendingSplice
and renames it tonegotiated_candidates
. It also removes unnecessary checks forFundedChannel::pending_splice
and renamesPendingSplice
toPendingFunding
. This allows for usingPendingFunding
for V2 channel establishment in order to support RBF.