Skip to content

Allow cancellation of pending splice funding negotiations#4490

Open
wpaulino wants to merge 2 commits intolightningdevkit:mainfrom
wpaulino:cancel-splice
Open

Allow cancellation of pending splice funding negotiations#4490
wpaulino wants to merge 2 commits intolightningdevkit:mainfrom
wpaulino:cancel-splice

Conversation

@wpaulino
Copy link
Copy Markdown
Contributor

A user may wish to cancel an in-flight funding negotiation for whatever reason (e.g., mempool feerates have gone down, inability to sign, etc.), so we should make it possible for them to do so. Note that this can only be done for splice funding negotiations for which the user has made a contribution to.

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

ldk-reviews-bot commented Mar 17, 2026

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

Comment thread lightning/src/ln/channelmanager.rs Outdated
Comment on lines +4941 to +4942
let splice_funding_failed = splice_funding_failed
.expect("Only splices with local contributions can be canceled");
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 .expect() can panic in release builds. While cancel_splice in channel.rs verifies made_contribution is true, the maybe_create_splice_funding_failed! macro additionally subtracts contributions that overlap with prior RBF rounds (via prior_contributed_inputs/outputs). For a non-initiator who reuses the same UTXOs across RBF attempts with no explicit output contributions, the subtraction can empty the lists, causing the macro to return None (line 6740-6742 of channel.rs: if !is_initiator && contributed_inputs.is_empty() && contributed_outputs.is_empty() { return None; }).

The debug_assert!(splice_funding_failed.is_some()) at channel.rs:12323 catches this in debug, but this expect will crash in release for that edge case. Consider handling None gracefully, e.g. by returning an APIError or skipping the events.

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.

@jkczyz looks like that if statement it's referring to is indeed happening after the filtering. We should check whether the contribution is empty prior to filtering. I also noticed that we'll always emit DiscardFunding even when both contributed inputs and outputs are empty, we should only do so when there is actually something to discard.

Copy link
Copy Markdown
Contributor

@jkczyz jkczyz Apr 8, 2026

Choose a reason for hiding this comment

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

@jkczyz looks like that if statement it's referring to is indeed happening after the filtering. We should check whether the contribution is empty prior to filtering.

Hmm... we may want to base this on #4514. It refactors that code a bit and removes maybe_create_splice_funding_failed!. I believe the new splice_funding_failed_for! macro does it correctly now (dc0609d)

I also noticed that we'll always emit DiscardFunding even when both contributed inputs and outputs are empty, we should only do so when there is actually something to discard.

I believe that is fixed in #4514, too. Can't recall if it's the same commit, but the PR should consolidate the filtering logic to FundingContribution::into_unique_contributions.

Comment thread lightning/src/ln/channel.rs
@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

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

After a thorough review of the entire PR diff, I confirm that my previously flagged issues remain applicable and no new issues were found in this review pass. All call sites for the counterparty_abortedallow_resumption rename are correctly inverted. The cancel_funding_contributed logic is sound across all FundingNegotiation states and the quiescent_action early path.

Review Summary

No new issues found beyond the four previously flagged. All prior issues remain applicable to the current diff:

Previously posted inline comments (still active):

  1. lightning/src/ln/channel.rs:12795debug_assert!(splice_funding_failed.is_some()) can fire in release for non-initiator RBF edge case where maybe_create_splice_funding_failed! filters all contributions.
  2. lightning/src/ln/channel.rs:12759has_local_contribution() vs contributed_inputs()/contributed_outputs() use different computation paths for the same semantic check across FundingNegotiation variants.
  3. lightning/src/ln/channelmanager.rs:4941PersistenceNotifierGuard::manually_notify does not set needs_persist_flag. The explicit event_persist_notifier.notify() at line 4983 ensures event delivery, but channel state changes (splice reset, quiescence exit) may not be persisted until the next unrelated trigger. Consider optionally_notify to match funding_contributed and funding_transaction_signed.
  4. lightning/src/ln/splicing_tests.rs:3007 — Dead code: if state == 0 branch is unreachable because state 0 returns early at line 2990.

Verification notes:

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 8 call sites.
  • The quiescent_action early path in cancel_funding_contributed correctly handles both WarnAndDisconnect (stfu/quiescent flags set → disconnect cleans up) and Abort (no flags → tx_abort is harmlessly ignored by counterparty with no active negotiation).
  • The stashed commitment_signed invariant ensures has_received_commitment_signed() remains false until after funding_transaction_signed(), making the reset_pending_splice_state debug_assert pass for the AwaitingSignatures cancel path.
  • Serialization preserves quiescence for AwaitingSignatures, enabling post-reconnect cancellation.

Comment thread lightning/src/ln/channel.rs
Comment thread lightning/src/ln/channel.rs
Comment thread lightning/src/ln/channelmanager.rs Outdated
}

debug_assert!(self.context.channel_state.is_quiescent());
let splice_funding_failed = self.reset_pending_splice_state();
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.

Do we need to worry about updating PendingFunding::contributions when reseting? This may be a pre-existing issue, though.

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.

Already fixed in a547960.

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

Comment thread lightning/src/ln/channelmanager.rs Outdated
Comment thread lightning/src/ln/channelmanager.rs Outdated
Comment thread lightning/src/ln/channel.rs
Comment on lines +4940 to +4941
let mut result = Ok(());
PersistenceNotifierGuard::manually_notify(self, || {
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.

The previous abandon_splice used PersistenceNotifierGuard::optionally_notify and returned NotifyOption::SkipPersistHandleEvents on success, which would wake up the background processor to deliver the newly-added SpliceFailed/DiscardFunding events and the tx_abort message promptly.

manually_notify delegates the notification decision to process_background_events(), which returns SkipPersistNoEvents when there are no pending background events. This means when no holding-cell HTLCs are freed (the handle_holding_cell_free_result path that calls notify()), the background processor is never woken up. Events and messages sit in memory until the next polling interval or until some unrelated activity triggers notification.

This is also a persistence concern: the splice state reset and quiescence exit modify channel state, but without notification, persistence may not happen until the next trigger. If the node crashes in between, the cancel is effectively lost (though the reestablishment protocol handles recovery).

Consider using optionally_notify (returning SkipPersistHandleEvents on success, SkipPersistNoEvents on error) to match the behavior of other public APIs like funding_contributed and funding_transaction_signed.

Comment thread lightning/src/ln/splicing_tests.rs Outdated
Comment on lines +3005 to +3007
acceptor.node.handle_tx_abort(node_id_initiator, tx_abort);
if state == 0 {
assert!(acceptor.node.get_and_clear_pending_msg_events().is_empty());
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.

Dead code: state == 0 can never be true here because that case returned early at line 2990. The if branch is unreachable — only the else ever runs.

Suggested change
acceptor.node.handle_tx_abort(node_id_initiator, tx_abort);
if state == 0 {
assert!(acceptor.node.get_and_clear_pending_msg_events().is_empty());
acceptor.node.handle_tx_abort(node_id_initiator, tx_abort);
{
let tx_abort = get_event_msg!(acceptor, MessageSendEvent::SendTxAbort, node_id_initiator);

A user may wish to cancel an in-flight funding negotiation for whatever
reason (e.g., mempool feerates have gone down, inability to sign, etc.),
so we should make it possible for them to do so. Note that this can only
be done for splice funding negotiations for which the user has made a
contribution to.
There's a case in `should_reset_pending_splice_state` where we are
awaiting signatures, but still want to preserve the pending negotiation
upon a disconnection. We previously used `counterparty_aborted` as a way
to toggle this behavior. Now that we support the user manually canceling
an ongoing negotiation, we interpret the argument a bit more
generically in terms of whether we wish to resume the negotiation or not
when we are found in such a state.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 79.16667% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.16%. Comparing base (42e198c) to head (aac57cc).

Files with missing lines Patch % Lines
lightning/src/ln/channelmanager.rs 70.83% 13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs 84.50% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4490      +/-   ##
==========================================
+ Coverage   87.15%   87.16%   +0.01%     
==========================================
  Files         161      161              
  Lines      109251   109278      +27     
  Branches   109251   109278      +27     
==========================================
+ Hits        95215    95256      +41     
+ Misses      11560    11549      -11     
+ Partials     2476     2473       -3     
Flag Coverage Δ
fuzzing-fake-hashes 31.18% <5.00%> (+0.03%) ⬆️
fuzzing-real-hashes 22.84% <3.33%> (-0.08%) ⬇️
tests 86.23% <79.16%> (+0.01%) ⬆️

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.

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