Skip to content

Commit

Permalink
fix: channel must exist before channel creator check (#7538)
Browse files Browse the repository at this point in the history
* fix: channel must exist before channel creator check

* Update modules/core/04-channel/v2/keeper/msg_server.go

Co-authored-by: DimitrisJim <[email protected]>

* fixed failing test

---------

Co-authored-by: DimitrisJim <[email protected]>
  • Loading branch information
gjermundgaraba and DimitrisJim authored Nov 7, 2024
1 parent ed714a9 commit 9239d5d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func (k *Keeper) CreateChannel(goCtx context.Context, msg *types.MsgCreateChanne
func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *types.MsgRegisterCounterparty) (*types.MsgRegisterCounterpartyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

channel, ok := k.GetChannel(ctx, msg.ChannelId)
if !ok {
return nil, errorsmod.Wrapf(types.ErrChannelNotFound, "channel must exist for channel id %s", msg.ChannelId)
}

creator, found := k.GetCreator(ctx, msg.ChannelId)
if !found {
return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set")
Expand All @@ -47,11 +52,6 @@ func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *types.MsgRegis
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "channel creator (%s) must match signer (%s)", creator, msg.Signer)
}

channel, ok := k.GetChannel(ctx, msg.ChannelId)
if !ok {
return nil, errorsmod.Wrapf(types.ErrInvalidChannel, "channel must exist for channel id %s", msg.ChannelId)
}

channel.CounterpartyChannelId = msg.CounterpartyChannelId
k.SetChannel(ctx, msg.ChannelId, channel)
// Delete client creator from state as it is not needed after this point.
Expand Down
3 changes: 2 additions & 1 deletion modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func (suite *KeeperTestSuite) TestRegisterCounterparty() {
{
"failure: channel must already exist",
func() {
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.DeleteCreator(suite.chainA.GetContext(), path.EndpointA.ChannelID)
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.ChannelStore(suite.chainA.GetContext(), path.EndpointA.ChannelID).Delete([]byte(channeltypesv2.ChannelKey))
},
channeltypesv2.ErrInvalidChannel,
channeltypesv2.ErrChannelNotFound,
},
}

Expand Down

0 comments on commit 9239d5d

Please sign in to comment.