Skip to content

Conversation

jkczyz
Copy link
Contributor

@jkczyz jkczyz commented Jul 3, 2025

FundedChannel::pending_funding and FundedChannel::pending_splice were developed independently, but the former will only contain values when the latter is set. This PR moves the former into PendingSplice and renames it to negotiated_candidates. It also removes unnecessary checks for FundedChannel::pending_splice and renames PendingSplice to PendingFunding. This allows for using PendingFunding for V2 channel establishment in order to support RBF.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jul 3, 2025

👋 Thanks for assigning @TheBlueMatt 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 self-assigned this Jul 3, 2025
@jkczyz jkczyz requested a review from wpaulino July 3, 2025 16:05
@jkczyz jkczyz moved this to Goal: Merge in Weekly Goals Jul 3, 2025
@@ -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
Copy link
Contributor

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?

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 the more important question is whether PendingSplice (or PendingFunding) should be persisted, because currently it isn't.

Copy link
Contributor Author

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.

@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

🔔 2nd 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-pending-funding branch from d8da168 to 12cc782 Compare July 7, 2025 20:38
@jkczyz
Copy link
Contributor Author

jkczyz commented Jul 7, 2025

Rebased.

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.

LGTM, CI is failing though

@jkczyz jkczyz force-pushed the 2025-07-pending-funding branch 2 times, most recently from 75850ff to db9149c Compare July 8, 2025 17:44
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.

Good to squash

@jkczyz jkczyz force-pushed the 2025-07-pending-funding branch from db9149c to 6dabb81 Compare July 8, 2025 17:59
@jkczyz
Copy link
Contributor Author

jkczyz commented Jul 8, 2025

Squashed. Hopefully CI will be happy.

wpaulino
wpaulino previously approved these changes Jul 8, 2025
@TheBlueMatt
Copy link
Collaborator

Looks like this stalled long enough that it needs rebase :/

@jkczyz
Copy link
Contributor Author

jkczyz commented Aug 7, 2025

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.

@jkczyz
Copy link
Contributor Author

jkczyz commented Sep 9, 2025

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.
@jkczyz jkczyz force-pushed the 2025-07-pending-funding branch from d5a7051 to d0780f7 Compare September 10, 2025 16:36
Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 61.06870% with 51 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.32%. Comparing base (867f084) to head (5350932).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 61.06% 47 Missing and 4 partials ⚠️
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     
Flag Coverage Δ
fuzzing 21.63% <24.42%> (-0.38%) ⬇️
tests 88.16% <61.06%> (-0.07%) ⬇️

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.

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.

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.
Comment on lines +10715 to +10739
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<_>>()
Copy link
Contributor

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

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Copy link
Contributor Author

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.

@jkczyz jkczyz requested a review from wpaulino September 11, 2025 13:52
@@ -2576,6 +2583,13 @@ enum FundingNegotiation {
},
}

impl_writeable_tlv_based_enum_upgradable!(FundingNegotiation,
(0, AwaitingSignatures) => {
(0, funding, required),
Copy link
Contributor

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?

Copy link
Contributor Author

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.
@jkczyz jkczyz force-pushed the 2025-07-pending-funding branch from 1d7f24f to 5350932 Compare September 12, 2025 01:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Goal: Merge
Development

Successfully merging this pull request may close these issues.

6 participants