Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/cian/issue#3447-modify-upgrade…
Browse files Browse the repository at this point in the history
…init-to-use-new-upgrade-type' into charly/#3448-modify-upgrade-try
  • Loading branch information
charleenfei committed Apr 19, 2023
2 parents c7c7884 + 0e8092b commit 4c23aa5
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 173 deletions.
3 changes: 0 additions & 3 deletions e2e/tests/core/04-channel/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

test "github.com/strangelove-ventures/interchaintest/v7/testutil"
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/e2e/testsuite"
Expand Down Expand Up @@ -44,8 +43,6 @@ func (s *ChannelUpgradeTestSuite) TestChannelUpgrade() {
s.Require().NoError(err)
s.AssertValidTxResponse(txResp)

s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA))

channel, err := s.QueryChannel(ctx, chainA, channelA.PortID, channelA.ChannelID)
s.Require().NoError(err)
s.Require().Equal(channeltypes.INITUPGRADE, channel.State)
Expand Down
23 changes: 8 additions & 15 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ func (k Keeper) ChanUpgradeInit(
channelID string,
upgradeFields types.UpgradeFields,
upgradeTimeout types.UpgradeTimeout,
) (proposedUpgrade types.Upgrade, err error) {
) (types.Upgrade, error) {
channel, found := k.GetChannel(ctx, portID, channelID)
if !found {
return proposedUpgrade, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
return types.Upgrade{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

if channel.State != types.OPEN {
return proposedUpgrade, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected %s, got %s", types.OPEN, channel.State)
return types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected %s, got %s", types.OPEN, channel.State)
}

if err := k.ValidateUpgradeFields(ctx, upgradeFields, channel); err != nil {
return proposedUpgrade, err
return types.Upgrade{}, err
}

proposedUpgrade, err = k.constructProposedUpgrade(ctx, portID, channelID, upgradeFields, upgradeTimeout)
proposedUpgrade, err := k.constructProposedUpgrade(ctx, portID, channelID, upgradeFields, upgradeTimeout)
if err != nil {
return proposedUpgrade, errorsmod.Wrap(err, "failed to construct proposed upgrade")
return types.Upgrade{}, errorsmod.Wrap(err, "failed to construct proposed upgrade")
}

channel.UpgradeSequence++
Expand Down Expand Up @@ -67,15 +67,8 @@ func (k Keeper) constructProposedUpgrade(ctx sdk.Context, portID, channelID stri
return types.Upgrade{}, types.ErrSequenceSendNotFound
}
return types.Upgrade{
Fields: types.UpgradeFields{
Ordering: fields.Ordering,
ConnectionHops: fields.ConnectionHops,
Version: fields.Version,
},
Timeout: types.UpgradeTimeout{
Height: timeout.Height,
Timestamp: timeout.Timestamp,
},
Fields: fields,
Timeout: timeout,
LatestSequenceSend: seq - 1,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeInit() {
false,
},
{
"invalid proposed channel upgrade ordering",
"stricter proposed channel upgrade ordering",
func() {
upgrade.Fields.Ordering = types.ORDERED
},
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func (msg MsgChannelUpgradeInit) ValidateBasic() error {
}

if !msg.Timeout.IsValid() {
return errorsmod.Wrap(ErrInvalidUpgrade, "upgrade timeout cannot be empty")
return errorsmod.Wrap(ErrInvalidUpgrade, "upgrade timeout height and upgrade timeout timestamp cannot both be 0")
}

return msg.Fields.ValidateBasic()
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ func (suite *TypesTestSuite) TestMsgChannelUpgradeInitValidateBasic() {
suite.Run(tc.name, func() {
msg = types.NewMsgChannelUpgradeInit(
ibctesting.MockPort, ibctesting.FirstChannelID,
types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstChannelID}, mock.Version),
types.NewUpgradeFields(types.UNORDERED, []string{ibctesting.FirstConnectionID}, mock.Version),
types.NewUpgradeTimeout(clienttypes.NewHeight(0, 10000), timeoutTimestamp),
addr,
)
Expand Down
282 changes: 143 additions & 139 deletions modules/core/04-channel/types/tx.pb.go

Large diffs are not rendered by default.

7 changes: 1 addition & 6 deletions modules/core/04-channel/types/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ibc-go/v7/internal/collections"
ibcerrors "github.com/cosmos/ibc-go/v7/internal/errors"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
)

Expand Down Expand Up @@ -45,11 +44,7 @@ func (u Upgrade) ValidateBasic() error {
}

if !u.Timeout.IsValid() {
return errorsmod.Wrap(ErrInvalidUpgrade, "upgrade timeout cannot be empty")
}

if u.LatestSequenceSend < 0 {
return errorsmod.Wrap(ibcerrors.ErrInvalidSequence, "latest sequence send must be greater than or equal to 0")
return errorsmod.Wrap(ErrInvalidUpgrade, "upgrade timeout height and upgrade timeout timestamp cannot both be 0")
}

return nil
Expand Down
8 changes: 4 additions & 4 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,19 +702,19 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC

module, _, err := k.ChannelKeeper.LookupModuleByChannel(ctx, msg.PortId, msg.ChannelId)
if err != nil {
ctx.Logger().Error("channel upgrade init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrap(err, "could not retrieve module from port-id"))
return nil, errorsmod.Wrap(err, "could not retrieve module from port-id")
}

cbs, ok := k.Router.GetRoute(module)
if !ok {
ctx.Logger().Error("channel upgrade init callback failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module))
ctx.Logger().Error("channel upgrade init failed", "port-id", msg.PortId, "error", errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module))
return nil, errorsmod.Wrapf(porttypes.ErrInvalidRoute, "route not found to module: %s", module)
}

proposedUpgrade, err := k.ChannelKeeper.ChanUpgradeInit(ctx, msg.PortId, msg.ChannelId, msg.Fields, msg.Timeout)
if err != nil {
ctx.Logger().Error("channel upgrade init callback failed", "error", errorsmod.Wrap(err, "channel handshake upgrade init failed"))
ctx.Logger().Error("channel upgrade init failed", "error", errorsmod.Wrap(err, "channel handshake upgrade init failed"))
return nil, errorsmod.Wrap(err, "channel handshake upgrade init failed")
}

Expand Down Expand Up @@ -745,7 +745,7 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC

return &channeltypes.MsgChannelUpgradeInitResponse{
ChannelId: msg.ChannelId,
Version: proposedVersion,
Upgrade: proposedUpgrade,
UpgradeSequence: channel.UpgradeSequence,
}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions proto/ibc/core/channel/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ message MsgChannelUpgradeInit {

// MsgChannelUpgradeInitResponse defines the MsgChannelUpgradeInit response type
message MsgChannelUpgradeInitResponse {
string channel_id = 1;
string version = 2;
uint64 upgrade_sequence = 3;
string channel_id = 1;
Upgrade upgrade = 2 [(gogoproto.nullable) = false];
uint64 upgrade_sequence = 3;
}

// MsgChannelUpgradeTry defines the request type for the ChannelUpgradeTry rpc
Expand Down

0 comments on commit 4c23aa5

Please sign in to comment.