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

Implement openUpgradeHandshake subprotocol #3759

Conversation

DimitrisJim
Copy link
Contributor

Description

Add the openUpgradeHandshake sub protocol (renamed to WriteUpgradeOpenChannel as per the comments in the issue.

closes: #3644

Commit Message / Changelog Entry

Implement openUpgradeHandshake subprotocol

see the guidelines for commit messages. (view raw markdown for examples)


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md).
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

// WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel fields. This can be called in one of two cases:
// - In the UpgradeAck step of the handshake both sides have already flushed any in-flight packets.
// - In the UpgradeOpen step of the handshake.
func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Question. It would be nice if we could get information about who called us (Ack or Open) since that can be used in the error messages and when incrementing the telemetry counter. Would a bool (or enum :^)) be the preferred approach?

I don't think we can use the previousState here to make assumptions about who called us but I haven't thought too hard about it yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we use the previousState?

Copy link
Contributor Author

@DimitrisJim DimitrisJim Jun 6, 2023

Choose a reason for hiding this comment

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

If my understanding of the state transitions are correct (ref recent PR https://github.com/cosmos/ibc/pull/978/files). We can end up in the subprotocol from both open and from ack with channel state being ACKUPGRADE for channel A.

Copy link
Contributor

Choose a reason for hiding this comment

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

are you talking about the case where this subprotocol is being called on chain B, where chain A has automatically moved from ACK -> OPEN bc the pending in flight packets check results in an automatic chan OPEN?

Copy link
Contributor

Choose a reason for hiding this comment

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

if so, i think we could then still use this because the previousState of the chain B channel should be accurate.

Copy link
Contributor Author

@DimitrisJim DimitrisJim Jun 8, 2023

Choose a reason for hiding this comment

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

wouldn't B be in TRYUPGRADE?

To be a bit more verbose about my confusion, during ChanUpgradeAck and after startFlushUpgradeHandshake the states of A and B will be (ACKUPGRADE, TRYUPGRADE) (referencing the PR linked in the previous comment). If at this point both A and B have finished flushing, openUpgradeHandShake will be called with those two states for A and B.

OTOH, if they have not finished flushing, after they do, the relayer will submit the ChanUpgradeClose messages to both A and B and the states, having not changed, will still be (ACKUPGRADE, TRYUPGRADE).

I feel I'm missing something here but can't see it yet. Either way, this doesn't affect the core logic, its mostly for the telemetry counter and the err messages.

// WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel fields. This can be called in one of two cases:
// - In the UpgradeAck step of the handshake both sides have already flushed any in-flight packets.
// - In the UpgradeOpen step of the handshake.
func (k Keeper) WriteUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why can't we use the previousState?

@DimitrisJim DimitrisJim force-pushed the jim/3644-implement-openupgradehandshake-subprotocol branch from a41350e to d394e0a Compare June 6, 2023 14:52
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Nice! LGTM

// WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel, sets the channel flush status to `NOTINFLUSH` and sets the channel state back to `OPEN`. This can be called in one of two cases:
// - In the UpgradeAck step of the handshake if both sides have already flushed all in-flight packets.
// - In the UpgradeOpen step of the handshake.
func (k Keeper) writeUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

will this method not be called from the core msg server and need to be unexported?

Copy link
Contributor

Choose a reason for hiding this comment

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

can be updated when its used

Copy link
Contributor

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

LGTM

// WriteUpgradeOpenChannel writes the agreed upon upgrade fields to the channel, sets the channel flush status to `NOTINFLUSH` and sets the channel state back to `OPEN`. This can be called in one of two cases:
// - In the UpgradeAck step of the handshake if both sides have already flushed all in-flight packets.
// - In the UpgradeOpen step of the handshake.
func (k Keeper) writeUpgradeOpenChannel(ctx sdk.Context, portID, channelID string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can be updated when its used

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

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

One note is that I didn't use checks in spec since they would be duplicated. So in spec it is caller responsibility. Up to implementation team whether it makes sense to have checks in the function or not

@DimitrisJim DimitrisJim force-pushed the jim/3644-implement-openupgradehandshake-subprotocol branch from 0f5c081 to 563548d Compare June 8, 2023 08:41
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.

Nice, @DimitrisJim!

@DimitrisJim DimitrisJim merged commit 44ed96a into 04-channel-upgrades Jun 13, 2023
@DimitrisJim DimitrisJim deleted the jim/3644-implement-openupgradehandshake-subprotocol branch June 13, 2023 13:04
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.

6 participants