From 4ac0e7b0a43fb5714ceb3621051740d9f5414a5f Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Tue, 25 Apr 2023 15:44:43 +0530 Subject: [PATCH 01/69] feat: add proto msg --- .../27-interchain-accounts/host/types/msgs.go | 35 ++ .../host/types/msgs_test.go | 7 + .../host/types/tx.pb.go | 592 ++++++++++++++++++ .../interchain_accounts/host/v1/tx.proto | 30 + 4 files changed, 664 insertions(+) create mode 100644 modules/apps/27-interchain-accounts/host/types/msgs.go create mode 100644 modules/apps/27-interchain-accounts/host/types/msgs_test.go create mode 100644 modules/apps/27-interchain-accounts/host/types/tx.pb.go create mode 100644 proto/ibc/applications/interchain_accounts/host/v1/tx.proto diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go new file mode 100644 index 00000000000..5553e3f190a --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -0,0 +1,35 @@ +package types + +import sdk "github.com/cosmos/cosmos-sdk/types" + +var _ sdk.Msg = (*MsgUpdateParams)(nil) + +// ValidateBasic implements sdk.Msg +func (msg MsgUpdateParams) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + return err + } + + return msg.Params.Validate() +} + +// GetSigners implements sdk.Msg +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { + accAddr, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { + panic(err) + } + + return []sdk.AccAddress{accAddr} +} + +// Route implements sdk.Msg +func (msg MsgUpdateParams) Route() string { + return sdk.MsgTypeURL(&msg) +} + +// Type implements sdk.Msg +func (msg MsgUpdateParams) Type() string { + return sdk.MsgTypeURL(&msg) +} diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go new file mode 100644 index 00000000000..48944f9852e --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -0,0 +1,7 @@ +package types_test + +import "testing" + +func TestMsgUpdateParamsValidateBasic(t *testing.T) { + +} diff --git a/modules/apps/27-interchain-accounts/host/types/tx.pb.go b/modules/apps/27-interchain-accounts/host/types/tx.pb.go new file mode 100644 index 00000000000..86c70762ae9 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/tx.pb.go @@ -0,0 +1,592 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: ibc/applications/interchain_accounts/host/v1/tx.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/cosmos/gogoproto/grpc" + proto "github.com/cosmos/gogoproto/proto" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// MsgUpdateParams defines the payload for Msg/UpdateParams +type MsgUpdateParams struct { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // params defines the 27-interchain-accounts/host parameters to update. + // + // NOTE: All parameters must be supplied. + Params Params `protobuf:"bytes,2,opt,name=params,proto3" json:"params"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_fa437afde7f1e7ae, []int{0} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +// MsgUpdateParamsResponse defines the response for Msg/UpdateParams +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_fa437afde7f1e7ae, []int{1} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + +func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "ibc.applications.interchain_accounts.host.v1.MsgUpdateParamsResponse") +} + +func init() { + proto.RegisterFile("ibc/applications/interchain_accounts/host/v1/tx.proto", fileDescriptor_fa437afde7f1e7ae) +} + +var fileDescriptor_fa437afde7f1e7ae = []byte{ + // 317 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x91, 0x31, 0x4b, 0x03, 0x31, + 0x18, 0x86, 0x2f, 0x2a, 0x85, 0x46, 0x41, 0x38, 0x04, 0x6b, 0x91, 0xb3, 0x74, 0xea, 0x60, 0x13, + 0x5a, 0x95, 0x4e, 0x2e, 0x05, 0x17, 0xa1, 0x20, 0x07, 0x2e, 0x2e, 0x92, 0x4b, 0x43, 0x2e, 0xd0, + 0xbb, 0x2f, 0xdc, 0x97, 0x2b, 0x76, 0xf6, 0x0f, 0x38, 0x38, 0xfa, 0x83, 0x3a, 0x76, 0x74, 0x12, + 0x69, 0xff, 0x88, 0xf4, 0xaa, 0xd4, 0x16, 0x97, 0xc3, 0x2d, 0x84, 0xef, 0x79, 0xdf, 0x07, 0x5e, + 0x7a, 0x65, 0x22, 0xc9, 0x85, 0xb5, 0x23, 0x23, 0x85, 0x33, 0x90, 0x22, 0x37, 0xa9, 0x53, 0x99, + 0x8c, 0x85, 0x49, 0x1f, 0x85, 0x94, 0x90, 0xa7, 0x0e, 0x79, 0x0c, 0xe8, 0xf8, 0xb8, 0xc3, 0xdd, + 0x13, 0xb3, 0x19, 0x38, 0xf0, 0xcf, 0x4d, 0x24, 0xd9, 0x6f, 0x8c, 0xfd, 0x81, 0xb1, 0x25, 0xc6, + 0xc6, 0x9d, 0xfa, 0x91, 0x06, 0x0d, 0x05, 0xc8, 0x97, 0xaf, 0x55, 0x46, 0xbd, 0x57, 0xaa, 0xba, + 0xc8, 0x2a, 0xc0, 0xe6, 0x33, 0xa1, 0x87, 0x03, 0xd4, 0xf7, 0x76, 0x28, 0x9c, 0xba, 0x13, 0x99, + 0x48, 0xd0, 0x3f, 0xa5, 0x55, 0x91, 0xbb, 0x18, 0x32, 0xe3, 0x26, 0x35, 0xd2, 0x20, 0xad, 0x6a, + 0xb8, 0xfe, 0xf0, 0x43, 0x5a, 0xb1, 0xc5, 0x5d, 0x6d, 0xa7, 0x41, 0x5a, 0xfb, 0xdd, 0x4b, 0x56, + 0xc6, 0x9f, 0xad, 0x3a, 0xfa, 0x7b, 0xd3, 0x8f, 0x33, 0x2f, 0xfc, 0x4e, 0x6a, 0x9e, 0xd0, 0xe3, + 0x2d, 0x89, 0x50, 0xa1, 0x85, 0x14, 0x55, 0xf7, 0x8d, 0xd0, 0xdd, 0x01, 0x6a, 0xff, 0x95, 0xd0, + 0x83, 0x0d, 0xcb, 0xeb, 0x72, 0xbd, 0x5b, 0xf9, 0xf5, 0x9b, 0x7f, 0xe1, 0x3f, 0x7a, 0xfd, 0xe1, + 0x74, 0x1e, 0x90, 0xd9, 0x3c, 0x20, 0x9f, 0xf3, 0x80, 0xbc, 0x2c, 0x02, 0x6f, 0xb6, 0x08, 0xbc, + 0xf7, 0x45, 0xe0, 0x3d, 0xdc, 0x6a, 0xe3, 0xe2, 0x3c, 0x62, 0x12, 0x12, 0x2e, 0x01, 0x13, 0x40, + 0x6e, 0x22, 0xd9, 0xd6, 0xc0, 0xc7, 0x3d, 0x9e, 0xc0, 0x30, 0x1f, 0x29, 0x5c, 0x4e, 0x86, 0xbc, + 0xdb, 0x6b, 0xaf, 0xab, 0xdb, 0x9b, 0x6b, 0xb9, 0x89, 0x55, 0x18, 0x55, 0x8a, 0xb1, 0x2e, 0xbe, + 0x02, 0x00, 0x00, 0xff, 0xff, 0xac, 0xa4, 0x80, 0x00, 0x62, 0x02, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// MsgClient is the client API for Msg service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type MsgClient interface { + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) +} + +type msgClient struct { + cc grpc1.ClientConn +} + +func NewMsgClient(cc grpc1.ClientConn) MsgClient { + return &msgClient{cc} +} + +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/ibc.applications.interchain_accounts.host.v1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// MsgServer is the server API for Msg service. +type MsgServer interface { + // UpdateParams defines a rpc handler for MsgUpdateParams. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) +} + +// UnimplementedMsgServer can be embedded to have forward compatible implementations. +type UnimplementedMsgServer struct { +} + +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} + +func RegisterMsgServer(s grpc1.Server, srv MsgServer) { + s.RegisterService(&_Msg_serviceDesc, srv) +} + +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ibc.applications.interchain_accounts.host.v1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + +var _Msg_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ibc.applications.interchain_accounts.host.v1.Msg", + HandlerType: (*MsgServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "ibc/applications/interchain_accounts/host/v1/tx.proto", +} + +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func encodeVarintTx(dAtA []byte, offset int, v uint64) int { + offset -= sovTx(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = m.Params.Size() + n += 1 + l + sovTx(uint64(l)) + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func sovTx(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozTx(x uint64) (n int) { + return sovTx(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTx(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTx + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthTx + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupTx + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthTx + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") +) diff --git a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto new file mode 100644 index 00000000000..394eb381179 --- /dev/null +++ b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; + +package ibc.applications.interchain_accounts.host.v1; + +option go_package = "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"; + +import "gogoproto/gogo.proto"; +import "ibc/applications/interchain_accounts/host/v1/host.proto"; + +// Msg defines the 27-interchain-accounts/host Msg service. +service Msg { + // UpdateParams defines a rpc handler for MsgUpdateParams. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); +} + +// MsgUpdateParams defines the payload for Msg/UpdateParams +message MsgUpdateParams { + // authority is the address that controls the module (defaults to x/gov unless overwritten). + string authority = 1; + + // params defines the 27-interchain-accounts/host parameters to update. + // + // NOTE: All parameters must be supplied. + Params params = 2 [(gogoproto.nullable) = false]; +} + +// MsgUpdateParamsResponse defines the response for Msg/UpdateParams +message MsgUpdateParamsResponse { + +} \ No newline at end of file From 3e8354b433407c91e722259c1d2aa9db3b277698 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Tue, 25 Apr 2023 16:50:39 +0530 Subject: [PATCH 02/69] feat: add msg-server implementation --- .../host/keeper/keeper.go | 11 +++ .../host/keeper/msg_server.go | 34 ++++++++++ .../host/keeper/params.go | 26 +++++-- .../27-interchain-accounts/host/types/keys.go | 3 + .../27-interchain-accounts/host/types/msgs.go | 10 --- .../host/types/msgs_test.go | 68 ++++++++++++++++++- .../host/types/params.go | 47 +------------ .../host/types/params_legacy.go | 63 +++++++++++++++++ testing/simapp/app.go | 1 + 9 files changed, 203 insertions(+), 60 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/host/keeper/msg_server.go create mode 100644 modules/apps/27-interchain-accounts/host/types/params_legacy.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index a922b38cca9..d7d1006c66e 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -34,6 +34,10 @@ type Keeper struct { scopedKeeper exported.ScopedKeeper msgRouter icatypes.MessageRouter + + // the address capable of executing a MsgUpdateParams message. Typically, this + // should be the x/gov module account. + authority string } // NewKeeper creates a new interchain accounts host Keeper instance @@ -41,6 +45,7 @@ func NewKeeper( cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, + authority string, ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { @@ -62,6 +67,7 @@ func NewKeeper( accountKeeper: accountKeeper, scopedKeeper: scopedKeeper, msgRouter: msgRouter, + authority: authority, } } @@ -199,3 +205,8 @@ func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portI store := ctx.KVStore(k.storeKey) store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) } + +// GetAuthority returns the 27-interchain-accounts/host module's authority. +func (k Keeper) GetAuthority() string { + return k.authority +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go new file mode 100644 index 00000000000..08a30ec906a --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -0,0 +1,34 @@ +package keeper + +import ( + "context" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +var _ types.MsgServer = (*msgServer)(nil) + +type msgServer struct { + *Keeper +} + +// NewMsgServerImpl returns an implementation of the ICS27 host MsgServer interface +// for the provided Keeper. +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { + return &msgServer{Keeper: keeper} +} + +// UpdateParams updates the params. +func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if m.authority != msg.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", m.authority, msg.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + m.SetParams(ctx, msg.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/params.go b/modules/apps/27-interchain-accounts/host/keeper/params.go index 6c95d737541..4d2b8ab8837 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/params.go +++ b/modules/apps/27-interchain-accounts/host/keeper/params.go @@ -16,17 +16,33 @@ func (k Keeper) IsHostEnabled(ctx sdk.Context) bool { // GetAllowMessages retrieves the host enabled msg types from the paramstore func (k Keeper) GetAllowMessages(ctx sdk.Context) []string { - var res []string - k.paramSpace.Get(ctx, types.KeyAllowMessages, &res) - return res + var params types.Params + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return []string{} + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params.AllowMessages } // GetParams returns the total set of the host submodule parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams(k.IsHostEnabled(ctx), k.GetAllowMessages(ctx)) + var params types.Params + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return types.Params{} + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params } // SetParams sets the total set of the host submodule parameters. func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramSpace.SetParamSet(ctx, ¶ms) + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(¶ms) + store.Set(types.ParamsKey, bz) } diff --git a/modules/apps/27-interchain-accounts/host/types/keys.go b/modules/apps/27-interchain-accounts/host/types/keys.go index 7e0ca350d0e..9409f76732d 100644 --- a/modules/apps/27-interchain-accounts/host/types/keys.go +++ b/modules/apps/27-interchain-accounts/host/types/keys.go @@ -4,6 +4,9 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) +// ParamsKey is the key to use for the storing params. +var ParamsKey = []byte{0x00} + const ( // SubModuleName defines the interchain accounts host module name SubModuleName = "icahost" diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go index 5553e3f190a..03d51c8c5ab 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -23,13 +23,3 @@ func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{accAddr} } - -// Route implements sdk.Msg -func (msg MsgUpdateParams) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// Type implements sdk.Msg -func (msg MsgUpdateParams) Type() string { - return sdk.MsgTypeURL(&msg) -} diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go index 48944f9852e..43e8f096ee8 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -1,7 +1,73 @@ package types_test -import "testing" +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + "github.com/stretchr/testify/require" +) func TestMsgUpdateParamsValidateBasic(t *testing.T) { + var msg *types.MsgUpdateParams + + testCases := []struct { + name string + malleate func() + expPass bool + }{ + { + "invalid authority address", + func() { + msg = &types.MsgUpdateParams{ + Authority: "authority", + } + }, + false, + }, + { + "invalid allowed message", + func() { + msg = &types.MsgUpdateParams{ + Authority: sdk.AccAddress("authority").String(), + Params: types.Params{ + AllowMessages: []string{""}, + }, + } + }, + false, + }, + { + "valid test case", + func() { + msg = &types.MsgUpdateParams{ + Authority: sdk.AccAddress("authority").String(), + Params: types.DefaultParams(), + } + }, + true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + tc.malleate() + + err := msg.ValidateBasic() + if tc.expPass { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} +func TestMsgUpdateParamsGetSigners(t *testing.T) { + authority := sdk.AccAddress("authority") + msg := types.MsgUpdateParams{ + Authority: authority.String(), + Params: types.DefaultParams(), + } + require.Equal(t, []sdk.AccAddress{authority}, msg.GetSigners()) } diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index 92a8ca84f46..ac0241be540 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -1,29 +1,10 @@ package types import ( - "fmt" + fmt "fmt" "strings" - - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -const ( - // DefaultHostEnabled is the default value for the host param (set to true) - DefaultHostEnabled = true -) - -var ( - // KeyHostEnabled is the store key for HostEnabled Params - KeyHostEnabled = []byte("HostEnabled") - // KeyAllowMessages is the store key for the AllowMessages Params - KeyAllowMessages = []byte("AllowMessages") ) -// ParamKeyTable type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // NewParams creates a new parameter configuration for the host submodule func NewParams(enableHost bool, allowMsgs []string) Params { return Params{ @@ -43,32 +24,10 @@ func (p Params) Validate() error { return err } - return validateAllowlist(p.AllowMessages) + return validateAllowedlist(p.AllowMessages) } -// ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), - paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlist), - } -} - -func validateEnabledType(i interface{}) error { - _, ok := i.(bool) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - - return nil -} - -func validateAllowlist(i interface{}) error { - allowMsgs, ok := i.([]string) - if !ok { - return fmt.Errorf("invalid parameter type: %T", i) - } - +func validateAllowedlist(allowMsgs []string) error { for _, typeURL := range allowMsgs { if strings.TrimSpace(typeURL) == "" { return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go new file mode 100644 index 00000000000..3a75756f527 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -0,0 +1,63 @@ +/* +NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov +controlled execution of MsgUpdateParams messages. These types remains solely +for migration purposes and will be removed in a future release. +*/ + +package types + +import ( + "fmt" + "strings" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +const ( + // DefaultHostEnabled is the default value for the host param (set to true) + DefaultHostEnabled = true +) + +var ( + // KeyHostEnabled is the store key for HostEnabled Params + KeyHostEnabled = []byte("HostEnabled") + // KeyAllowMessages is the store key for the AllowMessages Params + KeyAllowMessages = []byte("AllowMessages") +) + +// ParamKeyTable type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), + paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlist), + } +} + +func validateEnabledType(i interface{}) error { + _, ok := i.(bool) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} + +func validateAllowlist(i interface{}) error { + allowMsgs, ok := i.([]string) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + for _, typeURL := range allowMsgs { + if strings.TrimSpace(typeURL) == "" { + return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs) + } + } + + return nil +} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index c0e323c3a72..ac2027f054e 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -431,6 +431,7 @@ func NewSimApp( app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), + authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) // Create IBC Router From c17fdf29b64645c86bb9d16b9290c0dc097b8ca2 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Wed, 26 Apr 2023 16:24:38 +0530 Subject: [PATCH 03/69] wip: add migrations --- .../exported/exported.go | 18 +++++++++ .../host/keeper/migrator.go | 29 ++++++++++++++ .../host/migrations/v8/migrations.go | 40 +++++++++++++++++++ modules/apps/27-interchain-accounts/module.go | 16 ++++++-- .../27-interchain-accounts/module_test.go | 10 ++--- .../interchain_accounts/host/v1/tx.proto | 4 +- testing/simapp/app.go | 4 +- 7 files changed, 107 insertions(+), 14 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/exported/exported.go create mode 100644 modules/apps/27-interchain-accounts/host/keeper/migrator.go create mode 100644 modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go diff --git a/modules/apps/27-interchain-accounts/exported/exported.go b/modules/apps/27-interchain-accounts/exported/exported.go new file mode 100644 index 00000000000..000114e6194 --- /dev/null +++ b/modules/apps/27-interchain-accounts/exported/exported.go @@ -0,0 +1,18 @@ +package exported + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +type ( + ParamSet = paramtypes.ParamSet + + // Subspace defines an interface that implements the legacy x/params Subspace + // type. + // + // NOTE: This is used solely for migration of x/params managed parameters. + Subspace interface { + GetParamSet(ctx sdk.Context, ps ParamSet) + } +) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go new file mode 100644 index 00000000000..6a9b4623bf7 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -0,0 +1,29 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" + v8 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/migrations/v8" +) + +// Migrator is a struct for handling in-place state migrations. +type Migrator struct { + keeper *Keeper + legacySubspace exported.Subspace +} + +// NewMigrator returns Migrator instance for the state migration. +func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { + return Migrator{ + keeper: k, + legacySubspace: ss, + } +} + +// Migrate2to3 migrates the 27-interchain-accounts module state from the +// consensus version 2 to version 3. Specifically, it takes the parameters that +// are currently stored and managed by the x/params modules and stores them directly +// into the host submodule state. +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + return v8.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc) +} diff --git a/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go b/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go new file mode 100644 index 00000000000..f2e3d0596cf --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go @@ -0,0 +1,40 @@ +package v8 + +import ( + storetypes "github.com/cosmos/cosmos-sdk/store/types" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +const ( + SubModuleName = "icahost" +) + +var ParamsKey = []byte{0x00} + +// Migrate migrates the 27-interchain-accounts host submodule state from the consensus version 1 to +// version 2. Specifically, it takes the parameters that are currently stored +// and managed by the x/params modules and stores them directly into the host +// submodule state. +func Migrate( + ctx sdk.Context, + store storetypes.KVStore, + legacySubspace exported.Subspace, + cdc codec.BinaryCodec, +) error { + var currParams types.Params + legacySubspace.GetParamSet(ctx, &currParams) + + if err := currParams.Validate(); err != nil { + return err + } + + bz := cdc.MustMarshal(&currParams) + store.Set(ParamsKey, bz) + + return nil +} diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 3c737dd1c02..3e273bec27b 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -18,6 +18,7 @@ import ( "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/client/cli" controllerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" hostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" @@ -97,13 +98,17 @@ type AppModule struct { AppModuleBasic controllerKeeper *controllerkeeper.Keeper hostKeeper *hostkeeper.Keeper + + // legacyHostSubspace is used solely for migration of x/params managed parameters + legacyHostSubspace exported.Subspace } // NewAppModule creates a new IBC interchain accounts module -func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) AppModule { +func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper, hss exported.Subspace) AppModule { return AppModule{ - controllerKeeper: controllerKeeper, - hostKeeper: hostKeeper, + controllerKeeper: controllerKeeper, + hostKeeper: hostKeeper, + legacyHostSubspace: hss, } } @@ -143,6 +148,11 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { if err := cfg.RegisterMigration(types.ModuleName, 1, m.AssertChannelCapabilityMigrations); err != nil { panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 1 to 2: %v", err)) } + + hostm := hostkeeper.NewMigrator(am.hostKeeper, am.legacyHostSubspace) + if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.Migrate2to3); err != nil { + panic(fmt.Sprintf("failed to migrate interchainaccounts host params from version 2 to 3: %v", err)) + } } // InitGenesis performs genesis initialization for the interchain accounts module. diff --git a/modules/apps/27-interchain-accounts/module_test.go b/modules/apps/27-interchain-accounts/module_test.go index 461091b996d..6eecb3d1038 100644 --- a/modules/apps/27-interchain-accounts/module_test.go +++ b/modules/apps/27-interchain-accounts/module_test.go @@ -51,9 +51,7 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() { suite.Require().Panics(func() { app.ICAControllerKeeper.GetParams(ctx) }) - suite.Require().Panics(func() { - app.ICAHostKeeper.GetParams(ctx) - }) + suite.Require().Equal(app.ICAHostKeeper.GetParams(ctx), hosttypes.Params{}) controllerParams := controllertypes.DefaultParams() controllerParams.ControllerEnabled = true @@ -79,17 +77,17 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() { }, { "neither controller or host is set", func() { - appModule = ica.NewAppModule(nil, nil) + appModule = ica.NewAppModule(nil, nil, nil) }, false, false, }, { "only controller is set", func() { - appModule = ica.NewAppModule(&app.ICAControllerKeeper, nil) + appModule = ica.NewAppModule(&app.ICAControllerKeeper, nil, nil) }, true, false, }, { "only host is set", func() { - appModule = ica.NewAppModule(nil, &app.ICAHostKeeper) + appModule = ica.NewAppModule(nil, &app.ICAHostKeeper, nil) }, false, true, }, } diff --git a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto index 394eb381179..59a7ee86aba 100644 --- a/proto/ibc/applications/interchain_accounts/host/v1/tx.proto +++ b/proto/ibc/applications/interchain_accounts/host/v1/tx.proto @@ -25,6 +25,4 @@ message MsgUpdateParams { } // MsgUpdateParamsResponse defines the response for Msg/UpdateParams -message MsgUpdateParamsResponse { - -} \ No newline at end of file +message MsgUpdateParamsResponse {} diff --git a/testing/simapp/app.go b/testing/simapp/app.go index ac2027f054e..aa6e9c58ee7 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -567,7 +567,7 @@ func NewSimApp( ibc.NewAppModule(app.IBCKeeper), transfer.NewAppModule(app.TransferKeeper), ibcfee.NewAppModule(app.IBCFeeKeeper), - ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), + ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper, app.GetSubspace(icahosttypes.SubModuleName)), mockModule, ) @@ -636,7 +636,7 @@ func NewSimApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transfer.NewAppModule(app.TransferKeeper), - ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), + ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper, app.GetSubspace(icahosttypes.SubModuleName)), ) app.sm.RegisterStoreDecoders() From dc97796ec05559146b1acf7a5cc3211420d9c3e8 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Thu, 27 Apr 2023 14:14:46 +0530 Subject: [PATCH 04/69] fix failing tests --- .../27-interchain-accounts/host/keeper/keeper.go | 14 +++----------- .../27-interchain-accounts/host/keeper/params.go | 15 ++++++++++++--- testing/simapp/app.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index d7d1006c66e..d57d3ebf753 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -12,7 +12,6 @@ import ( capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" @@ -42,25 +41,18 @@ type Keeper struct { // NewKeeper creates a new interchain accounts host Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, - ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, - accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, - authority string, + cdc codec.BinaryCodec, key storetypes.StoreKey, ics4Wrapper porttypes.ICS4Wrapper, + channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper, + scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string, ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { panic("the Interchain Accounts module account has not been set") } - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) - } - return Keeper{ storeKey: key, cdc: cdc, - paramSpace: paramSpace, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, diff --git a/modules/apps/27-interchain-accounts/host/keeper/params.go b/modules/apps/27-interchain-accounts/host/keeper/params.go index 4d2b8ab8837..33c887960a5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/params.go +++ b/modules/apps/27-interchain-accounts/host/keeper/params.go @@ -9,9 +9,18 @@ import ( // IsHostEnabled retrieves the host enabled boolean from the paramstore. // True is returned if the host submodule is enabled. func (k Keeper) IsHostEnabled(ctx sdk.Context) bool { - var res bool - k.paramSpace.Get(ctx, types.KeyHostEnabled, &res) - return res + var params types.Params + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return false + } + + if err := k.cdc.Unmarshal(bz, ¶ms); err != nil { + return false + } + + return params.HostEnabled } // GetAllowMessages retrieves the host enabled msg types from the paramstore diff --git a/testing/simapp/app.go b/testing/simapp/app.go index aa6e9c58ee7..fa78bfec2ae 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -427,7 +427,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + appCodec, keys[icahosttypes.StoreKey], app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), From 2140a3e8dfbd8224a06c707aa86d579c8f69e9c8 Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Fri, 28 Apr 2023 11:47:17 +0530 Subject: [PATCH 05/69] cleanup --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 6 ++---- modules/apps/27-interchain-accounts/host/types/params.go | 5 +++++ .../apps/27-interchain-accounts/host/types/params_legacy.go | 5 ----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index d57d3ebf753..45a49488da4 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -8,7 +8,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" @@ -21,9 +20,8 @@ import ( // Keeper defines the IBC interchain accounts host keeper type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec - paramSpace paramtypes.Subspace + storeKey storetypes.StoreKey + cdc codec.BinaryCodec ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index ac0241be540..9f0add661a3 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -5,6 +5,11 @@ import ( "strings" ) +const ( + // DefaultHostEnabled is the default value for the host param (set to true) + DefaultHostEnabled = true +) + // NewParams creates a new parameter configuration for the host submodule func NewParams(enableHost bool, allowMsgs []string) Params { return Params{ diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go index 3a75756f527..e081d9a6437 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_legacy.go +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -13,11 +13,6 @@ import ( paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" ) -const ( - // DefaultHostEnabled is the default value for the host param (set to true) - DefaultHostEnabled = true -) - var ( // KeyHostEnabled is the store key for HostEnabled Params KeyHostEnabled = []byte("HostEnabled") From c9cd005c0a0efba747d211f16d0c25b9588367da Mon Sep 17 00:00:00 2001 From: aleem1314 Date: Wed, 3 May 2023 20:41:05 +0530 Subject: [PATCH 06/69] cleanup --- CHANGELOG.md | 2 + .../host/keeper/keeper.go | 2 +- .../host/keeper/msg_server.go | 2 +- .../host/keeper/msg_server_test.go | 56 +++++++++++++++++++ .../host/types/params.go | 4 +- .../host/types/params_legacy.go | 4 +- 6 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 28354f0c7c1..8c999304b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking +* (modules/apps/27-interchain-accounts/host) [\#3520](https://github.com/cosmos/ibc-go/pull/3520) Migrate `modules/apps/27-interchain-accounts/host` to self-managed parameters and deprecate it's usage of `x/params`. + ### Improvements * (tests) [\#3138](https://github.com/cosmos/ibc-go/pull/3138) Support benchmarks and fuzz tests through `testing.TB`. diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 45a49488da4..6724e9b0a01 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -196,7 +196,7 @@ func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portI store.Set(icatypes.KeyOwnerAccount(portID, connectionID), []byte(address)) } -// GetAuthority returns the 27-interchain-accounts/host module's authority. +// GetAuthority returns the 27-interchain-accounts host submodule's authority. func (k Keeper) GetAuthority() string { return k.authority } diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index 08a30ec906a..efe632e7709 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -21,7 +21,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { return &msgServer{Keeper: keeper} } -// UpdateParams updates the params. +// UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", m.authority, msg.Authority) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go new file mode 100644 index 00000000000..4dc1632a676 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go @@ -0,0 +1,56 @@ +package keeper_test + +import ( + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +func (suite *KeeperTestSuite) TestUpdateParams() { + msg := types.MsgUpdateParams{} + + testCases := []struct { + name string + malleate func(authority string) + expPass bool + }{ + { + "invalid authority address", + func(authority string) { + msg.Authority = "authority" + msg.Params = types.DefaultParams() + }, + false, + }, + { + "success", + func(authority string) { + msg.Authority = authority + msg.Params = types.DefaultParams() + }, + true, + }, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() + + ICAHostKeeper := &suite.chainA.GetSimApp().ICAHostKeeper + tc.malleate(ICAHostKeeper.GetAuthority()) // malleate mutates test data + + ctx := suite.chainA.GetContext() + msgServer := keeper.NewMsgServerImpl(ICAHostKeeper) + res, err := msgServer.UpdateParams(ctx, &msg) + + if tc.expPass { + suite.Require().NoError(err) + suite.Require().NotNil(res) + } else { + suite.Require().Error(err) + suite.Require().Nil(res) + } + }) + } +} diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index 9f0add661a3..c7938a461af 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -29,10 +29,10 @@ func (p Params) Validate() error { return err } - return validateAllowedlist(p.AllowMessages) + return validateAllowlist(p.AllowMessages) } -func validateAllowedlist(allowMsgs []string) error { +func validateAllowlist(allowMsgs []string) error { for _, typeURL := range allowMsgs { if strings.TrimSpace(typeURL) == "" { return fmt.Errorf("parameter must not contain empty strings: %s", allowMsgs) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go index e081d9a6437..079da928261 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_legacy.go +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -29,7 +29,7 @@ func ParamKeyTable() paramtypes.KeyTable { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), - paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlist), + paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlistLegacy), } } @@ -42,7 +42,7 @@ func validateEnabledType(i interface{}) error { return nil } -func validateAllowlist(i interface{}) error { +func validateAllowlistLegacy(i interface{}) error { allowMsgs, ok := i.([]string) if !ok { return fmt.Errorf("invalid parameter type: %T", i) From 98f213c2319df4e293e190807d6f454717a862a6 Mon Sep 17 00:00:00 2001 From: MD Aleem <72057206+aleem1314@users.noreply.github.com> Date: Wed, 3 May 2023 20:43:42 +0530 Subject: [PATCH 07/69] Update modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go --- .../27-interchain-accounts/host/migrations/v8/migrations.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go b/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go index f2e3d0596cf..9a88719cd5f 100644 --- a/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go +++ b/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go @@ -16,8 +16,8 @@ const ( var ParamsKey = []byte{0x00} -// Migrate migrates the 27-interchain-accounts host submodule state from the consensus version 1 to -// version 2. Specifically, it takes the parameters that are currently stored +// Migrate migrates the 27-interchain-accounts host submodule state from the consensus version 2 to +// version 3. Specifically, it takes the parameters that are currently stored // and managed by the x/params modules and stores them directly into the host // submodule state. func Migrate( From 9c53d6130e10006d9d5d5148477a6dc477efe0dd Mon Sep 17 00:00:00 2001 From: srdtrk <59252793+srdtrk@users.noreply.github.com> Date: Mon, 15 May 2023 16:57:41 +0300 Subject: [PATCH 08/69] fix(transfer): 'p.AllowMessages' missing '&' in 'NewParamSetPair' --- modules/apps/27-interchain-accounts/host/types/params_legacy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go index 079da928261..68a948552fa 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_legacy.go +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -29,7 +29,7 @@ func ParamKeyTable() paramtypes.KeyTable { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), - paramtypes.NewParamSetPair(KeyAllowMessages, p.AllowMessages, validateAllowlistLegacy), + paramtypes.NewParamSetPair(KeyAllowMessages, &p.AllowMessages, validateAllowlistLegacy), } } From b02d03b1a15bb3f78504bcd8bcf3061ab491e344 Mon Sep 17 00:00:00 2001 From: srdtrk <59252793+srdtrk@users.noreply.github.com> Date: Mon, 15 May 2023 16:58:05 +0300 Subject: [PATCH 09/69] fix(transfer): 'p.HostEnabled' missing '&' in 'NewParamSetPair' --- modules/apps/27-interchain-accounts/host/types/params_legacy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go index 68a948552fa..eef14dfedb5 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_legacy.go +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -28,7 +28,7 @@ func ParamKeyTable() paramtypes.KeyTable { // ParamSetPairs implements params.ParamSet func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyHostEnabled, p.HostEnabled, validateEnabledType), + paramtypes.NewParamSetPair(KeyHostEnabled, &p.HostEnabled, validateEnabledType), paramtypes.NewParamSetPair(KeyAllowMessages, &p.AllowMessages, validateAllowlistLegacy), } } From 6269d162a6ce1c4a1c1b72f94548db625daa4d73 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 15 May 2023 17:41:25 +0300 Subject: [PATCH 10/69] refactor(ica/host): reduce code duplication by removing 'IsHostEnabled' and 'GetAllowMessages' functions --- .../27-interchain-accounts/host/ibc_module.go | 6 ++-- .../host/keeper/params.go | 30 ------------------- .../host/keeper/relay.go | 2 +- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module.go b/modules/apps/27-interchain-accounts/host/ibc_module.go index 219199cb06d..82ba828a725 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module.go @@ -52,7 +52,7 @@ func (im IBCModule) OnChanOpenTry( counterparty channeltypes.Counterparty, counterpartyVersion string, ) (string, error) { - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { return "", types.ErrHostSubModuleDisabled } @@ -76,7 +76,7 @@ func (im IBCModule) OnChanOpenConfirm( portID, channelID string, ) error { - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { return types.ErrHostSubModuleDisabled } @@ -109,7 +109,7 @@ func (im IBCModule) OnRecvPacket( _ sdk.AccAddress, ) ibcexported.Acknowledgement { logger := im.keeper.Logger(ctx) - if !im.keeper.IsHostEnabled(ctx) { + if !im.keeper.GetParams(ctx).HostEnabled { logger.Info("host submodule is disabled") return channeltypes.NewErrorAcknowledgement(types.ErrHostSubModuleDisabled) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/params.go b/modules/apps/27-interchain-accounts/host/keeper/params.go index 33c887960a5..90903ef24a3 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/params.go +++ b/modules/apps/27-interchain-accounts/host/keeper/params.go @@ -6,36 +6,6 @@ import ( "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ) -// IsHostEnabled retrieves the host enabled boolean from the paramstore. -// True is returned if the host submodule is enabled. -func (k Keeper) IsHostEnabled(ctx sdk.Context) bool { - var params types.Params - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) - if bz == nil { - return false - } - - if err := k.cdc.Unmarshal(bz, ¶ms); err != nil { - return false - } - - return params.HostEnabled -} - -// GetAllowMessages retrieves the host enabled msg types from the paramstore -func (k Keeper) GetAllowMessages(ctx sdk.Context) []string { - var params types.Params - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) - if bz == nil { - return []string{} - } - - k.cdc.MustUnmarshal(bz, ¶ms) - return params.AllowMessages -} - // GetParams returns the total set of the host submodule parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { var params types.Params diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay.go b/modules/apps/27-interchain-accounts/host/keeper/relay.go index 4e620291a6b..7e1a14c78a5 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay.go @@ -91,7 +91,7 @@ func (k Keeper) authenticateTx(ctx sdk.Context, msgs []sdk.Msg, connectionID, po return errorsmod.Wrapf(icatypes.ErrInterchainAccountNotFound, "failed to retrieve interchain account on port %s", portID) } - allowMsgs := k.GetAllowMessages(ctx) + allowMsgs := k.GetParams(ctx).AllowMessages for _, msg := range msgs { if !types.ContainsMsgType(allowMsgs, msg) { return errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "message type not allowed: %s", sdk.MsgTypeURL(msg)) From b9f08171242c2c83f95032a35ff3e81102f24e73 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 15 May 2023 17:45:33 +0300 Subject: [PATCH 11/69] refactor(ica/host): moved getter and setters to 'keeper.go' --- .../host/keeper/keeper.go | 21 +++++++++++++++ .../host/keeper/params.go | 27 ------------------- 2 files changed, 21 insertions(+), 27 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/host/keeper/params.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 6724e9b0a01..56be52ead35 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -11,6 +11,7 @@ import ( capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" @@ -200,3 +201,23 @@ func (k Keeper) SetInterchainAccountAddress(ctx sdk.Context, connectionID, portI func (k Keeper) GetAuthority() string { return k.authority } + +// GetParams returns the total set of the host submodule parameters. +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + var params types.Params + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParamsKey) + if bz == nil { + return types.Params{} + } + + k.cdc.MustUnmarshal(bz, ¶ms) + return params +} + +// SetParams sets the total set of the host submodule parameters. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(¶ms) + store.Set(types.ParamsKey, bz) +} diff --git a/modules/apps/27-interchain-accounts/host/keeper/params.go b/modules/apps/27-interchain-accounts/host/keeper/params.go deleted file mode 100644 index 90903ef24a3..00000000000 --- a/modules/apps/27-interchain-accounts/host/keeper/params.go +++ /dev/null @@ -1,27 +0,0 @@ -package keeper - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" -) - -// GetParams returns the total set of the host submodule parameters. -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - var params types.Params - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) - if bz == nil { - return types.Params{} - } - - k.cdc.MustUnmarshal(bz, ¶ms) - return params -} - -// SetParams sets the total set of the host submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - store := ctx.KVStore(k.storeKey) - bz := k.cdc.MustMarshal(¶ms) - store.Set(types.ParamsKey, bz) -} From f5c9fea5af2a7309b5dd8c6cb14bdf24f7dc006d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 15 May 2023 18:05:09 +0300 Subject: [PATCH 12/69] refactor(ica/host): moved getter and setters to 'keeper.go' --- .../host/keeper/keeper.go | 7 +++- .../host/keeper/migrator.go | 14 +++---- .../host/migrations/v8/migrations.go | 40 ------------------- modules/apps/27-interchain-accounts/module.go | 2 +- 4 files changed, 14 insertions(+), 49 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 56be52ead35..4b5429fddce 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -216,8 +216,13 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the total set of the host submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + if err := params.Validate(); err != nil { + return err + } + store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(¶ms) store.Set(types.ParamsKey, bz) + return nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go index 6a9b4623bf7..f1c471d6a2f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -3,7 +3,7 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" - v8 "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/migrations/v8" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ) // Migrator is a struct for handling in-place state migrations. @@ -20,10 +20,10 @@ func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { } } -// Migrate2to3 migrates the 27-interchain-accounts module state from the -// consensus version 2 to version 3. Specifically, it takes the parameters that -// are currently stored and managed by the x/params modules and stores them directly -// into the host submodule state. -func (m Migrator) Migrate2to3(ctx sdk.Context) error { - return v8.Migrate(ctx, ctx.KVStore(m.keeper.storeKey), m.legacySubspace, m.keeper.cdc) +// MigrateParams migrates the host submodule's parameters from the x/params to self store. +func (m Migrator) MigrateParams(ctx sdk.Context) error { + var params types.Params + m.legacySubspace.GetParamSet(ctx, ¶ms) + + return m.keeper.SetParams(ctx, params) } diff --git a/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go b/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go deleted file mode 100644 index 9a88719cd5f..00000000000 --- a/modules/apps/27-interchain-accounts/host/migrations/v8/migrations.go +++ /dev/null @@ -1,40 +0,0 @@ -package v8 - -import ( - storetypes "github.com/cosmos/cosmos-sdk/store/types" - - "github.com/cosmos/cosmos-sdk/codec" - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" -) - -const ( - SubModuleName = "icahost" -) - -var ParamsKey = []byte{0x00} - -// Migrate migrates the 27-interchain-accounts host submodule state from the consensus version 2 to -// version 3. Specifically, it takes the parameters that are currently stored -// and managed by the x/params modules and stores them directly into the host -// submodule state. -func Migrate( - ctx sdk.Context, - store storetypes.KVStore, - legacySubspace exported.Subspace, - cdc codec.BinaryCodec, -) error { - var currParams types.Params - legacySubspace.GetParamSet(ctx, &currParams) - - if err := currParams.Validate(); err != nil { - return err - } - - bz := cdc.MustMarshal(&currParams) - store.Set(ParamsKey, bz) - - return nil -} diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 3e273bec27b..25264e1f083 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -150,7 +150,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } hostm := hostkeeper.NewMigrator(am.hostKeeper, am.legacyHostSubspace) - if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.Migrate2to3); err != nil { + if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.MigrateParams); err != nil { panic(fmt.Sprintf("failed to migrate interchainaccounts host params from version 2 to 3: %v", err)) } } From d9a12a8f5c8126abd94110da211c4213a1c7f3af Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 10:53:15 +0300 Subject: [PATCH 13/69] fix(ica/host): handling the SetParam errors now --- .../host/ibc_module_test.go | 15 ++++++--- .../host/keeper/genesis.go | 4 ++- .../host/keeper/msg_server.go | 4 ++- .../host/keeper/params_test.go | 3 +- .../host/keeper/relay_test.go | 33 ++++++++++++------- modules/apps/27-interchain-accounts/module.go | 6 ++-- 6 files changed, 44 insertions(+), 21 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index f8737c300a2..d1812f773ae 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -151,7 +151,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { }, { "host submodule disabled", func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + suite.Require().NoError(err) }, false, }, { @@ -273,7 +274,8 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { }, { "host submodule disabled", func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + suite.Require().NoError(err) }, false, }, { @@ -399,7 +401,8 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { }, { "host submodule disabled", func() { - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) + suite.Require().NoError(err) }, false, }, { @@ -464,7 +467,8 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { expectedAck := channeltypes.NewResultAcknowledgement(expectedTxResponse) params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) // malleate packetData for test cases tc.malleate() @@ -661,7 +665,8 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() } params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) //nolint: staticcheck // SA1019: ibctesting.FirstConnectionID is deprecated: use path.EndpointA.ConnectionID instead. (staticcheck) _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 4816f957a58..3fce4693544 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -27,7 +27,9 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress) } - keeper.SetParams(ctx, state.Params) + if err := keeper.SetParams(ctx, state.Params); err != nil { + panic(fmt.Sprintf("could not set ica host params at genesis: %v", err)) + } } // ExportGenesis returns the interchain accounts host exported genesis diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index efe632e7709..b93b73c4b7d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -28,7 +28,9 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam } ctx := sdk.UnwrapSDKContext(goCtx) - m.SetParams(ctx, msg.Params) + if err := m.SetParams(ctx, msg.Params); err != nil { + return nil, err + } return &types.MsgUpdateParamsResponse{}, nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/params_test.go b/modules/apps/27-interchain-accounts/host/keeper/params_test.go index a8d056ce007..abd92ccd036 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/params_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/params_test.go @@ -10,7 +10,8 @@ func (suite *KeeperTestSuite) TestParams() { expParams.HostEnabled = false expParams.AllowMessages = []string{"/cosmos.staking.v1beta1.MsgDelegate"} - suite.chainA.GetSimApp().ICAHostKeeper.SetParams(suite.chainA.GetContext(), expParams) + err := suite.chainA.GetSimApp().ICAHostKeeper.SetParams(suite.chainA.GetContext(), expParams) + suite.Require().NoError(err) params = suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) } diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go index 6e07e58715f..65b553d0ac9 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go @@ -67,7 +67,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{"*"}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -94,7 +95,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -122,7 +124,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -156,7 +159,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msgDelegate), sdk.MsgTypeURL(msgUndelegate)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -191,7 +195,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -233,7 +238,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -259,7 +265,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -285,7 +292,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -324,7 +332,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, true, }, @@ -344,7 +353,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{"/" + proto.MessageName(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, false, }, @@ -442,7 +452,8 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) }, false, }, diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 25264e1f083..f5e2c4d938e 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -112,7 +112,7 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee } } -// InitModule will initialize the interchain accounts moudule. It should only be +// InitModule will initialize the interchain accounts module. It should only be // called once and as an alternative to InitGenesis. func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes.Params, hostParams hosttypes.Params) { if am.controllerKeeper != nil { @@ -120,7 +120,9 @@ func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes } if am.hostKeeper != nil { - am.hostKeeper.SetParams(ctx, hostParams) + if err := am.hostKeeper.SetParams(ctx, hostParams); err != nil { + panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) + } capability := am.hostKeeper.BindPort(ctx, types.HostPortID) if err := am.hostKeeper.ClaimCapability(ctx, capability, ibchost.PortPath(types.HostPortID)); err != nil { From 3c97fba58711f19f91d994b9ecdea40462ff833d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 10:57:05 +0300 Subject: [PATCH 14/69] imp(ica/host): added failure cases to TestValidateParams --- modules/apps/27-interchain-accounts/host/types/params_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/apps/27-interchain-accounts/host/types/params_test.go b/modules/apps/27-interchain-accounts/host/types/params_test.go index e83b82e7447..81bb547f473 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_test.go +++ b/modules/apps/27-interchain-accounts/host/types/params_test.go @@ -11,4 +11,6 @@ import ( func TestValidateParams(t *testing.T) { require.NoError(t, types.DefaultParams().Validate()) require.NoError(t, types.NewParams(false, []string{}).Validate()) + require.Error(t, types.NewParams(true, []string{""}).Validate()) + require.Error(t, types.NewParams(true, []string{" "}).Validate()) } From a5f4b756c6534c91cec56bf29905c60913b6bae1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 14:47:03 +0300 Subject: [PATCH 15/69] feat(ica/host): added codec for msg --- .../27-interchain-accounts/host/types/codec.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 modules/apps/27-interchain-accounts/host/types/codec.go diff --git a/modules/apps/27-interchain-accounts/host/types/codec.go b/modules/apps/27-interchain-accounts/host/types/codec.go new file mode 100644 index 00000000000..5e5521e3999 --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/types/codec.go @@ -0,0 +1,14 @@ +package types + +import ( + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// RegisterInterfaces registers the interchain accounts controller message types using the provided InterfaceRegistry +func RegisterInterfaces(registry codectypes.InterfaceRegistry) { + registry.RegisterImplementations( + (*sdk.Msg)(nil), + &MsgUpdateParams{}, + ) +} From 09da84fa75c79fb783bb8474154873a4a2d1c600 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 14:49:00 +0300 Subject: [PATCH 16/69] fix(ica/host): added host's RegisterInterfaces to module.go --- modules/apps/27-interchain-accounts/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index f5e2c4d938e..e70c992c34b 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -51,6 +51,7 @@ func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {} // RegisterInterfaces registers module concrete types into protobuf Any func (AppModuleBasic) RegisterInterfaces(registry codectypes.InterfaceRegistry) { controllertypes.RegisterInterfaces(registry) + hosttypes.RegisterInterfaces(registry) types.RegisterInterfaces(registry) } From 926ffdd2ded88b964d614fbe63d1899f159e1175 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 14:51:48 +0300 Subject: [PATCH 17/69] fix(changelog): removed manual addition --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c999304b6b..28354f0c7c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,8 +42,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### State Machine Breaking -* (modules/apps/27-interchain-accounts/host) [\#3520](https://github.com/cosmos/ibc-go/pull/3520) Migrate `modules/apps/27-interchain-accounts/host` to self-managed parameters and deprecate it's usage of `x/params`. - ### Improvements * (tests) [\#3138](https://github.com/cosmos/ibc-go/pull/3138) Support benchmarks and fuzz tests through `testing.TB`. From b8db88a9fe7d919bc48b057505cea9ea36c4ab80 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 14:56:42 +0300 Subject: [PATCH 18/69] imp(ica/host): made GetParams more economical --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 4b5429fddce..9c8e7768142 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -204,13 +204,13 @@ func (k Keeper) GetAuthority() string { // GetParams returns the total set of the host submodule parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { - var params types.Params store := ctx.KVStore(k.storeKey) bz := store.Get(types.ParamsKey) if bz == nil { return types.Params{} } + var params types.Params k.cdc.MustUnmarshal(bz, ¶ms) return params } From 9c26d08251c70c186549344a0f958468f0a8b6ab Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 16:02:59 +0300 Subject: [PATCH 19/69] fix(fee/test): handled ica's 'SetParams' error during testing --- modules/apps/29-fee/ica_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/apps/29-fee/ica_test.go b/modules/apps/29-fee/ica_test.go index 090533cb875..ad3e3370de3 100644 --- a/modules/apps/29-fee/ica_test.go +++ b/modules/apps/29-fee/ica_test.go @@ -153,7 +153,8 @@ func (suite *FeeTestSuite) TestFeeInterchainAccounts() { // ensure chainB is allowed to execute stakingtypes.MsgDelegate params := icahosttypes.NewParams(true, []string{sdk.MsgTypeURL(msgDelegate)}) - suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) + suite.Require().NoError(err) // build the interchain accounts packet packet := buildInterchainAccountsPacket(path, icaPacketData.GetBytes(), 1) From e9827108a91696a9edd62e6cf35f065605ac4ce5 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:17:10 +0300 Subject: [PATCH 20/69] imp(ica/host): using ibcerrors instead of relying on sdk's govtypes --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index b93b73c4b7d..ae3ea34e128 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -5,8 +5,8 @@ import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" ) var _ types.MsgServer = (*msgServer)(nil) @@ -24,7 +24,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { - return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", m.authority, msg.Authority) + return nil, errors.Wrapf(ibcerrors.ErrInvalidAddress, "invalid authority; expected %s, got %s", m.authority, msg.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) From 26a44dfa3133f2021df2a555dc6269e632970e1d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:31:41 +0300 Subject: [PATCH 21/69] style(ica/host): removed '*' from Migrator's keeper --- modules/apps/27-interchain-accounts/host/keeper/migrator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go index f1c471d6a2f..a80ab07974a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -8,12 +8,12 @@ import ( // Migrator is a struct for handling in-place state migrations. type Migrator struct { - keeper *Keeper + keeper Keeper legacySubspace exported.Subspace } // NewMigrator returns Migrator instance for the state migration. -func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { +func NewMigrator(k Keeper, ss exported.Subspace) Migrator { return Migrator{ keeper: k, legacySubspace: ss, From d51de4ca81690d1038d7e545636b2f2cc1591a30 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:38:42 +0300 Subject: [PATCH 22/69] revert(ica/host): reverts to the previous commit as this is more consistent with what is done in module.go --- modules/apps/27-interchain-accounts/host/keeper/migrator.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go index a80ab07974a..f1c471d6a2f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -8,12 +8,12 @@ import ( // Migrator is a struct for handling in-place state migrations. type Migrator struct { - keeper Keeper + keeper *Keeper legacySubspace exported.Subspace } // NewMigrator returns Migrator instance for the state migration. -func NewMigrator(k Keeper, ss exported.Subspace) Migrator { +func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { return Migrator{ keeper: k, legacySubspace: ss, From f712f93a721ac8d206da9a84b110930e2d06a391 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:43:37 +0300 Subject: [PATCH 23/69] fix(simapp): added ParamKeyTable to the icahost subspace in app.go for migration --- testing/simapp/app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index fa78bfec2ae..5509a995cec 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -913,7 +913,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) - paramsKeeper.Subspace(icahosttypes.SubModuleName) + paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) return paramsKeeper } From b67a173f75fff1901d832b1dee3dec0f16bc2f09 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:45:14 +0300 Subject: [PATCH 24/69] feat(ica/host/test): added migrator_test.go --- .../host/keeper/migrator_test.go | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/apps/27-interchain-accounts/host/keeper/migrator_test.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go new file mode 100644 index 00000000000..4aeb8684fdf --- /dev/null +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go @@ -0,0 +1,42 @@ +package keeper_test + +import ( + "fmt" + + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" +) + +func (suite *KeeperTestSuite) TestMigratorMigrateParams() { + testCases := []struct { + msg string + malleate func(subspace paramstypes.Subspace) + expectedParams icahosttypes.Params + }{ + { + "success: default params", + func(subspace paramstypes.Subspace) { + params := icahosttypes.DefaultParams() + subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params + }, + icahosttypes.DefaultParams(), + }, + } + + for _, tc := range testCases { + suite.Run(fmt.Sprintf("case %s", tc.msg), func() { + suite.SetupTest() // reset + + subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace + tc.malleate(subspace) // explicitly set params + + migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper, subspace) + err := migrator.MigrateParams(suite.chainA.GetContext()) + suite.Require().NoError(err) + + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(tc.expectedParams, params) + }) + } +} \ No newline at end of file From 904cd3fd80f404dbf9c621fc2670bf0513189230 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 16 May 2023 21:49:25 +0300 Subject: [PATCH 25/69] style(ica/host/test): ran gofumpt --- .../apps/27-interchain-accounts/host/keeper/migrator_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go index 4aeb8684fdf..37f110e0dc2 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go @@ -39,4 +39,4 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { suite.Require().Equal(tc.expectedParams, params) }) } -} \ No newline at end of file +} From 525d431cb774fd3c26c7896af2448d2e4fe244b3 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 13:52:15 +0300 Subject: [PATCH 26/69] feat(ica/host): passing legacySubspace to keeper instead --- .../exported/exported.go | 18 ------------------ .../host/keeper/keeper.go | 15 ++++++++++++--- .../host/keeper/migrator.go | 7 ++----- modules/apps/27-interchain-accounts/module.go | 8 ++------ 4 files changed, 16 insertions(+), 32 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/exported/exported.go diff --git a/modules/apps/27-interchain-accounts/exported/exported.go b/modules/apps/27-interchain-accounts/exported/exported.go deleted file mode 100644 index 000114e6194..00000000000 --- a/modules/apps/27-interchain-accounts/exported/exported.go +++ /dev/null @@ -1,18 +0,0 @@ -package exported - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" -) - -type ( - ParamSet = paramtypes.ParamSet - - // Subspace defines an interface that implements the legacy x/params Subspace - // type. - // - // NOTE: This is used solely for migration of x/params managed parameters. - Subspace interface { - GetParamSet(ctx sdk.Context, ps ParamSet) - } -) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 9c8e7768142..ceaacfd4125 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -8,6 +8,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" @@ -23,6 +24,7 @@ import ( type Keeper struct { storeKey storetypes.StoreKey cdc codec.BinaryCodec + legacySubspace paramtypes.Subspace ics4Wrapper porttypes.ICS4Wrapper channelKeeper icatypes.ChannelKeeper @@ -40,18 +42,25 @@ type Keeper struct { // NewKeeper creates a new interchain accounts host Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, ics4Wrapper porttypes.ICS4Wrapper, - channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, accountKeeper icatypes.AccountKeeper, - scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, authority string, + cdc codec.BinaryCodec, key storetypes.StoreKey, legacySubspace paramtypes.Subspace, + ics4Wrapper porttypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper, + accountKeeper icatypes.AccountKeeper, scopedKeeper exported.ScopedKeeper, msgRouter icatypes.MessageRouter, + authority string, ) Keeper { // ensure ibc interchain accounts module account is set if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil { panic("the Interchain Accounts module account has not been set") } + // set KeyTable if it has not already been set + if !legacySubspace.HasKeyTable() { + legacySubspace = legacySubspace.WithKeyTable(types.ParamKeyTable()) + } + return Keeper{ storeKey: key, cdc: cdc, + legacySubspace: legacySubspace, ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go index f1c471d6a2f..c380587cf3d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -2,28 +2,25 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ) // Migrator is a struct for handling in-place state migrations. type Migrator struct { keeper *Keeper - legacySubspace exported.Subspace } // NewMigrator returns Migrator instance for the state migration. -func NewMigrator(k *Keeper, ss exported.Subspace) Migrator { +func NewMigrator(k *Keeper) Migrator { return Migrator{ keeper: k, - legacySubspace: ss, } } // MigrateParams migrates the host submodule's parameters from the x/params to self store. func (m Migrator) MigrateParams(ctx sdk.Context) error { var params types.Params - m.legacySubspace.GetParamSet(ctx, ¶ms) + m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) return m.keeper.SetParams(ctx, params) } diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index e70c992c34b..840fe0c0d17 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -12,13 +12,13 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/client/cli" controllerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper" controllertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types" - "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/exported" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" hostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" @@ -99,9 +99,6 @@ type AppModule struct { AppModuleBasic controllerKeeper *controllerkeeper.Keeper hostKeeper *hostkeeper.Keeper - - // legacyHostSubspace is used solely for migration of x/params managed parameters - legacyHostSubspace exported.Subspace } // NewAppModule creates a new IBC interchain accounts module @@ -109,7 +106,6 @@ func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkee return AppModule{ controllerKeeper: controllerKeeper, hostKeeper: hostKeeper, - legacyHostSubspace: hss, } } @@ -152,7 +148,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 1 to 2: %v", err)) } - hostm := hostkeeper.NewMigrator(am.hostKeeper, am.legacyHostSubspace) + hostm := hostkeeper.NewMigrator(am.hostKeeper) if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.MigrateParams); err != nil { panic(fmt.Sprintf("failed to migrate interchainaccounts host params from version 2 to 3: %v", err)) } From 6ff8f385399f1253df24daccda4b7b5a07a6b31e Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 13:56:20 +0300 Subject: [PATCH 27/69] fix(ica/host): removed unneeded reference to hss from 'NewAppModule' function --- modules/apps/27-interchain-accounts/module.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 840fe0c0d17..2ee0faacb2c 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -12,7 +12,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/exported" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" @@ -102,7 +101,7 @@ type AppModule struct { } // NewAppModule creates a new IBC interchain accounts module -func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper, hss exported.Subspace) AppModule { +func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) AppModule { return AppModule{ controllerKeeper: controllerKeeper, hostKeeper: hostKeeper, From 1ffbda6fcd6f4ec4c2211ccfa6a84f2398abaa9b Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 13:57:41 +0300 Subject: [PATCH 28/69] fix(simapp): reduced modifications to simapp to 1 --- testing/simapp/app.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 5509a995cec..ac2027f054e 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -427,7 +427,7 @@ func NewSimApp( // ICA Host keeper app.ICAHostKeeper = icahostkeeper.NewKeeper( - appCodec, keys[icahosttypes.StoreKey], + appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), @@ -567,7 +567,7 @@ func NewSimApp( ibc.NewAppModule(app.IBCKeeper), transfer.NewAppModule(app.TransferKeeper), ibcfee.NewAppModule(app.IBCFeeKeeper), - ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper, app.GetSubspace(icahosttypes.SubModuleName)), + ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), mockModule, ) @@ -636,7 +636,7 @@ func NewSimApp( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ibc.NewAppModule(app.IBCKeeper), transfer.NewAppModule(app.TransferKeeper), - ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper, app.GetSubspace(icahosttypes.SubModuleName)), + ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), ) app.sm.RegisterStoreDecoders() @@ -913,7 +913,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) - paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable()) + paramsKeeper.Subspace(icahosttypes.SubModuleName) return paramsKeeper } From 6667d995f2bb6ac92e2f3a2ea290c431051e3867 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 13:59:19 +0300 Subject: [PATCH 29/69] fix(ica/host/test): updated tests --- .../host/keeper/migrator_test.go | 11 +++++------ modules/apps/27-interchain-accounts/module_test.go | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go index 37f110e0dc2..2c1d430ebac 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go @@ -3,7 +3,6 @@ package keeper_test import ( "fmt" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ) @@ -11,13 +10,14 @@ import ( func (suite *KeeperTestSuite) TestMigratorMigrateParams() { testCases := []struct { msg string - malleate func(subspace paramstypes.Subspace) + malleate func() expectedParams icahosttypes.Params }{ { "success: default params", - func(subspace paramstypes.Subspace) { + func() { params := icahosttypes.DefaultParams() + subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params }, icahosttypes.DefaultParams(), @@ -28,10 +28,9 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset - subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace - tc.malleate(subspace) // explicitly set params + tc.malleate() // explicitly set params - migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper, subspace) + migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper) err := migrator.MigrateParams(suite.chainA.GetContext()) suite.Require().NoError(err) diff --git a/modules/apps/27-interchain-accounts/module_test.go b/modules/apps/27-interchain-accounts/module_test.go index 6eecb3d1038..0d3bdb19a93 100644 --- a/modules/apps/27-interchain-accounts/module_test.go +++ b/modules/apps/27-interchain-accounts/module_test.go @@ -77,17 +77,17 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() { }, { "neither controller or host is set", func() { - appModule = ica.NewAppModule(nil, nil, nil) + appModule = ica.NewAppModule(nil, nil) }, false, false, }, { "only controller is set", func() { - appModule = ica.NewAppModule(&app.ICAControllerKeeper, nil, nil) + appModule = ica.NewAppModule(&app.ICAControllerKeeper, nil) }, true, false, }, { "only host is set", func() { - appModule = ica.NewAppModule(nil, &app.ICAHostKeeper, nil) + appModule = ica.NewAppModule(nil, &app.ICAHostKeeper) }, false, true, }, } From f30f70354c5671668da4d131821af9d89a7aca88 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 14:00:38 +0300 Subject: [PATCH 30/69] style(ica/host): ran gofumpt --- .../host/keeper/keeper.go | 24 +++++++++---------- .../host/keeper/migrator.go | 4 ++-- .../host/keeper/migrator_test.go | 4 ++-- modules/apps/27-interchain-accounts/module.go | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index ceaacfd4125..1f710c246ed 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -22,8 +22,8 @@ import ( // Keeper defines the IBC interchain accounts host keeper type Keeper struct { - storeKey storetypes.StoreKey - cdc codec.BinaryCodec + storeKey storetypes.StoreKey + cdc codec.BinaryCodec legacySubspace paramtypes.Subspace ics4Wrapper porttypes.ICS4Wrapper @@ -58,16 +58,16 @@ func NewKeeper( } return Keeper{ - storeKey: key, - cdc: cdc, - legacySubspace: legacySubspace, - ics4Wrapper: ics4Wrapper, - channelKeeper: channelKeeper, - portKeeper: portKeeper, - accountKeeper: accountKeeper, - scopedKeeper: scopedKeeper, - msgRouter: msgRouter, - authority: authority, + storeKey: key, + cdc: cdc, + legacySubspace: legacySubspace, + ics4Wrapper: ics4Wrapper, + channelKeeper: channelKeeper, + portKeeper: portKeeper, + accountKeeper: accountKeeper, + scopedKeeper: scopedKeeper, + msgRouter: msgRouter, + authority: authority, } } diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrator.go index c380587cf3d..9608ce37dfb 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator.go @@ -7,13 +7,13 @@ import ( // Migrator is a struct for handling in-place state migrations. type Migrator struct { - keeper *Keeper + keeper *Keeper } // NewMigrator returns Migrator instance for the state migration. func NewMigrator(k *Keeper) Migrator { return Migrator{ - keeper: k, + keeper: k, } } diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go index 2c1d430ebac..2b73ecdd87b 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go @@ -18,7 +18,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { func() { params := icahosttypes.DefaultParams() subspace := suite.chainA.GetSimApp().GetSubspace(icahosttypes.SubModuleName) // get subspace - subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params + subspace.SetParamSet(suite.chainA.GetContext(), ¶ms) // set params }, icahosttypes.DefaultParams(), }, @@ -28,7 +28,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateParams() { suite.Run(fmt.Sprintf("case %s", tc.msg), func() { suite.SetupTest() // reset - tc.malleate() // explicitly set params + tc.malleate() // explicitly set params migrator := icahostkeeper.NewMigrator(&suite.chainA.GetSimApp().ICAHostKeeper) err := migrator.MigrateParams(suite.chainA.GetContext()) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 2ee0faacb2c..4a421acdbd0 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -103,8 +103,8 @@ type AppModule struct { // NewAppModule creates a new IBC interchain accounts module func NewAppModule(controllerKeeper *controllerkeeper.Keeper, hostKeeper *hostkeeper.Keeper) AppModule { return AppModule{ - controllerKeeper: controllerKeeper, - hostKeeper: hostKeeper, + controllerKeeper: controllerKeeper, + hostKeeper: hostKeeper, } } From 6fbd88c90372a261792062ab825ae8866bb6b35b Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 14:12:34 +0300 Subject: [PATCH 31/69] docs(ica/host): fixed a typo --- modules/apps/27-interchain-accounts/host/types/codec.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/types/codec.go b/modules/apps/27-interchain-accounts/host/types/codec.go index 5e5521e3999..ef94e88ae67 100644 --- a/modules/apps/27-interchain-accounts/host/types/codec.go +++ b/modules/apps/27-interchain-accounts/host/types/codec.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// RegisterInterfaces registers the interchain accounts controller message types using the provided InterfaceRegistry +// RegisterInterfaces registers the interchain accounts host message types using the provided InterfaceRegistry func RegisterInterfaces(registry codectypes.InterfaceRegistry) { registry.RegisterImplementations( (*sdk.Msg)(nil), From 3d757145546ffae604a851ee47406fe840babf7d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 14:14:14 +0300 Subject: [PATCH 32/69] style(ica/host): added a space for import separation --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index ae3ea34e128..ab9c452fe69 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -5,6 +5,7 @@ import ( "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" ) From de7739e967232b6ded9703012f845a2580a14e49 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 14:24:05 +0300 Subject: [PATCH 33/69] style(ica/host): renamed 'migrator.go' to 'migrations.go' --- .../host/keeper/{migrator.go => migrations.go} | 0 .../host/keeper/{migrator_test.go => migrations_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename modules/apps/27-interchain-accounts/host/keeper/{migrator.go => migrations.go} (100%) rename modules/apps/27-interchain-accounts/host/keeper/{migrator_test.go => migrations_test.go} (100%) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go similarity index 100% rename from modules/apps/27-interchain-accounts/host/keeper/migrator.go rename to modules/apps/27-interchain-accounts/host/keeper/migrations.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrator_test.go b/modules/apps/27-interchain-accounts/host/keeper/migrations_test.go similarity index 100% rename from modules/apps/27-interchain-accounts/host/keeper/migrator_test.go rename to modules/apps/27-interchain-accounts/host/keeper/migrations_test.go From 9041fa484d3554d9df2f9952c8966472f975b52a Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 14:31:57 +0300 Subject: [PATCH 34/69] refactor(ica/host): removed unneeded validate function --- modules/apps/27-interchain-accounts/host/types/params.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index c7938a461af..9a240870d24 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -25,10 +25,6 @@ func DefaultParams() Params { // Validate validates all host submodule parameters func (p Params) Validate() error { - if err := validateEnabledType(p.HostEnabled); err != nil { - return err - } - return validateAllowlist(p.AllowMessages) } From 0b59b8ee59ce4f10470e9c1e5e79e7b650ceabdc Mon Sep 17 00:00:00 2001 From: srdtrk Date: Thu, 18 May 2023 15:40:52 +0300 Subject: [PATCH 35/69] style(ica/host): storing ParamsKey using a string --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 4 ++-- modules/apps/27-interchain-accounts/host/types/keys.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 1f710c246ed..7848537df64 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -214,7 +214,7 @@ func (k Keeper) GetAuthority() string { // GetParams returns the total set of the host submodule parameters. func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ParamsKey) + bz := store.Get([]byte(types.ParamsKey)) if bz == nil { return types.Params{} } @@ -232,6 +232,6 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(¶ms) - store.Set(types.ParamsKey, bz) + store.Set([]byte(types.ParamsKey), bz) return nil } diff --git a/modules/apps/27-interchain-accounts/host/types/keys.go b/modules/apps/27-interchain-accounts/host/types/keys.go index 9409f76732d..b566a613f55 100644 --- a/modules/apps/27-interchain-accounts/host/types/keys.go +++ b/modules/apps/27-interchain-accounts/host/types/keys.go @@ -4,9 +4,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ) -// ParamsKey is the key to use for the storing params. -var ParamsKey = []byte{0x00} - const ( // SubModuleName defines the interchain accounts host module name SubModuleName = "icahost" @@ -14,6 +11,9 @@ const ( // StoreKey is the store key string for the interchain accounts host module StoreKey = SubModuleName + // ParamsKey is the key to use for the storing params. + ParamsKey = "params" + // AllowAllHostMsgs holds the string key that allows all message types on interchain accounts host module AllowAllHostMsgs = "*" ) From 20d3800d84f67d612060dcf6defc6b131a514ec2 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 19 May 2023 21:47:51 +0300 Subject: [PATCH 36/69] fix(ica/host): registered the msg_server in ica's module.go --- modules/apps/27-interchain-accounts/module.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 4a421acdbd0..356824830ec 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -139,6 +139,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { } if am.hostKeeper != nil { + hosttypes.RegisterMsgServer(cfg.MsgServer(), hostkeeper.NewMsgServerImpl(am.hostKeeper)) hosttypes.RegisterQueryServer(cfg.QueryServer(), am.hostKeeper) } From 9019c739c4ffcc7c3d7306298ded545776b200c2 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Fri, 19 May 2023 21:51:59 +0300 Subject: [PATCH 37/69] style(ica/host): removed unneeded fmt variable assignment --- modules/apps/27-interchain-accounts/host/types/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/types/params.go b/modules/apps/27-interchain-accounts/host/types/params.go index 9a240870d24..1da41757819 100644 --- a/modules/apps/27-interchain-accounts/host/types/params.go +++ b/modules/apps/27-interchain-accounts/host/types/params.go @@ -1,7 +1,7 @@ package types import ( - fmt "fmt" + "fmt" "strings" ) From 47e72c18a448fdcec968fd8786645daffc67c2b8 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 00:29:42 +0300 Subject: [PATCH 38/69] imp(ica/host/test): added more test cases, and refactored the test --- .../host/keeper/keeper_test.go | 38 +++++++++++++++++++ .../host/keeper/params_test.go | 17 --------- 2 files changed, 38 insertions(+), 17 deletions(-) delete mode 100644 modules/apps/27-interchain-accounts/host/keeper/params_test.go diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 6a731ef66fc..f2823b7052e 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -6,6 +6,8 @@ import ( "github.com/stretchr/testify/suite" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" + "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" + icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" @@ -218,3 +220,39 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { suite.Require().True(found) suite.Require().Equal(expectedAccAddr, retrievedAddr) } + +func (suite *KeeperTestSuite) TestParams() { + expParams := icahosttypes.DefaultParams() + + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + + testCases := []struct { + name string + input icahosttypes.Params + expPass bool + }{ + {name: "success: set default params", input: types.DefaultParams(), expPass: true}, + {name: "success: non-default params", input: types.NewParams(!icahosttypes.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, + {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, + {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + ctx := suite.chainA.GetContext() + err := suite.chainA.GetSimApp().ICAHostKeeper.SetParams(ctx, tc.input) + if tc.expPass { + suite.Require().NoError(err) + expected := tc.input + p := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) + suite.Require().Equal(expected, p) + } else { + suite.Require().Error(err) + } + }) + } +} \ No newline at end of file diff --git a/modules/apps/27-interchain-accounts/host/keeper/params_test.go b/modules/apps/27-interchain-accounts/host/keeper/params_test.go deleted file mode 100644 index abd92ccd036..00000000000 --- a/modules/apps/27-interchain-accounts/host/keeper/params_test.go +++ /dev/null @@ -1,17 +0,0 @@ -package keeper_test - -import "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - -func (suite *KeeperTestSuite) TestParams() { - expParams := types.DefaultParams() - - params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) - - expParams.HostEnabled = false - expParams.AllowMessages = []string{"/cosmos.staking.v1beta1.MsgDelegate"} - err := suite.chainA.GetSimApp().ICAHostKeeper.SetParams(suite.chainA.GetContext(), expParams) - suite.Require().NoError(err) - params = suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) - suite.Require().Equal(expParams, params) -} From 04136971c1edc4a1563aad34b4ead547649b92f1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 00:31:50 +0300 Subject: [PATCH 39/69] style(ica/host/test): ran gofumpt --- .../27-interchain-accounts/host/keeper/keeper_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index f2823b7052e..a633efd8e17 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -7,7 +7,6 @@ import ( genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" - icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" @@ -222,18 +221,18 @@ func (suite *KeeperTestSuite) TestSetInterchainAccountAddress() { } func (suite *KeeperTestSuite) TestParams() { - expParams := icahosttypes.DefaultParams() + expParams := types.DefaultParams() params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) testCases := []struct { name string - input icahosttypes.Params + input types.Params expPass bool }{ {name: "success: set default params", input: types.DefaultParams(), expPass: true}, - {name: "success: non-default params", input: types.NewParams(!icahosttypes.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, + {name: "success: non-default params", input: types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, } @@ -255,4 +254,4 @@ func (suite *KeeperTestSuite) TestParams() { } }) } -} \ No newline at end of file +} From ac4566ad06cfcfcb67019e7ab4a61b8c2df48ec0 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 11:39:19 +0300 Subject: [PATCH 40/69] imp(ica/host): 'GetParams' panics now if it can't find the params --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 7848537df64..7e18fec408e 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -216,7 +216,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { - return types.Params{} + panic("ica/host params have not been set") } var params types.Params From 5b1825835c5d81a627b463b040b094e4a4147d32 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 11:42:41 +0300 Subject: [PATCH 41/69] imp(core): added 'ErrInvalidAuthority' --- modules/core/errors/errors.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/core/errors/errors.go b/modules/core/errors/errors.go index 79b96856a87..762059962fc 100644 --- a/modules/core/errors/errors.go +++ b/modules/core/errors/errors.go @@ -60,4 +60,7 @@ var ( // ErrNotFound defines an error when requested entity doesn't exist in the state. ErrNotFound = errorsmod.Register(codespace, 16, "not found") + + // ErrInvalidAuthority defines an error when the authority address is invalid. + ErrInvalidAuthority = errorsmod.Register(codespace, 17, "invalid authority") ) From 50f2b67483c37bde7ede21de3b279ec0785d2129 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 11:43:33 +0300 Subject: [PATCH 42/69] imp(ica/host): uses 'ErrInvalidAuthority' --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index ab9c452fe69..d89b0703e2a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -25,7 +25,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { - return nil, errors.Wrapf(ibcerrors.ErrInvalidAddress, "invalid authority; expected %s, got %s", m.authority, msg.Authority) + return nil, errors.Wrapf(ibcerrors.ErrInvalidAuthority, "invalid authority; expected %s, got %s", m.authority, msg.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) From ddf60d40a0c0d0979cbde5a91875b5fea1a1c15d Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 12:05:25 +0300 Subject: [PATCH 43/69] fix(ica/test): fixed test for the ica module --- modules/apps/27-interchain-accounts/module_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/module_test.go b/modules/apps/27-interchain-accounts/module_test.go index 0d3bdb19a93..461091b996d 100644 --- a/modules/apps/27-interchain-accounts/module_test.go +++ b/modules/apps/27-interchain-accounts/module_test.go @@ -51,7 +51,9 @@ func (suite *InterchainAccountsTestSuite) TestInitModule() { suite.Require().Panics(func() { app.ICAControllerKeeper.GetParams(ctx) }) - suite.Require().Equal(app.ICAHostKeeper.GetParams(ctx), hosttypes.Params{}) + suite.Require().Panics(func() { + app.ICAHostKeeper.GetParams(ctx) + }) controllerParams := controllertypes.DefaultParams() controllerParams.ControllerEnabled = true From c0ce6a3896ff73b42ba47456490ae59050a25dc2 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 12:34:08 +0300 Subject: [PATCH 44/69] imp(ica/host/test): added a new test case --- modules/apps/27-interchain-accounts/host/keeper/keeper_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index a633efd8e17..3587d76c4e6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -233,6 +233,7 @@ func (suite *KeeperTestSuite) TestParams() { }{ {name: "success: set default params", input: types.DefaultParams(), expPass: true}, {name: "success: non-default params", input: types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, + {name: "success: set empty allowMsg", input: types.NewParams(true, nil), expPass: true}, {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, } From 588fcbe2145f6eabb2b5d0ee07c17855b4f3f203 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 12:41:16 +0300 Subject: [PATCH 45/69] imp(ica/host/test): added params test to genesis --- .../host/keeper/genesis_test.go | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 7851b730527..29bf5ddc0f9 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -46,6 +46,66 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().Equal(expParams, params) } +func (suite *KeeperTestSuite) TestGenesisParams() { + testCases := []struct { + name string + input types.Params + expPass bool + }{ + {name: "success: set default params", input: types.DefaultParams(), expPass: true}, + {name: "success: non-default params", input: types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, + {name: "success: set empty allowMsg", input: types.NewParams(true, nil), expPass: true}, + {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, + {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, + } + + for _, tc := range testCases { + tc := tc + + suite.Run(tc.name, func() { + suite.SetupTest() // reset + interchainAccAddr := icatypes.GenerateAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, TestPortID) + genesisState := genesistypes.HostGenesisState{ + ActiveChannels: []genesistypes.ActiveChannel{ + { + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + ChannelId: ibctesting.FirstChannelID, + }, + }, + InterchainAccounts: []genesistypes.RegisteredInterchainAccount{ + { + ConnectionId: ibctesting.FirstConnectionID, + PortId: TestPortID, + AccountAddress: interchainAccAddr.String(), + }, + }, + Port: icatypes.HostPortID, + Params: tc.input, + } + if tc.expPass { + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + + channelID, found := suite.chainA.GetSimApp().ICAHostKeeper.GetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(ibctesting.FirstChannelID, channelID) + + accountAdrr, found := suite.chainA.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, TestPortID) + suite.Require().True(found) + suite.Require().Equal(interchainAccAddr.String(), accountAdrr) + + expParams := tc.input + params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) + suite.Require().Equal(expParams, params) + } else { + suite.Require().Panics(func() { + keeper.InitGenesis(suite.chainA.GetContext(), suite.chainA.GetSimApp().ICAHostKeeper, genesisState) + }) + } + }) + } +} + func (suite *KeeperTestSuite) TestExportGenesis() { suite.SetupTest() From a87581bc3c0f4b2100e0b8315bc81b6f7a6a5a7a Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 12:42:37 +0300 Subject: [PATCH 46/69] style(ica/host): ran gofumpt --- modules/apps/27-interchain-accounts/host/keeper/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 29bf5ddc0f9..60afdacb626 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -80,7 +80,7 @@ func (suite *KeeperTestSuite) TestGenesisParams() { AccountAddress: interchainAccAddr.String(), }, }, - Port: icatypes.HostPortID, + Port: icatypes.HostPortID, Params: tc.input, } if tc.expPass { From 7ab55133fc67eced710f11cf0620402873f5a2f9 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 14:19:15 +0300 Subject: [PATCH 47/69] imp(ica/host/test): added unset param test to keeper --- .../host/keeper/keeper_test.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 3587d76c4e6..03deda44464 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -3,6 +3,11 @@ package keeper_test import ( "testing" + dbm "github.com/cometbft/cometbft-db" + "github.com/cometbft/cometbft/libs/log" + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/cosmos-sdk/baseapp" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/stretchr/testify/suite" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" @@ -10,6 +15,7 @@ import ( icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" + "github.com/cosmos/ibc-go/v7/testing/simapp" ) var ( @@ -256,3 +262,20 @@ func (suite *KeeperTestSuite) TestParams() { }) } } + +func (suite *KeeperTestSuite) TestUnsetParams() { + // this state should not be possible outside of tests + chainID := "testchain" + header := tmproto.Header{ + ChainID: chainID, + Height: 1, + Time: suite.coordinator.CurrentTime.UTC(), + } + + app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simtestutil.EmptyAppOptions{}, baseapp.SetChainID(chainID)) + ctx := app.GetBaseApp().NewContext(true, header) + + suite.Require().Panics(func() { + suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) + }) +} From d4b70103a1dd47838ce1c56d281aaf35cb351519 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 14:33:02 +0300 Subject: [PATCH 48/69] docs(ica/host): added tracker issue for removing params_legacy.go --- modules/apps/27-interchain-accounts/host/types/params_legacy.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/27-interchain-accounts/host/types/params_legacy.go b/modules/apps/27-interchain-accounts/host/types/params_legacy.go index eef14dfedb5..8e8a95143e8 100644 --- a/modules/apps/27-interchain-accounts/host/types/params_legacy.go +++ b/modules/apps/27-interchain-accounts/host/types/params_legacy.go @@ -2,6 +2,7 @@ NOTE: Usage of x/params to manage parameters is deprecated in favor of x/gov controlled execution of MsgUpdateParams messages. These types remains solely for migration purposes and will be removed in a future release. +[#3621](https://github.com/cosmos/ibc-go/issues/3621) */ package types From c51e2c6ed444631da85ae796f1f430d4b75d407c Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 18:19:24 +0300 Subject: [PATCH 49/69] style(ica/host): improved test case naming --- .../host/types/msgs_test.go | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/types/msgs_test.go b/modules/apps/27-interchain-accounts/host/types/msgs_test.go index 43e8f096ee8..ede00f761ff 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs_test.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs_test.go @@ -17,35 +17,35 @@ func TestMsgUpdateParamsValidateBasic(t *testing.T) { expPass bool }{ { - "invalid authority address", + "success: valid authority address", func() { msg = &types.MsgUpdateParams{ - Authority: "authority", + Authority: sdk.AccAddress("authority").String(), + Params: types.DefaultParams(), } }, - false, + true, }, { - "invalid allowed message", + "failure: invalid authority address", func() { msg = &types.MsgUpdateParams{ - Authority: sdk.AccAddress("authority").String(), - Params: types.Params{ - AllowMessages: []string{""}, - }, + Authority: "authority", } }, false, }, { - "valid test case", + "failure: invalid allowed message", func() { msg = &types.MsgUpdateParams{ Authority: sdk.AccAddress("authority").String(), - Params: types.DefaultParams(), + Params: types.Params{ + AllowMessages: []string{""}, + }, } }, - true, + false, }, } From 5a75a4370a9fcc4109b63159c90ad72d6adf753a Mon Sep 17 00:00:00 2001 From: srdtrk Date: Sat, 20 May 2023 18:35:09 +0300 Subject: [PATCH 50/69] fix(ica/host/test): fixed a minor inaccuracy with the test in the hopes of increasing codecov --- modules/apps/27-interchain-accounts/host/keeper/keeper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 03deda44464..688d556c908 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -276,6 +276,6 @@ func (suite *KeeperTestSuite) TestUnsetParams() { ctx := app.GetBaseApp().NewContext(true, header) suite.Require().Panics(func() { - suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) + app.ICAHostKeeper.GetParams(ctx) }) } From 3d3d8aac7690262307f8d4f1d20ac6dbb324dd21 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:40:06 +0300 Subject: [PATCH 51/69] style(ica/host): updated err message --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index d89b0703e2a..a947d99d133 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -25,7 +25,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { - return nil, errors.Wrapf(ibcerrors.ErrInvalidAuthority, "invalid authority; expected %s, got %s", m.authority, msg.Authority) + return nil, errors.Wrapf(ibcerrors.ErrInvalidAuthority, "expected %s, got %s", m.authority, msg.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) From 289855dcdb05ff5b7ead1b416ee6c28638eb7bfa Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:47:32 +0300 Subject: [PATCH 52/69] imp(ica/transfer, core/errors): removed ErrInvalidAuthority --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 2 +- modules/core/errors/errors.go | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index a947d99d133..812685034e1 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -25,7 +25,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { - return nil, errors.Wrapf(ibcerrors.ErrInvalidAuthority, "expected %s, got %s", m.authority, msg.Authority) + return nil, errors.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", m.authority, msg.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/modules/core/errors/errors.go b/modules/core/errors/errors.go index 762059962fc..79b96856a87 100644 --- a/modules/core/errors/errors.go +++ b/modules/core/errors/errors.go @@ -60,7 +60,4 @@ var ( // ErrNotFound defines an error when requested entity doesn't exist in the state. ErrNotFound = errorsmod.Register(codespace, 16, "not found") - - // ErrInvalidAuthority defines an error when the authority address is invalid. - ErrInvalidAuthority = errorsmod.Register(codespace, 17, "invalid authority") ) From df22e885d4484a96ddfcf0a1cbfd3062eab681b1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:49:49 +0300 Subject: [PATCH 53/69] style(ica/host): updated nil check to be more consistent --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 7e18fec408e..042661dfcfd 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -215,7 +215,7 @@ func (k Keeper) GetAuthority() string { func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) - if bz == nil { + if len(bz) == 0 { panic("ica/host params have not been set") } From 708d5c82b7e87620d140998549e26cb69fd63b46 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:52:30 +0300 Subject: [PATCH 54/69] style(transfer): renamed errors to errorsmod to avoid shadowing --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index 812685034e1..679d03920b0 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -3,7 +3,7 @@ package keeper import ( "context" - "cosmossdk.io/errors" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" @@ -25,7 +25,7 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { // UpdateParams updates the host submodule's params. func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { if m.authority != msg.Authority { - return nil, errors.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", m.authority, msg.Authority) + return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", m.authority, msg.Authority) } ctx := sdk.UnwrapSDKContext(goCtx) From 72bd14d45d2c4822d8232f0cc791daae3a6e1d78 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:55:58 +0300 Subject: [PATCH 55/69] imp(ica/host/test): made test shorter --- .../host/keeper/keeper_test.go | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 688d556c908..7465b42b785 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -3,11 +3,6 @@ package keeper_test import ( "testing" - dbm "github.com/cometbft/cometbft-db" - "github.com/cometbft/cometbft/libs/log" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/baseapp" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" "github.com/stretchr/testify/suite" genesistypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/genesis/types" @@ -15,7 +10,6 @@ import ( icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" ibctesting "github.com/cosmos/ibc-go/v7/testing" - "github.com/cosmos/ibc-go/v7/testing/simapp" ) var ( @@ -264,18 +258,12 @@ func (suite *KeeperTestSuite) TestParams() { } func (suite *KeeperTestSuite) TestUnsetParams() { - // this state should not be possible outside of tests - chainID := "testchain" - header := tmproto.Header{ - ChainID: chainID, - Height: 1, - Time: suite.coordinator.CurrentTime.UTC(), - } - - app := simapp.NewSimApp(log.NewNopLogger(), dbm.NewMemDB(), nil, true, map[int64]bool{}, simapp.DefaultNodeHome, 5, simapp.MakeTestEncodingConfig(), simtestutil.EmptyAppOptions{}, baseapp.SetChainID(chainID)) - ctx := app.GetBaseApp().NewContext(true, header) + suite.SetupTest() // reset + ctx := suite.chainA.GetContext() + store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.SubModuleName)) + store.Delete([]byte(types.ParamsKey)) suite.Require().Panics(func() { - app.ICAHostKeeper.GetParams(ctx) + suite.chainA.GetSimApp().ICAHostKeeper.GetParams(ctx) }) } From 2b0aaae5d74702954b5aa5ca17e2e9681c43ddf1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 14:56:42 +0300 Subject: [PATCH 56/69] imp(ica/host/test): removed unneeded comment --- modules/apps/27-interchain-accounts/host/keeper/keeper_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 7465b42b785..8383856bddb 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -258,7 +258,7 @@ func (suite *KeeperTestSuite) TestParams() { } func (suite *KeeperTestSuite) TestUnsetParams() { - suite.SetupTest() // reset + suite.SetupTest() ctx := suite.chainA.GetContext() store := suite.chainA.GetContext().KVStore(suite.chainA.GetSimApp().GetKey(types.SubModuleName)) store.Delete([]byte(types.ParamsKey)) From d8049023462bb105bc0998aeb7fc72e1f56e42a0 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:00:26 +0300 Subject: [PATCH 57/69] style(ica/host/test): removed test case field names --- .../27-interchain-accounts/host/keeper/keeper_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 8383856bddb..cfaacd4bc5f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -231,11 +231,11 @@ func (suite *KeeperTestSuite) TestParams() { input types.Params expPass bool }{ - {name: "success: set default params", input: types.DefaultParams(), expPass: true}, - {name: "success: non-default params", input: types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, - {name: "success: set empty allowMsg", input: types.NewParams(true, nil), expPass: true}, - {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, - {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, + {"success: set default params", types.DefaultParams(), true}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, + {"success: set empty allowMsg", types.NewParams(true, nil), true}, + {"failure: set empty string", types.NewParams(true, []string{""}), false}, + {"failure: set space string", types.NewParams(true, []string{" "}), false}, } for _, tc := range testCases { From ba74181b767fc213bfe0d214e12ba82d1dcd4528 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:23:24 +0300 Subject: [PATCH 58/69] refactor(ica/host, fee/test): refactored Validate out of SetParams --- .../host/ibc_module_test.go | 15 +++------ .../host/keeper/genesis.go | 3 +- .../host/keeper/keeper.go | 7 +--- .../host/keeper/keeper_test.go | 3 +- .../host/keeper/migrations.go | 7 +++- .../host/keeper/msg_server.go | 3 +- .../host/keeper/relay_test.go | 33 +++++++------------ modules/apps/27-interchain-accounts/module.go | 3 +- modules/apps/29-fee/ica_test.go | 3 +- 9 files changed, 32 insertions(+), 45 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/ibc_module_test.go b/modules/apps/27-interchain-accounts/host/ibc_module_test.go index d1812f773ae..f8737c300a2 100644 --- a/modules/apps/27-interchain-accounts/host/ibc_module_test.go +++ b/modules/apps/27-interchain-accounts/host/ibc_module_test.go @@ -151,8 +151,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenTry() { }, { "host submodule disabled", func() { - err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) }, false, }, { @@ -274,8 +273,7 @@ func (suite *InterchainAccountsTestSuite) TestOnChanOpenConfirm() { }, { "host submodule disabled", func() { - err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) }, false, }, { @@ -401,8 +399,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { }, { "host submodule disabled", func() { - err := suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), types.NewParams(false, []string{})) }, false, }, { @@ -467,8 +464,7 @@ func (suite *InterchainAccountsTestSuite) TestOnRecvPacket() { expectedAck := channeltypes.NewResultAcknowledgement(expectedTxResponse) params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) // malleate packetData for test cases tc.malleate() @@ -665,8 +661,7 @@ func (suite *InterchainAccountsTestSuite) TestControlAccountAfterChannelClose() } params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) //nolint: staticcheck // SA1019: ibctesting.FirstConnectionID is deprecated: use path.EndpointA.ConnectionID instead. (staticcheck) _, err = suite.chainA.GetSimApp().ICAControllerKeeper.SendTx(suite.chainA.GetContext(), nil, ibctesting.FirstConnectionID, path.EndpointA.ChannelConfig.PortID, icaPacketData, ^uint64(0)) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis.go b/modules/apps/27-interchain-accounts/host/keeper/genesis.go index 3fce4693544..eaa4c4462ed 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis.go @@ -27,9 +27,10 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, state genesistypes.HostGenesisS keeper.SetInterchainAccountAddress(ctx, acc.ConnectionId, acc.PortId, acc.AccountAddress) } - if err := keeper.SetParams(ctx, state.Params); err != nil { + if err := state.Params.Validate(); err != nil { panic(fmt.Sprintf("could not set ica host params at genesis: %v", err)) } + keeper.SetParams(ctx, state.Params) } // ExportGenesis returns the interchain accounts host exported genesis diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index 042661dfcfd..fa31d6d97ac 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -225,13 +225,8 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { } // SetParams sets the total set of the host submodule parameters. -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { - if err := params.Validate(); err != nil { - return err - } - +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(¶ms) store.Set([]byte(types.ParamsKey), bz) - return nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index cfaacd4bc5f..1305e540650 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -244,7 +244,8 @@ func (suite *KeeperTestSuite) TestParams() { suite.Run(tc.name, func() { suite.SetupTest() // reset ctx := suite.chainA.GetContext() - err := suite.chainA.GetSimApp().ICAHostKeeper.SetParams(ctx, tc.input) + err := tc.input.Validate() + suite.chainA.GetSimApp().ICAHostKeeper.SetParams(ctx, tc.input) if tc.expPass { suite.Require().NoError(err) expected := tc.input diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index 9608ce37dfb..f21b9c5ac5d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -22,5 +22,10 @@ func (m Migrator) MigrateParams(ctx sdk.Context) error { var params types.Params m.keeper.legacySubspace.GetParamSet(ctx, ¶ms) - return m.keeper.SetParams(ctx, params) + if err := params.Validate(); err != nil { + return err + } + m.keeper.SetParams(ctx, params) + + return nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index 679d03920b0..975f16a0806 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -29,9 +29,10 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam } ctx := sdk.UnwrapSDKContext(goCtx) - if err := m.SetParams(ctx, msg.Params); err != nil { + if err := msg.Params.Validate(); err != nil { return nil, err } + m.SetParams(ctx, msg.Params) return &types.MsgUpdateParamsResponse{}, nil } diff --git a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go index 65b553d0ac9..6e07e58715f 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/relay_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/relay_test.go @@ -67,8 +67,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{"*"}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -95,8 +94,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -124,8 +122,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -159,8 +156,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msgDelegate), sdk.MsgTypeURL(msgUndelegate)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -195,8 +191,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -238,8 +233,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -265,8 +259,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -292,8 +285,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -332,8 +324,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, true, }, @@ -353,8 +344,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{"/" + proto.MessageName(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, false, }, @@ -452,8 +442,7 @@ func (suite *KeeperTestSuite) TestOnRecvPacket() { packetData = icaPacketData.GetBytes() params := types.NewParams(true, []string{sdk.MsgTypeURL(msg)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) }, false, }, diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 356824830ec..6ee3a0fe609 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -116,9 +116,10 @@ func (am AppModule) InitModule(ctx sdk.Context, controllerParams controllertypes } if am.hostKeeper != nil { - if err := am.hostKeeper.SetParams(ctx, hostParams); err != nil { + if err := hostParams.Validate(); err != nil { panic(fmt.Sprintf("could not set ica host params at initialization: %v", err)) } + am.hostKeeper.SetParams(ctx, hostParams) capability := am.hostKeeper.BindPort(ctx, types.HostPortID) if err := am.hostKeeper.ClaimCapability(ctx, capability, ibchost.PortPath(types.HostPortID)); err != nil { diff --git a/modules/apps/29-fee/ica_test.go b/modules/apps/29-fee/ica_test.go index ad3e3370de3..090533cb875 100644 --- a/modules/apps/29-fee/ica_test.go +++ b/modules/apps/29-fee/ica_test.go @@ -153,8 +153,7 @@ func (suite *FeeTestSuite) TestFeeInterchainAccounts() { // ensure chainB is allowed to execute stakingtypes.MsgDelegate params := icahosttypes.NewParams(true, []string{sdk.MsgTypeURL(msgDelegate)}) - err = suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) - suite.Require().NoError(err) + suite.chainB.GetSimApp().ICAHostKeeper.SetParams(suite.chainB.GetContext(), params) // build the interchain accounts packet packet := buildInterchainAccountsPacket(path, icaPacketData.GetBytes(), 1) From c806a23f021579f077eeacdb87770e79a4f5c874 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:27:46 +0300 Subject: [PATCH 59/69] style(ica/host): ran gofumpt --- modules/apps/27-interchain-accounts/host/keeper/migrations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/migrations.go b/modules/apps/27-interchain-accounts/host/keeper/migrations.go index f21b9c5ac5d..c71c3080d1d 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/migrations.go +++ b/modules/apps/27-interchain-accounts/host/keeper/migrations.go @@ -26,6 +26,6 @@ func (m Migrator) MigrateParams(ctx sdk.Context) error { return err } m.keeper.SetParams(ctx, params) - + return nil } From c0f74e095ff63a8d48e808c491e15282758e7dbb Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:50:14 +0300 Subject: [PATCH 60/69] imp(ica/types): switched back to 'bz == nil' --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index fa31d6d97ac..e692481d2fe 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -215,7 +215,7 @@ func (k Keeper) GetAuthority() string { func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) - if len(bz) == 0 { + if bz == nil { panic("ica/host params have not been set") } From e19914f24b8a7bc95bae0afe9e16b73edc535821 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:53:31 +0300 Subject: [PATCH 61/69] style(ica/host/test): looks better --- modules/apps/27-interchain-accounts/host/keeper/genesis_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index 60afdacb626..ee42f6ee471 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -41,7 +41,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() { suite.Require().True(found) suite.Require().Equal(interchainAccAddr.String(), accountAdrr) - expParams := types.NewParams(false, nil) + expParams := genesisState.GetParams() params := suite.chainA.GetSimApp().ICAHostKeeper.GetParams(suite.chainA.GetContext()) suite.Require().Equal(expParams, params) } From 27c90290b9a181583309ffd9ffeca5c6c0795354 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 15:57:12 +0300 Subject: [PATCH 62/69] style(ica/host): changed panic message --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index e692481d2fe..af99a3f59fc 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -216,7 +216,7 @@ func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) if bz == nil { - panic("ica/host params have not been set") + panic("ica/host params are not set in store") } var params types.Params From a0884ca7787df14d722341485b4cd48b840b666b Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 20:22:03 +0300 Subject: [PATCH 63/69] imp(ica/host): removed redundant Validate from msg server, handled in ValidateBasic --- modules/apps/27-interchain-accounts/host/keeper/msg_server.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go index 975f16a0806..388f78c744a 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server.go @@ -29,9 +29,6 @@ func (m msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam } ctx := sdk.UnwrapSDKContext(goCtx) - if err := msg.Params.Validate(); err != nil { - return nil, err - } m.SetParams(ctx, msg.Params) return &types.MsgUpdateParamsResponse{}, nil From 0bc9281546ca1c15f227cf97daaf0201f5716564 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Mon, 22 May 2023 20:34:34 +0300 Subject: [PATCH 64/69] style(ica/host): added code comment --- modules/apps/27-interchain-accounts/host/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper.go b/modules/apps/27-interchain-accounts/host/keeper/keeper.go index af99a3f59fc..c8f806486d6 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper.go @@ -215,7 +215,7 @@ func (k Keeper) GetAuthority() string { func (k Keeper) GetParams(ctx sdk.Context) types.Params { store := ctx.KVStore(k.storeKey) bz := store.Get([]byte(types.ParamsKey)) - if bz == nil { + if bz == nil { // only panic on unset params and not on empty params panic("ica/host params are not set in store") } From ce98d84bc3bf6ea57500263a79a0efde3e5e8107 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 23 May 2023 00:46:35 +0300 Subject: [PATCH 65/69] fix(ica/host): increase consensus version --- modules/apps/27-interchain-accounts/module.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/module.go b/modules/apps/27-interchain-accounts/module.go index 6ee3a0fe609..649ef7959da 100644 --- a/modules/apps/27-interchain-accounts/module.go +++ b/modules/apps/27-interchain-accounts/module.go @@ -151,7 +151,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { hostm := hostkeeper.NewMigrator(am.hostKeeper) if err := cfg.RegisterMigration(types.ModuleName, 2, hostm.MigrateParams); err != nil { - panic(fmt.Sprintf("failed to migrate interchainaccounts host params from version 2 to 3: %v", err)) + panic(fmt.Sprintf("failed to migrate interchainaccounts app from version 2 to 3: %v", err)) } } @@ -193,7 +193,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw } // ConsensusVersion implements AppModule/ConsensusVersion. -func (AppModule) ConsensusVersion() uint64 { return 2 } +func (AppModule) ConsensusVersion() uint64 { return 3 } // BeginBlock implements the AppModule interface func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock) { From e84d975e272b2525bb068e85b5bb64843d72bcb1 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 23 May 2023 00:49:22 +0300 Subject: [PATCH 66/69] style(ica/host/test): moved success case to top --- .../host/keeper/msg_server_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go index 4dc1632a676..9bebd157ef7 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go @@ -14,20 +14,20 @@ func (suite *KeeperTestSuite) TestUpdateParams() { expPass bool }{ { - "invalid authority address", + "success", func(authority string) { - msg.Authority = "authority" + msg.Authority = authority msg.Params = types.DefaultParams() }, - false, + true, }, { - "success", + "invalid authority address", func(authority string) { - msg.Authority = authority + msg.Authority = "authority" msg.Params = types.DefaultParams() }, - true, + false, }, } From 32ebf33251050d2b354cfeeab7c5a99109e96611 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 23 May 2023 00:52:29 +0300 Subject: [PATCH 67/69] style(ica/host/test): improve test styling --- .../27-interchain-accounts/host/keeper/genesis_test.go | 10 +++++----- .../27-interchain-accounts/host/keeper/keeper_test.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go index ee42f6ee471..8e9893be333 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/genesis_test.go @@ -52,11 +52,11 @@ func (suite *KeeperTestSuite) TestGenesisParams() { input types.Params expPass bool }{ - {name: "success: set default params", input: types.DefaultParams(), expPass: true}, - {name: "success: non-default params", input: types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), expPass: true}, - {name: "success: set empty allowMsg", input: types.NewParams(true, nil), expPass: true}, - {name: "failure: set empty string", input: types.NewParams(true, []string{""}), expPass: false}, - {name: "failure: set space string", input: types.NewParams(true, []string{" "}), expPass: false}, + {"success: set default params", types.DefaultParams(), true}, + {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, } for _, tc := range testCases { diff --git a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go index 1305e540650..71854cbbe16 100644 --- a/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go +++ b/modules/apps/27-interchain-accounts/host/keeper/keeper_test.go @@ -233,9 +233,9 @@ func (suite *KeeperTestSuite) TestParams() { }{ {"success: set default params", types.DefaultParams(), true}, {"success: non-default params", types.NewParams(!types.DefaultHostEnabled, []string{"/cosmos.staking.v1beta1.MsgDelegate"}), true}, - {"success: set empty allowMsg", types.NewParams(true, nil), true}, - {"failure: set empty string", types.NewParams(true, []string{""}), false}, - {"failure: set space string", types.NewParams(true, []string{" "}), false}, + {"success: set empty byte for allow messages", types.NewParams(true, nil), true}, + {"failure: set empty string for allow messages", types.NewParams(true, []string{""}), false}, + {"failure: set space string for allow messages", types.NewParams(true, []string{" "}), false}, } for _, tc := range testCases { From 61fee14024206e2d0945bd8c778cc697f954a122 Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 23 May 2023 22:13:36 +0300 Subject: [PATCH 68/69] docs(migration): added changes in app.go --- docs/migrations/v7-to-v8.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/migrations/v7-to-v8.md b/docs/migrations/v7-to-v8.md index fd40f5d27c9..2b8bb459061 100644 --- a/docs/migrations/v7-to-v8.md +++ b/docs/migrations/v7-to-v8.md @@ -16,6 +16,21 @@ There are four sections based on the four potential user groups of this document TODO: https://github.com/cosmos/ibc-go/pull/3505 (extra parameter added to transfer's `GenesisState`) +- You should pass the `authority` to the icahost keeper. ([#3520](https://github.com/cosmos/ibc-go/pull/3520)) See [diff](https://github.com/cosmos/ibc-go/pull/3520/files#diff-d18972debee5e64f16e40807b2ae112ddbe609504a93ea5e1c80a5d489c3a08a). + +```diff +// app.go + + // ICA Host keeper + app.ICAHostKeeper = icahostkeeper.NewKeeper( + appCodec, keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), + app.IBCFeeKeeper, // use ics29 fee as ics4Wrapper in middleware stack + app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, + app.AccountKeeper, scopedICAHostKeeper, app.MsgServiceRouter(), ++ authtypes.NewModuleAddress(govtypes.ModuleName).String(), + ) +``` + ## IBC Apps TODO: https://github.com/cosmos/ibc-go/pull/3303 From 2eb440cfd585522fe88f59ca91f1110f51a5aa0c Mon Sep 17 00:00:00 2001 From: srdtrk Date: Tue, 23 May 2023 22:22:25 +0300 Subject: [PATCH 69/69] imp(ica/host): improved the error message --- modules/apps/27-interchain-accounts/host/types/msgs.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/apps/27-interchain-accounts/host/types/msgs.go b/modules/apps/27-interchain-accounts/host/types/msgs.go index 03d51c8c5ab..67dc6566c19 100644 --- a/modules/apps/27-interchain-accounts/host/types/msgs.go +++ b/modules/apps/27-interchain-accounts/host/types/msgs.go @@ -1,6 +1,11 @@ package types -import sdk "github.com/cosmos/cosmos-sdk/types" +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors" +) var _ sdk.Msg = (*MsgUpdateParams)(nil) @@ -8,7 +13,7 @@ var _ sdk.Msg = (*MsgUpdateParams)(nil) func (msg MsgUpdateParams) ValidateBasic() error { _, err := sdk.AccAddressFromBech32(msg.Authority) if err != nil { - return err + return errorsmod.Wrapf(ibcerrors.ErrInvalidAddress, "string could not be parsed as address: %v", err) } return msg.Params.Validate()