Skip to content
LearnBitcoin

ResearchBitcoin Dev Archive lightning-dev list

Splice Lock Race Condition Solution

3 messages, Apr 4 to 6, 2023. Started by Dusty Daemon.

Dusty Daemon (2), Bastien TEINTURIER

Permalink First message in the Wayback Machine

Dusty Daemon permalink original

Hey,

In testing the `splice_locked` workflow I discovered a race condition which is critical we solve correctly. The core problem happens if any channel activity occurs in the time after `splice_locked` is sent and before `splice_locked` is received.

`splice_locked` is defined as being locked once it is both sent and received. It is fairly trivial to build a test case for this -- have a node continually spamming payments while `splice_lock`ing is occurring and the race condition will trigger relatively often.

The race condition effects two messages in particular: `commitment_signed` and `announcement_signatures`. Below is an example of how it occurs with commitment but the flow is essentially the same for announcement:

Legend: Item -> means sent Item <- means received Chan X (implies a channel at block height X) (Since these happen at different times) Splice locked race condition example Node A. Node B. * Channel starts at block height 100 splice_locked -> <- splice_locked <- commitments_signed (Chan 100) -> splice_locked Node B now considers splice locked (Chan 106) <- commitments_signed (Chan 106) splice_locked <- Node A now considers splice locked (Chan 106) commitments_signed <- (Chan 100) commitments_signed <- (Chan 106) Node A considers the commitments_signed for Chan 100 invalid. The commitments_signed for Chan 106 is, however, valid. This example uses commitments_signed but remains a problem for any message that depends on channel state.

The solution requires the temporary storing of two items: * [scid] last_short_channel_id (the pre-splice short channel id) * [bool] splice_await_commitment_succcess

