Skip to content

lightningd: lock in the mined RBF inflight, not the latest one - #9374

Open
ksedgwic wants to merge 2 commits into
ElementsProject:masterfrom
ksedgwic:fix-rbf-lockin-wrong-inflight
Open

lightningd: lock in the mined RBF inflight, not the latest one#9374
ksedgwic wants to merge 2 commits into
ElementsProject:masterfrom
ksedgwic:fix-rbf-lockin-wrong-inflight

Conversation

@ksedgwic

@ksedgwic ksedgwic commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Fixes #9373.

If a non-tip RBF inflight is the one that gets mined, and the peer reconnects while we are still catching up on blocks, we locked the channel in with the tip inflight -- which was never mined. Full sequence in the issue.

Two commits:

  1. lightningd: record the mined inflight on the channel as soon as its block is processed (dual_funding_found), rather than waiting for catch-up to finish; and make peer_restart_dualopend reestablish with the inflight matching the recorded funding when the scid is already set, rather than assuming the latest one.

  2. pytest: deterministic regression test. It stalls the block fetch after the funding block via the bitcoind proxy, holding the catch-up window open, then reconnects. Without the previous commit this locks in the never-mined tip inflight on every run; with it, the mined one.

When a block containing a non-tip inflight's funding tx was
processed, dual_funding_found set the channel's scid right away, but
the channel's funding fields were only updated to the mined inflight
once block catch-up completed (opening_depth_cb, via the blockdepth
watches).  A peer reconnecting inside that window reestablished
against channel_current_inflight() -- the latest inflight -- with the
scid already set, so dualopend sent channel_ready and the channel
locked in a funding tx that was never mined: its last_tx spends a
nonexistent outpoint, and the two peers disagree about the channel's
funding.

Record the mined inflight on the channel as soon as its block is
seen, and make peer_restart_dualopend reestablish with the inflight
matching the recorded funding when the scid is already set.

Fixes: ElementsProject#9373
Changelog-Fixed: Protocol: dual-funding: reconnecting during block catch-up could lock in a channel with the latest RBF candidate rather than the one that was actually mined.
test_rbf_non_last_mined occasionally fails in CI when the peer
reconnects while the node is still catching up on blocks (ElementsProject#9373).
Reproduce that window deterministically: stall the fetch of the
block after the funding block via the bitcoind proxy, so the node
has seen the funding confirm but cannot finish catching up, then
reconnect.  Without the previous commit, this locks in the
never-mined latest inflight on every run.
@ksedgwic
ksedgwic requested review from cdecker and ddustin August 3, 2026 23:41
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.

dualopend: reconnect during block catch-up locks in the wrong RBF inflight

1 participant