Skip to content

lightningd: fail a splice command when channeld goes - #110

Open
davelund110 wants to merge 1 commit into
privkeyio:blake2b-unifiedfrom
davelund110:splice-init-disconnect
Open

davelund110 wants to merge 1 commit into
privkeyio:blake2b-unifiedfrom
davelund110:splice-init-disconnect

Conversation

@davelund110

@davelund110 davelund110 commented Nov 14, 2026 •

Copy link
Copy Markdown

If the peer closes the connection during a splice negotiation, channeld exits and the negotiation ends with it, but channel_control_errmsg() only failed the pending splice command for an error or warning that disconnects. So splice_init (or splice_update) never returned. The same when lightningd stops channeld itself, say for a forced disconnect, a reconnect or a failure it starts: the command waited for ever, and every later splice on the channel was refused as busy.

Fail it wherever channeld goes: in channel_err(), which every transient failure ends in, in force_peer_disconnect(), in channel_fail_perm(), when closingd takes over after a shutdown, and in delete_channel(). Unless channeld has saved splice_signed's signatures, which it now says with a flag in update_inflight: a reconnect then resumes the splice, and our broadcast answers the command, as does the splice on chain if the peer broadcasts it without sending us its tx_signatures.

That wait is bounded, connected or not: if the peer's tx_signatures haven't come 60 seconds (the new --splice-sigs-wait) after ours were saved, the command fails, and a reconnect doesn't restart the bound. A splice_signed that fails once our signatures are saved, at the bound, on the peer's abort or with no splice to resume, gets its own code, 364, with the splice's txid: the peer may hold our signatures, so the splice may still confirm. And channeld now refuses a tx_abort outside the negotiation, as it does within it, while the last splice lacks the peer's signatures and we may have sent ours.

Tests in tests/test_splicing_disconnect.py:

  • the peer dropping the connection instead of answering splice_init;
  • lightningd stopping channeld itself (a forced disconnect), after which the same splice goes through;
  • our tx_signatures lost after splice_signed, so the peer's never come: a reconnect resumes the splice, and splice_signed returns its txid. We only wait for the peer's tx_signatures when we sign first, as when the peer adds more than we do; a CLN peer adds nothing and signs first, so the new --dev-splice-sign-first makes us sign first here;
  • the same with the peer staying connected: splice_signed fails with 364 at the bound, and the splice confirms after a reconnect;
  • a disconnect and reconnect in between don't restart the bound;
  • dev-fail with our signatures saved: splice_signed fails with 364 and the txid;
  • the peer broadcasting the splice without sending its tx_signatures: the splice on chain answers splice_signed;
  • the peer answering our tx_signatures with a warning and then tx_abort: we refuse the abort, and splice_signed fails with 364.

And test_splice_signed_conflicting_locktimes in tests/test_splicing.py: splice_signed refuses a PSBT whose inputs leave it no valid locktime.

Checklist

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed. (splice_signed's schema now lists its error codes, and lightningd-config.5 documents --splice-sigs-wait.)
  • Related issues have been listed and linked, including any that this PR closes. (None.)
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade. (No persistent changes.)

@kwsantiago kwsantiago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, the hang is real and failing the command is the right fix. Changes needed before merge, inline below plus two here.

  1. handle_splice_confirmed_init and handle_splice_confirmed_update in lightningd/channel_control.c call channel_internal_error on the PSBT version conversion failure and then fall through to json_stream_success(cc->cmd). With this change channel_internal_error reaches channel_set_owner(channel, NULL), which fails and frees the command cc hangs off, so that is now a use after free. Add a return after each.
  2. This is a user-visible fix, so it needs a Changelog-Fixed: line in the commit. Pre-build checks stop at that, so nothing has been built or tested yet.

Comment thread lightningd/channel_control.c Resolved
Comment thread lightningd/channel.c Resolved
Comment thread lightningd/channel_control.c Resolved
Comment thread tests/test_splicing_disconnect.py Resolved
@davelund110
davelund110 force-pushed the splice-init-disconnect branch from 3173577 to 53f78c4 Compare November 15, 2026 20:43
@davelund110

Copy link
Copy Markdown
Author

Thanks. Done in 53f78c4: both handlers return after the internal error, and the commit has a Changelog-Fixed line.

@kwsantiago kwsantiago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, both points are fixed. A few more before merge, inline below plus two here.

  1. Can a splice or stfu command still be pending when peer_start_closingd_after_shutdown or forget() retires channeld? Neither goes through the new hooks.
  2. The description still says the command is failed from channel_set_owner() and lists two tests.

Comment thread lightningd/channel_control.c Resolved
Comment thread lightningd/channel_control.c Resolved
Comment thread lightningd/channel_control.c Resolved
Comment thread tests/test_splicing_disconnect.py Resolved
@davelund110
davelund110 force-pushed the splice-init-disconnect branch from 53f78c4 to 83621e4 Compare November 19, 2026 23:25
@davelund110

Copy link
Copy Markdown
Author

Thanks. Done in 83621e4:

  • peer_start_closingd_after_shutdown() now fails a pending splice or stfu command before closingd takes over, and delete_channel() fails it before the channel is freed, which covers forget(). No splice resumes after either, so neither waits.
  • Looking for other paths, four callers of channel_fail_transient() drop channeld without channel_cleanup_commands(): an HTLC add timing out, a bad shutdown script, bad announcement_signatures and a zeroconf funding reorg. So the command is now failed from channel_err(), which every transient failure ends in, instead of from channel_cleanup_commands().
  • The description is updated.

The branch is also rebased onto the latest blake2b-unified (6693675).

@kwsantiago kwsantiago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, all five are fixed. Four more, two inline.

handle_peer_splice_locked never completes a pending splice_signed. If we sign first and the peer withholds its tx_signatures but broadcasts the splice itself, the splice confirms and locks while the command stays pending, then fails on the timer or at closingd with the user's inputs already spent. Could the lock (or splice_found seeing the tx) complete the matching signing command with the txid?

Separately, a peer that stays connected and never sends tx_signatures still leaves the command waiting with no bound, since the timer starts only when channeld goes. Either scope the changelog line or start the bound when our signatures go out.

Comment thread lightningd/channel_control.c Outdated
/* A reconnect resumes the splice, and our broadcast answers the
* command, but the peer may not come back: don't wait for ever. */
if (!cc->resume_timer)
cc->resume_timer = new_reltimer(ld->timers, cc,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The timer is armed once and never cancelled when the splice resumes. If the peer reconnects at 55 s and its tx_signatures arrive at 62 s, the command fails saying the splice has not resumed while the tx broadcasts, and the busy state is cleared mid-splice. Could it be freed when channeld restarts for that channel (or on the resumed update_inflight) and re-armed on the next drop?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

With the bound starting when our signatures are saved, there's one timer and nothing to cancel: a reconnect doesn't restart it, so a peer that keeps reconnecting can't hold the command for ever. In your 55/62 s case the command now fails at 60 s with 364 and the txid, saying the splice may still confirm, which is true at that point, and the splice then confirms as usual. lightningd is then in the same state as after a restart mid-splice, where no command survives either. test_splice_signed_sigs_wait_not_restarted checks that a reconnect doesn't restart the bound.

Comment thread lightningd/channel_control.c Outdated
if (!cc)
return;

if (!resumable || !cc->sigs_saved) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With sigs_saved set, a non-resumable failure (peer error, internal error, closingd, delete) still reports a plain "Splice command failed", though the peer holds our signatures and can broadcast the splice. Could this case say so, with the txid, and use its own error code so a caller can tell "may be committed" from "not committed"?

@davelund110 davelund110 Nov 21, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done: once our signatures are saved, a failure no reconnect resumes from, and the bound, fail with a new code, 364 (SPLICE_MAY_BE_COMMITTED): "the peer may hold our signatures for splice <txid>, so it may still confirm", with the txid in the error's data. For splice_signed, 363 now only comes before our signatures are saved, when the splice can't confirm. splice_signed's schema lists its error codes. test_splice_signed_fails_may_be_committed covers it with dev-fail.

@davelund110
davelund110 force-pushed the splice-init-disconnect branch from 83621e4 to 4c625ae Compare November 21, 2026 21:30
@davelund110

Copy link
Copy Markdown
Author

Thanks. Done in 4c625ae:

splice_found() now answers a pending splice_signed when the splice it signed is seen on chain, with the tx from the block, so a peer that broadcasts without sending its tx_signatures completes the command. test_splice_signed_answered_by_chain covers it, and fails without the change.

The bound now starts when channeld saves our signatures, connected or not, so a peer that stays connected and never sends tx_signatures can't hold the command. test_splice_signed_sigs_wait_ends has the peer stay connected. The changelog line now covers this too.

@kwsantiago kwsantiago left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks, all four hold up. One more, and two inline.

A peer can still get a 362 after our signatures are out. If we sign first and the peer sends a warning instead of tx_signatures, resume_splice_negotiation returns to the main loop, and a tx_abort then reaches check_tx_abort(peer, msg, NULL) from peer_in. With no txid the sent-sigs guard is skipped, and handle_splice_abort fails splice_signed with 362 "Peer aborted" while the peer can still broadcast. Could handle_splice_abort answer 364 when cc->signing && cc->sigs_saved, and check_tx_abort apply the guard to the last inflight when no txid is given? A test with --dev-splice-sign-first, a warning and then tx_abort would cover it.

Comment thread lightningd/options.c Outdated
opt_set_bool,
&ld->dev_splice_sign_first,
"Always send splice tx_signatures first");
clnopt_witharg("--dev-splice-sigs-wait", OPT_DEV|OPT_SHOWINT,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could this be a normal option? A block usually takes longer than 60 s, so on mainnet the 364 nearly always comes before splice_found can answer, and an operator can only change that with --developer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done: it's --splice-sigs-wait now, in lightningd-config.5 and listconfigs, still 60 by default, so a connected peer that never sends tx_signatures is reported promptly. The doc says that a value above a block interval lets splice_signed wait for a splice the peer broadcasts itself.

Comment thread doc/schemas/splice_signed.json Outdated
"- 355: Another splice command is still running on the channel.",
"- 356: The PSBT is invalid.",
"- 358: channeld can't sign the splice now, or the PSBT is missing a signature.",
"- 363: The splice failed before our signatures were saved, so it can't confirm.",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This leaves out 351, 354 and 362, which splice_signed can still return. On an RBF, 363 means this candidate can't confirm, though an earlier one the peer holds our signatures for still can. Could it say so?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done: 351, 354 and 362 are in, and 362 and 363 now say that after an RBF, an earlier version that the peer holds our signatures for can still confirm.

If the peer closes the connection during a splice negotiation, channeld
exits and the negotiation ends with it, but channel_control_errmsg() only
failed the pending splice command for an error or warning that
disconnects.  So splice_init (or splice_update) never returned.  The same
when lightningd stops channeld itself, say for a forced disconnect, a
reconnect or a failure it starts: the command waited for ever, and every
later splice on the channel was refused as busy.

Fail it wherever channeld goes: in channel_err(), which every transient
failure ends in (channel_errmsg() and the peer disconnecting, and also an
HTLC add timing out, a bad shutdown script, bad announcement_signatures
and a zeroconf funding reorg, which don't go through
channel_cleanup_commands()); in force_peer_disconnect(), which drops
channeld without channel_err(); in channel_fail_perm(); when closingd
takes over after a shutdown; and in delete_channel(), so the command
doesn't outlive the channel (forget(), say).

Unless channeld has saved splice_signed's signatures, which it now says
with a flag in update_inflight: a reconnect then resumes the splice, and
our broadcast answers the command.  So does the splice on chain
(splice_found()), as the peer can broadcast it without sending us its
tx_signatures.

That wait is bounded, connected or not: if the peer's tx_signatures
haven't come 60 seconds after channeld saved ours, the command fails.  A
reconnect doesn't restart the bound, so a peer that keeps reconnecting
can't stretch it.  The new --splice-sigs-wait sets the 60: blocks
usually take longer, so an operator who would rather wait for the
splice on chain can raise it.

A splice_signed that fails once our signatures are saved, at the bound or
after channel_fail_perm(), closingd starting or the channel's deletion
(where no splice resumes), may still confirm, as the peer may hold them.
It fails with its own code, SPLICE_MAY_BE_COMMITTED (364), saying so,
with the splice's txid in the error's data, so a caller can tell it from
a splice that can't confirm (362, 363).  That includes the peer aborting
it.  splice_signed's schema lists its error codes.

channeld refused a tx_abort once it had sent its tx_signatures, but only
within the negotiation: one outside it carries no txid, and was let
through.  A peer that answers our tx_signatures with a warning (which
ends the negotiation) and then sends tx_abort could so have lightningd
end the splice_signed while it can still broadcast the splice.  channeld
now refuses that too while the last splice lacks the peer's signatures,
as within the negotiation; an RBF attempt on a complete one can still be
aborted.  --dev-splice-abort-instead-of-sigs makes a peer do this, for
the test.

We only wait for the peer's tx_signatures after splice_signed when we
send ours first, as when the peer adds more than we do.  A CLN peer adds
nothing and signs first, and channeld has its tx_signatures before
splice_update returns, so --dev-splice-sign-first makes channeld send
ours first, for the tests.

handle_splice_confirmed_init() and handle_splice_confirmed_update() went
on to answer the command after an internal error, which now fails and
frees it: they return instead.

Changelog-Fixed: lightningd: a splice command no longer waits for ever when the peer disconnects or channeld stops during the splice, or when the peer never sends its signatures for `splice_signed`.
Changelog-Added: JSON-RPC: `splice_signed` fails with code 364, and the splice's `txid`, when the peer may hold our signatures, so the splice may still confirm.
Changelog-Added: Config: `splice-sigs-wait` sets how long `splice_signed` waits for the peer's signatures once ours are saved (default 60 seconds).
@davelund110
davelund110 force-pushed the splice-init-disconnect branch from 4c625ae to dbb86bb Compare November 22, 2026 16:03
@davelund110

Copy link
Copy Markdown
Author

Thanks. Done in dbb86bb:

  • A tx_abort that reaches channeld outside the negotiation (from peer_in, with no txid) is now refused like one inside it, when the last inflight lacks the peer's tx_signatures and we may have sent ours: channeld fails the channel and keeps the inflight, and splice_signed fails with 364. An inflight that has the peer's signatures too is left out, since aborting an RBF attempt on it also reaches check_tx_abort with no txid, and that still has to work. handle_splice_abort also answers 364 for a signing command with saved signatures, in case another path gets there. test_splice_signed_peer_aborts_after_warning covers it with a new --dev-splice-abort-instead-of-sigs (a warning and then tx_abort, instead of tx_signatures), and fails without the channeld change.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants