From 02b3968858737b277a441bdbc5ada23ae43521a4 Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:45:37 +0900 Subject: [PATCH] add ordering at ica account creation (#276) --- proto/initia/intertx/v1/tx.proto | 2 + x/intertx/client/cli/flags.go | 4 ++ x/intertx/client/cli/tx.go | 8 +++ x/intertx/keeper/msg_server.go | 2 + x/intertx/keeper/msg_server_test.go | 1 + x/intertx/types/tx.pb.go | 106 ++++++++++++++++++---------- 6 files changed, 86 insertions(+), 37 deletions(-) diff --git a/proto/initia/intertx/v1/tx.proto b/proto/initia/intertx/v1/tx.proto index 7b583207..0ea50603 100644 --- a/proto/initia/intertx/v1/tx.proto +++ b/proto/initia/intertx/v1/tx.proto @@ -6,6 +6,7 @@ import "amino/amino.proto"; import "cosmos/msg/v1/msg.proto"; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; +import "ibc/core/channel/v1/channel.proto"; option go_package = "github.com/initia-labs/initia/x/intertx/types"; @@ -30,6 +31,7 @@ message MsgRegisterAccount { string owner = 1; string connection_id = 2 [(gogoproto.moretags) = "yaml:\"connection_id\""]; string version = 3; + ibc.core.channel.v1.Order ordering = 4; } // MsgRegisterAccountResponse defines the response for Msg/RegisterAccount diff --git a/x/intertx/client/cli/flags.go b/x/intertx/client/cli/flags.go index e43898cd..37c964ac 100644 --- a/x/intertx/client/cli/flags.go +++ b/x/intertx/client/cli/flags.go @@ -9,15 +9,19 @@ const ( FlagConnectionID = "connection-id" // The controller chain channel version FlagVersion = "version" + // Set the ordering of the channel to ordered + FlagOrdered = "ordered" ) // common flagsets to add to various functions var ( fsConnectionID = flag.NewFlagSet("", flag.ContinueOnError) fsVersion = flag.NewFlagSet("", flag.ContinueOnError) + fsOrdered = flag.NewFlagSet("", flag.ContinueOnError) ) func init() { fsConnectionID.String(FlagConnectionID, "", "Connection ID") fsVersion.String(FlagVersion, "", "Version") + fsOrdered.Bool(FlagOrdered, false, "Set the ordering of the channel to ordered") } diff --git a/x/intertx/client/cli/tx.go b/x/intertx/client/cli/tx.go index af91b2d2..b9148456 100644 --- a/x/intertx/client/cli/tx.go +++ b/x/intertx/client/cli/tx.go @@ -15,6 +15,8 @@ import ( "github.com/cosmos/cosmos-sdk/client/tx" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + + channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" ) // GetTxCmd creates and returns the intertx tx command @@ -55,6 +57,11 @@ func getRegisterAccountCmd(ac address.Codec) *cobra.Command { viper.GetString(FlagVersion), ) + ordered := viper.GetBool(FlagOrdered) + if ordered { + msg.Ordering = channeltypes.ORDERED + } + if err := msg.Validate(ac); err != nil { return err } @@ -65,6 +72,7 @@ func getRegisterAccountCmd(ac address.Codec) *cobra.Command { cmd.Flags().AddFlagSet(fsConnectionID) cmd.Flags().AddFlagSet(fsVersion) + cmd.Flags().AddFlagSet(fsOrdered) _ = cmd.MarkFlagRequired(FlagConnectionID) flags.AddTxFlagsToCmd(cmd) diff --git a/x/intertx/keeper/msg_server.go b/x/intertx/keeper/msg_server.go index de49b002..8e479f1d 100644 --- a/x/intertx/keeper/msg_server.go +++ b/x/intertx/keeper/msg_server.go @@ -35,6 +35,8 @@ func (k msgServer) RegisterAccount(goCtx context.Context, msg *types.MsgRegister ctx := sdk.UnwrapSDKContext(goCtx) icaMsg := icacontrollertypes.NewMsgRegisterInterchainAccount(msg.ConnectionId, msg.Owner, msg.Version) + icaMsg.Ordering = msg.Ordering + if _, err := k.icaControllerMsgServer.RegisterInterchainAccount(ctx, icaMsg); err != nil { return nil, err } diff --git a/x/intertx/keeper/msg_server_test.go b/x/intertx/keeper/msg_server_test.go index 59499a23..84845395 100644 --- a/x/intertx/keeper/msg_server_test.go +++ b/x/intertx/keeper/msg_server_test.go @@ -77,6 +77,7 @@ func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { msgSrv := keeper.NewMsgServerImpl(*GetICAApp(suite.chainA).GetICAAuthKeeper()) msg := types.NewMsgRegisterAccount(owner, path.EndpointA.ConnectionID, path.EndpointA.ChannelConfig.Version) + msg.Ordering = channeltypes.ORDERED res, err := msgSrv.RegisterAccount(sdk.WrapSDKContext(suite.chainA.GetContext()), msg) diff --git a/x/intertx/types/tx.pb.go b/x/intertx/types/tx.pb.go index c9d1a470..05243718 100644 --- a/x/intertx/types/tx.pb.go +++ b/x/intertx/types/tx.pb.go @@ -6,12 +6,13 @@ package types import ( context "context" fmt "fmt" - types "github.com/cosmos/cosmos-sdk/codec/types" + types1 "github.com/cosmos/cosmos-sdk/codec/types" _ "github.com/cosmos/cosmos-sdk/types/msgservice" _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" + types "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" @@ -33,9 +34,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // MsgRegisterAccount defines the payload for Msg/RegisterAccount type MsgRegisterAccount struct { - Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` - Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"` + Ordering types.Order `protobuf:"varint,4,opt,name=ordering,proto3,enum=ibc.core.channel.v1.Order" json:"ordering,omitempty"` } func (m *MsgRegisterAccount) Reset() { *m = MsgRegisterAccount{} } @@ -110,9 +112,9 @@ var xxx_messageInfo_MsgRegisterAccountResponse proto.InternalMessageInfo // MsgSubmitTx defines the payload for Msg/SubmitTx type MsgSubmitTx struct { - Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` - ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` - Msg *types.Any `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` + Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"` + ConnectionId string `protobuf:"bytes,2,opt,name=connection_id,json=connectionId,proto3" json:"connection_id,omitempty" yaml:"connection_id"` + Msg *types1.Any `protobuf:"bytes,3,opt,name=msg,proto3" json:"msg,omitempty"` } func (m *MsgSubmitTx) Reset() { *m = MsgSubmitTx{} } @@ -195,35 +197,38 @@ func init() { func init() { proto.RegisterFile("initia/intertx/v1/tx.proto", fileDescriptor_6e4a3b10f7578888) } var fileDescriptor_6e4a3b10f7578888 = []byte{ - // 439 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x93, 0x3f, 0x8f, 0xd3, 0x30, - 0x18, 0xc6, 0x63, 0xaa, 0xe3, 0x8f, 0x0f, 0x84, 0x2e, 0x57, 0x44, 0xb0, 0x50, 0x8a, 0x22, 0x71, - 0x42, 0x95, 0x6a, 0xab, 0xc7, 0x56, 0x89, 0xe1, 0x6e, 0x41, 0x0c, 0x5d, 0x02, 0x13, 0x0b, 0x4a, - 0x72, 0xc6, 0x58, 0xaa, 0xfd, 0x56, 0xb1, 0x5b, 0x9a, 0x0d, 0x31, 0x21, 0x26, 0x3e, 0xc2, 0x7d, - 0x84, 0x4e, 0x7c, 0x06, 0xd8, 0x6e, 0x64, 0x42, 0xa8, 0x1d, 0xca, 0xcc, 0x27, 0x40, 0xf9, 0xe3, - 0xe3, 0x20, 0x15, 0x62, 0x61, 0x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d, 0x4c, 0xda, 0xab, 0x31, - 0x37, 0x53, 0xd0, 0x86, 0x97, 0xb6, 0x76, 0xc7, 0x46, 0x3c, 0x9d, 0xa5, 0x4a, 0xda, 0x67, 0x8b, - 0xff, 0xe3, 0xe7, 0x00, 0x77, 0x94, 0x11, 0x95, 0x97, 0xdd, 0xc3, 0x2e, 0xad, 0x43, 0xa6, 0x2e, - 0x64, 0x7a, 0xa4, 0x8b, 0xb8, 0x6c, 0x18, 0xf5, 0xb7, 0xbb, 0xdb, 0xbf, 0xe0, 0xce, 0x5d, 0x34, - 0xba, 0x85, 0xf7, 0x2f, 0x48, 0xe7, 0xe7, 0xf0, 0x33, 0xc2, 0x9d, 0xb1, 0x11, 0xbe, 0xc0, 0x37, - 0xff, 0x7c, 0x55, 0xf7, 0x69, 0xeb, 0x93, 0xa1, 0xed, 0x64, 0xc8, 0xe0, 0x9f, 0xda, 0xdc, 0x81, - 0x7e, 0x8c, 0xaf, 0x9e, 0x87, 0x17, 0x6e, 0xdf, 0xea, 0x38, 0x39, 0xf8, 0x3b, 0x77, 0x33, 0xc9, - 0xce, 0x9b, 0xcd, 0xb2, 0x8f, 0x8e, 0x1f, 0x7f, 0x5a, 0x85, 0xe8, 0x6c, 0x15, 0xa2, 0x6f, 0xab, - 0x10, 0x7d, 0x58, 0x87, 0xde, 0xd9, 0x3a, 0xf4, 0xbe, 0xac, 0x43, 0xef, 0xf9, 0x40, 0x48, 0xfb, - 0x6a, 0x96, 0xd2, 0x0c, 0x14, 0xab, 0x47, 0x0e, 0x26, 0x49, 0x6a, 0x9a, 0x9a, 0x2d, 0xce, 0xff, - 0x18, 0x5b, 0x4c, 0xb9, 0x49, 0x2f, 0x57, 0x51, 0x3f, 0xfc, 0x19, 0x00, 0x00, 0xff, 0xff, 0x49, - 0x15, 0x0f, 0xe8, 0x50, 0x03, 0x00, 0x00, + // 493 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x53, 0xbb, 0x8e, 0xd3, 0x40, + 0x14, 0xf5, 0x10, 0x16, 0x96, 0x59, 0x1e, 0x5a, 0x6f, 0x10, 0xc6, 0x42, 0xce, 0x62, 0x89, 0xd5, + 0x2a, 0x52, 0x66, 0x94, 0x20, 0x51, 0x44, 0xa2, 0xd8, 0x6d, 0x10, 0x45, 0x84, 0x64, 0xa8, 0x68, + 0x90, 0x3d, 0x19, 0x66, 0x47, 0x8a, 0xe7, 0x46, 0x9e, 0x49, 0x48, 0x3a, 0x44, 0x85, 0xa8, 0xf8, + 0x84, 0xfd, 0x84, 0x54, 0x7c, 0x03, 0x74, 0x5b, 0x52, 0x21, 0x94, 0x14, 0xa1, 0xa2, 0xe0, 0x0b, + 0x90, 0x1f, 0x13, 0x16, 0x12, 0x21, 0x1a, 0x1a, 0xeb, 0x9e, 0x39, 0x67, 0xae, 0xef, 0x39, 0xd7, + 0xc6, 0xbe, 0x54, 0xd2, 0xc8, 0x98, 0x4a, 0x65, 0x78, 0x66, 0x26, 0x74, 0xdc, 0xa6, 0x66, 0x42, + 0x86, 0x19, 0x18, 0x70, 0x77, 0x4b, 0x8e, 0x54, 0x1c, 0x19, 0xb7, 0xfd, 0xdd, 0x38, 0x95, 0x0a, + 0x68, 0xf1, 0x2c, 0x55, 0xfe, 0x2d, 0x06, 0x3a, 0x05, 0x4d, 0x53, 0x2d, 0xf2, 0xdb, 0xa9, 0x16, + 0x15, 0x51, 0x17, 0x20, 0xa0, 0x28, 0x69, 0x5e, 0x55, 0xa7, 0xb7, 0x05, 0x80, 0x18, 0x70, 0x5a, + 0xa0, 0x64, 0xf4, 0x92, 0xc6, 0x6a, 0x5a, 0x51, 0x77, 0x65, 0xc2, 0x28, 0x83, 0x8c, 0x53, 0x76, + 0x12, 0x2b, 0xc5, 0x07, 0x79, 0xbf, 0xaa, 0x2c, 0x25, 0xe1, 0x77, 0x84, 0xdd, 0x9e, 0x16, 0x11, + 0x17, 0x52, 0x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, 0x1c, 0xb4, 0x7e, 0x3a, 0x9f, 0x10, 0xae, + 0xf5, 0xb4, 0x70, 0x05, 0xbe, 0xf1, 0xe7, 0x8a, 0xef, 0x91, 0xb5, 0xaf, 0x91, 0xac, 0x27, 0xe3, + 0xb7, 0xfe, 0x49, 0x66, 0x5f, 0xe8, 0x46, 0x78, 0x7b, 0x15, 0x5e, 0xb0, 0xf9, 0xaa, 0xe5, 0xfd, + 0x83, 0xbf, 0xf3, 0xb6, 0xa7, 0xbf, 0xf5, 0x7a, 0x39, 0x6b, 0xa2, 0xe3, 0x47, 0x1f, 0xe7, 0x01, + 0x3a, 0x9b, 0x07, 0xe8, 0xeb, 0x3c, 0x40, 0xef, 0x17, 0x81, 0x73, 0xb6, 0x08, 0x9c, 0xcf, 0x8b, + 0xc0, 0x79, 0xde, 0x12, 0xd2, 0x9c, 0x8c, 0x12, 0xc2, 0x20, 0xa5, 0x65, 0xcb, 0xd6, 0x20, 0x4e, + 0x74, 0x55, 0xd3, 0xc9, 0xea, 0x67, 0x34, 0xd3, 0x21, 0xd7, 0xc9, 0xa5, 0x22, 0xea, 0xfb, 0x3f, + 0x03, 0x00, 0x00, 0xff, 0xff, 0x8f, 0x10, 0xd1, 0xab, 0xab, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -366,6 +371,11 @@ func (m *MsgRegisterAccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.Ordering != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Ordering)) + i-- + dAtA[i] = 0x20 + } if len(m.Version) > 0 { i -= len(m.Version) copy(dAtA[i:], m.Version) @@ -514,6 +524,9 @@ func (m *MsgRegisterAccount) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.Ordering != 0 { + n += 1 + sovTx(uint64(m.Ordering)) + } return n } @@ -687,6 +700,25 @@ func (m *MsgRegisterAccount) Unmarshal(dAtA []byte) error { } m.Version = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Ordering", wireType) + } + m.Ordering = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Ordering |= types.Order(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) @@ -881,7 +913,7 @@ func (m *MsgSubmitTx) Unmarshal(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Msg == nil { - m.Msg = &types.Any{} + m.Msg = &types1.Any{} } if err := m.Msg.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err