Skip to content

Produce FundingInfo::Contribution variants in ChannelMonitor#4498

Open
wpaulino wants to merge 2 commits intolightningdevkit:mainfrom
wpaulino:channel-monitor-discard-funding-contribution
Open

Produce FundingInfo::Contribution variants in ChannelMonitor#4498
wpaulino wants to merge 2 commits intolightningdevkit:mainfrom
wpaulino:channel-monitor-discard-funding-contribution

Conversation

@wpaulino
Copy link
Copy Markdown
Contributor

Similar to the `ChannelManager`, we expose the contributed inputs and
outputs of a splice via `FundingInfo::Contribution` at the
`ChannelMonitor` level such that we don't lose the context when the
channel closes while a splice is still pending.

@wpaulino wpaulino added this to the 0.3 milestone Mar 19, 2026
@wpaulino wpaulino requested a review from jkczyz March 19, 2026 18:47
@wpaulino wpaulino self-assigned this Mar 19, 2026
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Mar 19, 2026

👋 Thanks for assigning @jkczyz 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/chain/channelmonitor.rs
Comment thread lightning/src/chain/channelmonitor.rs Outdated
Comment thread lightning/src/chain/channelmonitor.rs Outdated
@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented Mar 19, 2026

Review Summary

After a thorough review of all files and hunks in this PR, I found the code to be generally well-structured and correct. The prior review already identified the key issues (HashSet ordering nondeterminism, None vs Some(vec![]) semantics). One new observation is posted inline:

  • lightning/src/ln/channel.rs:8321-8326debug_assert changed to expect, escalating from debug-only to production panic for missing signing session.

Cross-cutting observations (not tied to specific lines):

  1. FundingInfo::Contribution serialization format change: The outputs field changes from Vec<TxOut> (consensus-serialized) to Vec<ScriptBuf> (length-prefixed bytes). These are wire-incompatible. Any persisted DiscardFunding events with the old format would fail to deserialize after upgrade. This is acceptable since splicing is experimental/unreleased, but worth confirming that no stable release has ever emitted FundingInfo::Contribution.

  2. into_unique_contributions semantic change: Output comparison changed from full TxOut equality (value + script) to script-only matching. This means two outputs with the same script but different values are now treated as duplicates during filtering. This is intentional per the PR's design, but it does mean a user with multiple outputs to the same script (different amounts) in a discarded funding would have all of them filtered out if that script appears in the current funding.

@jkczyz jkczyz mentioned this pull request Mar 19, 2026
36 tasks
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 91.11111% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.09%. Comparing base (23b620a) to head (e07c154).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
lightning/src/ln/interactivetxs.rs 73.07% 7 Missing ⚠️
lightning/src/chain/channelmonitor.rs 91.22% 1 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4498      +/-   ##
==========================================
- Coverage   87.11%   87.09%   -0.03%     
==========================================
  Files         161      161              
  Lines      109246   109322      +76     
  Branches   109246   109322      +76     
==========================================
+ Hits        95173    95209      +36     
- Misses      11592    11627      +35     
- Partials     2481     2486       +5     
Flag Coverage Δ
fuzzing-fake-hashes 31.17% <50.37%> (+0.04%) ⬆️
fuzzing-real-hashes 22.67% <2.96%> (+0.07%) ⬆️
tests 86.15% <91.11%> (-0.03%) ⬇️

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.

@ldk-reviews-bot
Copy link
Copy Markdown

🔔 1st Reminder

Hey @jkczyz! 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 @jkczyz! 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 @jkczyz! 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 @jkczyz! 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

🔔 5th Reminder

Hey @jkczyz! 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

🔔 6th Reminder

Hey @jkczyz! 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

🔔 7th Reminder

Hey @jkczyz! 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

🔔 8th Reminder

Hey @jkczyz! 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

🔔 9th Reminder

Hey @jkczyz! 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

🔔 10th Reminder

Hey @jkczyz! 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

🔔 11th Reminder

Hey @jkczyz! 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

🔔 12th Reminder

Hey @jkczyz! 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

🔔 13th Reminder

Hey @jkczyz! 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

🔔 14th Reminder

Hey @jkczyz! 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

🔔 15th Reminder

Hey @jkczyz! 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

🔔 16th Reminder

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

Exposing the amounts for each output isn't very helpful because it's
possible that they vary across over multiple splice candidates due to
RBF. This commit changes `FundingInfo::Contribution` and several of the
helpers used to derive it to be based on output scripts instead.
Similar to the `ChannelManager`, we expose the contributed inputs and
outputs of a splice via `FundingInfo::Contribution` at the
`ChannelMonitor` level such that we don't lose the context when the
channel closes while a splice is still pending. This relies on tracking
the `FundingContribution` that was provided to the `ChannelManager`
prior to negotiating the new funding transaction. If no
`FundingContribution` exists, then we continue to emit the
`FundingInfo::OutPoint` variant.
@wpaulino wpaulino force-pushed the channel-monitor-discard-funding-contribution branch from ca819d9 to e07c154 Compare April 27, 2026 17:23
Comment on lines +8321 to +8326
let signing_session = self
.context
.interactive_tx_signing_session
.as_ref()
.map(|signing_session| !signing_session.has_received_tx_signatures())
.unwrap_or(false));
.expect("Signing session must exist for negotiated pending splice");
debug_assert!(!signing_session.has_received_tx_signatures());
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.

Nit: This changes from a debug_assert (no-op in release builds) to expect (panics in release builds). The old code combined the existence check and state check into a single debug assertion; now existence is enforced unconditionally while the state check remains debug-only.

This is arguably safer (fail-fast instead of silent invariant violation), but since signing_session isn't used beyond the debug_assert on the next line, consider whether returning a ChannelError would be more robust than panicking — consistent with how this function handles other missing state (e.g., the commitment_point error path at line 8340).

Copy link
Copy Markdown
Contributor

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

At least much of the first commit will conflict with #4514. Which should we merge first?

Comment on lines +4125 to +4131
self.pending_events.push(Event::DiscardFunding {
channel_id: self.channel_id,
funding_info: FundingInfo::Contribution {
inputs: discarded_inputs.into_iter().collect(),
outputs: discarded_outputs.into_iter().collect(),
},
});
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.

Hmm... in channelmanager.rs, we make a separate DiscardFunding event for each attempt. Should we do the same here? It would remove the non-determinism introduced by the hash set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants