Skip to content

Add pending SpliceDetails to ChannelDetails#4687

Open
jkczyz wants to merge 5 commits into
lightningdevkit:mainfrom
jkczyz:2026-06-splice-details-fable
Open

Add pending SpliceDetails to ChannelDetails#4687
jkczyz wants to merge 5 commits into
lightningdevkit:mainfrom
jkczyz:2026-06-splice-details-fable

Conversation

@jkczyz

@jkczyz jkczyz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Wallets like LDK Node need to show a channel's pending splice state (e.g., when displaying channel details), but it is currently only observable by tracking events or the broadcaster's TransactionType::InteractiveFunding, neither of which can be queried on demand.

This adds an optional splice_details field to ChannelDetails exposing that state: any splice/RBF round under negotiation (status, feerate, our contribution, txid and post-splice value once known) and any negotiated candidates awaiting confirmations, along with the splice_locked txids exchanged.

The first commit refactors PendingFunding to store each round's contribution with its negotiated candidate instead of in a tail-aligned parallel list, which every consumer had to realign (and which this API initially got wrong). The on-disk format is unchanged and remains readable by LDK 0.2.

@ldk-reviews-bot

ldk-reviews-bot commented Jun 12, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @joostjager 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.

Comment thread lightning/src/ln/channel.rs Outdated
Comment on lines +3121 to +3130
// Data written before the in-flight round's contribution was stored separately kept it
// as the last entry while a negotiation was pending.
if negotiation_contribution.is_none() && contributions.len() > fundings.len() {
negotiation_contribution = contributions.pop();
}
// An in-flight contribution is only meaningful while its negotiation round is alive;
// rounds not surviving serialization round trips have their events handled separately.
if funding_negotiation.is_none() {
negotiation_contribution = None;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This heuristic for recovering the in-flight contribution from LDK 0.2 data is insufficient when there are leading counterparty-only (None) candidates.

In the old format the in-flight (AwaitingSignatures) round's contribution was appended as the last entry of contributions while a negotiation was pending, but it is not in negotiated_candidates yet. Since contributions form a suffix, with K contributed prior candidates and M total prior candidates (M >= K), the old contributions length is K + 1 (the +1 being the in-flight). This heuristic only pops when K + 1 > M, i.e. only when K == M (no leading None candidates).

When M > K (at least one leading counterparty-only candidate), K + 1 <= M, so the pop is skipped and:

  • negotiation_contribution stays None (the in-flight contribution is lost), and
  • contrib_offset = M - (K+1) mis-assigns: one prior candidate at contrib_offset wrongly receives a contribution and the in-flight contribution is consumed into the candidate list.

Concrete minimal case from old 0.2 data: candidates=[None] (counterparty-only splice) followed by a we-contribute RBF round at AwaitingSignatures → old bytes are fundings=[f0], contributions=[c]. Here 1 > 1 is false, so this reads back as candidate[0].contribution = Some(c) and negotiation_contribution = None, both incorrect (should be candidate[0].contribution = None, negotiation_contribution = Some(c)). This is exactly the first-contribution-on-RBF flow exercised by the new test, and would corrupt contribution tracking / splice_funding_failed and later trip the suffix debug_assert! in splice_funding_negotiated.

The presence of an in-flight contribution in old data can't be detected by length alone here; it needs to be tied to funding_negotiation.is_some() together with the suffix structure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is an issue, 0.2 doesn't support RBF so it can't have multiple candidates/contributions.

@ldk-claude-review-bot

ldk-claude-review-bot commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Memory is current. No update needed — the design matches my notes and HEAD is consistent.

No issues found.

The serialization redesign resolves both of my prior inline findings (the even-field-12 in-flight contribution and the length-based recovery heuristic). The contribution now lives in odd TLV 13 (skippable by 0.2), TLV 11 is authoritative, and the legacy fallback maps every TLV-3 funding to contribution: None with no length heuristic. I re-verified:

  • Write/read round-trip consistency for the leading-None / first-contribution-on-RBF case and the in-flight AwaitingSignatures case.
  • contributions_form_suffix holds across on_tx_signatures_exchange.
  • to_details / pending_splice_details correctly surface negotiation/candidate/confirmed/queued state; minimum_depth().expect(...) is safe since only reached via as_funded().
  • The prior-version splice_channel rejection triggers exactly when both last_funding_feerate and the in-flight negotiation feerate are absent (0.2-written data), which cannot occur for a complete current-version pending splice.
  • The pending_funding() slice→iterator refactor: all .is_empty()/.len() callers correctly switched to negotiated_candidates() / ExactSizeIterator.

Cross-cutting carry-over (already raised in the prior pass, not re-posted inline): the 8 → 9 renumber of last_funding_feerate_sat_per_1000_weight (channel.rs:3104/3129) is only safe if no released LDK 0.2 build ever persisted the old even field 8 for a pending splice; otherwise a current reader would hit UnknownRequiredFeature on 0.2 data. The "feerate/contribution are 0.3-only" reasoning plus the passing upgrade_single_splice_from_0_2 test is consistent with this, but it still warrants maintainer confirmation as it can't be verified from this repo alone.

@ldk-reviews-bot

Copy link
Copy Markdown

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

Comment thread lightning/src/ln/channel.rs Outdated
Comment on lines +3121 to +3130
// Data written before the in-flight round's contribution was stored separately kept it
// as the last entry while a negotiation was pending.
if negotiation_contribution.is_none() && contributions.len() > fundings.len() {
negotiation_contribution = contributions.pop();
}
// An in-flight contribution is only meaningful while its negotiation round is alive;
// rounds not surviving serialization round trips have their events handled separately.
if funding_negotiation.is_none() {
negotiation_contribution = None;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is an issue, 0.2 doesn't support RBF so it can't have multiple candidates/contributions.

Comment thread lightning/src/ln/channel_state.rs Outdated
@wpaulino wpaulino requested a review from TheBlueMatt June 15, 2026 18:43
@jkczyz jkczyz mentioned this pull request Jun 15, 2026
50 tasks
@jkczyz jkczyz requested a review from wpaulino June 15, 2026 23:08
Comment thread lightning/src/ln/channel.rs Outdated
Comment thread lightning/src/ln/channel_state.rs Outdated
@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch from 30fdc02 to 3f954c5 Compare June 16, 2026 23:12
@jkczyz jkczyz requested a review from wpaulino June 16, 2026 23:13
@jkczyz jkczyz added this to the 0.3 milestone Jun 17, 2026
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 1st Reminder

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

}

#[test]
fn upgrade_single_splice_from_0_2() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's expand this test to also attempt an RBF after upgrading?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm, seems like we won't be able to RBF as we can't determine if we've contributed. At least we can't without losing our prior contributions. I added a guard to prevent this, which was previously a debug_assert on the last funding feerate.

}

