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

Small consistency updates for channel upgrade spec #1036

Merged
merged 3 commits into from
Nov 20, 2023

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Nov 16, 2023

While re-reviewing the channel upgrades spec to regain context, I noticed a few small inconsistencies in code style in the pseudo code and a few suggestions for different wording in several cases.

Copy link
Contributor

@sangier sangier left a comment

Choose a reason for hiding this comment

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

Thanks @chatton ! I just left an additional comment. Apart from that, LGTM!

// counterparty has already successfully upgraded so we cannot timeout
abortTransactionUnless(false)
}
}
abortTransactionUnless(counterpartyChannel.upgradeSequence >== channel.upgradeSequence)
abortTransactionUnless(counterpartyChannel.upgradeSequence >= channel.upgradeSequence)
Copy link
Contributor

Choose a reason for hiding this comment

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

Another consideration for the comment at line 999 :
"Both parties must not complete the upgrade handshake if the counterparty upgrade timeout has already passed. Even if both sides could have successfully moved to FLUSHCOMPLETE. This will prevent the channel ends from reaching incompatible states."

Note that the timeoutChannelUpgrade cannot be called if we reach the state where both chain are in FLUSHING_COMPLETE because abortTransactionUnless(counterpartyChannel.state !== FLUSHCOMPLETE) will bring to failure. That means that in this state we cannot send a ChanUpgradeTimeout datagram.

Thus to ensure we can still timeout in this state, we should add a check in ChanUpgradeOpen checking if CounterPartyTimeoutHasExpired. If yes we could write an error, error that the counterparty chain can use to restore its channelEnd.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please correct me if I'm wrong: we check the counterpartyUpgradeTimeout in timeoutPacket and acknowledgePacket and if the timeout has passed, then we execute restoreChannel, which should write an error receipt that can be used to cancel the upgrade on the counterparty. So in this case we wouldn't need to call timeoutChannelUpgrade, but we would call cancelChannelUpgrade instead?

And one question that was wondering after reading your comment: would it be possible for both channel ends to move to FLUSH_COMPLETE and then detect that the counterpartyUpgradeTimeout has passed? Asking because if the channel end moves to FLUSH_COMPLETE then we don't check the counterpartyUpgradeTimeout anymore in timeoutPacket and acknowledgePacket, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

In my understanding:

  1. We only send a timeoutChannelUpgrade datagram if the timeout is detected in our end. Otherwise we write the error and then send a cancelChannelUpgrade. Thus, your statement is correct.
  2. Once we reach the (FLUSH_COMPLETE,FLUSH_COMPLETE) the upgrade is mostly finalised and we only need to move to OPEN. At this point we don't care anymore about timeouts because all packets have been flushed.

I also open this PR to clarify the spec comment in bold mentioned in the previous message. As per this fix, we don't need to to ensure we can still timeout in this state. Thus no modification to ChanUpgradeOpen is required.

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thank you, @chatton. I think I wouldn't change the ==/!= to ===/!== for the regular if statements. In the rest of the specs the usage of ===/!== is (mostly) limited to the boolean statements inside assert or abortTransactionUnless. In most of the if statements ==/!=` are used, which is also closer to typescript, since that's the programming language we kinda use for the pseudocode.

Copy link
Contributor

@crodriguezvega crodriguezvega left a comment

Choose a reason for hiding this comment

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

Thank you, @chatton!

@crodriguezvega crodriguezvega merged commit c0711a0 into main Nov 20, 2023
3 checks passed
@crodriguezvega crodriguezvega deleted the cian/review-channel-upgrades branch November 20, 2023 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants