Repository navigation
lightningd: fail a splice command when channeld goes - #110
davelund110 wants to merge 1 commit into
Conversation
kwsantiago
left a comment
There was a problem hiding this comment.
Thanks, the hang is real and failing the command is the right fix. Changes needed before merge, inline below plus two here.
handle_splice_confirmed_initandhandle_splice_confirmed_updateinlightningd/channel_control.ccallchannel_internal_erroron the PSBT version conversion failure and then fall through tojson_stream_success(cc->cmd). With this changechannel_internal_errorreacheschannel_set_owner(channel, NULL), which fails and frees the commandcchangs off, so that is now a use after free. Add areturnafter each.- 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.
3173577 to
53f78c4
Compare
|
Thanks. Done in 53f78c4: both handlers return after the internal error, and the commit has a Changelog-Fixed line. |
kwsantiago
left a comment
There was a problem hiding this comment.
Thanks, both points are fixed. A few more before merge, inline below plus two here.
- Can a splice or stfu command still be pending when
peer_start_closingd_after_shutdownorforget()retires channeld? Neither goes through the new hooks. - The description still says the command is failed from
channel_set_owner()and lists two tests.
53f78c4 to
83621e4
Compare
|
Thanks. Done in 83621e4:
The branch is also rebased onto the latest blake2b-unified (6693675). |
kwsantiago
left a comment
There was a problem hiding this comment.
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.
| /* 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| if (!cc) | ||
| return; | ||
|
|
||
| if (!resumable || !cc->sigs_saved) { |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
83621e4 to
4c625ae
Compare
|
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
left a comment
There was a problem hiding this comment.
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.
| opt_set_bool, | ||
| &ld->dev_splice_sign_first, | ||
| "Always send splice tx_signatures first"); | ||
| clnopt_witharg("--dev-splice-sigs-wait", OPT_DEV|OPT_SHOWINT, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| "- 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.", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
4c625ae to
dbb86bb
Compare
|
Thanks. Done in dbb86bb:
|
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:
And test_splice_signed_conflicting_locktimes in tests/test_splicing.py: splice_signed refuses a PSBT whose inputs leave it no valid locktime.
Checklist
--splice-sigs-wait.)tools/lightning-downgrade. (No persistent changes.)