After sending & receiving `splice_locked` (so called 'mutual splice lock), the last_short_channel_id should be set to the pre-splice short channel id and splice_await_commitment_succcess should be flagged to true.

If an `announcement_signatures` is received with an scid matching `last_short_channel_id` the message should be ignored and the channel connection should not be aborted (as it normally would).

If a `commitment_signed` message is received with the tlv splice_info->splice_channel_id set to something other than the successfully confirmed splice channel_id, the message should be ignored.

Once a revoke_and_ack is successfully sent OR received, `last_short_channel_id` and `splice_await_commitment_succcess` should be reset and normal validation of `announcement_signatures` and `commitment_signed` should be resumed.

This solves the race condition while preserving as strict a validation of messages as possible and removes the need to add new fields to these messages.

Cheers, Dusty

Bastien TEINTURIER in reply to Dusty Daemon permalink original

Hi Dustin,

I believe this is the scenario I described in [1]?

I haven't looked at the `announcement_signatures` case yet, but at least for the `commit_sig` case this should never be an issue. It only means that sometimes, after sending `splice_locked`, you will receive some `commit_sig` messages that are for commitments that you don't care about anymore. You should be able to safely ignore those `commit_sig`. I have provided more details in the gist linked.

Let me know if I'm missing something, but I believe this is simply an edge case that implementations need to correctly handle, not a protocol issue? Or maybe I'm not understanding the scenario correctly?

By the way, I find your notation a bit hard to follow...I think that we really need to detail the exact message flow (like I did in the linked gist) to be able to explain protocol issues, otherwise there's always a risk that people think about a slightly different message flow, which means we'll just talk past each other...

Cheers, Bastien

[1] https://gist.github.com/t-bast/1ac31f4e27734a10c5b9847d06db8d86#multiple-splices-with-racy-splice_locked

Le jeu. 6 avr. 2023 à 02:40, Dustin Dettmer <dustin at koinkeep.com> a écrit :

Quoted text (71 lines)
> Hey,
>
> In testing the `splice_locked` workflow I discovered a race condition
> which is critical we solve correctly. The core problem happens if any
> channel activity occurs in the time after `splice_locked` is sent and
> before `splice_locked` is received.
>
> `splice_locked` is defined as being locked once it is both sent and
> received. It is fairly trivial to build a test case for this -- have a node
> continually spamming payments while `splice_lock`ing is occurring and the
> race condition will trigger relatively often.
>
> The race condition effects two messages in particular: `commitment_signed`
> and `announcement_signatures`. Below is an example of how it occurs with
> commitment but the flow is essentially the same for announcement:
>
> Legend:
> Item -> means sent
> Item <- means received
> Chan X (implies a channel at block height X)
> (Since these happen at different times)
> Splice locked race condition example
> Node A. Node B.
> * Channel starts at block height 100
> splice_locked ->
> <- splice_locked
> <- commitments_signed (Chan 100)
> -> splice_locked
> Node B now considers splice locked (Chan 106)
> <- commitments_signed (Chan 106)
> splice_locked <-
> Node A now considers splice locked (Chan 106)
> commitments_signed <- (Chan 100)
> commitments_signed <- (Chan 106)
> Node A considers the commitments_signed for Chan 100 invalid.
> The commitments_signed for Chan 106 is, however, valid.
> This example uses commitments_signed but remains a problem for any message
> that depends on channel state.
>
> The solution requires the temporary storing of two items:
> * [scid] last_short_channel_id (the pre-splice short channel id)
> * [bool] splice_await_commitment_succcess
>
> After sending & receiving `splice_locked` (so called 'mutual splice lock),
> the last_short_channel_id should be set to the pre-splice short channel id
> and splice_await_commitment_succcess should be flagged to true.
>
> If an `announcement_signatures` is received with an scid matching
> `last_short_channel_id` the message should be ignored and the channel
> connection should not be aborted (as it normally would).
>
> If a `commitment_signed` message is received with the
> tlv splice_info->splice_channel_id set to something other than the
> successfully confirmed splice channel_id, the message should be ignored.
>
> Once a revoke_and_ack is successfully sent OR received,
> `last_short_channel_id` and `splice_await_commitment_succcess` should be
> reset and normal validation of `announcement_signatures` and
> `commitment_signed` should be resumed.
>
> This solves the race condition while preserving as strict a validation of
> messages as possible and removes the need to add new fields to these
> messages.
>
> Cheers,
> Dusty
> _______________________________________________
> Lightning-dev mailing list
> Lightning-dev at lists.linuxfoundation.org
> https://www.learnbitcoin.com/archive/lists/lightning-dev
>
Dusty Daemon in reply to Bastien TEINTURIER permalink original
Quoted text (4 lines)
>
> I haven't looked at the `announcement_signatures` case yet, but at least
> for the `commit_sig` case this should never be an issue.
>

Yup the issue is the same for `announcement_signatures`. Storing the last_short_channel_id is key here so you know which announcement message you can safely ignore and which are considered errors. This behavior should be enacted until sending OR receiving `revoke_and_ack`.

Quoted text (6 lines)
> It only means
> that sometimes, after sending `splice_locked`, you will receive some
> `commit_sig` messages that are for commitments that you don't care about
> anymore. You should be able to safely ignore those `commit_sig`. I have
> provided more details in the gist linked.
>

Yup you should ignore invalid commit_sigs for this brief period of time but then go back to rejecting invalid commit_sigs after sending OR receiving `revoke_and_ack`.

Quoted text (4 lines)
> Let me know if I'm missing something, but I believe this is simply an
> edge case that implementations need to correctly handle, not a protocol
> issue? Or maybe I'm not understanding the scenario correctly?
>

It is a critical detail to implement correctly. Implementations without good test coverage can easily ship releases that will break / force close randomly during the splice lock process. What's worse is this effects the larger more valuable/busy routing nodes more often and is easy to miss on a simple regtest node 😳.

Quoted text (6 lines)
By the way, I find your notation a bit hard to follow...I think that we
> really need to detail the exact message flow (like I did in the linked
> gist) to be able to explain protocol issues, otherwise there's always
> a risk that people think about a slightly different message flow, which
> means we'll just talk past each other...
>

The original gist from back in January is here: https://gist.github.com/ddustin/7ee222eb31c3eac5b141c991c0937fae

Happy to add more details but the example is accurate to exactly the messages sent during this time. Confirmed it with actual tests as well.

Is there some message that it looks like I missed here? If it helps I can give you an actual log message flow from the real tests, but honestly, they just make it more confusing to understand 🤷.

It might be simpler to follow by working backwards from this solution: https://gist.github.com/ddustin/017aeadfbf34d2fcd950f1238614afe2

My original proposal from late January ^ 100% solves the issue but adds a lock on the connection via an extra STFU step.

My current proposal is essentially "let's allow the race condition and observe which things become invalid during it." I settled on two things invalid events that occur: * A stale `commitments_signed` message (bundle) with extra signatures * A stale `announcement_sigs` message for the pre-splice channel

An "easy" solution an implementation could do is allow any invalid `commitments_signed` or `announcement_sigs` to come through and ignore them without warning or error. This "works" but leaves the node in a messy state where actual errors are being squelched and opens up a potential DoS issue.

So the ideal solution is to allow a certain class of 'stale' messages for a period of time, that time being from: A) mutual_splice_locked (the moment we have both sent & received `splice_locked`) B) A successful `commitment_signed` <-> `revoke_and_ack` round trip (in either direction)

The definition of A is pretty straightforward and we need to detect mutual_splice_lock anyway so that's easy.

The definition of B can be a couple of things but the simplest is I believe the sending OR receiving of `revoke_and_ack`.

Is it a little more work to implement it this way? Yeah. But I think the effort is worth it to make the protocol & our nodes more robust.

Cheers, Dusty