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

feat: adding msg server implementation for ChannelUpgradeAck #3849

Merged
merged 32 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1293330
adding boilerplate skeleton for chanUpgradeAck handler
damiannolan May 31, 2023
c4dce22
Merge branch '04-channel-upgrades' into damian/1620-chan-upgrade-ack
damiannolan Jun 5, 2023
a8c6882
updating msg servers args
damiannolan Jun 5, 2023
c17c8ed
adding test scaffolding and syncing latest changes of feat branch
damiannolan Jun 5, 2023
152a873
Merge branch '04-channel-upgrades' into damian/1620-chan-upgrade-ack
damiannolan Jun 5, 2023
fbacd83
configure both proposed upgrades to use mock.UpgradeVersion
damiannolan Jun 6, 2023
dfaf589
Merge branch '04-channel-upgrades' into damian/1620-chan-upgrade-ack
damiannolan Jun 7, 2023
2834124
Merge branch '04-channel-upgrades' into damian/1620-chan-upgrade-ack
damiannolan Jun 12, 2023
f92edcb
updating chanUpgradeAck test cases
damiannolan Jun 12, 2023
0ae120f
updating var naming for consistency, adding additional testcases
damiannolan Jun 12, 2023
73e9352
rm msg server implementation
damiannolan Jun 12, 2023
2b8b3fe
adding invalid flush status err and rm lint ignore comment
damiannolan Jun 13, 2023
e53d1aa
adding test helpers to endpoint for get/set channel upgrade
damiannolan Jun 13, 2023
f9c2167
lint it
damiannolan Jun 13, 2023
566ab66
adding initial msg server impl skeleton
damiannolan Jun 13, 2023
c241a63
pull in code for WriteUpgradeAckChannel
damiannolan Jun 13, 2023
b1958fd
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 14, 2023
ec60447
adding result to MsgChannelUpgradeAckResponse
damiannolan Jun 14, 2023
b82afaf
Merge branch 'damian/update-ack-response-args' into damian/3742-upgra…
damiannolan Jun 14, 2023
7082cd8
add initial test cases
damiannolan Jun 14, 2023
80326a0
adding additional testcases
damiannolan Jun 14, 2023
c870ce1
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 14, 2023
cd3d443
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 20, 2023
d23c6f1
apply testcase naming review suggestions
damiannolan Jun 20, 2023
4ba1751
apply error return wrapping suggestions from review
damiannolan Jun 20, 2023
a710ee4
fix error to use Wrapf and correct channel id arg, adding success log
damiannolan Jun 20, 2023
e75f1ca
correct testing imports and satisy linter
damiannolan Jun 20, 2023
0169d98
apply self suggestions for testcase context with in-line comments
damiannolan Jun 21, 2023
9d71ee5
updating test func to use path.EndpointA and chainA sender acc
damiannolan Jun 21, 2023
970d006
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 21, 2023
d60bf1f
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 21, 2023
215280c
Merge branch '04-channel-upgrades' into damian/3742-upgrade-ack-msg-s…
damiannolan Jun 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 54 additions & 46 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,52 +204,6 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string
return channel, upgrade
}

// WriteUpgradeAckChannel writes a channel which has successfully passed the UpgradeAck handshake step as well as
// setting the upgrade for that channel.
// An event is emitted for the handshake step.
func (k Keeper) WriteUpgradeAckChannel(
ctx sdk.Context,
portID, channelID string,
proposedUpgrade types.Upgrade,
) {
defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack")

channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanUpgradeAck step, channelID: %s, portID: %s", channelID, portID))
}

previousState := channel.State
channel.State = types.ACKUPGRADE
channel.FlushStatus = types.FLUSHING

k.SetChannel(ctx, portID, channelID, channel)
k.SetUpgrade(ctx, portID, channelID, proposedUpgrade)

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState, "new-state", types.ACKUPGRADE.String())
emitChannelUpgradeAckEvent(ctx, portID, channelID, channel, proposedUpgrade)
}

// WriteUpgradeCancelChannel writes a channel which has canceled the upgrade process.Auxiliary upgrade state is
// also deleted.
func (k Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID string) {
Copy link
Member Author

@damiannolan damiannolan Jun 20, 2023

Choose a reason for hiding this comment

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

this was cut and paste from a merge conflict, whoops -_-

wanted to fix ordering of funcs

defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-cancel")

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find upgrade when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

k.restoreChannel(ctx, portID, channelID, channel)

emitChannelUpgradeCancelEvent(ctx, portID, channelID, channel, upgrade)
}

// ChanUpgradeAck is called by a module to accept the ACKUPGRADE handshake step of the channel upgrade protocol.
// This method should only be called by the IBC core msg server.
// This method will verify that the counterparty has entered TRYUPGRADE
Expand Down Expand Up @@ -313,6 +267,60 @@ func (k Keeper) ChanUpgradeAck(
return nil
}

// WriteUpgradeAckChannel writes a channel which has successfully passed the UpgradeAck handshake step as well as
// setting the upgrade for that channel.
// An event is emitted for the handshake step.
func (k Keeper) WriteUpgradeAckChannel(
ctx sdk.Context,
portID, channelID string,
upgradeVersion string,
) {
defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-ack")

channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanUpgradeAck step, channelID: %s, portID: %s", channelID, portID))
}

previousState := channel.State
channel.State = types.ACKUPGRADE
channel.FlushStatus = types.FLUSHING

k.SetChannel(ctx, portID, channelID, channel)

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("cound not find existing upgrade when updating channel state in successful ChanUpgradeAck step, channelID: %s, portID: %s", channelID, portID))
}

upgrade.Fields.Version = upgradeVersion

k.SetUpgrade(ctx, portID, channelID, upgrade)

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", previousState, "new-state", types.ACKUPGRADE.String())
emitChannelUpgradeAckEvent(ctx, portID, channelID, channel, upgrade)
}

// WriteUpgradeCancelChannel writes a channel which has canceled the upgrade process.Auxiliary upgrade state is
// also deleted.
func (k Keeper) WriteUpgradeCancelChannel(ctx sdk.Context, portID, channelID string) {
defer telemetry.IncrCounter(1, "ibc", "channel", "upgrade-cancel")

upgrade, found := k.GetUpgrade(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find upgrade when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
panic(fmt.Sprintf("could not find existing channel when updating channel state, channelID: %s, portID: %s", channelID, portID))
}

k.restoreChannel(ctx, portID, channelID, channel)

emitChannelUpgradeCancelEvent(ctx, portID, channelID, channel, upgrade)
}

// startFlushUpgradeHandshake will verify the counterparty proposed upgrade and the current channel state.
// Once the counterparty information has been verified, it will be validated against the self proposed upgrade.
// If any of the proposed upgrade fields are incompatible, an upgrade error will be returned resulting in an
Expand Down
Loading