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

refactor: modify ack handler expected channel state #4371

Merged
3 changes: 1 addition & 2 deletions modules/core/04-channel/keeper/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@ func (k Keeper) AcknowledgePacket(
)
}

// TODO(damian): update TRYUPGRADE to FLUSHING following https://github.com/cosmos/ibc-go/issues/4243
if !collections.Contains(channel.State, []types.State{types.OPEN, types.TRYUPGRADE}) {
if !collections.Contains(channel.State, []types.State{types.OPEN, types.STATE_FLUSHING}) {
return errorsmod.Wrapf(types.ErrInvalidChannelState, "packets cannot be acknowledged on channel with state (%s)", channel.State)
}

Expand Down
3 changes: 1 addition & 2 deletions modules/core/04-channel/keeper/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,9 +788,8 @@ func (suite *KeeperTestSuite) TestAcknowledgePacket() {

channelCap = suite.chainA.GetChannelCapability(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)

// TODO(damian): update TRYUPGRADE to FLUSHING following https://github.com/cosmos/ibc-go/issues/4243
channel := path.EndpointA.GetChannel()
channel.State = types.TRYUPGRADE
channel.State = types.STATE_FLUSHING

path.EndpointA.SetChannel(channel)
}, true},
Expand Down
10 changes: 2 additions & 8 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,10 @@ func (k Keeper) WriteUpgradeTryChannel(ctx sdk.Context, portID, channelID string
panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanUpgradeTry step, channelID: %s, portID: %s", channelID, portID))
}

previousState := channel.State
channel.State = types.TRYUPGRADE

upgrade.Fields.Version = upgradeVersion

k.SetCounterpartyLastPacketSequence(ctx, portID, channelID, counterpartyLastSequenceSend)
k.SetChannel(ctx, portID, channelID, channel)
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.TRYUPGRADE.String())
k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", types.OPEN, "new-state", channel.State)
emitChannelUpgradeTryEvent(ctx, portID, channelID, channel, upgrade)

return channel, upgrade
Expand Down Expand Up @@ -242,7 +236,7 @@ func (k Keeper) ChanUpgradeAck(

counterpartyHops := []string{connection.GetCounterparty().GetConnectionID()}
counterpartyChannel := types.Channel{
State: types.TRYUPGRADE,
State: types.STATE_FLUSHING,
Ordering: channel.Ordering,
ConnectionHops: counterpartyHops,
Counterparty: types.NewCounterparty(portID, channelID),
Expand Down
5 changes: 0 additions & 5 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,8 @@ func (suite *KeeperTestSuite) TestWriteUpgradeTry() {

upgrade, found := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.GetUpgrade(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
suite.Require().True(found)
suite.Require().Equal(types.TRYUPGRADE, channel.State)
suite.Require().Equal(upgradeWithAppCallbackVersion, upgrade)

actualCounterpartyLastSequenceSend, ok := suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.GetCounterpartyLastPacketSequence(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID)
suite.Require().True(ok)
suite.Require().Equal(proposedUpgrade.LatestSequenceSend, actualCounterpartyLastSequenceSend)

events := ctx.EventManager().Events().ToABCIEvents()
expEvents := ibctesting.EventsMap{
types.EventTypeChannelUpgradeTry: {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ func (suite *KeeperTestSuite) TestChannelUpgradeTry() {
suite.Require().Equal(channeltypes.SUCCESS, res.Result)

channel := path.EndpointB.GetChannel()
suite.Require().Equal(channeltypes.TRYUPGRADE, channel.State)
suite.Require().Equal(channeltypes.STATE_FLUSHING, channel.State)
suite.Require().Equal(uint64(1), channel.UpgradeSequence)
},
},
Expand Down
Loading