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

Add implementation for WriteUpgradeCancelChannel #3773

Merged

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Jun 7, 2023

Description

This PR uses some methods introduced in #3728 so should be reviewed after.

closes: #3752

Commit Message / Changelog Entry

N/A Feature Branch


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.

Comment on lines 128 to 130
if err := k.restoreChannel(ctx, portID, channelID); err != nil {
return errorsmod.Wrap(types.ErrUpgradeRestoreFailed, fmt.Sprintf("failed to restore channel, channelID: %s, portID: %s", channelID, portID))
}
Copy link
Contributor Author

@chatton chatton Jun 7, 2023

Choose a reason for hiding this comment

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

do we want to just panic here too? I think mixing errors/panics is worse than using one or the other. Is a regular state reversion an okay outcome if a restore fails?

The current implementation of restore is using an error return, but I guess this could be a panic as well

My personal preference would be to use errors everywhere, even if the code should be unreachable (i.e. channel not found in a later handshake step)

Copy link
Contributor

Choose a reason for hiding this comment

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

i like the idea of returning an error, because as we discussed before then it is clear from the method signature that WriteUpgrade... could fail.

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.

@@ -388,3 +386,24 @@ func emitErrorReceiptEvent(ctx sdk.Context, portID string, channelID string, cur
),
})
}

// emitUpgradedCancelledEvent emits an upgraded cancelled event.
func emitUpgradedCancelledEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) {
Copy link
Contributor

Choose a reason for hiding this comment

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

To make it more consistent with the naming of the other functions:

Suggested change
func emitUpgradedCancelledEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) {
func emitChannelUpgradeCancelEvent(ctx sdk.Context, portID string, channelID string, currentChannel types.Channel, upgrade types.Upgrade) {

EventTypeChannelUpgradeTry = "channel_upgrade_try"
EventTypeChannelUpgradeAck = "channel_upgrade_ack"
EventTypeChannelUpgradeOpen = "channel_upgrade_open"
EventTypeChannelUpgradeCancelled = "channel_upgrade_cancelled"
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though I agree that events should be named in simple past tense, this is not the convention in the codebase at the moment...

Suggested change
EventTypeChannelUpgradeCancelled = "channel_upgrade_cancelled"
EventTypeChannelUpgradeCancel = "channel_upgrade_cancelled"


errorReceipt, found := channelKeeper.GetUpgradeErrorReceipt(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
if upgradeError != nil {
suite.Require().True(found, "error receipt should be found")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove the if upgradeError != nil check completely? In the success case, the error receipt should be present, so suite.Require().True(found... will fail if it's not.

if tc.channelPresent {
suite.Require().True(found, "channel should be found")
suite.Require().Equal(types.INITUPGRADE, channel.State, "channel state should not be restored to %s", types.INITUPGRADE.String())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be here an else block to check suite.Require().False(found, "channel should not be found") in case the test case has channelPresent set to false?


channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when cancelling channel upgrade, channelID: %s, portID: %s", channelID, portID))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really necessary to add when cancelling channel upgrade to the error message? Wouldn't there be any other information in the log (like a stack trace) to figure that out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah you're right it's not really required

@chatton chatton marked this pull request as ready for review June 14, 2023 10:10
@chatton chatton requested a review from colin-axner as a code owner June 14, 2023 10:10
@chatton chatton mentioned this pull request Jun 14, 2023
9 tasks
Copy link
Contributor

@DimitrisJim DimitrisJim left a comment

Choose a reason for hiding this comment

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

lgtm

@chatton chatton merged commit 87d8158 into 04-channel-upgrades Jun 14, 2023
@chatton chatton deleted the cian/issue#3752-implement-writeupgradecancelchannel branch June 14, 2023 14:32
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.

5 participants