#[test]
fn downgrade_single_splice_loads_on_0_2() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we still RBF if we negotiate the splice on 0.3, downgrade to 0.2, and upgrade back? I assume no since we're missing the contribution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, same as upgrading from 0.2. See other comment.

/// Note that a negotiation which has not yet reached
/// [`SpliceNegotiationStatus::AwaitingSignatures`] does not survive a restart, so this only
/// reflects in-memory negotiation state.
pub negotiation: Option<SpliceNegotiationDetails>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would it be possible to also surface the state after funding_contributed but before actual splice negotiation? This might be useful to tighten fuzz invariants.

Suggestion from #4699 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good idea. If they called funding_contributed successfully, it should show up here even if we haven't reached quiescence.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great, will then tighten the invariant SpliceDetails when this lands

@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch from 22eba7d to 984f4cc Compare June 18, 2026 16:12
@jkczyz jkczyz requested review from joostjager and wpaulino June 18, 2026 16:13
@wpaulino

Copy link
Copy Markdown
Contributor

LGTM after squash+rebase

@jkczyz jkczyz self-assigned this Jun 18, 2026
Comment thread lightning/src/ln/channel.rs
@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch 3 times, most recently from 0b47b8b to 6bec475 Compare June 18, 2026 21:34
@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch from 6bec475 to 0c00583 Compare June 18, 2026 22:50
@jkczyz

jkczyz commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

@jkczyz jkczyz requested a review from joostjager June 18, 2026 22:52

@joostjager joostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PR title is underselling the whole serialization/migration change, and I think it could have been two PRs. This one is large, maybe too large.

No big findings other than potentially the zero-conf flow. Will go and try out SpliceDetails with the fuzzer!

Comment thread lightning/src/ln/channel.rs
Comment thread lightning/src/ln/channel.rs Outdated
Comment thread lightning/src/ln/channel_state.rs Outdated
Comment thread lightning/src/ln/channel_state.rs Outdated
Comment thread lightning/src/ln/channel_state.rs
Comment thread lightning-tests/src/upgrade_downgrade_tests.rs Outdated
Comment thread lightning-tests/src/upgrade_downgrade_tests.rs
Comment thread lightning-tests/src/upgrade_downgrade_tests.rs
Comment thread lightning/src/ln/channel.rs
Comment thread pending_changelog/4687-pending-splice-details.txt Outdated
@ldk-reviews-bot

Copy link
Copy Markdown

🔔 2nd Reminder

Hey @TheBlueMatt @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
Copy Markdown

🔔 1st Reminder

Hey @TheBlueMatt @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
Copy Markdown

🔔 3rd Reminder

Hey @TheBlueMatt @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
Copy Markdown

🔔 2nd Reminder

Hey @TheBlueMatt @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
Copy Markdown

🔔 4th Reminder

Hey @TheBlueMatt @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
Copy Markdown

🔔 3rd Reminder

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

PendingFunding tracked our splice contributions in a compact list
implicitly aligned to the tail of the negotiated candidates, with the
in-flight negotiation round's contribution as the implicit last entry.
Every consumer had to re-derive this positional relationship, which is
easy to get wrong -- e.g., attributing an in-flight round's
contribution to a completed counterparty-only candidate.

