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

chore: rename apis to align with spec #7511

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 1 addition & 1 deletion modules/core/04-channel/v2/client/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewTxCmd() *cobra.Command {

txCmd.AddCommand(
newCreateChannelTxCmd(),
newProvideCounterpartyTxCmd(),
newRegisterCounterpartyTxCmd(),
)

return txCmd
Expand Down
14 changes: 7 additions & 7 deletions modules/core/04-channel/v2/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func newCreateChannelTxCmd() *cobra.Command {
return cmd
}

// newProvideCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel.
func newProvideCounterpartyTxCmd() *cobra.Command {
// newRegisterCounterpartyCmd defines the command to provide the counterparty channel identifier to an IBC channel.
func newRegisterCounterpartyTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "provide-counterparty [channel-identifier] [counterparty-channel-identifier]",
Use: "register-counterparty [channel-identifier] [counterparty-channel-identifier]",
Args: cobra.ExactArgs(2),
Short: "provide the counterparty channel id to an IBC channel",
Long: `Provide the counterparty channel id to an IBC channel specified by its channel ID.`,
Example: fmt.Sprintf("%s tx %s %s provide-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName),
Short: "Register the counterparty channel identifier for an IBC channel",
Long: `Register the counterparty channel identifier for an IBC channel specified by its channel ID.`,
Example: fmt.Sprintf("%s tx %s %s register-counterparty channel-0 channel-1", version.AppName, exported.ModuleName, types.SubModuleName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -64,7 +64,7 @@ func newProvideCounterpartyTxCmd() *cobra.Command {
channelID := args[0]
counterpartyChannelID := args[1]

msg := types.MsgProvideCounterparty{
msg := types.MsgRegisterCounterparty{
ChannelId: channelID,
CounterpartyChannelId: counterpartyChannelID,
Signer: clientCtx.GetFromAddress().String(),
Expand Down
93 changes: 47 additions & 46 deletions modules/core/04-channel/v2/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,50 @@ import (

var _ channeltypesv2.MsgServer = &Keeper{}

// SendPacket implements the PacketMsgServer SendPacket method.
// CreateChannel defines a rpc handler method for MsgCreateChannel.
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved CreateChannel and RegisterCounterparty to top of file so things read logically wrt exec flow

Copy link
Contributor

Choose a reason for hiding this comment

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

I also wanted to move ack after recv 😬 (both here and in packet.go iirc)

Copy link
Member Author

Choose a reason for hiding this comment

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

say no more!

func (k *Keeper) CreateChannel(goCtx context.Context, msg *channeltypesv2.MsgCreateChannel) (*channeltypesv2.MsgCreateChannelResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

channelID := k.channelKeeperV1.GenerateChannelIdentifier(ctx)

// Initialize channel with empty counterparty channel identifier.
channel := channeltypesv2.NewChannel(msg.ClientId, "", msg.MerklePathPrefix)
k.SetChannel(ctx, channelID, channel)
k.SetCreator(ctx, channelID, msg.Signer)
k.SetNextSequenceSend(ctx, channelID, 1)

k.EmitCreateChannelEvent(goCtx, channelID)

return &channeltypesv2.MsgCreateChannelResponse{ChannelId: channelID}, nil
}

// RegisterCounterparty defines a rpc handler method for MsgRegisterCounterparty.
func (k *Keeper) RegisterCounterparty(goCtx context.Context, msg *channeltypesv2.MsgRegisterCounterparty) (*channeltypesv2.MsgRegisterCounterpartyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

creator, found := k.GetCreator(ctx, msg.ChannelId)
if !found {
return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set")
}

if creator != msg.Signer {
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(channeltypesv2.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.
k.DeleteCreator(ctx, msg.ChannelId)

return &channeltypesv2.MsgRegisterCounterpartyResponse{}, nil
}

// SendPacket defines a rpc handler method for MsgSendPacket.
func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPacket) (*channeltypesv2.MsgSendPacketResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
sequence, destChannel, err := k.sendPacket(ctx, msg.SourceChannel, msg.TimeoutTimestamp, msg.Payloads)
Expand All @@ -43,6 +86,7 @@ func (k *Keeper) SendPacket(ctx context.Context, msg *channeltypesv2.MsgSendPack
return &channeltypesv2.MsgSendPacketResponse{Sequence: sequence}, nil
}

// Acknowledgement defines an rpc handler method for MsgAcknowledgement.
func (k *Keeper) Acknowledgement(ctx context.Context, msg *channeltypesv2.MsgAcknowledgement) (*channeltypesv2.MsgAcknowledgementResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
relayer, err := sdk.AccAddressFromBech32(msg.Signer)
Expand Down Expand Up @@ -82,7 +126,7 @@ func (k *Keeper) Acknowledgement(ctx context.Context, msg *channeltypesv2.MsgAck
return &channeltypesv2.MsgAcknowledgementResponse{Result: channeltypesv1.SUCCESS}, nil
}

// RecvPacket implements the PacketMsgServer RecvPacket method.
// RecvPacket defines a rpc handler method for MsgRecvPacket.
func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPacket) (*channeltypesv2.MsgRecvPacketResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -162,7 +206,7 @@ func (k *Keeper) RecvPacket(ctx context.Context, msg *channeltypesv2.MsgRecvPack
return &channeltypesv2.MsgRecvPacketResponse{Result: channeltypesv1.SUCCESS}, nil
}

// Timeout implements the PacketMsgServer Timeout method.
// Timeout defines a rpc handler method for MsgTimeout.
func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout) (*channeltypesv2.MsgTimeoutResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)

Expand Down Expand Up @@ -200,46 +244,3 @@ func (k *Keeper) Timeout(ctx context.Context, timeout *channeltypesv2.MsgTimeout

return &channeltypesv2.MsgTimeoutResponse{Result: channeltypesv1.SUCCESS}, nil
}

// CreateChannel defines a rpc handler method for MsgCreateChannel
func (k *Keeper) CreateChannel(goCtx context.Context, msg *channeltypesv2.MsgCreateChannel) (*channeltypesv2.MsgCreateChannelResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

channelID := k.channelKeeperV1.GenerateChannelIdentifier(ctx)

// Initialize channel with empty counterparty channel identifier.
channel := channeltypesv2.NewChannel(msg.ClientId, "", msg.MerklePathPrefix)
k.SetChannel(ctx, channelID, channel)
k.SetCreator(ctx, channelID, msg.Signer)
k.SetNextSequenceSend(ctx, channelID, 1)

k.EmitCreateChannelEvent(goCtx, channelID)

return &channeltypesv2.MsgCreateChannelResponse{ChannelId: channelID}, nil
}

// ProvideCounterparty defines a rpc handler method for MsgProvideCounterparty.
func (k *Keeper) ProvideCounterparty(goCtx context.Context, msg *channeltypesv2.MsgProvideCounterparty) (*channeltypesv2.MsgProvideCounterpartyResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

creator, found := k.GetCreator(ctx, msg.ChannelId)
if !found {
return nil, errorsmod.Wrap(ibcerrors.ErrUnauthorized, "channel creator must be set")
}

if creator != msg.Signer {
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(channeltypesv2.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.
k.DeleteCreator(ctx, msg.ChannelId)

return &channeltypesv2.MsgProvideCounterpartyResponse{}, nil
}
6 changes: 3 additions & 3 deletions modules/core/04-channel/v2/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ func (suite *KeeperTestSuite) TestMsgRecvPacket() {
}
}

func (suite *KeeperTestSuite) TestProvideCounterparty() {
func (suite *KeeperTestSuite) TestRegisterCounterparty() {
var (
path *ibctesting.Path
msg *channeltypesv2.MsgProvideCounterparty
msg *channeltypesv2.MsgRegisterCounterparty
)
cases := []struct {
name string
Expand Down Expand Up @@ -306,7 +306,7 @@ func (suite *KeeperTestSuite) TestProvideCounterparty() {
suite.Require().NoError(path.EndpointB.CreateChannel())

signer := path.EndpointA.Chain.SenderAccount.GetAddress().String()
msg = channeltypesv2.NewMsgProvideCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)
msg = channeltypesv2.NewMsgRegisterCounterparty(path.EndpointA.ChannelID, path.EndpointB.ChannelID, signer)

tc.malleate()

Expand Down
4 changes: 2 additions & 2 deletions modules/core/04-channel/v2/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgCreateChannel{},
&MsgRegisterCounterparty{},
&MsgSendPacket{},
&MsgRecvPacket{},
&MsgTimeout{},
&MsgAcknowledgement{},
&MsgCreateChannel{},
&MsgProvideCounterparty{},
)
}
46 changes: 23 additions & 23 deletions modules/core/04-channel/v2/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
)

var (
_ sdk.Msg = (*MsgProvideCounterparty)(nil)
_ sdk.HasValidateBasic = (*MsgProvideCounterparty)(nil)

_ sdk.Msg = (*MsgCreateChannel)(nil)
_ sdk.HasValidateBasic = (*MsgCreateChannel)(nil)

_ sdk.Msg = (*MsgRegisterCounterparty)(nil)
_ sdk.HasValidateBasic = (*MsgRegisterCounterparty)(nil)

_ sdk.Msg = (*MsgSendPacket)(nil)
_ sdk.HasValidateBasic = (*MsgSendPacket)(nil)

Expand All @@ -33,52 +33,52 @@ var (
_ sdk.HasValidateBasic = (*MsgAcknowledgement)(nil)
)

// NewMsgProvideCounterparty creates a new MsgProvideCounterparty instance
func NewMsgProvideCounterparty(channelID, counterpartyChannelID string, signer string) *MsgProvideCounterparty {
return &MsgProvideCounterparty{
Signer: signer,
ChannelId: channelID,
CounterpartyChannelId: counterpartyChannelID,
// NewMsgCreateChannel creates a new MsgCreateChannel instance
func NewMsgCreateChannel(clientID string, merklePathPrefix commitmenttypesv2.MerklePath, signer string) *MsgCreateChannel {
return &MsgCreateChannel{
Signer: signer,
ClientId: clientID,
MerklePathPrefix: merklePathPrefix,
}
}

// ValidateBasic performs basic checks on a MsgProvideCounterparty.
func (msg *MsgProvideCounterparty) ValidateBasic() error {
// ValidateBasic performs basic checks on a MsgCreateChannel.
func (msg *MsgCreateChannel) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}

if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil {
if err := host.ClientIdentifierValidator(msg.ClientId); err != nil {
return err
}

if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil {
if err := msg.MerklePathPrefix.ValidateAsPrefix(); err != nil {
return err
}

return nil
}

// NewMsgCreateChannel creates a new MsgCreateChannel instance
func NewMsgCreateChannel(clientID string, merklePathPrefix commitmenttypesv2.MerklePath, signer string) *MsgCreateChannel {
return &MsgCreateChannel{
Signer: signer,
ClientId: clientID,
MerklePathPrefix: merklePathPrefix,
// NewMsgRegisterCounterparty creates a new MsgRegisterCounterparty instance
func NewMsgRegisterCounterparty(channelID, counterpartyChannelID string, signer string) *MsgRegisterCounterparty {
return &MsgRegisterCounterparty{
Signer: signer,
ChannelId: channelID,
CounterpartyChannelId: counterpartyChannelID,
}
}

// ValidateBasic performs basic checks on a MsgCreateChannel.
func (msg *MsgCreateChannel) ValidateBasic() error {
// ValidateBasic performs basic checks on a MsgRegisterCounterparty.
func (msg *MsgRegisterCounterparty) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Signer); err != nil {
return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err)
}

if err := host.ClientIdentifierValidator(msg.ClientId); err != nil {
if err := host.ChannelIdentifierValidator(msg.ChannelId); err != nil {
return err
}

if err := msg.MerklePathPrefix.ValidateAsPrefix(); err != nil {
if err := host.ChannelIdentifierValidator(msg.CounterpartyChannelId); err != nil {
return err
}

Expand Down
7 changes: 3 additions & 4 deletions modules/core/04-channel/v2/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func TestTypesTestSuite(t *testing.T) {
suite.Run(t, new(TypesTestSuite))
}

// TestMsgProvideCounterpartyValidateBasic tests ValidateBasic for MsgProvideCounterparty
func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() {
var msg *types.MsgProvideCounterparty
func (s *TypesTestSuite) TestMsgRegisterCounterpartyValidateBasic() {
var msg *types.MsgRegisterCounterparty

testCases := []struct {
name string
Expand Down Expand Up @@ -74,7 +73,7 @@ func (s *TypesTestSuite) TestMsgProvideCounterpartyValidateBasic() {
}

for _, tc := range testCases {
msg = types.NewMsgProvideCounterparty(
msg = types.NewMsgRegisterCounterparty(
ibctesting.FirstChannelID,
ibctesting.SecondChannelID,
ibctesting.TestAccAddress,
Expand Down
Loading
Loading