Commit message · auto-pr-botReject inbound channel acceptance when its ID is already in use
do_accept_inbound_channel removed a pending request from
`inbound_channel_request_by_id` and inserted the resulting channel into
`channel_by_id` without rechecking whether that ID had become occupied
since the request was queued. Because a peer chooses its
`temporary_channel_id` freely and a v1 channel's final ID is derived
from a funding outpoint the peer knows before we accept a second
request from it, a pending request could be accepted under the final ID
of another channel from the same peer.
@val asked:
> do_accept_inbound_channel inserts an accepted channel into
> channel_by_id without checking whether that ID became occupied after
> the OpenChannelRequest was queued. A channel-opening peer can first
> negotiate channel A, construct its funding transaction and calculate
> its final channel ID C, then send open_channel B with
> temporary_channel_id=C while A is still indexed under its original
> temporary ID. [...] When the application accepts B, this insert
> silently drops A's funded channel state and replaces it with an
> unfunded channel.
Recheck `channel_by_id` after the accepted channel's ID is known, while
still holding the peer-state lock that guards both ID maps. Checking at
acceptance time covers every way the ID can be taken in the meantime,
including `funding_created` inserting a funded channel under its
funding-derived ID, so the message handlers need no changes of their
own. The stale request is dropped and the caller gets
`ChannelUnavailable`; the already-tracked channel is left untouched.
The regression test queues a colliding request, funds and confirms the
first channel, then asserts that accepting the stale request fails and
the funded channel's state is preserved.
Requested-by: @val
Authored-By: matt/GLM-5.3-Flash-GGUF:Q4_K_XL <goose@users.noreply.local>
95/100 · StrongMessage clarity
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Mentions testing or verification
Why it was queuedfuzzing or regression evidence