Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Allow cancellation of pending splice funding negotiations - #4490

Merged
TheBlueMatt merged 2 commits into
lightningdevkit:mainfrom
wpaulino:cancel-splice
May 8, 2026
Merged

Allow cancellation of pending splice funding negotiations#4490
TheBlueMatt merged 2 commits into
lightningdevkit: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.

@wpaulinowpaulino added this to the 0.3 milestone Mar 17, 2026
@wpaulino
wpaulino requested a review from jkczyzMarch 17, 2026 18:00
@wpaulinowpaulino self-assigned this Mar 17, 2026
@ldk-reviews-bot

ldk-reviews-bot commented Mar 17, 2026

Copy link
Copy Markdown

👋 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 threadlightning/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
ContributorAuthor

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.

@jkczyzjkczyzApr 8, 2026

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.

@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 threadlightning/src/ln/channel.rs
@ldk-claude-review-bot

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

Copy link
Copy Markdown
Collaborator

I've completed a thorough review of the entire PR diff, examining every hunk and cross-referencing with the codebase. All prior review comments have been verified against the current code.

Two prior comments appear to be resolved in the current code:

  • events/mod.rs:193 — Display string is now correctly "splice locally canceled"
  • interactivetxs.rs:142 — Doc link now resolves correctly

Review Summary

No new issues found beyond those flagged in the prior review pass. The remaining prior findings that are still applicable:

  1. lightning/src/ln/channelmanager.rs:4942debug_assert!(splice_funding_failed.is_some()) / potential release-mode silent event loss for non-initiator RBF edge case where splice_funding_failed_for! macro filters all contributions to None.
  2. lightning/src/ln/channel.rs:12830has_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. While the explicit event_persist_notifier.notify() at line 4978 ensures prompt event delivery, channel state changes (splice reset, quiescence exit) won't be persisted until an unrelated trigger. If the node crashes before then, the cancel is lost and the splice may resume on reconnection.
  4. lightning/src/ln/splicing_tests.rs:3140if state == 0 is unreachable dead code since that case returns early at line 3152.

Verification notes

  • The counterparty_abortedallow_resumption boolean inversion is correct across all 9 call sites (verified each one).
  • Lock ordering in cancel_funding_contributed is correct — peer/channel locks dropped before handle_interactive_tx_msg_err/handle_error.
  • The debug_assert!(self.should_reset_pending_splice_state(false)) in reset_pending_splice_state holds for the cancel_funding_contributed path because: has_holder_tx_signatures()=false implies has_received_commitment_signed()=false (counterparty's commitment_signed is stashed until funding_transaction_signed is called).
  • The quiescent_action cancellation path correctly handles three sub-cases: stfu not yet sent (Ignore), stfu sent but not received (WarnAndDisconnect), and both stfus exchanged (Ignore — counterparty's splice continues unaffected).
  • No TOCTOU risk between the has_holder_tx_signatures() check and reset_pending_splice_state since both run under the peer_state lock.
  • TLV tag 11 is reused for LocallyCanceled (renamed from LocallyAbandoned), maintaining wire compatibility.

Comment threadlightning/src/ln/channel.rs
Comment threadlightning/src/ln/channel.rs
Comment threadlightning/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
ContributorAuthor

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 threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/src/ln/channelmanager.rs Outdated
Comment threadlightning/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 threadlightning/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);

@codecov

codecovBot commented Apr 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.60000% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.11%. Comparing base (c766417) to head (637cc41).
⚠️ Report is 17 commits behind head on main.

Files with missing linesPatch %Lines
lightning/src/ln/channelmanager.rs72.54%13 Missing and 1 partial ⚠️
lightning/src/ln/channel.rs88.88%8 Missing ⚠️
lightning/src/events/mod.rs0.00%1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #4490 +/- ##
=======================================
Coverage 86.11% 86.11% =======================================
Files 157 157 Lines 108851 108817 -34 Branches 108851 108817 -34 =======================================
- Hits 93735 93706 -29 + Misses 12503 12494 -9 - Partials 2613 2617 +4 
FlagCoverage Δ
tests86.11% <81.60%> (+<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.

Comment threadlightning/src/ln/interactivetxs.rs Outdated
/// [`Event::FundingTransactionReadyForSigning`]: events::Event::FundingTransactionReadyForSigning
/// [`ChannelUnavailable`]: APIError::ChannelUnavailable
/// [`APIMisuseError`]: APIError::APIMisuseError
pub fn cancel_funding_contributed(

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.

please add calls to this in the fuzzer.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'll look into adding this when I restore splicing in the fuzzer

.as_ref()
.expect("We have a pending splice awaiting signatures")
.has_holder_tx_signatures();
if already_signed {

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.

Does this suffice? We call reset_pending_splice_state which asserts that !has_received_commitment_signed() but we don't check it here?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

We can only process the counterparty's initial commitment_signed once the user calls back with ChannelManager::funding_transaction_signed.

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

Comment threadlightning/src/ln/channel.rs Outdated
Comment threadlightning/src/ln/interactivetxs.rs Outdated
Comment threadlightning/src/ln/channel.rs
jkczyz
jkczyz previously approved these changes May 6, 2026
TheBlueMatt
TheBlueMatt previously approved these changes May 7, 2026
Comment threadlightning/src/ln/channelmanager.rs Outdated
@wpaulino
wpaulino dismissed stale reviews from TheBlueMatt and jkczyz via 575ae0bMay 7, 2026 16:40
@wpaulino
wpaulino requested a review from TheBlueMattMay 7, 2026 16:40
@jkczyz

Copy link
Copy Markdown
Contributor

CI is unhappy. One of my PRs added a parameter to one of the test helpers. So probably need a rebase.

jkczyz
jkczyz previously approved these changes May 7, 2026

@TheBlueMattTheBlueMatt left a comment

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.

Needs rebase now

Comment threadlightning/src/events/mod.rs Outdated
wpaulino added 2 commits May 7, 2026 16:06
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.
user_channel_id,
contribution,
reason: events::NegotiationFailureReason::NegotiationError {
reason: reason.unwrap_or(events::NegotiationFailureReason::NegotiationError {

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 really feels like it should be coming from the channel in the InteractiveTxMsgError, not set randomly here.

@TheBlueMatt
TheBlueMatt merged commit a1d4e2f into lightningdevkit:mainMay 8, 2026
19 of 20 checks passed
@wpaulino
wpaulino deleted the cancel-splice branch May 8, 2026 17:36
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants

@wpaulino@ldk-reviews-bot@ldk-claude-review-bot@jkczyz@TheBlueMatt