Commit message · cdeckerlightningd: don't lock in a dual-funding RBF candidate that was never mined
We recorded a confirmed dual-funding open in two steps which ran on
different schedules:
- dual_funding_found() set channel->scid, inline from filter_block_txs()
as each block was added, and
- opening_depth_cb() moved channel->funding (and last_tx/last_sig) over
to the inflight that confirmed -- but that only runs from the
blockdepth watches, which fire from updates_complete(), i.e. only once
we've run out of blocks to fetch.
Every RBF attempt overwrites channel->funding and channel->last_tx with
the newest candidate, so while a node was catching up on blocks it could
sit with a scid from the candidate that was mined and a funding outpoint
naming a completely different one.
A reconnect landing in that window saw the mixed state: peer_restart_dualopend()
derives local_channel_ready from channel->scid != NULL, so dualopend
retransmitted channel_ready, the peer replied, and handle_channel_locked()
committed to channel->funding -- a tx which may never have been mined --
and then cleared every inflight, destroying the last_tx/last_sig for the
candidate that actually confirmed. The channel looked healthy but could
not be closed unilaterally, and the real funding output was no longer
being watched. A peer can drive this deliberately: contribute an input to
the final RBF attempt, double-spend it so it can never confirm, and
reconnect while the victim is catching up (restart, upgrade, stalled
bitcoind).
Do what the splice path already does: record the scid on the inflight
rather than the channel, and promote scid and funding together, in one
callback and one db transaction, once we're deep enough. Clear the
inflight's scid on reorg, which the open path was missing entirely.
Also pick the inflight matching channel->funding on reinit rather than the
list tail -- inflights reload ORDER BY funding_feerate, so after a restart
the tail is the highest-feerate attempt regardless of which one was mined.
And refuse to lock in (and so wipe the inflights) if the funding tx isn't
one we've actually seen on-chain.
As a side effect this also stops a reconnect at depth 1 from locking in a
channel whose minimum_depth is higher, which the scid-based
local_channel_ready flag allowed.
The regression test from #9374 is rewritten rather than kept alongside a
near-duplicate: it detected the window by waiting for the scid to appear
and expected lockin to complete while the node was still catching up,
neither of which holds once the scid only appears together with the
funding outpoint. The replacement covers the same scenario from the
victim's side -- it stalls the node that has to reload its inflights from
the database, so it also exercises the reinit picking the mined inflight
rather than the list tail -- and additionally asserts that the locked-in
channel holds the matching commitment tx and can still be closed
unilaterally.
Reported-by: Ken Sedgwick (@ksedgwic)
Changelog-Fixed: lightningd: dual-funding channels no longer lock in an RBF candidate which was never mined if a reconnect arrives while catching up on blocks.
91/100 · StrongMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
Why it was queuedfuzzing or regression evidence