Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify relative order of some messages after reestablish #810

Merged
merged 1 commit into from
Nov 23, 2020
Merged

Conversation

t-bast
Copy link
Collaborator

@t-bast t-bast commented Oct 23, 2020

The existing requirements were not specifying the case where both a commitment_signed and revoke_and_ack need to be retransmitted.

This is an important case to specify because if the relative order is not preserved, the channel will close.
See for example the following two scenarios.

Rev then Sig

A            B
 <---add-----
 ----add---->
 <---sig-----
 ----rev----x
 ----sig----x

A needs to retransmit:

----add-->
----rev-->
----sig-->

With some leeway on when she sends the add: it can be either before or after rev, she can choose to not send it at all, or update the fees. The important point is that sig must occur after rev.

Sig then Rev

A            B
 <---add-----
 ----add---->
 ----sig----x
 <---sig-----
 ----rev----x

A needs to retransmit:

----add-->
----sig-->
----rev-->

With some leeway on the add, she may choose to omit it, update the fees, etc (but all of these before the sig). The important point is that sig must occur before rev.

Fixes #794

The existing requirements were not specifying the case where both a
`commitment_signed` and `revoke_and_ack` need to be retransmitted.

This is an important case to specify because if the relative order is not
preserved, the channel will close.

Fixes #794
@Crypt-iQ
Copy link
Contributor

ACK fc07aab
I don't know the language format of the spec too well, but this would fix the issue.

@Roasbeef
Copy link
Collaborator

Roasbeef commented Nov 7, 2020

Interestingly, I considered this case when first implementing our retransmission ordering and arbitrarily chose an ordering: https://github.com/lightningnetwork/lnd/blob/master/lnwallet/channel.go#L3810

@Roasbeef
Copy link
Collaborator

Roasbeef commented Nov 7, 2020

However the ordering may not be the same with how we implement it atm, since we always do revoke->sig if we need to send both.

Copy link
Collaborator

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I thought initially that we need to prescribe a global ordering, but reading this I realize that the main requirement is that the sender itself be consistent in their retransmission ordering.

@@ -1256,6 +1256,10 @@ A node:
the last `revoke_and_ack` the receiving node sent, AND the receiving node
hasn't already received a `closing_signed`:
- MUST re-send the `revoke_and_ack`.
- if it has previously sent a `commitment_signed` that needs to be
retransmitted:
- MUST retransmit `revoke_and_ack` and `commitment_signed` in the same
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should also spell out the recommended persistence requirements here as well? This was something lnd did incorrectly in a few places (not storing what we need to in order to properly reconstruct a commitment to validate a retransmission. However np with also leaving this off for a more fundamental path to make things more explicit generally.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah re-reading again, there is a light requirement re naive persistence down below where the diff touches the spec.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I didn't update that paragraph about persistence that rusty wrote a while ago, but I could, let me know what changes you think would make sense there (if any)!

@Roasbeef
Copy link
Collaborator

Roasbeef commented Nov 9, 2020

One question that comes to mind: do we need to care about backwards compatibility for this at all? I'm leaning towards no, as this is the "right" way, although switching to this may create a period of instability (spurious force closes) in the network).

@manreo
Copy link

manreo commented Nov 12, 2020

Fixes lightningnetwork/lnd#4613 ?

although switching to this may create a period of instability (spurious force closes) in the network).

There are already spurious force closes... So I think it does not matter

@t-bast
Copy link
Collaborator Author

t-bast commented Nov 16, 2020

@Roasbeef do you think I need to add some changes, or is the last state of the PR ok to you?

@t-bast t-bast merged commit 920e519 into master Nov 23, 2020
@t-bast t-bast deleted the issue-794 branch November 23, 2020 19:14
SomberNight added a commit to SomberNight/electrum that referenced this pull request May 24, 2022
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements lightning/bolts#810

The logic here is somewhat based on what c-lightning does:
https://github.com/ElementsProject/lightning/blob/01e5f1886e31816e652f417a1ff789a26aaeec3b/channeld/channeld.c#L3059
SomberNight added a commit to SomberNight/electrum that referenced this pull request May 25, 2022
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements lightning/bolts#810

The logic here is somewhat based on what c-lightning does:
https://github.com/ElementsProject/lightning/blob/01e5f1886e31816e652f417a1ff789a26aaeec3b/channeld/channeld.c#L3059
SomberNight added a commit to SomberNight/electrum that referenced this pull request May 25, 2022
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements lightning/bolts#810

The logic here is somewhat based on what c-lightning does:
https://github.com/ElementsProject/lightning/blob/01e5f1886e31816e652f417a1ff789a26aaeec3b/channeld/channeld.c#L3059
SomberNight added a commit to SomberNight/electrum that referenced this pull request May 25, 2022
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements lightning/bolts#810

The logic here is somewhat based on what c-lightning does:
https://github.com/ElementsProject/lightning/blob/01e5f1886e31816e652f417a1ff789a26aaeec3b/channeld/channeld.c#L3059
SomberNight added a commit to spesmilo/electrum that referenced this pull request May 26, 2022
When replaying messages during channel-reestablishment,
previously we first resent all update messages, along with potential commitment_signed messages,
and then we potentially resent a single revoke_and_ack.

This can result in incorrect behaviour in case both a commitment_signed and a revoke_and_ack needs to be resent.
When replaying messages, the relative order of commitment_signed and revoke_and_messages needs to be preserved.
(the order of updates (htlc/fee) in relation to the revack messages does not matter)

implements lightning/bolts#810

The logic here is somewhat based on what c-lightning does:
https://github.com/ElementsProject/lightning/blob/01e5f1886e31816e652f417a1ff789a26aaeec3b/channeld/channeld.c#L3059
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.

commit_sig, revoke_and_ack ordering in channel reestablish flow
6 participants