Instead, store each candidate's contribution with the candidate itself
and give the in-flight round's contribution its own field, making such
misattribution unrepresentable. The contributions still form a suffix
of the candidates -- once a round includes our contribution, every
subsequent round carries it forward (possibly feerate-adjusted) so the
splice intention is never lost -- which is now asserted when a round
completes.

Serialize this so a single (non-RBF) pending splice stays loadable by
LDK 0.2 while RBF is refused loudly. 0.2 predates per-candidate
contributions, the in-flight contribution, and the last-negotiated
feerate, so writing any of them in an even (required) TLV would make 0.2
refuse even a single splice it can otherwise operate. The legacy TLV 3
therefore carries only the first candidate's funding -- the single-splice
view 0.2 reads -- while the full candidate list, the in-flight
contribution, and the feerate go in odd TLVs that 0.2 skips. An even gate
TLV is written only when there is more than one negotiation round (RBF),
so 0.2 loads single splices and refuses RBF, which it cannot operate.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch from 0c00583 to a9861ef Compare June 24, 2026 17:03
@jkczyz jkczyz requested a review from joostjager June 24, 2026 17:04
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.25490% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.97%. Comparing base (e225350) to head (9619e39).
⚠️ Report is 3224 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/channel.rs 97.35% 6 Missing ⚠️
lightning/src/routing/router.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4687      +/-   ##
==========================================
+ Coverage   84.51%   86.97%   +2.45%     
==========================================
  Files         137      161      +24     
  Lines       77446   111811   +34365     
  Branches    77446   111811   +34365     
==========================================
+ Hits        65456    97248   +31792     
- Misses       9949    12054    +2105     
- Partials     2041     2509     +468     
Flag Coverage Δ
fuzzing-fake-hashes 8.42% <0.00%> (?)
fuzzing-real-hashes 32.55% <92.13%> (?)
tests 86.30% <97.25%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

joostjager
joostjager previously approved these changes Jun 25, 2026

@joostjager joostjager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! No blockers

Comment thread lightning/src/ln/channel.rs Outdated
// The `splice_locked` we sent always refers to the confirmed candidate, as it is
// cleared if that candidate is ever unconfirmed by a reorg.
let splice_locked_sent = self.sent_funding_txid == Some(txid);
(confirmations > 0 || splice_locked_sent).then(|| ConfirmedSpliceCandidate {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bit unusual shape perhaps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Used an explicit return None instead.

Comment thread lightning/src/ln/splicing_tests.rs Outdated
let (funding_tx, channel_id) =
open_zero_conf_channel_with_value(&nodes[0], &nodes[1], None, initial_channel_value_sat, 0);
mine_transaction(&nodes[0], &funding_tx);
mine_transaction(&nodes[1], &funding_tx);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't the sharper version of this test also not mining the original finding?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, just needed to unroll the helpers. Claude wanted to be lazy.

Comment thread lightning/src/ln/splicing_tests.rs
Comment thread lightning/src/ln/channel_state.rs
let chan_id_bytes;
let (v3_mgr, v3_mon);
{
let chanmon_cfgs = create_chanmon_cfgs(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this downgrade_setup_single_splice again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like the only real difference is needing the channel id bytes for use later. Updated the helper to return it.

jkczyz and others added 4 commits June 25, 2026 10:10
A channel may have splice attempts in progress: a contribution we have
committed but not yet begun negotiating, one under negotiation with the
counterparty, and any negotiated transactions (the original splice and
any RBF replacements) waiting on confirmations. This state was only
observable through events and the broadcaster's
TransactionType::InteractiveFunding, neither of which can be queried on
demand.

Add an optional splice_details field to ChannelDetails exposing: the
negotiation status and our contribution to it; a contribution queued
ahead of negotiation; the negotiated candidates (txid, post-splice
channel value, and our contribution); the single candidate that has
confirmed, with its confirmation progress and whether we have sent
splice_locked for it; and the txid of any splice_locked received from
the counterparty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add tests exercising the 0.2/current wire boundary for pending splices:
- A current node with a single pending splice (whether or not we
  contributed to it) is loadable by LDK 0.2.
- A current node with a splice under RBF is refused by 0.2 via the even
  RBF-gate TLV.
- A single pending splice written by 0.2 is read by current with no
  contribution recorded, since 0.2 never tracked one.

The downgrade reload configs enable anchors so 0.2 accepts the current
channel type rather than refusing it before the splice state is reached.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…rsion

A pending splice negotiated before an upgrade from a prior LDK version
(e.g. 0.2) returns without its feerate or our contribution: 0.2 persists
neither and drops the odd TLVs that carry them. splice_channel derives the
RBF feerate floor from the prior splice's feerate and assumed it was always
present via a debug assertion, so attempting to splice such a channel
tripped that assertion.

Return a clean error instead, refusing to splice a channel whose pending
splice lacks the metadata to reconstruct the prior request.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jkczyz jkczyz force-pushed the 2026-06-splice-details-fable branch from a9861ef to 9619e39 Compare June 25, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants