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

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

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

After thorough review of the entire diff, I verified:

  1. Parameter rename counterparty_aborted -> allow_resumption: All 8 call sites correctly apply the semantic inversion. The logic within the function body is correctly swapped between the if/else branches.

  2. cancel_funding_contributed in channel.rs: The three FundingNegotiation variant checks, the has_holder_tx_signatures guard for AwaitingSignatures, and the reset_pending_splice_state call are all correct. The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state is safe because has_received_commitment_signed() is never true when cancellation can occur (commitment_signed is stashed, not processed through the signing session, until funding_transaction_signed is called).

  3. cancel_funding_contributed in channelmanager.rs: Lock ordering, event emission, error routing through handle_error, and holding cell release via exited_quiescence are all correct. The disconnect case is handled by the re-establishment protocol (sends tx_abort if counterparty has next_funding_txid but we lack a signing session).

  4. Test changes: The fail_splice_on_tx_abort test correctly adapts to inject a fake tx_abort since abandon_splice was removed. The new tests cover all three FundingNegotiation states, the acceptor-with-contribution flow, the post-signing rejection, and holding cell HTLC release on quiescence exit.

  5. AbortReason::ManualIntervention: Correctly added and displayed.

No new issues found beyond those already flagged in my prior review (the .expect() on splice_funding_failed and the contribution-check divergence across variants). Both prior issues remain unaddressed in the current code.

No issues found.

}

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.

wpaulino added 2 commits April 8, 2026 15:09
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.
@wpaulino wpaulino requested a review from jkczyz April 8, 2026 22:17
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