Commit message · cdeckerlightningd: drop the dual-funding lock-in guard, and un-promote on reorg
Review follow-up to the dual-funding RBF fix.
The belt-and-braces lock-in guard in handle_channel_locked() force-closed
healthy channels: get_tx_depth() reads our_txs.blockheight, which every
startup zeroes for the whole --rescan window while peer reestablish runs
concurrently (setup_peers() precedes begin_topology()). A dual-funded
channel that reached minimum_depth while its peer was offline, then
reconnected before the rescan re-confirmed the funding block, hit
"Tried to lock in funding tx ... which we have not seen mined" and was
unilaterally closed. The scid/funding pair only ever moves together
(opening_depth_cb), so by the time both sides are ready the funding tx
was seen mined; drop the guard entirely.
The reorg path also left channel->scid/channel->funding committed to a
candidate that was reorged out: opening_reorged_cb cleared only the
inflight's scid, so reestablish still claimed local_channel_ready against
a dead scid. If the reorged inflight is the promoted one, un-promote it
by clearing the scid -- its mere presence is what makes reestablish claim
local_channel_ready -- and save explicitly, since channel_set_scid()
doesn't persist. channel->funding is deliberately left alone: rolling it
back to the newest inflight would also rewrite last_tx (that's what
update_channel_from_inflight() does), pointing the channel at a candidate
that was never mined -- this very bug, reached through the reorg path
instead of through a reconnect. Leaving it be keeps it naming the only
candidate we ever saw mined, so channel_inflight_find() still resolves at
reinit, and a candidate mining re-promotes properly.
That un-promote is a new way for channel->scid to be NULL at lock-in, and
dualopend never un-latches channel_ready[LOCAL]: it is set on
DEPTH_REACHED and only reset by a reinit, which seeds it from
channel->scid. So on a live connection the pre-reorg latch combines with
the peer's re-arriving channel_ready and reaches handle_channel_locked()
with no scid, where the assert() would take the whole node down -- and a
bare return would leave the channel awaiting lock-in forever, the
surviving dualopend having exited with its latch spent. Restart dualopend
over the peer fd it handed us instead (from_abort=true, since we're still
connected), seeded with the truth: local ready = scid != NULL = false,
remote ready = latched. When a candidate re-mines, the depth callback
fires DEPTH_REACHED and lock-in completes.
Add regression tests for both: test_lockin_restart_rescan_race and
test_lockin_reorg_after_promotion.
Changelog-None
Co-Authored-By: Ken Sedgwick <ken@bonsai.com>
83/100 · StrongMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification
Why it was queuedfuzzing or regression evidence