From b8539bcb2be21defd488a2dcf7c91b2d9ebf624e Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Fri, 10 Nov 2023 09:40:56 +0100 Subject: [PATCH 1/8] Added MsgUpdateParams --- .../ccv/provider/v1/query.proto | 13 + .../ccv/provider/v1/tx.proto | 19 + x/ccv/provider/types/query.pb.go | 502 +++++++++++++--- x/ccv/provider/types/query.pb.gw.go | 65 ++ x/ccv/provider/types/tx.pb.go | 566 +++++++++++++++--- 5 files changed, 991 insertions(+), 174 deletions(-) diff --git a/proto/interchain_security/ccv/provider/v1/query.proto b/proto/interchain_security/ccv/provider/v1/query.proto index b0c1dc2b47..772f1f2a9e 100644 --- a/proto/interchain_security/ccv/provider/v1/query.proto +++ b/proto/interchain_security/ccv/provider/v1/query.proto @@ -81,6 +81,10 @@ service Query { option (google.api.http).get = "/interchain_security/ccv/provider/registered_consumer_reward_denoms"; } + + rpc QueryParams(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/interchain_security/ccv/provider/params"; + } } message QueryConsumerGenesisRequest { string chain_id = 1; } @@ -187,3 +191,12 @@ message QueryRegisteredConsumerRewardDenomsRequest {} message QueryRegisteredConsumerRewardDenomsResponse { repeated string denoms = 1; } + +// Request to query values set for provider parameters +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + interchain_security.ccv.provider.v1.Params params = 1 [ (gogoproto.nullable) = false ]; +} diff --git a/proto/interchain_security/ccv/provider/v1/tx.proto b/proto/interchain_security/ccv/provider/v1/tx.proto index 69ccee0a73..4b07c47a0c 100644 --- a/proto/interchain_security/ccv/provider/v1/tx.proto +++ b/proto/interchain_security/ccv/provider/v1/tx.proto @@ -12,6 +12,7 @@ import "gogoproto/gogo.proto"; import "cosmos_proto/cosmos.proto"; import "cosmos/msg/v1/msg.proto"; import "ibc/core/client/v1/client.proto"; +import "interchain_security/ccv/provider/v1/provider.proto"; // Msg defines the Msg service. service Msg { @@ -28,8 +29,26 @@ service Msg { rpc ChangeRewardDenoms(MsgChangeRewardDenoms) returns (MsgChangeRewardDenomsResponse); + + rpc UpdateParams(MsgUpdateParams) + returns (MsgUpdateParamsResponse); } + + +// MsgUpdateParams is the Msg/UpdateParams request type +message MsgUpdateParams { + option (cosmos.msg.v1.signer) = "signer"; + + // signer is the address of the governance account. + string signer = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // params defines the x/provider parameters to update. + Params params = 2 [(gogoproto.nullable) = false]; +} + +message MsgUpdateParamsResponse {} + message MsgAssignConsumerKey { option (gogoproto.equal) = false; option (gogoproto.goproto_getters) = false; diff --git a/x/ccv/provider/types/query.pb.go b/x/ccv/provider/types/query.pb.go index 9fc9178e09..858a529c6e 100644 --- a/x/ccv/provider/types/query.pb.go +++ b/x/ccv/provider/types/query.pb.go @@ -1039,6 +1039,89 @@ func (m *QueryRegisteredConsumerRewardDenomsResponse) GetDenoms() []string { return nil } +// Request to query values set for provider parameters +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_422512d7b7586cd7, []int{21} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.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 *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_422512d7b7586cd7, []int{22} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.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 *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func init() { proto.RegisterType((*QueryConsumerGenesisRequest)(nil), "interchain_security.ccv.provider.v1.QueryConsumerGenesisRequest") proto.RegisterType((*QueryConsumerGenesisResponse)(nil), "interchain_security.ccv.provider.v1.QueryConsumerGenesisResponse") @@ -1061,6 +1144,8 @@ func init() { proto.RegisterType((*ThrottledPacketDataWrapper)(nil), "interchain_security.ccv.provider.v1.ThrottledPacketDataWrapper") proto.RegisterType((*QueryRegisteredConsumerRewardDenomsRequest)(nil), "interchain_security.ccv.provider.v1.QueryRegisteredConsumerRewardDenomsRequest") proto.RegisterType((*QueryRegisteredConsumerRewardDenomsResponse)(nil), "interchain_security.ccv.provider.v1.QueryRegisteredConsumerRewardDenomsResponse") + proto.RegisterType((*QueryParamsRequest)(nil), "interchain_security.ccv.provider.v1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "interchain_security.ccv.provider.v1.QueryParamsResponse") } func init() { @@ -1068,90 +1153,94 @@ func init() { } var fileDescriptor_422512d7b7586cd7 = []byte{ - // 1323 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xcf, 0x6f, 0x1b, 0xc5, - 0x1f, 0xf5, 0x3a, 0x69, 0x9a, 0x4c, 0xfa, 0xfd, 0xb6, 0x4c, 0x4b, 0x71, 0xb7, 0x95, 0x5d, 0xb6, - 0x02, 0xd2, 0x16, 0x76, 0x1b, 0x57, 0x48, 0x6d, 0x21, 0x75, 0xed, 0x24, 0xa4, 0x51, 0x1b, 0x35, - 0xac, 0xab, 0x56, 0x02, 0xd4, 0x65, 0xb2, 0x3b, 0xd8, 0x2b, 0xd6, 0x3b, 0xdb, 0x99, 0xb1, 0xd3, - 0x80, 0x38, 0x00, 0x12, 0xf4, 0x58, 0x09, 0x71, 0xe3, 0xd0, 0x13, 0xff, 0x05, 0xf7, 0xde, 0xa8, - 0xe8, 0xa5, 0xa7, 0x82, 0x12, 0x0e, 0x1c, 0x11, 0x77, 0x24, 0xb4, 0xb3, 0xb3, 0xfe, 0x11, 0x6f, - 0xec, 0xb5, 0x9b, 0x9b, 0x3d, 0x3b, 0x9f, 0xf7, 0x79, 0xef, 0xe9, 0x33, 0xb3, 0x6f, 0x81, 0xe1, - 0xfa, 0x1c, 0x53, 0xbb, 0x8e, 0x5c, 0xdf, 0x62, 0xd8, 0x6e, 0x52, 0x97, 0x6f, 0x19, 0xb6, 0xdd, - 0x32, 0x02, 0x4a, 0x5a, 0xae, 0x83, 0xa9, 0xd1, 0x9a, 0x37, 0xee, 0x37, 0x31, 0xdd, 0xd2, 0x03, - 0x4a, 0x38, 0x81, 0x67, 0x12, 0x0a, 0x74, 0xdb, 0x6e, 0xe9, 0x71, 0x81, 0xde, 0x9a, 0x57, 0x4f, - 0xd5, 0x08, 0xa9, 0x79, 0xd8, 0x40, 0x81, 0x6b, 0x20, 0xdf, 0x27, 0x1c, 0x71, 0x97, 0xf8, 0x2c, - 0x82, 0x50, 0x8f, 0xd5, 0x48, 0x8d, 0x88, 0x9f, 0x46, 0xf8, 0x4b, 0xae, 0x16, 0x64, 0x8d, 0xf8, - 0xb7, 0xd1, 0xfc, 0xcc, 0xe0, 0x6e, 0x03, 0x33, 0x8e, 0x1a, 0x81, 0xdc, 0x50, 0x4c, 0x43, 0xb5, - 0xcd, 0x22, 0xaa, 0xb9, 0xb0, 0x57, 0x4d, 0x6b, 0xde, 0x60, 0x75, 0x44, 0xb1, 0x63, 0xd9, 0xc4, - 0x67, 0xcd, 0x46, 0xbb, 0xe2, 0x8d, 0x01, 0x15, 0x9b, 0x2e, 0xc5, 0xd1, 0x36, 0xed, 0x12, 0x38, - 0xf9, 0x61, 0xe8, 0xca, 0xa2, 0xac, 0x5e, 0xc1, 0x3e, 0x66, 0x2e, 0x33, 0xf1, 0xfd, 0x26, 0x66, - 0x1c, 0x9e, 0x00, 0xd3, 0x11, 0x84, 0xeb, 0xe4, 0x94, 0xd3, 0xca, 0xdc, 0x8c, 0x79, 0x50, 0xfc, - 0x5f, 0x75, 0x34, 0x06, 0x4e, 0x25, 0x57, 0xb2, 0x80, 0xf8, 0x0c, 0xc3, 0x2a, 0xf8, 0x5f, 0x2d, - 0x5a, 0xb2, 0x18, 0x47, 0x1c, 0x8b, 0xfa, 0xd9, 0xe2, 0x9c, 0xbe, 0x97, 0xf1, 0xad, 0x79, 0x5d, - 0x62, 0x54, 0xc3, 0xfd, 0x95, 0xc9, 0x27, 0x2f, 0x0a, 0x19, 0xf3, 0x50, 0xad, 0x6b, 0x4d, 0x3b, - 0x05, 0xd4, 0x9e, 0xa6, 0x8b, 0x21, 0x4c, 0xcc, 0x56, 0x43, 0xbb, 0xc4, 0xc4, 0x4f, 0x25, 0xa3, - 0x0a, 0x98, 0x12, 0x6d, 0x59, 0x4e, 0x39, 0x3d, 0x31, 0x37, 0x5b, 0x3c, 0xa7, 0xa7, 0x98, 0x01, - 0x5d, 0x80, 0x98, 0xb2, 0x52, 0x3b, 0x0b, 0xde, 0xea, 0x6f, 0x51, 0xe5, 0x88, 0xf2, 0x75, 0x4a, - 0x02, 0xc2, 0x90, 0xd7, 0x66, 0xf3, 0x50, 0x01, 0x73, 0xc3, 0xf7, 0x4a, 0x6e, 0x9f, 0x80, 0x99, - 0x20, 0x5e, 0x94, 0x4e, 0x5d, 0x4d, 0x47, 0x4f, 0x82, 0x97, 0x1d, 0xc7, 0x0d, 0x87, 0xb3, 0x03, - 0xdd, 0x01, 0xd4, 0xe6, 0xc0, 0x9b, 0x49, 0x4c, 0x48, 0xd0, 0x47, 0xfa, 0x3b, 0x25, 0x59, 0x60, - 0xcf, 0x56, 0xc9, 0xf9, 0xe3, 0x7e, 0xce, 0x0b, 0x23, 0x71, 0x36, 0x71, 0x83, 0xb4, 0x90, 0x97, - 0x48, 0xb9, 0x04, 0x0e, 0x88, 0xd6, 0x03, 0x46, 0x10, 0x9e, 0x04, 0x33, 0xb6, 0xe7, 0x62, 0x9f, - 0x87, 0xcf, 0xb2, 0xe2, 0xd9, 0x74, 0xb4, 0xb0, 0xea, 0x68, 0xdf, 0x2b, 0xe0, 0x75, 0xa1, 0xe4, - 0x0e, 0xf2, 0x5c, 0x07, 0x71, 0x42, 0xbb, 0xac, 0xa2, 0xc3, 0x07, 0x1c, 0x2e, 0x80, 0x23, 0x31, - 0x69, 0x0b, 0x39, 0x0e, 0xc5, 0x8c, 0x45, 0x4d, 0x2a, 0xf0, 0x9f, 0x17, 0x85, 0xff, 0x6f, 0xa1, - 0x86, 0x77, 0x45, 0x93, 0x0f, 0x34, 0xf3, 0x70, 0xbc, 0xb7, 0x1c, 0xad, 0x5c, 0x99, 0x7e, 0xf8, - 0xb8, 0x90, 0xf9, 0xeb, 0x71, 0x21, 0xa3, 0xdd, 0x02, 0xda, 0x20, 0x22, 0xd2, 0xcd, 0xb3, 0xe0, - 0x48, 0x7c, 0x84, 0xdb, 0xed, 0x22, 0x46, 0x87, 0xed, 0xae, 0xfd, 0x61, 0xb3, 0x7e, 0x69, 0xeb, - 0x5d, 0xcd, 0xd3, 0x49, 0xeb, 0xeb, 0x35, 0x40, 0xda, 0xae, 0xfe, 0x83, 0xa4, 0xf5, 0x12, 0xe9, - 0x48, 0xeb, 0x73, 0x52, 0x4a, 0xdb, 0xe5, 0x9a, 0x76, 0x12, 0x9c, 0x10, 0x80, 0xb7, 0xeb, 0x94, - 0x70, 0xee, 0x61, 0x71, 0xec, 0xe3, 0xe1, 0xfc, 0x39, 0x2b, 0x8f, 0xff, 0xae, 0xa7, 0xb2, 0x4d, - 0x01, 0xcc, 0x32, 0x0f, 0xb1, 0xba, 0xd5, 0xc0, 0x1c, 0x53, 0xd1, 0x61, 0xc2, 0x04, 0x62, 0x69, - 0x2d, 0x5c, 0x81, 0x45, 0xf0, 0x6a, 0xd7, 0x06, 0x0b, 0x79, 0x1e, 0xd9, 0x44, 0xbe, 0x8d, 0x85, - 0xf6, 0x09, 0xf3, 0x68, 0x67, 0x6b, 0x39, 0x7e, 0x04, 0xef, 0x81, 0x9c, 0x8f, 0x1f, 0x70, 0x8b, - 0xe2, 0xc0, 0xc3, 0xbe, 0xcb, 0xea, 0x96, 0x8d, 0x7c, 0x27, 0x14, 0x8b, 0x73, 0x13, 0x62, 0xe6, - 0x55, 0x3d, 0xba, 0xf1, 0xf5, 0xf8, 0xc6, 0xd7, 0x6f, 0xc7, 0x37, 0x7e, 0x65, 0x3a, 0xbc, 0xc3, - 0x1e, 0xfd, 0x5e, 0x50, 0xcc, 0xe3, 0x21, 0x8a, 0x19, 0x83, 0x2c, 0xc6, 0x18, 0xb0, 0x0a, 0x0e, - 0x06, 0xc8, 0xfe, 0x1c, 0x73, 0x96, 0x9b, 0x14, 0xb7, 0xd2, 0xe5, 0x54, 0x47, 0x28, 0x76, 0xc0, - 0xa9, 0x86, 0x9c, 0xd7, 0x05, 0x82, 0x19, 0x23, 0x69, 0x4b, 0xf2, 0x10, 0xb7, 0x77, 0xc5, 0x13, - 0x17, 0x6d, 0x5c, 0x42, 0x1c, 0xa5, 0xb8, 0xe1, 0x7f, 0x8b, 0x2f, 0xb0, 0x81, 0x30, 0xd2, 0xfc, - 0x01, 0xd3, 0x06, 0xc1, 0x24, 0x73, 0xbf, 0x88, 0x5c, 0x9e, 0x34, 0xc5, 0x6f, 0xb8, 0x09, 0x8e, - 0x06, 0x6d, 0x90, 0x55, 0x9f, 0xf1, 0xd0, 0x6c, 0x96, 0x9b, 0x10, 0x16, 0x94, 0x46, 0xb3, 0xa0, - 0xc3, 0xe6, 0x2e, 0x45, 0x41, 0x80, 0xa9, 0x7c, 0x75, 0x24, 0x75, 0xd0, 0x7e, 0x51, 0xc0, 0xb1, - 0x24, 0xf3, 0xe0, 0x3d, 0x70, 0xa8, 0xe6, 0x91, 0x0d, 0xe4, 0x59, 0xd8, 0xe7, 0x74, 0x4b, 0x5e, - 0x68, 0xef, 0xa6, 0xa2, 0xb2, 0x22, 0x0a, 0x05, 0xda, 0x72, 0x58, 0x2c, 0x09, 0xcc, 0x46, 0x80, - 0x62, 0x09, 0x2e, 0x83, 0x49, 0x07, 0x71, 0x24, 0x5c, 0x98, 0x2d, 0x9e, 0x1f, 0xf4, 0x1a, 0xec, - 0xa2, 0x15, 0x92, 0x97, 0x68, 0xa2, 0x5c, 0x7b, 0xae, 0x00, 0x75, 0x6f, 0xe5, 0x70, 0x1d, 0x1c, - 0x8a, 0x46, 0x3c, 0xd2, 0x2e, 0x55, 0x8c, 0xd2, 0xed, 0x7a, 0xc6, 0x8c, 0x8e, 0x91, 0xf4, 0xe5, - 0x53, 0x00, 0x5b, 0xcc, 0xb6, 0x1a, 0x88, 0x37, 0xc3, 0x98, 0x21, 0x71, 0x23, 0x15, 0x17, 0x06, - 0xe1, 0xde, 0xa9, 0x2e, 0xae, 0x45, 0x45, 0x3d, 0xe0, 0x47, 0x5a, 0xcc, 0xee, 0x59, 0xaf, 0x4c, - 0x45, 0xce, 0x68, 0x6f, 0x83, 0x73, 0x62, 0xdc, 0x4c, 0x5c, 0x73, 0x19, 0xc7, 0xb4, 0x33, 0x6f, - 0x26, 0xde, 0x44, 0xd4, 0x59, 0xc2, 0x3e, 0x69, 0xb4, 0xdf, 0x54, 0xcb, 0xe0, 0x7c, 0xaa, 0xdd, - 0x72, 0x3e, 0x8f, 0x83, 0x29, 0x47, 0xac, 0x88, 0x97, 0xff, 0x8c, 0x29, 0xff, 0x15, 0x7f, 0x7a, - 0x05, 0x1c, 0x10, 0x38, 0x70, 0x5b, 0x01, 0xc7, 0x92, 0x12, 0x0d, 0xbc, 0x96, 0x6a, 0x06, 0x06, - 0xc4, 0x28, 0xb5, 0xfc, 0x12, 0x08, 0x11, 0x7f, 0x6d, 0xf9, 0x9b, 0x67, 0x7f, 0xfe, 0x90, 0x2d, - 0xc1, 0x85, 0xe1, 0x49, 0xb7, 0x7d, 0xb5, 0xcb, 0xe8, 0x64, 0x7c, 0x19, 0x9f, 0xcc, 0xaf, 0xe0, - 0x33, 0x05, 0x1c, 0x4d, 0xc8, 0x48, 0xb0, 0x34, 0x3a, 0xc3, 0x9e, 0xec, 0xa5, 0x5e, 0x1b, 0x1f, - 0x40, 0x2a, 0xbc, 0x2c, 0x14, 0x5e, 0x84, 0xf3, 0x23, 0x28, 0x8c, 0x52, 0x19, 0xfc, 0x3a, 0x0b, - 0x72, 0x7b, 0x44, 0x2d, 0x06, 0x6f, 0x8e, 0xc9, 0x2c, 0x31, 0xd5, 0xa9, 0x6b, 0xfb, 0x84, 0x26, - 0x45, 0x5f, 0x17, 0xa2, 0x2b, 0xf0, 0xda, 0xa8, 0xa2, 0xc3, 0x50, 0x4d, 0xb9, 0xd5, 0x0e, 0x4c, - 0xf0, 0x5f, 0x05, 0xbc, 0x96, 0x9c, 0xdc, 0x18, 0xbc, 0x31, 0x36, 0xe9, 0xfe, 0x88, 0xa8, 0xde, - 0xdc, 0x1f, 0x30, 0x69, 0xc0, 0x8a, 0x30, 0xa0, 0x0c, 0x4b, 0x63, 0x18, 0x40, 0x82, 0x2e, 0xfd, - 0x7f, 0x2b, 0x32, 0x1c, 0x24, 0xc6, 0x2c, 0xf8, 0x41, 0x7a, 0xd6, 0x83, 0x02, 0xa3, 0xba, 0xf2, - 0xd2, 0x38, 0x52, 0x78, 0x59, 0x08, 0x7f, 0x0f, 0x5e, 0x4e, 0xf1, 0xe9, 0x1a, 0x03, 0x59, 0x3d, - 0xa9, 0x2d, 0x41, 0x72, 0x77, 0xfc, 0x1a, 0x4b, 0x72, 0x42, 0x90, 0x1c, 0x4b, 0x72, 0x52, 0x0e, - 0x1c, 0x4f, 0x72, 0x4f, 0x72, 0x84, 0xbf, 0x2a, 0x00, 0xf6, 0x47, 0x40, 0x78, 0x35, 0x3d, 0xc5, - 0xa4, 0x64, 0xa9, 0x96, 0xc6, 0xae, 0x97, 0xd2, 0x2e, 0x09, 0x69, 0x45, 0x78, 0x61, 0xb8, 0x34, - 0x2e, 0x01, 0xa2, 0xcf, 0x62, 0xf8, 0x6d, 0x16, 0x9c, 0x1e, 0x96, 0xb2, 0x46, 0xb9, 0xc3, 0x86, - 0x67, 0xbe, 0x51, 0xee, 0xb0, 0x14, 0xd1, 0x4f, 0xab, 0x08, 0xed, 0xef, 0xc3, 0x2b, 0xc3, 0xb5, - 0x07, 0xd8, 0x77, 0x5c, 0xbf, 0xd6, 0x99, 0x63, 0x99, 0x58, 0xe1, 0x8f, 0x59, 0x70, 0x26, 0xc5, - 0xeb, 0x1c, 0xde, 0x4a, 0x4f, 0x3d, 0x55, 0x8c, 0x50, 0xd7, 0xf7, 0x0f, 0x50, 0xda, 0x71, 0x43, - 0xd8, 0xb1, 0x0c, 0x17, 0x87, 0xdb, 0x41, 0xdb, 0x88, 0x1d, 0x47, 0xa8, 0xc0, 0xb4, 0xa2, 0x78, - 0x52, 0xb9, 0xfb, 0x64, 0x3b, 0xaf, 0x3c, 0xdd, 0xce, 0x2b, 0x7f, 0x6c, 0xe7, 0x95, 0x47, 0x3b, - 0xf9, 0xcc, 0xd3, 0x9d, 0x7c, 0xe6, 0xf9, 0x4e, 0x3e, 0xf3, 0xd1, 0x42, 0xcd, 0xe5, 0xf5, 0xe6, - 0x86, 0x6e, 0x93, 0x86, 0x61, 0x13, 0xd6, 0x20, 0xac, 0xab, 0xdf, 0x3b, 0xed, 0x7e, 0xad, 0x8b, - 0xc6, 0x83, 0x5d, 0xf3, 0xb7, 0x15, 0x60, 0xb6, 0x31, 0x25, 0xbe, 0x56, 0x2e, 0xfe, 0x17, 0x00, - 0x00, 0xff, 0xff, 0x84, 0xab, 0xda, 0x7b, 0x39, 0x13, 0x00, 0x00, + // 1384 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x57, 0xc1, 0x6f, 0x13, 0xc7, + 0x1b, 0xf5, 0x26, 0x21, 0x24, 0x13, 0x7e, 0x3f, 0xd0, 0x90, 0x52, 0xb3, 0xa0, 0x98, 0x2e, 0x6a, + 0x1b, 0xa0, 0xdd, 0x4d, 0x8c, 0xaa, 0x02, 0x6d, 0x08, 0x71, 0x48, 0x43, 0x04, 0x88, 0x74, 0x83, + 0x40, 0x6a, 0x2b, 0x96, 0xc9, 0xee, 0xd4, 0x59, 0x75, 0xbd, 0xb3, 0xcc, 0x8c, 0x1d, 0xd2, 0xaa, + 0x87, 0xb6, 0x52, 0xcb, 0x11, 0xa9, 0xea, 0x9d, 0x53, 0xff, 0x80, 0xde, 0x7b, 0xe7, 0x56, 0x5a, + 0x2e, 0x9c, 0x68, 0x15, 0x7a, 0xe8, 0xb1, 0xea, 0xbd, 0x52, 0xb5, 0x33, 0xb3, 0xb6, 0x37, 0xde, + 0xd8, 0x6b, 0x93, 0x9b, 0x3d, 0x3b, 0xdf, 0xfb, 0xde, 0x7b, 0xfe, 0x66, 0xf6, 0x19, 0x58, 0x7e, + 0xc8, 0x31, 0x75, 0x37, 0x90, 0x1f, 0x3a, 0x0c, 0xbb, 0x75, 0xea, 0xf3, 0x2d, 0xcb, 0x75, 0x1b, + 0x56, 0x44, 0x49, 0xc3, 0xf7, 0x30, 0xb5, 0x1a, 0xb3, 0xd6, 0xbd, 0x3a, 0xa6, 0x5b, 0x66, 0x44, + 0x09, 0x27, 0xf0, 0x64, 0x46, 0x81, 0xe9, 0xba, 0x0d, 0x33, 0x29, 0x30, 0x1b, 0xb3, 0xfa, 0xf1, + 0x2a, 0x21, 0xd5, 0x00, 0x5b, 0x28, 0xf2, 0x2d, 0x14, 0x86, 0x84, 0x23, 0xee, 0x93, 0x90, 0x49, + 0x08, 0x7d, 0xb2, 0x4a, 0xaa, 0x44, 0x7c, 0xb4, 0xe2, 0x4f, 0x6a, 0xb5, 0xa4, 0x6a, 0xc4, 0xb7, + 0xf5, 0xfa, 0xa7, 0x16, 0xf7, 0x6b, 0x98, 0x71, 0x54, 0x8b, 0xd4, 0x86, 0x72, 0x1e, 0xaa, 0x4d, + 0x16, 0xb2, 0x66, 0x66, 0xb7, 0x9a, 0xc6, 0xac, 0xc5, 0x36, 0x10, 0xc5, 0x9e, 0xe3, 0x92, 0x90, + 0xd5, 0x6b, 0xcd, 0x8a, 0xd7, 0xbb, 0x54, 0x6c, 0xfa, 0x14, 0xcb, 0x6d, 0xc6, 0x39, 0x70, 0xec, + 0xc3, 0xd8, 0x95, 0x45, 0x55, 0xbd, 0x8c, 0x43, 0xcc, 0x7c, 0x66, 0xe3, 0x7b, 0x75, 0xcc, 0x38, + 0x3c, 0x0a, 0xc6, 0x24, 0x84, 0xef, 0x15, 0xb5, 0x13, 0xda, 0xf4, 0xb8, 0xbd, 0x5f, 0x7c, 0x5f, + 0xf1, 0x0c, 0x06, 0x8e, 0x67, 0x57, 0xb2, 0x88, 0x84, 0x0c, 0xc3, 0x35, 0xf0, 0xbf, 0xaa, 0x5c, + 0x72, 0x18, 0x47, 0x1c, 0x8b, 0xfa, 0x89, 0xf2, 0xb4, 0xb9, 0x9b, 0xf1, 0x8d, 0x59, 0x53, 0x61, + 0xac, 0xc5, 0xfb, 0x2b, 0x23, 0x8f, 0x9f, 0x97, 0x0a, 0xf6, 0x81, 0x6a, 0xdb, 0x9a, 0x71, 0x1c, + 0xe8, 0xa9, 0xa6, 0x8b, 0x31, 0x4c, 0xc2, 0xd6, 0x40, 0x3b, 0xc4, 0x24, 0x4f, 0x15, 0xa3, 0x0a, + 0x18, 0x15, 0x6d, 0x59, 0x51, 0x3b, 0x31, 0x3c, 0x3d, 0x51, 0x3e, 0x6d, 0xe6, 0x98, 0x01, 0x53, + 0x80, 0xd8, 0xaa, 0xd2, 0x38, 0x05, 0xde, 0xec, 0x6c, 0xb1, 0xc6, 0x11, 0xe5, 0xab, 0x94, 0x44, + 0x84, 0xa1, 0xa0, 0xc9, 0xe6, 0x81, 0x06, 0xa6, 0x7b, 0xef, 0x55, 0xdc, 0x3e, 0x01, 0xe3, 0x51, + 0xb2, 0xa8, 0x9c, 0xba, 0x98, 0x8f, 0x9e, 0x02, 0x5f, 0xf0, 0x3c, 0x3f, 0x1e, 0xce, 0x16, 0x74, + 0x0b, 0xd0, 0x98, 0x06, 0x6f, 0x64, 0x31, 0x21, 0x51, 0x07, 0xe9, 0x6f, 0xb5, 0x6c, 0x81, 0xa9, + 0xad, 0x8a, 0xf3, 0xc7, 0x9d, 0x9c, 0xe7, 0xfa, 0xe2, 0x6c, 0xe3, 0x1a, 0x69, 0xa0, 0x20, 0x93, + 0xf2, 0x3c, 0xd8, 0x27, 0x5a, 0x77, 0x19, 0x41, 0x78, 0x0c, 0x8c, 0xbb, 0x81, 0x8f, 0x43, 0x1e, + 0x3f, 0x1b, 0x12, 0xcf, 0xc6, 0xe4, 0xc2, 0x8a, 0x67, 0x7c, 0xa7, 0x81, 0xd7, 0x84, 0x92, 0x5b, + 0x28, 0xf0, 0x3d, 0xc4, 0x09, 0x6d, 0xb3, 0x8a, 0xf6, 0x1e, 0x70, 0x38, 0x07, 0x0e, 0x25, 0xa4, + 0x1d, 0xe4, 0x79, 0x14, 0x33, 0x26, 0x9b, 0x54, 0xe0, 0x3f, 0xcf, 0x4b, 0xff, 0xdf, 0x42, 0xb5, + 0xe0, 0x82, 0xa1, 0x1e, 0x18, 0xf6, 0xc1, 0x64, 0xef, 0x82, 0x5c, 0xb9, 0x30, 0xf6, 0xe0, 0x51, + 0xa9, 0xf0, 0xd7, 0xa3, 0x52, 0xc1, 0xb8, 0x01, 0x8c, 0x6e, 0x44, 0x94, 0x9b, 0xa7, 0xc0, 0xa1, + 0xe4, 0x08, 0x37, 0xdb, 0x49, 0x46, 0x07, 0xdd, 0xb6, 0xfd, 0x71, 0xb3, 0x4e, 0x69, 0xab, 0x6d, + 0xcd, 0xf3, 0x49, 0xeb, 0xe8, 0xd5, 0x45, 0xda, 0x8e, 0xfe, 0xdd, 0xa4, 0xa5, 0x89, 0xb4, 0xa4, + 0x75, 0x38, 0xa9, 0xa4, 0xed, 0x70, 0xcd, 0x38, 0x06, 0x8e, 0x0a, 0xc0, 0x9b, 0x1b, 0x94, 0x70, + 0x1e, 0x60, 0x71, 0xec, 0x93, 0xe1, 0xfc, 0x71, 0x48, 0x1d, 0xff, 0x1d, 0x4f, 0x55, 0x9b, 0x12, + 0x98, 0x60, 0x01, 0x62, 0x1b, 0x4e, 0x0d, 0x73, 0x4c, 0x45, 0x87, 0x61, 0x1b, 0x88, 0xa5, 0xeb, + 0xf1, 0x0a, 0x2c, 0x83, 0x57, 0xda, 0x36, 0x38, 0x28, 0x08, 0xc8, 0x26, 0x0a, 0x5d, 0x2c, 0xb4, + 0x0f, 0xdb, 0x87, 0x5b, 0x5b, 0x17, 0x92, 0x47, 0xf0, 0x0e, 0x28, 0x86, 0xf8, 0x3e, 0x77, 0x28, + 0x8e, 0x02, 0x1c, 0xfa, 0x6c, 0xc3, 0x71, 0x51, 0xe8, 0xc5, 0x62, 0x71, 0x71, 0x58, 0xcc, 0xbc, + 0x6e, 0xca, 0x1b, 0xdf, 0x4c, 0x6e, 0x7c, 0xf3, 0x66, 0x72, 0xe3, 0x57, 0xc6, 0xe2, 0x3b, 0xec, + 0xe1, 0xef, 0x25, 0xcd, 0x3e, 0x12, 0xa3, 0xd8, 0x09, 0xc8, 0x62, 0x82, 0x01, 0xd7, 0xc0, 0xfe, + 0x08, 0xb9, 0x9f, 0x61, 0xce, 0x8a, 0x23, 0xe2, 0x56, 0x3a, 0x9f, 0xeb, 0x08, 0x25, 0x0e, 0x78, + 0x6b, 0x31, 0xe7, 0x55, 0x81, 0x60, 0x27, 0x48, 0xc6, 0x65, 0x75, 0x88, 0x9b, 0xbb, 0x92, 0x89, + 0x93, 0x1b, 0x2f, 0x23, 0x8e, 0x72, 0xdc, 0xf0, 0xbf, 0x25, 0x17, 0x58, 0x57, 0x18, 0x65, 0x7e, + 0x97, 0x69, 0x83, 0x60, 0x84, 0xf9, 0x9f, 0x4b, 0x97, 0x47, 0x6c, 0xf1, 0x19, 0x6e, 0x82, 0xc3, + 0x51, 0x13, 0x64, 0x25, 0x64, 0x3c, 0x36, 0x9b, 0x15, 0x87, 0x85, 0x05, 0xf3, 0xfd, 0x59, 0xd0, + 0x62, 0x73, 0x9b, 0xa2, 0x28, 0xc2, 0x54, 0xbd, 0x3a, 0xb2, 0x3a, 0x18, 0x3f, 0x6b, 0x60, 0x32, + 0xcb, 0x3c, 0x78, 0x07, 0x1c, 0xa8, 0x06, 0x64, 0x1d, 0x05, 0x0e, 0x0e, 0x39, 0xdd, 0x52, 0x17, + 0xda, 0x3b, 0xb9, 0xa8, 0x2c, 0x8b, 0x42, 0x81, 0xb6, 0x14, 0x17, 0x2b, 0x02, 0x13, 0x12, 0x50, + 0x2c, 0xc1, 0x25, 0x30, 0xe2, 0x21, 0x8e, 0x84, 0x0b, 0x13, 0xe5, 0x33, 0xdd, 0x5e, 0x83, 0x6d, + 0xb4, 0x62, 0xf2, 0x0a, 0x4d, 0x94, 0x1b, 0xcf, 0x34, 0xa0, 0xef, 0xae, 0x1c, 0xae, 0x82, 0x03, + 0x72, 0xc4, 0xa5, 0x76, 0xa5, 0xa2, 0x9f, 0x6e, 0x57, 0x0a, 0xb6, 0x3c, 0x46, 0xca, 0x97, 0xbb, + 0x00, 0x36, 0x98, 0xeb, 0xd4, 0x10, 0xaf, 0xc7, 0x31, 0x43, 0xe1, 0x4a, 0x15, 0x33, 0xdd, 0x70, + 0x6f, 0xad, 0x2d, 0x5e, 0x97, 0x45, 0x29, 0xf0, 0x43, 0x0d, 0xe6, 0xa6, 0xd6, 0x2b, 0xa3, 0xd2, + 0x19, 0xe3, 0x2d, 0x70, 0x5a, 0x8c, 0x9b, 0x8d, 0xab, 0x3e, 0xe3, 0x98, 0xb6, 0xe6, 0xcd, 0xc6, + 0x9b, 0x88, 0x7a, 0x97, 0x71, 0x48, 0x6a, 0xcd, 0x37, 0xd5, 0x12, 0x38, 0x93, 0x6b, 0xb7, 0x9a, + 0xcf, 0x23, 0x60, 0xd4, 0x13, 0x2b, 0xe2, 0xe5, 0x3f, 0x6e, 0xab, 0x6f, 0xc6, 0x24, 0x80, 0x02, + 0x66, 0x15, 0x51, 0xd4, 0x02, 0xbf, 0x0b, 0x0e, 0xa7, 0x56, 0x15, 0xc8, 0x0a, 0x18, 0x8d, 0xc4, + 0x4a, 0x4f, 0x5f, 0xdb, 0xa7, 0x43, 0x82, 0xa8, 0x5f, 0x51, 0x01, 0x94, 0x7f, 0x85, 0x60, 0x9f, + 0x68, 0x01, 0xb7, 0x35, 0x30, 0x99, 0x95, 0xa4, 0xe0, 0xa5, 0x5c, 0xe8, 0x5d, 0xe2, 0x9b, 0xbe, + 0xf0, 0x12, 0x08, 0x52, 0xb2, 0xb1, 0xf4, 0xf5, 0xd3, 0x3f, 0xbf, 0x1f, 0x9a, 0x87, 0x73, 0xbd, + 0x13, 0x76, 0xf3, 0x95, 0xa2, 0x22, 0x9b, 0xf5, 0x45, 0x72, 0x23, 0x7c, 0x09, 0x9f, 0x6a, 0xca, + 0xd1, 0x74, 0x36, 0x83, 0xf3, 0xfd, 0x33, 0x4c, 0x65, 0x3e, 0xfd, 0xd2, 0xe0, 0x00, 0x4a, 0xe1, + 0x79, 0xa1, 0xf0, 0x2c, 0x9c, 0xed, 0x43, 0xa1, 0x4c, 0x83, 0xf0, 0xab, 0x21, 0x50, 0xdc, 0x25, + 0xe2, 0x31, 0x78, 0x6d, 0x40, 0x66, 0x99, 0x69, 0x52, 0xbf, 0xbe, 0x47, 0x68, 0x4a, 0xf4, 0x15, + 0x21, 0xba, 0x02, 0x2f, 0xf5, 0x2b, 0x3a, 0x0e, 0xf3, 0x94, 0x3b, 0xcd, 0xa0, 0x06, 0xff, 0xd5, + 0xc0, 0xab, 0xd9, 0x89, 0x91, 0xc1, 0xab, 0x03, 0x93, 0xee, 0x8c, 0xa6, 0xfa, 0xb5, 0xbd, 0x01, + 0x53, 0x06, 0x2c, 0x0b, 0x03, 0x16, 0xe0, 0xfc, 0x00, 0x06, 0x90, 0xa8, 0x4d, 0xff, 0xdf, 0x9a, + 0x0a, 0x25, 0x99, 0xf1, 0x0e, 0x7e, 0x90, 0x9f, 0x75, 0xb7, 0xa0, 0xaa, 0x2f, 0xbf, 0x34, 0x8e, + 0x12, 0xbe, 0x20, 0x84, 0xbf, 0x07, 0xcf, 0xe7, 0xf8, 0xcb, 0x9c, 0x00, 0x39, 0xa9, 0xb4, 0x98, + 0x21, 0xb9, 0x3d, 0xf6, 0x0d, 0x24, 0x39, 0x23, 0xc0, 0x0e, 0x24, 0x39, 0x2b, 0x7f, 0x0e, 0x26, + 0x39, 0x95, 0x58, 0xe1, 0x2f, 0x9a, 0x7a, 0x4f, 0xa4, 0xa2, 0x27, 0xbc, 0x98, 0x9f, 0x62, 0x56, + 0xa2, 0xd5, 0xe7, 0x07, 0xae, 0x57, 0xd2, 0xce, 0x09, 0x69, 0x65, 0x38, 0xd3, 0x5b, 0x1a, 0x57, + 0x00, 0xf2, 0xef, 0x38, 0xfc, 0x66, 0x08, 0x9c, 0xe8, 0x95, 0xee, 0xfa, 0xb9, 0xc3, 0x7a, 0x67, + 0xcd, 0x7e, 0xee, 0xb0, 0x1c, 0x91, 0xd3, 0xa8, 0x08, 0xed, 0xef, 0xc3, 0x0b, 0xbd, 0xb5, 0x47, + 0x38, 0xf4, 0xfc, 0xb0, 0xda, 0x9a, 0x63, 0x95, 0x94, 0xe1, 0x0f, 0x43, 0xe0, 0x64, 0x8e, 0x18, + 0x01, 0x6f, 0xe4, 0xa7, 0x9e, 0x2b, 0xbe, 0xe8, 0xab, 0x7b, 0x07, 0xa8, 0xec, 0xb8, 0x2a, 0xec, + 0x58, 0x82, 0x8b, 0xbd, 0xed, 0xa0, 0x4d, 0xc4, 0x96, 0x23, 0x54, 0x60, 0x3a, 0x32, 0x16, 0xc1, + 0x9f, 0x34, 0x30, 0xd1, 0x96, 0x80, 0xe0, 0xbb, 0xf9, 0xe9, 0xa6, 0x92, 0x94, 0x7e, 0xae, 0xff, + 0x42, 0xa5, 0x67, 0x46, 0xe8, 0x39, 0x0d, 0xa7, 0x73, 0xfc, 0xbc, 0x32, 0x61, 0xdd, 0x7e, 0xbc, + 0x3d, 0xa5, 0x3d, 0xd9, 0x9e, 0xd2, 0xfe, 0xd8, 0x9e, 0xd2, 0x1e, 0xbe, 0x98, 0x2a, 0x3c, 0x79, + 0x31, 0x55, 0x78, 0xf6, 0x62, 0xaa, 0xf0, 0xd1, 0x5c, 0xd5, 0xe7, 0x1b, 0xf5, 0x75, 0xd3, 0x25, + 0x35, 0xcb, 0x25, 0xac, 0x46, 0x58, 0x1b, 0xe8, 0xdb, 0x4d, 0xd0, 0xc6, 0x59, 0xeb, 0xfe, 0x8e, + 0x43, 0xb3, 0x15, 0x61, 0xb6, 0x3e, 0x2a, 0xfe, 0xda, 0x9d, 0xfd, 0x2f, 0x00, 0x00, 0xff, 0xff, + 0x0d, 0xfa, 0x6f, 0xc1, 0x66, 0x14, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1191,6 +1280,7 @@ type QueryClient interface { // QueryRegisteredConsumerRewardDenoms returns a list of consumer reward // denoms that are registered QueryRegisteredConsumerRewardDenoms(ctx context.Context, in *QueryRegisteredConsumerRewardDenomsRequest, opts ...grpc.CallOption) (*QueryRegisteredConsumerRewardDenomsResponse, error) + QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -1282,6 +1372,15 @@ func (c *queryClient) QueryRegisteredConsumerRewardDenoms(ctx context.Context, i return out, nil } +func (c *queryClient) QueryParams(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/interchain_security.ccv.provider.v1.Query/QueryParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // ConsumerGenesis queries the genesis state needed to start a consumer chain @@ -1309,6 +1408,7 @@ type QueryServer interface { // QueryRegisteredConsumerRewardDenoms returns a list of consumer reward // denoms that are registered QueryRegisteredConsumerRewardDenoms(context.Context, *QueryRegisteredConsumerRewardDenomsRequest) (*QueryRegisteredConsumerRewardDenomsResponse, error) + QueryParams(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -1342,6 +1442,9 @@ func (*UnimplementedQueryServer) QueryThrottledConsumerPacketData(ctx context.Co func (*UnimplementedQueryServer) QueryRegisteredConsumerRewardDenoms(ctx context.Context, req *QueryRegisteredConsumerRewardDenomsRequest) (*QueryRegisteredConsumerRewardDenomsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method QueryRegisteredConsumerRewardDenoms not implemented") } +func (*UnimplementedQueryServer) QueryParams(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method QueryParams not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -1509,6 +1612,24 @@ func _Query_QueryRegisteredConsumerRewardDenoms_Handler(srv interface{}, ctx con return interceptor(ctx, in, info, handler) } +func _Query_QueryParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).QueryParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/interchain_security.ccv.provider.v1.Query/QueryParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).QueryParams(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "interchain_security.ccv.provider.v1.Query", HandlerType: (*QueryServer)(nil), @@ -1549,6 +1670,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "QueryRegisteredConsumerRewardDenoms", Handler: _Query_QueryRegisteredConsumerRewardDenoms_Handler, }, + { + MethodName: "QueryParams", + Handler: _Query_QueryParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "interchain_security/ccv/provider/v1/query.proto", @@ -2293,6 +2418,62 @@ func (m *QueryRegisteredConsumerRewardDenomsResponse) MarshalToSizedBuffer(dAtA return len(dAtA) - i, nil } +func (m *QueryParamsRequest) 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 *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) 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 *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) 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 = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { offset -= sovQuery(v) base := offset @@ -2613,6 +2794,26 @@ func (m *QueryRegisteredConsumerRewardDenomsResponse) Size() (n int) { return n } +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -4486,6 +4687,139 @@ func (m *QueryRegisteredConsumerRewardDenomsResponse) Unmarshal(dAtA []byte) err } return nil } +func (m *QueryParamsRequest) 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 ErrIntOverflowQuery + } + 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: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) 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 ErrIntOverflowQuery + } + 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: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + 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 ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + 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 := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipQuery(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/ccv/provider/types/query.pb.gw.go b/x/ccv/provider/types/query.pb.gw.go index 6a249ca2a2..86eecb97a2 100644 --- a/x/ccv/provider/types/query.pb.gw.go +++ b/x/ccv/provider/types/query.pb.gw.go @@ -285,6 +285,24 @@ func local_request_Query_QueryRegisteredConsumerRewardDenoms_0(ctx context.Conte } +func request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.QueryParams(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_QueryParams_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.QueryParams(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterQueryHandlerServer registers the http handlers for service Query to "mux". // UnaryRPC :call QueryServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -498,6 +516,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_QueryParams_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -719,6 +760,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_QueryParams_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_QueryParams_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_QueryParams_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -740,6 +801,8 @@ var ( pattern_Query_QueryThrottledConsumerPacketData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "pending_consumer_packets"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_QueryRegisteredConsumerRewardDenoms_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "registered_consumer_reward_denoms"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_QueryParams_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"interchain_security", "ccv", "provider", "params"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -760,4 +823,6 @@ var ( forward_Query_QueryThrottledConsumerPacketData_0 = runtime.ForwardResponseMessage forward_Query_QueryRegisteredConsumerRewardDenoms_0 = runtime.ForwardResponseMessage + + forward_Query_QueryParams_0 = runtime.ForwardResponseMessage ) diff --git a/x/ccv/provider/types/tx.pb.go b/x/ccv/provider/types/tx.pb.go index 168401053f..186c0ec7ca 100644 --- a/x/ccv/provider/types/tx.pb.go +++ b/x/ccv/provider/types/tx.pb.go @@ -39,6 +39,97 @@ var _ = time.Kitchen // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// MsgUpdateParams is the Msg/UpdateParams request type +type MsgUpdateParams struct { + // signer is the address of the governance account. + Signer string `protobuf:"bytes,1,opt,name=signer,proto3" json:"signer,omitempty"` + // params defines the x/provider parameters to update. + 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_43221a4391e9fbf4, []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) GetSigner() string { + if m != nil { + return m.Signer + } + return "" +} + +func (m *MsgUpdateParams) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +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_43221a4391e9fbf4, []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 + type MsgAssignConsumerKey struct { // The chain id of the consumer chain to assign a consensus public key to ChainId string `protobuf:"bytes,1,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` @@ -56,7 +147,7 @@ func (m *MsgAssignConsumerKey) Reset() { *m = MsgAssignConsumerKey{} } func (m *MsgAssignConsumerKey) String() string { return proto.CompactTextString(m) } func (*MsgAssignConsumerKey) ProtoMessage() {} func (*MsgAssignConsumerKey) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{0} + return fileDescriptor_43221a4391e9fbf4, []int{2} } func (m *MsgAssignConsumerKey) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -92,7 +183,7 @@ func (m *MsgAssignConsumerKeyResponse) Reset() { *m = MsgAssignConsumerK func (m *MsgAssignConsumerKeyResponse) String() string { return proto.CompactTextString(m) } func (*MsgAssignConsumerKeyResponse) ProtoMessage() {} func (*MsgAssignConsumerKeyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{1} + return fileDescriptor_43221a4391e9fbf4, []int{3} } func (m *MsgAssignConsumerKeyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -182,7 +273,7 @@ func (m *MsgConsumerAddition) Reset() { *m = MsgConsumerAddition{} } func (m *MsgConsumerAddition) String() string { return proto.CompactTextString(m) } func (*MsgConsumerAddition) ProtoMessage() {} func (*MsgConsumerAddition) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{2} + return fileDescriptor_43221a4391e9fbf4, []int{4} } func (m *MsgConsumerAddition) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -310,7 +401,7 @@ func (m *MsgConsumerAdditionResponse) Reset() { *m = MsgConsumerAddition func (m *MsgConsumerAdditionResponse) String() string { return proto.CompactTextString(m) } func (*MsgConsumerAdditionResponse) ProtoMessage() {} func (*MsgConsumerAdditionResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{3} + return fileDescriptor_43221a4391e9fbf4, []int{5} } func (m *MsgConsumerAdditionResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -359,7 +450,7 @@ func (m *MsgConsumerRemoval) Reset() { *m = MsgConsumerRemoval{} } func (m *MsgConsumerRemoval) String() string { return proto.CompactTextString(m) } func (*MsgConsumerRemoval) ProtoMessage() {} func (*MsgConsumerRemoval) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{4} + return fileDescriptor_43221a4391e9fbf4, []int{6} } func (m *MsgConsumerRemoval) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -417,7 +508,7 @@ func (m *MsgConsumerRemovalResponse) Reset() { *m = MsgConsumerRemovalRe func (m *MsgConsumerRemovalResponse) String() string { return proto.CompactTextString(m) } func (*MsgConsumerRemovalResponse) ProtoMessage() {} func (*MsgConsumerRemovalResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{5} + return fileDescriptor_43221a4391e9fbf4, []int{7} } func (m *MsgConsumerRemovalResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -463,7 +554,7 @@ func (m *MsgChangeRewardDenoms) Reset() { *m = MsgChangeRewardDenoms{} } func (m *MsgChangeRewardDenoms) String() string { return proto.CompactTextString(m) } func (*MsgChangeRewardDenoms) ProtoMessage() {} func (*MsgChangeRewardDenoms) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{6} + return fileDescriptor_43221a4391e9fbf4, []int{8} } func (m *MsgChangeRewardDenoms) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -521,7 +612,7 @@ func (m *MsgChangeRewardDenomsResponse) Reset() { *m = MsgChangeRewardDe func (m *MsgChangeRewardDenomsResponse) String() string { return proto.CompactTextString(m) } func (*MsgChangeRewardDenomsResponse) ProtoMessage() {} func (*MsgChangeRewardDenomsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_43221a4391e9fbf4, []int{7} + return fileDescriptor_43221a4391e9fbf4, []int{9} } func (m *MsgChangeRewardDenomsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -551,6 +642,8 @@ func (m *MsgChangeRewardDenomsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgChangeRewardDenomsResponse proto.InternalMessageInfo func init() { + proto.RegisterType((*MsgUpdateParams)(nil), "interchain_security.ccv.provider.v1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "interchain_security.ccv.provider.v1.MsgUpdateParamsResponse") proto.RegisterType((*MsgAssignConsumerKey)(nil), "interchain_security.ccv.provider.v1.MsgAssignConsumerKey") proto.RegisterType((*MsgAssignConsumerKeyResponse)(nil), "interchain_security.ccv.provider.v1.MsgAssignConsumerKeyResponse") proto.RegisterType((*MsgConsumerAddition)(nil), "interchain_security.ccv.provider.v1.MsgConsumerAddition") @@ -566,70 +659,75 @@ func init() { } var fileDescriptor_43221a4391e9fbf4 = []byte{ - // 995 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0xcf, 0x6f, 0x1b, 0xc5, - 0x17, 0xf7, 0x36, 0x69, 0x9a, 0x8c, 0x93, 0x34, 0xd9, 0xa6, 0xea, 0xc6, 0xdf, 0xd4, 0x4e, 0xfc, - 0xe5, 0x10, 0x55, 0x64, 0x97, 0xb4, 0x87, 0x42, 0x24, 0x04, 0x4e, 0x02, 0x04, 0x50, 0xa0, 0x2c, - 0x91, 0x90, 0xe0, 0xb0, 0x1a, 0xcf, 0x4e, 0x76, 0x47, 0xf5, 0xce, 0x58, 0x33, 0xe3, 0x6d, 0x7d, - 0x43, 0x9c, 0x90, 0x90, 0x50, 0x91, 0x38, 0x70, 0xec, 0x81, 0x3f, 0xa0, 0x48, 0xfc, 0x11, 0x3d, - 0x56, 0x08, 0x01, 0xa7, 0x82, 0x92, 0x43, 0x39, 0xf3, 0x17, 0xa0, 0xf9, 0xb1, 0x8e, 0x63, 0xbb, - 0x95, 0x6b, 0x2e, 0xd1, 0xcc, 0x7c, 0x7e, 0xbc, 0xf7, 0x26, 0xef, 0x8d, 0x17, 0xbc, 0x4a, 0xa8, - 0xc4, 0x1c, 0xa5, 0x90, 0xd0, 0x48, 0x60, 0xd4, 0xe1, 0x44, 0x76, 0x03, 0x84, 0xf2, 0xa0, 0xcd, - 0x59, 0x4e, 0x62, 0xcc, 0x83, 0x7c, 0x3b, 0x90, 0xf7, 0xfd, 0x36, 0x67, 0x92, 0xb9, 0xff, 0x1f, - 0xc1, 0xf6, 0x11, 0xca, 0xfd, 0x82, 0xed, 0xe7, 0xdb, 0x95, 0x65, 0x98, 0x11, 0xca, 0x02, 0xfd, - 0xd7, 0xe8, 0x2a, 0x6b, 0x09, 0x63, 0x49, 0x0b, 0x07, 0xb0, 0x4d, 0x02, 0x48, 0x29, 0x93, 0x50, - 0x12, 0x46, 0x85, 0x45, 0x6b, 0x16, 0xd5, 0xbb, 0x66, 0xe7, 0x38, 0x90, 0x24, 0xc3, 0x42, 0xc2, - 0xac, 0x6d, 0x09, 0xd5, 0x41, 0x42, 0xdc, 0xe1, 0xda, 0xc1, 0xe2, 0xab, 0x83, 0x38, 0xa4, 0x5d, - 0x0b, 0xad, 0x24, 0x2c, 0x61, 0x7a, 0x19, 0xa8, 0x55, 0x21, 0x40, 0x4c, 0x64, 0x4c, 0x44, 0x06, - 0x30, 0x1b, 0x0b, 0x5d, 0x33, 0xbb, 0x20, 0x13, 0x89, 0x2a, 0x3d, 0x13, 0x49, 0x91, 0x25, 0x69, - 0xa2, 0x00, 0x31, 0x8e, 0x03, 0xd4, 0x22, 0x98, 0x4a, 0x85, 0x9a, 0x95, 0x21, 0xd4, 0x7f, 0x75, - 0xc0, 0xca, 0xa1, 0x48, 0x1a, 0x42, 0x90, 0x84, 0xee, 0x31, 0x2a, 0x3a, 0x19, 0xe6, 0x1f, 0xe2, - 0xae, 0xbb, 0x0a, 0x66, 0xcd, 0x95, 0x91, 0xd8, 0x73, 0xd6, 0x9d, 0xcd, 0xb9, 0xf0, 0x92, 0xde, - 0xbf, 0x1f, 0xbb, 0xb7, 0xc1, 0x42, 0x71, 0x75, 0x11, 0x8c, 0x63, 0xee, 0x5d, 0x50, 0xf8, 0xae, - 0xfb, 0xcf, 0xd3, 0xda, 0x62, 0x17, 0x66, 0xad, 0x9d, 0xba, 0x3a, 0xc5, 0x42, 0xd4, 0xc3, 0xf9, - 0x82, 0xd8, 0x88, 0x63, 0xee, 0x6e, 0x80, 0x79, 0x64, 0x43, 0x44, 0x77, 0x71, 0xd7, 0x9b, 0xd2, - 0xbe, 0x65, 0xd4, 0x17, 0xf6, 0x35, 0x30, 0xa3, 0x32, 0xc1, 0xdc, 0x9b, 0xd6, 0xa6, 0xde, 0x2f, - 0x3f, 0x6f, 0xad, 0xd8, 0x5a, 0x1b, 0xc6, 0xf5, 0x53, 0xc9, 0x09, 0x4d, 0x42, 0xcb, 0xdb, 0xb9, - 0xf2, 0xf5, 0xc3, 0x5a, 0xe9, 0xef, 0x87, 0xb5, 0xd2, 0x57, 0xcf, 0x1e, 0xdd, 0xb0, 0x87, 0xf5, - 0x2a, 0x58, 0x1b, 0x55, 0x55, 0x88, 0x45, 0x9b, 0x51, 0x81, 0xeb, 0xbf, 0xcf, 0x80, 0x2b, 0x87, - 0x22, 0x29, 0xa0, 0x46, 0x1c, 0x13, 0xf5, 0xaf, 0x79, 0x51, 0xd5, 0xef, 0x81, 0x45, 0x42, 0x89, - 0x24, 0xb0, 0x15, 0xa5, 0x98, 0x24, 0xa9, 0xd4, 0x65, 0x97, 0x6f, 0x56, 0x7c, 0xd2, 0x44, 0xbe, - 0xba, 0x63, 0xdf, 0xde, 0x6c, 0xbe, 0xed, 0x1f, 0x68, 0xc6, 0xee, 0xf4, 0xe3, 0xa7, 0xb5, 0x52, - 0xb8, 0x60, 0x75, 0xe6, 0x50, 0xdd, 0x42, 0x82, 0x29, 0x16, 0x44, 0x44, 0x29, 0x14, 0xa9, 0xbe, - 0x85, 0xf9, 0xb0, 0x6c, 0xcf, 0x0e, 0xa0, 0x48, 0xdd, 0x1a, 0x28, 0x37, 0x09, 0x85, 0xbc, 0x6b, - 0x18, 0xd3, 0x9a, 0x01, 0xcc, 0x91, 0x26, 0xec, 0x01, 0x20, 0xda, 0xf0, 0x1e, 0x8d, 0x54, 0xd7, - 0x79, 0x17, 0x6d, 0x22, 0xa6, 0xa3, 0xfc, 0xa2, 0xa3, 0xfc, 0xa3, 0xa2, 0x25, 0x77, 0x67, 0x55, - 0x22, 0x0f, 0xfe, 0xac, 0x39, 0xe1, 0x9c, 0xd6, 0x29, 0xc4, 0xfd, 0x08, 0x2c, 0x75, 0x68, 0x93, - 0xd1, 0x98, 0xd0, 0x24, 0x6a, 0x63, 0x4e, 0x58, 0xec, 0xcd, 0x68, 0xab, 0xd5, 0x21, 0xab, 0x7d, - 0xdb, 0xbc, 0xc6, 0xe9, 0x07, 0xe5, 0x74, 0xb9, 0x27, 0xbe, 0xa3, 0xb5, 0xee, 0x27, 0xc0, 0x45, - 0x28, 0xd7, 0x29, 0xb1, 0x8e, 0x2c, 0x1c, 0x2f, 0x8d, 0xef, 0xb8, 0x84, 0x50, 0x7e, 0x64, 0xd4, - 0xd6, 0xf2, 0x0b, 0x70, 0x4d, 0x72, 0x48, 0xc5, 0x31, 0xe6, 0x83, 0xbe, 0xb3, 0xe3, 0xfb, 0x5e, - 0x2d, 0x3c, 0xce, 0x9b, 0x1f, 0x80, 0xf5, 0x5e, 0x3b, 0x72, 0x1c, 0x13, 0x21, 0x39, 0x69, 0x76, - 0x94, 0x36, 0x3a, 0xe6, 0x10, 0xa9, 0x85, 0x37, 0xa7, 0x9b, 0xa0, 0x5a, 0xf0, 0xc2, 0x73, 0xb4, - 0x77, 0x2d, 0xcb, 0xfd, 0x18, 0xbc, 0xd2, 0x6c, 0x31, 0x74, 0x57, 0xa8, 0xe4, 0xa2, 0x73, 0x4e, - 0x3a, 0x74, 0x46, 0x84, 0x50, 0x6e, 0x60, 0xdd, 0xd9, 0x9c, 0x0a, 0x37, 0x0c, 0xf7, 0x0e, 0xe6, - 0xfb, 0x7d, 0xcc, 0xa3, 0x3e, 0xa2, 0xbb, 0x05, 0xdc, 0x94, 0x08, 0xc9, 0x38, 0x41, 0xb0, 0x15, - 0x61, 0x2a, 0x39, 0xc1, 0xc2, 0x2b, 0x6b, 0xf9, 0xf2, 0x19, 0xf2, 0x8e, 0x01, 0xdc, 0x0f, 0xc0, - 0xc6, 0x73, 0x83, 0x46, 0x28, 0x85, 0x94, 0xe2, 0x96, 0x37, 0xaf, 0x4b, 0xa9, 0xc5, 0xcf, 0x89, - 0xb9, 0x67, 0x68, 0x7d, 0x13, 0xb8, 0x30, 0xe6, 0x04, 0x96, 0xfb, 0x27, 0xef, 0x3a, 0xf8, 0xdf, - 0x88, 0xc1, 0xea, 0x0d, 0xde, 0x4f, 0x0e, 0x70, 0xfb, 0xf0, 0x10, 0x67, 0x2c, 0x87, 0xad, 0x17, - 0xcd, 0x5d, 0x03, 0xcc, 0x09, 0xc9, 0xda, 0xa6, 0xd3, 0x2f, 0xbc, 0x44, 0xa7, 0xcf, 0x2a, 0x99, - 0x6e, 0xf4, 0xb3, 0x92, 0xa6, 0x26, 0x29, 0x69, 0x0d, 0x54, 0x86, 0x53, 0xee, 0x55, 0xf4, 0xa3, - 0x03, 0xae, 0x2a, 0x38, 0x85, 0x34, 0xc1, 0x21, 0xbe, 0x07, 0x79, 0xbc, 0x8f, 0x29, 0xcb, 0x84, - 0x5b, 0x07, 0x0b, 0xb1, 0x5e, 0x45, 0x92, 0xa9, 0x87, 0xd2, 0x73, 0xd6, 0xa7, 0xd4, 0x7b, 0x67, - 0x0e, 0x8f, 0x58, 0x23, 0x8e, 0xdd, 0x4d, 0xb0, 0x74, 0xc6, 0xe1, 0xca, 0x5a, 0x15, 0xa9, 0x68, - 0x8b, 0x05, 0x4d, 0x07, 0xfc, 0xcf, 0x45, 0xd4, 0xc0, 0xf5, 0x91, 0x59, 0x16, 0x75, 0xdc, 0xfc, - 0x6d, 0x1a, 0x4c, 0x1d, 0x8a, 0xc4, 0xfd, 0xce, 0x01, 0xcb, 0xc3, 0x3f, 0x07, 0x6f, 0xf8, 0x63, - 0xfc, 0x8a, 0xfa, 0xa3, 0xde, 0xdc, 0x4a, 0x63, 0x62, 0x69, 0x91, 0x9b, 0xfb, 0xad, 0x03, 0x96, - 0x86, 0xde, 0xea, 0xd7, 0xc7, 0xf5, 0x1d, 0x54, 0x56, 0xde, 0x9e, 0x54, 0xd9, 0x4b, 0xe8, 0x1b, - 0x07, 0x5c, 0x1e, 0xec, 0xe1, 0xdb, 0x2f, 0xeb, 0x6a, 0x85, 0x95, 0xb7, 0x26, 0x14, 0xf6, 0xb2, - 0xf9, 0xde, 0x01, 0xee, 0x88, 0xfe, 0xdb, 0x19, 0xdb, 0x77, 0x48, 0x5b, 0xd9, 0x9d, 0x5c, 0x5b, - 0xa4, 0x55, 0xb9, 0xf8, 0xe5, 0xb3, 0x47, 0x37, 0x9c, 0xdd, 0xcf, 0x1e, 0x9f, 0x54, 0x9d, 0x27, - 0x27, 0x55, 0xe7, 0xaf, 0x93, 0xaa, 0xf3, 0xe0, 0xb4, 0x5a, 0x7a, 0x72, 0x5a, 0x2d, 0xfd, 0x71, - 0x5a, 0x2d, 0x7d, 0xfe, 0x66, 0x42, 0x64, 0xda, 0x69, 0xfa, 0x88, 0x65, 0xf6, 0x7b, 0x26, 0x38, - 0x8b, 0xba, 0xd5, 0xfb, 0xb2, 0xcb, 0x6f, 0x05, 0xf7, 0xcf, 0x7f, 0xde, 0xc9, 0x6e, 0x1b, 0x8b, - 0xe6, 0x8c, 0x1e, 0xff, 0x5b, 0xff, 0x06, 0x00, 0x00, 0xff, 0xff, 0x2d, 0x6a, 0x00, 0xc7, 0x0f, - 0x0a, 0x00, 0x00, + // 1075 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x56, 0x41, 0x6f, 0x1b, 0x45, + 0x14, 0xf6, 0x36, 0x6d, 0x9a, 0x8c, 0x93, 0x26, 0x99, 0xa6, 0x8a, 0x63, 0x52, 0x3b, 0x31, 0x1c, + 0xa2, 0x42, 0x76, 0x49, 0x8a, 0x54, 0x88, 0x40, 0x60, 0x27, 0x40, 0x0a, 0x0a, 0x84, 0x25, 0x08, + 0x09, 0x0e, 0xab, 0xf1, 0xec, 0x64, 0x3d, 0xaa, 0x77, 0x66, 0x35, 0x33, 0x76, 0xeb, 0x1b, 0xea, + 0x09, 0x09, 0x09, 0x15, 0x89, 0x03, 0x12, 0x97, 0x1e, 0xf8, 0x01, 0x45, 0xe2, 0x47, 0xf4, 0x58, + 0x21, 0x24, 0x90, 0x90, 0x0a, 0x4a, 0x0e, 0xe5, 0xcc, 0x2f, 0x40, 0x33, 0x3b, 0xeb, 0xd8, 0x8e, + 0x5b, 0xb9, 0xe6, 0x62, 0xcd, 0xee, 0xfb, 0xbe, 0xef, 0x7d, 0x6f, 0xf6, 0xbd, 0xf1, 0x80, 0x57, + 0x28, 0x53, 0x44, 0xe0, 0x06, 0xa2, 0x2c, 0x90, 0x04, 0xb7, 0x04, 0x55, 0x1d, 0x0f, 0xe3, 0xb6, + 0x97, 0x08, 0xde, 0xa6, 0x21, 0x11, 0x5e, 0x7b, 0xd3, 0x53, 0x77, 0xdc, 0x44, 0x70, 0xc5, 0xe1, + 0x8b, 0x43, 0xd0, 0x2e, 0xc6, 0x6d, 0x37, 0x43, 0xbb, 0xed, 0xcd, 0xe2, 0x02, 0x8a, 0x29, 0xe3, + 0x9e, 0xf9, 0x4d, 0x79, 0xc5, 0x95, 0x88, 0xf3, 0xa8, 0x49, 0x3c, 0x94, 0x50, 0x0f, 0x31, 0xc6, + 0x15, 0x52, 0x94, 0x33, 0x69, 0xa3, 0x65, 0x1b, 0x35, 0x4f, 0xf5, 0xd6, 0x91, 0xa7, 0x68, 0x4c, + 0xa4, 0x42, 0x71, 0x62, 0x01, 0xa5, 0x41, 0x40, 0xd8, 0x12, 0x46, 0xc1, 0xc6, 0x97, 0x07, 0xe3, + 0x88, 0x75, 0x6c, 0x68, 0x31, 0xe2, 0x11, 0x37, 0x4b, 0x4f, 0xaf, 0x32, 0x02, 0xe6, 0x32, 0xe6, + 0x32, 0x48, 0x03, 0xe9, 0x83, 0x0d, 0x2d, 0xa5, 0x4f, 0x5e, 0x2c, 0x23, 0x5d, 0x7a, 0x2c, 0xa3, + 0xcc, 0x25, 0xad, 0x63, 0x0f, 0x73, 0x41, 0x3c, 0xdc, 0xa4, 0x84, 0x29, 0x1d, 0x4d, 0x57, 0x16, + 0xb0, 0x35, 0xca, 0x56, 0x76, 0x37, 0xca, 0x70, 0x2a, 0x3f, 0x3a, 0x60, 0x6e, 0x5f, 0x46, 0x9f, + 0x25, 0x21, 0x52, 0xe4, 0x00, 0x09, 0x14, 0x4b, 0xf8, 0x2a, 0x98, 0x94, 0x34, 0x62, 0x44, 0x14, + 0x9c, 0x55, 0x67, 0x7d, 0xba, 0x56, 0xf8, 0xf5, 0x97, 0x8d, 0x45, 0xeb, 0xb1, 0x1a, 0x86, 0x82, + 0x48, 0xf9, 0xa9, 0x12, 0x94, 0x45, 0xbe, 0xc5, 0xc1, 0x9b, 0x60, 0x32, 0x31, 0xdc, 0xc2, 0xb9, + 0x55, 0x67, 0x3d, 0xbf, 0xf5, 0xb2, 0x3b, 0xc2, 0x77, 0x72, 0xd3, 0x74, 0xb5, 0xf3, 0x0f, 0x1f, + 0x97, 0x73, 0xbe, 0x15, 0xd8, 0xce, 0xdf, 0x7d, 0xf2, 0xe0, 0x9a, 0xd5, 0xad, 0x2c, 0x83, 0xa5, + 0x01, 0x73, 0x3e, 0x91, 0x09, 0x67, 0x92, 0x54, 0x7e, 0x73, 0xc0, 0xe2, 0xbe, 0x8c, 0xaa, 0x52, + 0x43, 0x77, 0x38, 0x93, 0xad, 0x98, 0x88, 0x0f, 0x49, 0x07, 0x2e, 0x83, 0xa9, 0x34, 0x2f, 0x0d, + 0x53, 0xff, 0xfe, 0x45, 0xf3, 0x7c, 0x33, 0x84, 0x37, 0xc0, 0x6c, 0x96, 0x3f, 0x40, 0x61, 0x28, + 0x8c, 0xdb, 0xe9, 0x1a, 0xfc, 0xf7, 0x71, 0xf9, 0x52, 0x07, 0xc5, 0xcd, 0xed, 0x0a, 0x4a, 0xcb, + 0xab, 0xf8, 0x33, 0x19, 0x50, 0x17, 0x0c, 0xd7, 0xc0, 0x0c, 0xb6, 0x29, 0x82, 0x5b, 0xa4, 0x53, + 0x98, 0x30, 0xba, 0x79, 0xdc, 0x93, 0xf6, 0x74, 0xd3, 0xce, 0x8f, 0xb6, 0x69, 0xdb, 0x97, 0xbf, + 0xbe, 0x5f, 0xce, 0xfd, 0x73, 0xbf, 0x9c, 0xeb, 0xad, 0xb8, 0x04, 0x56, 0x86, 0x55, 0xd5, 0x2d, + 0xfb, 0xf7, 0x49, 0x70, 0x79, 0x5f, 0x46, 0x59, 0xa8, 0x1a, 0x86, 0x54, 0xf7, 0xe1, 0xb3, 0xaa, + 0x7e, 0x1f, 0x5c, 0xa2, 0x8c, 0x2a, 0x8a, 0x9a, 0x41, 0x83, 0xd0, 0xa8, 0xa1, 0xec, 0x47, 0x2a, + 0xba, 0xb4, 0x8e, 0x5d, 0xdd, 0x50, 0xae, 0x6d, 0xa3, 0xf6, 0xa6, 0xbb, 0x67, 0x10, 0xf6, 0x9b, + 0xcc, 0x5a, 0x5e, 0xfa, 0x52, 0xef, 0x42, 0x44, 0x18, 0x91, 0x54, 0x06, 0x0d, 0x24, 0x1b, 0x66, + 0x17, 0x66, 0xfc, 0xbc, 0x7d, 0xb7, 0x87, 0x64, 0x03, 0x96, 0x41, 0xbe, 0x4e, 0x19, 0x12, 0x9d, + 0x14, 0x71, 0xde, 0x20, 0x40, 0xfa, 0xca, 0x00, 0x76, 0x00, 0x90, 0x09, 0xba, 0xcd, 0x02, 0x3d, + 0x62, 0x85, 0x0b, 0xd6, 0x48, 0x3a, 0x3e, 0x6e, 0x36, 0x3e, 0xee, 0x61, 0x36, 0x7f, 0xb5, 0x29, + 0x6d, 0xe4, 0xde, 0x5f, 0x65, 0xc7, 0x9f, 0x36, 0x3c, 0x1d, 0x81, 0x1f, 0x81, 0xf9, 0x16, 0xab, + 0x73, 0x16, 0x52, 0x16, 0x05, 0x09, 0x11, 0x94, 0x87, 0x85, 0x49, 0x23, 0xb5, 0x7c, 0x46, 0x6a, + 0xd7, 0x4e, 0x6a, 0xaa, 0xf4, 0x83, 0x56, 0x9a, 0xeb, 0x92, 0x0f, 0x0c, 0x17, 0x7e, 0x02, 0x20, + 0xc6, 0x6d, 0x63, 0x89, 0xb7, 0x54, 0xa6, 0x78, 0x71, 0x74, 0xc5, 0x79, 0x8c, 0xdb, 0x87, 0x29, + 0xdb, 0x4a, 0x7e, 0x09, 0x96, 0x94, 0x40, 0x4c, 0x1e, 0x11, 0x31, 0xa8, 0x3b, 0x35, 0xba, 0xee, + 0x95, 0x4c, 0xa3, 0x5f, 0x7c, 0x0f, 0xac, 0x76, 0xdb, 0x51, 0x90, 0x90, 0x4a, 0x25, 0x68, 0xbd, + 0xa5, 0xb9, 0xc1, 0x91, 0x40, 0x58, 0x2f, 0x0a, 0xd3, 0xa6, 0x09, 0x4a, 0x19, 0xce, 0xef, 0x83, + 0xbd, 0x67, 0x51, 0xf0, 0x63, 0xf0, 0x52, 0xbd, 0xc9, 0xf1, 0x2d, 0xa9, 0xcd, 0x05, 0x7d, 0x4a, + 0x26, 0x75, 0x4c, 0xa5, 0xd4, 0x6a, 0x60, 0xd5, 0x59, 0x9f, 0xf0, 0xd7, 0x52, 0xec, 0x01, 0x11, + 0xbb, 0x3d, 0xc8, 0xc3, 0x1e, 0x20, 0xdc, 0x00, 0xb0, 0x41, 0xa5, 0xe2, 0x82, 0x62, 0xd4, 0x0c, + 0x08, 0x53, 0x82, 0x12, 0x59, 0xc8, 0x1b, 0xfa, 0xc2, 0x69, 0xe4, 0xdd, 0x34, 0x00, 0x3f, 0x00, + 0x6b, 0x4f, 0x4d, 0x1a, 0xe0, 0x06, 0x62, 0x8c, 0x34, 0x0b, 0x33, 0xa6, 0x94, 0x72, 0xf8, 0x94, + 0x9c, 0x3b, 0x29, 0xac, 0x67, 0x02, 0x67, 0x47, 0x9c, 0xc0, 0xbe, 0xb3, 0xe6, 0x2a, 0x78, 0x61, + 0xc8, 0x60, 0x75, 0x07, 0xef, 0x67, 0x07, 0xc0, 0x9e, 0xb8, 0x4f, 0x62, 0xde, 0x46, 0xcd, 0x67, + 0xcd, 0x5d, 0x15, 0x4c, 0x4b, 0xc5, 0x93, 0xb4, 0xd3, 0xcf, 0x3d, 0x47, 0xa7, 0x4f, 0x69, 0x9a, + 0x69, 0xf4, 0xd3, 0x92, 0x26, 0xc6, 0x29, 0x69, 0x05, 0x14, 0xcf, 0x5a, 0xee, 0x56, 0xf4, 0x93, + 0x03, 0xae, 0xe8, 0x70, 0x03, 0xb1, 0x88, 0xf8, 0xe4, 0x36, 0x12, 0xe1, 0x2e, 0x61, 0x3c, 0x96, + 0xb0, 0x02, 0x66, 0x43, 0xb3, 0x0a, 0x14, 0xd7, 0x07, 0x65, 0xc1, 0x59, 0x9d, 0xd0, 0xe7, 0x5d, + 0xfa, 0xf2, 0x90, 0x57, 0xc3, 0x10, 0xae, 0x83, 0xf9, 0x53, 0x8c, 0xd0, 0xd2, 0xba, 0x48, 0x0d, + 0xbb, 0x94, 0xc1, 0x4c, 0xc2, 0xff, 0x5d, 0x44, 0x19, 0x5c, 0x1d, 0xea, 0x32, 0xab, 0x63, 0xeb, + 0xcf, 0x0b, 0x60, 0x62, 0x5f, 0x46, 0xf0, 0x3b, 0x07, 0x2c, 0x9c, 0xfd, 0x3b, 0x78, 0x63, 0xa4, + 0xbf, 0xa2, 0x61, 0x67, 0x6e, 0xb1, 0x3a, 0x36, 0x35, 0xf3, 0x06, 0xbf, 0x75, 0xc0, 0xfc, 0x99, + 0xb3, 0xfa, 0xf5, 0x51, 0x75, 0x07, 0x99, 0xc5, 0x77, 0xc6, 0x65, 0x76, 0x0d, 0x7d, 0xe3, 0x80, + 0xb9, 0xc1, 0x1e, 0xbe, 0xf1, 0xbc, 0xaa, 0x96, 0x58, 0x7c, 0x7b, 0x4c, 0x62, 0xd7, 0xcd, 0xf7, + 0x0e, 0x80, 0x43, 0xfa, 0x6f, 0x7b, 0x64, 0xdd, 0x33, 0xdc, 0x62, 0x6d, 0x7c, 0x6e, 0xd7, 0xd6, + 0x5d, 0x07, 0xcc, 0xf4, 0xdd, 0x88, 0x5e, 0x1b, 0x55, 0xb4, 0x97, 0x55, 0x7c, 0x73, 0x1c, 0x56, + 0x66, 0xa2, 0x78, 0xe1, 0xab, 0x27, 0x0f, 0xae, 0x39, 0xb5, 0xcf, 0x1f, 0x1e, 0x97, 0x9c, 0x47, + 0xc7, 0x25, 0xe7, 0xef, 0xe3, 0x92, 0x73, 0xef, 0xa4, 0x94, 0x7b, 0x74, 0x52, 0xca, 0xfd, 0x71, + 0x52, 0xca, 0x7d, 0xf1, 0x56, 0x44, 0x55, 0xa3, 0x55, 0x77, 0x31, 0x8f, 0xed, 0x0d, 0xd2, 0x3b, + 0xcd, 0xb7, 0xd1, 0xbd, 0x00, 0xb6, 0xaf, 0x7b, 0x77, 0xfa, 0x6f, 0x81, 0xaa, 0x93, 0x10, 0x59, + 0x9f, 0x34, 0x67, 0xd0, 0xf5, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0xc8, 0x60, 0xfa, 0xcb, 0x81, + 0x0b, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -648,6 +746,7 @@ type MsgClient interface { ConsumerAddition(ctx context.Context, in *MsgConsumerAddition, opts ...grpc.CallOption) (*MsgConsumerAdditionResponse, error) ConsumerRemoval(ctx context.Context, in *MsgConsumerRemoval, opts ...grpc.CallOption) (*MsgConsumerRemovalResponse, error) ChangeRewardDenoms(ctx context.Context, in *MsgChangeRewardDenoms, opts ...grpc.CallOption) (*MsgChangeRewardDenomsResponse, error) + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -694,12 +793,22 @@ func (c *msgClient) ChangeRewardDenoms(ctx context.Context, in *MsgChangeRewardD return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/interchain_security.ccv.provider.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 { AssignConsumerKey(context.Context, *MsgAssignConsumerKey) (*MsgAssignConsumerKeyResponse, error) ConsumerAddition(context.Context, *MsgConsumerAddition) (*MsgConsumerAdditionResponse, error) ConsumerRemoval(context.Context, *MsgConsumerRemoval) (*MsgConsumerRemovalResponse, error) ChangeRewardDenoms(context.Context, *MsgChangeRewardDenoms) (*MsgChangeRewardDenomsResponse, error) + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -718,6 +827,9 @@ func (*UnimplementedMsgServer) ConsumerRemoval(ctx context.Context, req *MsgCons func (*UnimplementedMsgServer) ChangeRewardDenoms(ctx context.Context, req *MsgChangeRewardDenoms) (*MsgChangeRewardDenomsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ChangeRewardDenoms not implemented") } +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) @@ -795,6 +907,24 @@ func _Msg_ChangeRewardDenoms_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +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: "/interchain_security.ccv.provider.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: "interchain_security.ccv.provider.v1.Msg", HandlerType: (*MsgServer)(nil), @@ -815,11 +945,78 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "ChangeRewardDenoms", Handler: _Msg_ChangeRewardDenoms_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "interchain_security/ccv/provider/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.Signer) > 0 { + i -= len(m.Signer) + copy(dAtA[i:], m.Signer) + i = encodeVarintTx(dAtA, i, uint64(len(m.Signer))) + 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 (m *MsgAssignConsumerKey) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -945,37 +1142,37 @@ func (m *MsgConsumerAddition) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x4a } - n1, err1 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.TransferTimeoutPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.TransferTimeoutPeriod):]) - if err1 != nil { - return 0, err1 - } - i -= n1 - i = encodeVarintTx(dAtA, i, uint64(n1)) - i-- - dAtA[i] = 0x42 - n2, err2 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.CcvTimeoutPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.CcvTimeoutPeriod):]) + n2, err2 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.TransferTimeoutPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.TransferTimeoutPeriod):]) if err2 != nil { return 0, err2 } i -= n2 i = encodeVarintTx(dAtA, i, uint64(n2)) i-- - dAtA[i] = 0x3a - n3, err3 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.UnbondingPeriod):]) + dAtA[i] = 0x42 + n3, err3 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.CcvTimeoutPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.CcvTimeoutPeriod):]) if err3 != nil { return 0, err3 } i -= n3 i = encodeVarintTx(dAtA, i, uint64(n3)) i-- - dAtA[i] = 0x32 - n4, err4 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.SpawnTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.SpawnTime):]) + dAtA[i] = 0x3a + n4, err4 := github_com_cosmos_gogoproto_types.StdDurationMarshalTo(m.UnbondingPeriod, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdDuration(m.UnbondingPeriod):]) if err4 != nil { return 0, err4 } i -= n4 i = encodeVarintTx(dAtA, i, uint64(n4)) i-- + dAtA[i] = 0x32 + n5, err5 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.SpawnTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.SpawnTime):]) + if err5 != nil { + return 0, err5 + } + i -= n5 + i = encodeVarintTx(dAtA, i, uint64(n5)) + i-- dAtA[i] = 0x2a if len(m.BinaryHash) > 0 { i -= len(m.BinaryHash) @@ -1061,12 +1258,12 @@ func (m *MsgConsumerRemoval) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x1a } - n6, err6 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StopTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StopTime):]) - if err6 != nil { - return 0, err6 + n7, err7 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.StopTime, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.StopTime):]) + if err7 != nil { + return 0, err7 } - i -= n6 - i = encodeVarintTx(dAtA, i, uint64(n6)) + i -= n7 + i = encodeVarintTx(dAtA, i, uint64(n7)) i-- dAtA[i] = 0x12 if len(m.ChainId) > 0 { @@ -1184,6 +1381,30 @@ func encodeVarintTx(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Signer) + 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 (m *MsgAssignConsumerKey) Size() (n int) { if m == nil { return 0 @@ -1344,6 +1565,171 @@ func sovTx(x uint64) (n int) { 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 Signer", 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.Signer = 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 (m *MsgAssignConsumerKey) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 From e96a3f1a568e1016472df69fc8ee805b48048198 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Mon, 13 Nov 2023 09:12:31 +0100 Subject: [PATCH 2/8] added handlers MsgUpdateParams and migration for legacy parameter updates --- x/ccv/consumer/types/keys.go | 7 +++++ x/ccv/consumer/types/keys_test.go | 1 + x/ccv/provider/client/cli/query.go | 41 +++++++++++++++++++++++++++-- x/ccv/provider/keeper/grpc_query.go | 21 ++++++++++++--- x/ccv/provider/keeper/migration.go | 28 ++++++++++++++++++++ x/ccv/provider/keeper/msg_server.go | 15 +++++++++++ x/ccv/provider/module.go | 9 +++++++ x/ccv/provider/types/codec.go | 1 + x/ccv/provider/types/keys.go | 7 +++++ x/ccv/provider/types/keys_test.go | 1 + 10 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 x/ccv/provider/keeper/migration.go diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index c9a3d3f5b0..379f52246c 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -106,6 +106,9 @@ const ( // SlashRecordByteKey is the single byte key storing the consumer's slash record. SlashRecordByteKey + // ParametersKey is the is the single byte key for storing consumer's parameters. + ParametersByteKey + // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go ) @@ -113,6 +116,10 @@ const ( // Fully defined key func section // +func ParametersKey() []byte { + return []byte{ParametersByteKey} +} + // PortKey returns the key to the port ID in the store func PortKey() []byte { return []byte{PortByteKey} diff --git a/x/ccv/consumer/types/keys_test.go b/x/ccv/consumer/types/keys_test.go index a8cebee284..e1fcbcf733 100644 --- a/x/ccv/consumer/types/keys_test.go +++ b/x/ccv/consumer/types/keys_test.go @@ -43,6 +43,7 @@ func getAllKeyPrefixes() []byte { PrevStandaloneChainByteKey, PendingPacketsIndexByteKey, SlashRecordByteKey, + ParametersByteKey, } } diff --git a/x/ccv/provider/client/cli/query.go b/x/ccv/provider/client/cli/query.go index 1240e242f0..119ee90b82 100644 --- a/x/ccv/provider/client/cli/query.go +++ b/x/ccv/provider/client/cli/query.go @@ -33,7 +33,7 @@ func NewQueryCmd() *cobra.Command { cmd.AddCommand(CmdThrottleState()) cmd.AddCommand(CmdThrottledConsumerPacketData()) cmd.AddCommand(CmdRegisteredConsumerRewardDenoms()) - + cmd.AddCommand(CmdProviderParams()) return cmd } @@ -292,7 +292,7 @@ func CmdThrottledConsumerPacketData() *cobra.Command { Short: "Query pending VSCMatured and slash packet data for a consumer chainId", Long: strings.TrimSpace( fmt.Sprintf(`Returns the current pending VSCMatured and slash packet data instances for a consumer chainId. - Queue is ordered by ibc sequence number. + Queue is ordered by ibc sequence number. Example: $ %s query provider throttled-consumer-packet-data foochain `, @@ -356,3 +356,40 @@ $ %s query provider registered-consumer-reward-denoms return cmd } + +// NewQuerySubspaceParamsCmd returns a CLI command handler for querying subspace +// parameters managed by the x/params module. +func CmdProviderParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params [flags]", + Short: "Query values set as provider parameters", + /* Long: strings.TrimSpace( + fmt.Sprintf(`Returns the registered consumer reward denoms. + Example: + $ %s query provider registered-consumer-reward-denoms + `, + version.AppName, + ), + ), */ + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + queryClient := types.NewQueryClient(clientCtx) + + req := types.QueryParamsRequest{} + res, err := queryClient.QueryParams(cmd.Context(), &req) + if err != nil { + return err + } + + return clientCtx.PrintProto(&res.Params) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 2b522ea9ef..189796738f 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -36,6 +36,19 @@ func (k Keeper) QueryConsumerGenesis(c context.Context, req *types.QueryConsumer return &types.QueryConsumerGenesisResponse{GenesisState: gen}, nil } +func (k Keeper) QueryParams(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "empty request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + params, err := k.GetParams(ctx) + if err != nil { + return nil, status.Error(codes.NotFound, "no parameters found") + } + return &types.QueryParamsResponse{Params: params}, nil +} + func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsumerChainsRequest) (*types.QueryConsumerChainsResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "empty request") @@ -220,9 +233,9 @@ func (k Keeper) QueryThrottledConsumerPacketData(goCtx context.Context, req *typ // getSlashPacketData fetches a slash packet data from the store using consumerChainId and ibcSeqNum (direct access) // If the returned bytes do not unmarshal to SlashPacketData, the data is considered not found. func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcSeqNum uint64) (ccvtypes.SlashPacketData, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) - if len(bz) == 0 { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) + if err != nil || len(bz) == 0 { return ccvtypes.SlashPacketData{}, false } @@ -231,7 +244,7 @@ func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcS } packet := ccvtypes.SlashPacketData{} - err := packet.Unmarshal(bz[1:]) + err = packet.Unmarshal(bz[1:]) if err != nil { // If the data cannot be unmarshaled, it is considered not found return ccvtypes.SlashPacketData{}, false diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go new file mode 100644 index 0000000000..3b6db16463 --- /dev/null +++ b/x/ccv/provider/keeper/migration.go @@ -0,0 +1,28 @@ +package keeper + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" +) + +type Migrator struct { + keeper Keeper +} + +// NewMigrator returns a new Migrator. +func NewMigrator(keeper Keeper) Migrator { + return Migrator{ + keeper: keeper, + } +} + +// MigrateParams migrates the provider module's parameters from the x/params to self store. +func (m Migrator) MigrateParams(ctx sdk.Context, paramSpace paramtypes.Subspace) error { + var params types.Params + paramSpace.GetParamSet(ctx, ¶ms) + + m.keeper.SetParams(ctx, params) + m.keeper.Logger(ctx).Info("successfully migrated provider parameters") + return nil +} diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index 491e585f60..2e8098cc5d 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -10,6 +10,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" @@ -27,6 +28,20 @@ func NewMsgServerImpl(keeper *Keeper) types.MsgServer { var _ types.MsgServer = msgServer{} +// UpdateParams updates the params. +func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.GetAuthority() != msg.Signer { + return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Signer) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + if err := k.Keeper.SetParams(ctx, msg.Params); err != nil { + return nil, err + } + + return &types.MsgUpdateParamsResponse{}, nil +} + // CreateValidator defines a method for creating a new validator func (k msgServer) AssignConsumerKey(goCtx context.Context, msg *types.MsgAssignConsumerKey) (*types.MsgAssignConsumerKeyResponse, error) { ctx := sdk.UnwrapSDKContext(goCtx) diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index cfc4e9dfe0..12eba7dab8 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -119,6 +119,15 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { func (am AppModule) RegisterServices(cfg module.Configurator) { providertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) providertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + migrator := keeper.NewMigrator(*am.keeper) + err := cfg.RegisterMigration(am.Name(), 2, + func(ctx sdk.Context) error { + return migrator.MigrateParams(ctx, am.paramSpace) + }) + if err != nil { + panic(err) + } } // InitGenesis performs genesis initialization for the provider module. It returns no validator updates. diff --git a/x/ccv/provider/types/codec.go b/x/ccv/provider/types/codec.go index b33a390c5f..300a83f1db 100644 --- a/x/ccv/provider/types/codec.go +++ b/x/ccv/provider/types/codec.go @@ -31,6 +31,7 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) { &MsgConsumerAddition{}, &MsgConsumerRemoval{}, &MsgChangeRewardDenoms{}, + &MsgUpdateParams{}, ) registry.RegisterImplementations( (*govv1beta1.Content)(nil), diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index ee4c11015b..f34f29bc4c 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -138,6 +138,9 @@ const ( // handled in the current block VSCMaturedHandledThisBlockBytePrefix + // ParametersKey is the is the single byte key for storing consumer's parameters. + ParametersByteKey + // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go ) @@ -145,6 +148,10 @@ const ( // Fully defined key func section // +func ParametersKey() []byte { + return []byte{ParametersByteKey} +} + // PortKey returns the key to the port ID in the store func PortKey() []byte { return []byte{PortByteKey} diff --git a/x/ccv/provider/types/keys_test.go b/x/ccv/provider/types/keys_test.go index 9f470f4a82..fbdfe1f267 100644 --- a/x/ccv/provider/types/keys_test.go +++ b/x/ccv/provider/types/keys_test.go @@ -54,6 +54,7 @@ func getAllKeyPrefixes() []byte { providertypes.ConsumerAddrsToPruneBytePrefix, providertypes.SlashLogBytePrefix, providertypes.VSCMaturedHandledThisBlockBytePrefix, + providertypes.ParametersByteKey, } } From a95885322eeeb5bd16d161dbdb984cf4cfd1e6e7 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Mon, 13 Nov 2023 09:20:04 +0100 Subject: [PATCH 3/8] Changed to store service --- app/consumer-democracy/app.go | 6 +- app/consumer/app.go | 6 +- app/provider/app.go | 3 +- tests/integration/channel_init.go | 5 +- tests/integration/distribution.go | 32 ++- tests/integration/throttle.go | 22 +- testutil/keeper/unit_test_helpers.go | 7 +- x/ccv/consumer/ibc_module_test.go | 6 +- x/ccv/consumer/keeper/distribution.go | 8 +- x/ccv/consumer/keeper/genesis.go | 6 +- x/ccv/consumer/keeper/genesis_test.go | 12 +- x/ccv/consumer/keeper/grpc_query.go | 5 +- x/ccv/consumer/keeper/keeper.go | 279 ++++++++++++---------- x/ccv/consumer/keeper/migration.go | 10 +- x/ccv/consumer/keeper/params.go | 180 +++++++++----- x/ccv/consumer/keeper/params_test.go | 6 +- x/ccv/consumer/keeper/soft_opt_out.go | 8 +- x/ccv/consumer/keeper/throttle_retry.go | 12 +- x/ccv/consumer/keeper/validators.go | 10 +- x/ccv/provider/keeper/distribution.go | 28 ++- x/ccv/provider/keeper/genesis.go | 5 +- x/ccv/provider/keeper/genesis_test.go | 6 +- x/ccv/provider/keeper/keeper.go | 303 +++++++++++++----------- x/ccv/provider/keeper/key_assignment.go | 89 ++++--- x/ccv/provider/keeper/params.go | 124 ++++++---- x/ccv/provider/keeper/params_test.go | 6 +- x/ccv/provider/keeper/proposal.go | 64 +++-- x/ccv/provider/keeper/relay.go | 6 +- x/ccv/provider/keeper/throttle.go | 75 +++--- x/ccv/provider/module_test.go | 4 +- x/ccv/provider/types/params.go | 5 - x/ccv/types/params.go | 35 --- 32 files changed, 814 insertions(+), 559 deletions(-) diff --git a/app/consumer-democracy/app.go b/app/consumer-democracy/app.go index ed4e8d81fa..91d5ed333b 100644 --- a/app/consumer-democracy/app.go +++ b/app/consumer-democracy/app.go @@ -431,8 +431,7 @@ func New( // communication over IBC is not affected by these changes app.ConsumerKeeper = consumerkeeper.NewNonZeroKeeper( appCodec, - keys[consumertypes.StoreKey], - app.GetSubspace(consumertypes.ModuleName), + runtime.NewKVStoreService(keys[consumertypes.StoreKey]), ) app.IBCKeeper = ibckeeper.NewKeeper( @@ -448,8 +447,7 @@ func New( // Create CCV consumer and modules app.ConsumerKeeper = consumerkeeper.NewKeeper( appCodec, - keys[consumertypes.StoreKey], - app.GetSubspace(consumertypes.ModuleName), + runtime.NewKVStoreService(keys[consumertypes.StoreKey]), scopedIBCConsumerKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/app/consumer/app.go b/app/consumer/app.go index f6f354c777..0029e75cf3 100644 --- a/app/consumer/app.go +++ b/app/consumer/app.go @@ -357,8 +357,7 @@ func New( // communication over IBC is not affected by these changes app.ConsumerKeeper = ibcconsumerkeeper.NewNonZeroKeeper( appCodec, - keys[ibcconsumertypes.StoreKey], - app.GetSubspace(ibcconsumertypes.ModuleName), + runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]), ) app.IBCKeeper = ibckeeper.NewKeeper( @@ -374,8 +373,7 @@ func New( // initialize the actual consumer keeper app.ConsumerKeeper = ibcconsumerkeeper.NewKeeper( appCodec, - keys[ibcconsumertypes.StoreKey], - app.GetSubspace(ibcconsumertypes.ModuleName), + runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]), scopedIBCConsumerKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/app/provider/app.go b/app/provider/app.go index 00c775043e..fa4912a186 100644 --- a/app/provider/app.go +++ b/app/provider/app.go @@ -436,8 +436,7 @@ func New( app.ProviderKeeper = icsproviderkeeper.NewKeeper( appCodec, - keys[providertypes.StoreKey], - app.GetSubspace(providertypes.ModuleName), + runtime.NewKVStoreService(keys[providertypes.StoreKey]), scopedIBCProviderKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/tests/integration/channel_init.go b/tests/integration/channel_init.go index e9a41c66f5..0c67136896 100644 --- a/tests/integration/channel_init.go +++ b/tests/integration/channel_init.go @@ -60,7 +60,10 @@ func (suite *CCVTestSuite) TestInitTimeout() { for i, tc := range testCases { providerKeeper := suite.providerApp.GetProviderKeeper() - initTimeout := providerKeeper.GetParams(suite.providerCtx()).InitTimeoutPeriod + params, err := providerKeeper.GetParams(suite.providerCtx()) + suite.Require().NoError(err) + initTimeout := params.InitTimeoutPeriod + chainID := suite.consumerChain.ChainID // check that the init timeout timestamp is set diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index 410837fb5b..ef072c9cb3 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -28,7 +28,8 @@ func (s *CCVTestSuite) TestRewardsDistribution() { s.providerChain.NextBlock() // register a consumer reward denom - params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + s.Require().NoError(err) params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) @@ -49,7 +50,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() { consumerFeePoolAddr := consumerAccountKeeper.GetModuleAccount(s.consumerCtx(), authtypes.FeeCollectorName).GetAddress() feePoolTokensOld := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) - err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) + err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) feePoolTokens := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) s.Require().Equal(math.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom)) @@ -139,7 +140,9 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { s.providerChain.NextBlock() // Register denom on consumer chain - params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + s.Require().NoError(err) + params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) @@ -155,7 +158,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { // fill fee pool fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) - err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), + err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) @@ -268,7 +271,8 @@ func (s *CCVTestSuite) TestEndBlockRD() { s.providerChain.NextBlock() if tc.denomRegistered { - params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) + s.Require().NoError(err) params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) } @@ -338,12 +342,13 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params := keeper.GetConsumerParams(ctx) + params, err := keeper.GetConsumerParams(ctx) + s.Require().NoError(err) params.RewardDenoms = []string{sdk.DefaultBondDenom} keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err := bankKeeper.SendCoinsFromAccountToModule( + err = bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, @@ -375,7 +380,8 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params := keeper.GetConsumerParams(ctx) + params, err := keeper.GetConsumerParams(ctx) + s.Require().NoError(err) params.RewardDenoms = []string{"uatom"} keeper.SetParams(ctx, params) @@ -391,13 +397,14 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params := keeper.GetConsumerParams(ctx) + params, err := keeper.GetConsumerParams(ctx) + s.Require().NoError(err) params.RewardDenoms = []string{sdk.DefaultBondDenom} params.DistributionTransmissionChannel = "" keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err := bankKeeper.SendCoinsFromAccountToModule( + err = bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, @@ -414,13 +421,14 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params := keeper.GetConsumerParams(ctx) + params, err := keeper.GetConsumerParams(ctx) + s.Require().NoError(err) params.RewardDenoms = []string{sdk.DefaultBondDenom} params.ProviderFeePoolAddrStr = "" keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err := bankKeeper.SendCoinsFromAccountToModule( + err = bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index 73762b6b59..1b5ad63752 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -308,7 +308,8 @@ func (s *CCVTestSuite) TestPacketSpam() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = "0.75" // Allow 3/4 of validators to be jailed providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -376,7 +377,8 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = "0.1" providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -469,7 +471,8 @@ func (s *CCVTestSuite) TestQueueOrdering() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = "0.05" // 5% total power can be jailed providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -706,7 +709,8 @@ func (s *CCVTestSuite) TestSlashMeterAllowanceChanges() { s.Require().Equal(int64(200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64()) // Now we change replenish fraction and assert new expected allowance. - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = "0.3" providerKeeper.SetParams(s.providerCtx(), params) s.Require().Equal(int64(1200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64()) @@ -725,7 +729,8 @@ func (s *CCVTestSuite) TestSlashSameValidator() { providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling) - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -785,7 +790,8 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no throttling) - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -939,7 +945,9 @@ func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() { providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no jail throttling) - params := providerKeeper.GetParams(s.providerCtx()) + params, err := providerKeeper.GetParams(s.providerCtx()) + s.Require().NoError(err) + params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index d808689436..59e7be67ae 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -19,6 +19,7 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -116,8 +117,7 @@ func NewMockedKeepers(ctrl *gomock.Controller) MockedKeepers { func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) providerkeeper.Keeper { return providerkeeper.NewKeeper( params.Cdc, - params.StoreKey, - *params.ParamsSubspace, + runtime.NewKVStoreService(params.StoreKey), mocks.MockScopedKeeper, mocks.MockChannelKeeper, mocks.MockPortKeeper, @@ -139,8 +139,7 @@ func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) provi func NewInMemConsumerKeeper(params InMemKeeperParams, mocks MockedKeepers) consumerkeeper.Keeper { return consumerkeeper.NewKeeper( params.Cdc, - params.StoreKey, - *params.ParamsSubspace, + runtime.NewKVStoreService(params.StoreKey), mocks.MockScopedKeeper, mocks.MockChannelKeeper, mocks.MockPortKeeper, diff --git a/x/ccv/consumer/ibc_module_test.go b/x/ccv/consumer/ibc_module_test.go index b84c30b117..1005bca573 100644 --- a/x/ccv/consumer/ibc_module_test.go +++ b/x/ccv/consumer/ibc_module_test.go @@ -1,6 +1,7 @@ package consumer_test import ( + "fmt" "testing" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" @@ -226,7 +227,10 @@ func TestOnChanOpenAck(t *testing.T) { transfertypes.PortID, "", // signer unused ) - + err := keeper.SetParams(params.ctx, ccv.DefaultParams()) + if err != nil { + panic(fmt.Sprintf("Setting params failed %v", err)) + } transferChannelID := "" keeper.SetDistributionTransmissionChannel(params.ctx, transferChannelID) diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index 64240990cb..b60bd61afe 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -204,10 +204,10 @@ func (k Keeper) AllowedRewardDenoms(ctx sdk.Context) []string { } func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmissionBlockHeight { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.LastDistributionTransmissionKey()) + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.LastDistributionTransmissionKey()) ltbh := ccv.LastTransmissionBlockHeight{} - if bz != nil { + if err == nil && bz != nil { if err := ltbh.Unmarshal(bz); err != nil { panic(fmt.Errorf("failed to unmarshal LastTransmissionBlockHeight: %w", err)) } @@ -216,7 +216,7 @@ func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmis } func (k Keeper) SetLastTransmissionBlockHeight(ctx sdk.Context, ltbh ccv.LastTransmissionBlockHeight) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := ltbh.Marshal() if err != nil { panic(fmt.Errorf("failed to marshal LastTransmissionBlockHeight: %w", err)) diff --git a/x/ccv/consumer/keeper/genesis.go b/x/ccv/consumer/keeper/genesis.go index 2ac38f650c..ca5c60515f 100644 --- a/x/ccv/consumer/keeper/genesis.go +++ b/x/ccv/consumer/keeper/genesis.go @@ -116,7 +116,11 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.Val // ExportGenesis returns the CCV consumer module's exported genesis func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) { - params := k.GetConsumerParams(ctx) + params, err := k.GetConsumerParams(ctx) + if err != nil { + panic(fmt.Sprintf("failed getting consumer parameters: %v", err)) + } + if !params.Enabled { return ccv.DefaultGenesisState() } diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 6bb67b10c3..7cae90b0d8 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -125,7 +125,9 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs) require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address) - require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) + params, err := ck.GetConsumerParams(ctx) + require.NoError(t, err) + require.Equal(t, gs.Params, params) }, }, { "restart a chain without an established CCV channel", @@ -157,7 +159,9 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs) assertProviderClientID(t, ctx, &ck, provClientID) require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address) - require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) + params, err := ck.GetConsumerParams(ctx) + require.NoError(t, err) + require.Equal(t, gs.Params, params) }, }, { "restart a chain with an established CCV channel", @@ -206,7 +210,9 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, updatedHeightValsetUpdateIDs) assertProviderClientID(t, ctx, &ck, provClientID) - require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) + params, err := ck.GetConsumerParams(ctx) + require.NoError(t, err) + require.Equal(t, gs.Params, params) }, }, } diff --git a/x/ccv/consumer/keeper/grpc_query.go b/x/ccv/consumer/keeper/grpc_query.go index 80e6b695a9..7c0be1a7ab 100644 --- a/x/ccv/consumer/keeper/grpc_query.go +++ b/x/ccv/consumer/keeper/grpc_query.go @@ -36,7 +36,10 @@ func (k Keeper) QueryParams(c context.Context, //nolint:golint return nil, status.Errorf(codes.InvalidArgument, "empty request") } - p := k.GetConsumerParams(ctx) + p, err := k.GetConsumerParams(ctx) + if err != nil { + return nil, status.Errorf(codes.NotFound, "no consumer parameters found") + } return &types.QueryParamsResponse{Params: p}, nil } diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 84167e61f8..624a4a2ebc 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -19,7 +19,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -36,10 +35,9 @@ type Keeper struct { // should be the x/gov module account. authority string - storeKey storetypes.StoreKey // TODO: maybe needs to be removed? - storeService store.KVStoreService - cdc codec.BinaryCodec - paramStore paramtypes.Subspace + storeService store.KVStoreService + cdc codec.BinaryCodec + //paramStore paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -65,7 +63,7 @@ type Keeper struct { // NOTE: the feeCollectorName is in reference to the consumer-chain fee // collector (and not the provider chain) func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, + cdc codec.BinaryCodec, storeService store.KVStoreService, scopedKeeper ccv.ScopedKeeper, channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper, connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper, @@ -74,16 +72,10 @@ func NewKeeper( feeCollectorName, authority string, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, ) Keeper { - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(ccv.ParamKeyTable()) - } - k := Keeper{ authority: authority, - storeKey: key, + storeService: storeService, cdc: cdc, - paramStore: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -104,61 +96,57 @@ func NewKeeper( return k } -// Returns a keeper with cdc, key and paramSpace set it does not raise any panics during registration (eg with IBCKeeper). +// Returns a keeper with cdc, key it does not raise any panics during registration (eg with IBCKeeper). // Used only in testing. -func NewNonZeroKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace) Keeper { +func NewNonZeroKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService) Keeper { return Keeper{ - storeKey: key, - cdc: cdc, - paramStore: paramSpace, + storeService: storeService, + cdc: cdc, } } +func (k *Keeper) GetAuthority() string { + return k.authority +} + // SetStandaloneStakingKeeper sets the standalone staking keeper for the consumer chain. // This method should only be called for previously standalone chains that are now consumers. func (k *Keeper) SetStandaloneStakingKeeper(sk ccv.StakingKeeper) { k.standaloneStakingKeeper = sk } -// SetParamSpace sets the param space for the consumer keeper. -// Note: this is only used for testing! -func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { - k.paramStore = ps -} - // Validates that the consumer keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation // TODO: @MSalopek hangle this better - if reflect.ValueOf(k).NumField() != 20 { - panic(fmt.Sprintf("number of fields in consumer keeper is not 19 - have %d", reflect.ValueOf(k).NumField())) // incorrect number + if reflect.ValueOf(k).NumField() != 18 { + panic(fmt.Sprintf("number of fields in consumer keeper is not 18 - have %d", reflect.ValueOf(k).NumField())) // incorrect number } if k.validatorAddressCodec == nil || k.consensusAddressCodec == nil { panic("validator and/or consensus address codec are nil") } - // Note 17 / 20 fields will be validated, + // Note 16 / 20 fields will be validated, // hooks are explicitly set after the constructor, // stakingKeeper is optionally set after the constructor, - ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 1 + ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 1 ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 2 - ccv.PanicIfZeroOrNil(k.paramStore, "paramStore") // 3 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 9 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 10 - ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 11 - ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 12 - ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 13 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 7 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 8 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 9 + ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 10 + ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 11 + ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 12 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 } // Logger returns a module-specific logger. @@ -214,13 +202,17 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { // GetPort returns the portID for the transfer module. Used in ExportGenesis func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey())) + store := k.storeService.OpenKVStore(ctx) + port, err := store.Get(types.PortKey()) + if err != nil || port == nil { + return "" + } + return string(port) } // SetPort sets the portID for the CCV module. Used in InitGenesis func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.PortKey(), []byte(portID)) } @@ -237,15 +229,15 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // SetProviderClientID sets the clientID for the client to the provider. // Set in InitGenesis func (k Keeper) SetProviderClientID(ctx sdk.Context, clientID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.ProviderClientIDKey(), []byte(clientID)) } // GetProviderClientID gets the clientID for the client to the provider. func (k Keeper) GetProviderClientID(ctx sdk.Context) (string, bool) { - store := ctx.KVStore(k.storeKey) - clientIdBytes := store.Get(types.ProviderClientIDKey()) - if clientIdBytes == nil { + store := k.storeService.OpenKVStore(ctx) + clientIdBytes, err := store.Get(types.ProviderClientIDKey()) + if err != nil || clientIdBytes == nil { return "", false } return string(clientIdBytes), true @@ -253,15 +245,15 @@ func (k Keeper) GetProviderClientID(ctx sdk.Context) (string, bool) { // SetProviderChannel sets the channelID for the channel to the provider. func (k Keeper) SetProviderChannel(ctx sdk.Context, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.ProviderChannelKey(), []byte(channelID)) } // GetProviderChannel gets the channelID for the channel to the provider. func (k Keeper) GetProviderChannel(ctx sdk.Context) (string, bool) { - store := ctx.KVStore(k.storeKey) - channelIdBytes := store.Get(types.ProviderChannelKey()) - if len(channelIdBytes) == 0 { + store := k.storeService.OpenKVStore(ctx) + channelIdBytes, err := store.Get(types.ProviderChannelKey()) + if err != nil || len(channelIdBytes) == 0 { return "", false } return string(channelIdBytes), true @@ -269,13 +261,13 @@ func (k Keeper) GetProviderChannel(ctx sdk.Context) (string, bool) { // DeleteProviderChannel deletes the channelID for the channel to the provider. func (k Keeper) DeleteProviderChannel(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ProviderChannelKey()) } // SetPendingChanges sets the pending validator set change packet that haven't been flushed to ABCI func (k Keeper) SetPendingChanges(ctx sdk.Context, updates ccv.ValidatorSetChangePacketData) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := updates.Marshal() if err != nil { // This should never happen @@ -286,9 +278,9 @@ func (k Keeper) SetPendingChanges(ctx sdk.Context, updates ccv.ValidatorSetChang // GetPendingChanges gets the pending changes that haven't been flushed over ABCI func (k Keeper) GetPendingChanges(ctx sdk.Context) (*ccv.ValidatorSetChangePacketData, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingChangesKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PendingChangesKey()) + if err != nil || bz == nil { return nil, false } var data ccv.ValidatorSetChangePacketData @@ -302,14 +294,14 @@ func (k Keeper) GetPendingChanges(ctx sdk.Context) (*ccv.ValidatorSetChangePacke // DeletePendingChanges deletes the pending changes after they've been flushed to ABCI func (k Keeper) DeletePendingChanges(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.PendingChangesKey()) } func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.InitGenesisHeightKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.InitGenesisHeightKey()) + if err != nil || bz == nil { panic("last standalone height not set") } height := sdk.BigEndianToUint64(bz) @@ -318,29 +310,29 @@ func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 { func (k Keeper) SetInitGenesisHeight(ctx sdk.Context, height int64) { bz := sdk.Uint64ToBigEndian(uint64(height)) - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.InitGenesisHeightKey(), bz) } func (k Keeper) IsPreCCV(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PreCCVKey()) - return bz != nil + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PreCCVKey()) + return err == nil && bz != nil } func (k Keeper) SetPreCCVTrue(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz := sdk.Uint64ToBigEndian(uint64(1)) store.Set(types.PreCCVKey(), bz) } func (k Keeper) DeletePreCCV(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.PreCCVKey()) } func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.ValidatorUpdate) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) initialValSetState := ccv.GenesisState{ InitialValSet: initialValSet, } @@ -349,10 +341,10 @@ func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.Valida } func (k Keeper) GetInitialValSet(ctx sdk.Context) []tmtypes.ValidatorUpdate { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) initialValSet := ccv.GenesisState{} - bz := store.Get(types.InitialValSetKey()) - if bz != nil { + bz, err := store.Get(types.InitialValSetKey()) + if err == nil && bz != nil { k.cdc.MustUnmarshal(bz, &initialValSet) return initialValSet.InitialValSet } @@ -369,8 +361,13 @@ func (k Keeper) GetLastStandaloneValidators(ctx sdk.Context) ([]stakingtypes.Val // GetElapsedPacketMaturityTimes returns a slice of already elapsed PacketMaturityTimes, sorted by maturity times, // i.e., the slice contains the IDs of the matured VSCPackets. func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PacketMaturityTimeBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting elapsed PacketMaturityTimes: %v", err) + return []ccv.MaturingVSCPacket{} + } defer iterator.Close() @@ -401,8 +398,13 @@ func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPacke // Thus, the returned array is in ascending order of maturityTimes. // If two entries have the same maturityTime, then they are ordered by vscID. func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PacketMaturityTimeBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all PacketMaturityTimes: %v", err) + return []ccv.MaturingVSCPacket{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -420,7 +422,7 @@ func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets [ // SetPacketMaturityTime sets the maturity time for a given received VSC packet id func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, vscId uint64, maturityTime time.Time) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) maturingVSCPacket := ccv.MaturingVSCPacket{ VscId: vscId, MaturityTime: maturityTime, @@ -438,14 +440,14 @@ func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, vscId uint64, maturityTim // // Note: this method is only used in testing. func (k Keeper) PacketMaturityTimeExists(ctx sdk.Context, vscId uint64, maturityTime time.Time) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PacketMaturityTimeKey(vscId, maturityTime)) - return bz != nil + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PacketMaturityTimeKey(vscId, maturityTime)) + return err == nil && bz != nil } // DeletePacketMaturityTimes deletes the packet maturity time for a given vscId and maturityTime func (k Keeper) DeletePacketMaturityTimes(ctx sdk.Context, vscId uint64, maturityTime time.Time) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.PacketMaturityTimeKey(vscId, maturityTime)) } @@ -474,7 +476,7 @@ func (k Keeper) VerifyProviderChain(ctx sdk.Context, connectionHops []string) er // SetHeightValsetUpdateID sets the valset update id for a given block height func (k Keeper) SetHeightValsetUpdateID(ctx sdk.Context, height, valsetUpdateId uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) valBytes := make([]byte, 8) binary.BigEndian.PutUint64(valBytes, valsetUpdateId) store.Set(types.HeightValsetUpdateIDKey(height), valBytes) @@ -482,9 +484,9 @@ func (k Keeper) SetHeightValsetUpdateID(ctx sdk.Context, height, valsetUpdateId // GetHeightValsetUpdateID gets the valset update id recorded for a given block height func (k Keeper) GetHeightValsetUpdateID(ctx sdk.Context, height uint64) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.HeightValsetUpdateIDKey(height)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.HeightValsetUpdateIDKey(height)) + if err != nil || bz == nil { return 0 } return binary.BigEndian.Uint64(bz) @@ -492,7 +494,7 @@ func (k Keeper) GetHeightValsetUpdateID(ctx sdk.Context, height uint64) uint64 { // DeleteHeightValsetUpdateID deletes the valset update id for a given block height func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.HeightValsetUpdateIDKey(height)) } @@ -502,8 +504,13 @@ func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { // HeightValsetUpdateIDBytePrefix | height // Thus, the returned array is in ascending order of heights. func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUpdateIDs []ccv.HeightToValsetUpdateID) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.HeightValsetUpdateIDBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.HeightValsetUpdateIDBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all heights to ValSet IDs: %v", err) + return []ccv.HeightToValsetUpdateID{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -521,14 +528,14 @@ func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUp // OutstandingDowntime returns the outstanding downtime flag for a given validator func (k Keeper) OutstandingDowntime(ctx sdk.Context, address sdk.ConsAddress) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.OutstandingDowntimeKey(address)) - return bz != nil + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.OutstandingDowntimeKey(address)) + return err == nil && bz != nil } // SetOutstandingDowntime sets the outstanding downtime flag for a given validator func (k Keeper) SetOutstandingDowntime(ctx sdk.Context, address sdk.ConsAddress) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.OutstandingDowntimeKey(address), []byte{}) } @@ -538,7 +545,7 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { if err != nil { return // TODO: this should panic with appropriate tests to validate the panic wont happen in normal cases. } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.OutstandingDowntimeKey(consAddr)) } @@ -548,8 +555,13 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { // OutstandingDowntimeBytePrefix | consAddress // Thus, the returned array is in ascending order of consAddresses. func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []ccv.OutstandingDowntime) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.OutstandingDowntimeBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.OutstandingDowntimeBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting validator addresses of outstanding downtimes: %v", err) + return []ccv.OutstandingDowntime{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -566,7 +578,7 @@ func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []ccv.Out // SetCCValidator sets a cross-chain validator under its validator address func (k Keeper) SetCCValidator(ctx sdk.Context, v types.CrossChainValidator) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz := k.cdc.MustMarshal(&v) store.Set(types.CrossChainValidatorKey(v.Address), bz) @@ -574,9 +586,9 @@ func (k Keeper) SetCCValidator(ctx sdk.Context, v types.CrossChainValidator) { // GetCCValidator returns a cross-chain validator for a given address func (k Keeper) GetCCValidator(ctx sdk.Context, addr []byte) (validator types.CrossChainValidator, found bool) { - store := ctx.KVStore(k.storeKey) - v := store.Get(types.CrossChainValidatorKey(addr)) - if v == nil { + store := k.storeService.OpenKVStore(ctx) + v, err := store.Get(types.CrossChainValidatorKey(addr)) + if err != nil || v == nil { return } k.cdc.MustUnmarshal(v, &validator) @@ -587,7 +599,7 @@ func (k Keeper) GetCCValidator(ctx sdk.Context, addr []byte) (validator types.Cr // DeleteCCValidator deletes a cross-chain validator for a given address func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.CrossChainValidatorKey(addr)) } @@ -597,10 +609,15 @@ func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { // CrossChainValidatorBytePrefix | address // Thus, the returned array is in ascending order of addresses. func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChainValidator) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.CrossChainValidatorBytePrefix}) - + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.CrossChainValidatorBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all cross-chain validators: %v", err) + return []types.CrossChainValidator{} + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { val := types.CrossChainValidator{} k.cdc.MustUnmarshal(iterator.Value(), &val) @@ -613,9 +630,13 @@ func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChai // Implement from stakingkeeper interface func (k Keeper) GetAllValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := sdkCtx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(sdkCtx) - iterator := storetypes.KVStorePrefixIterator(store, stakingtypes.ValidatorsKey) + prefix := stakingtypes.ValidatorsKey + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + return nil, err + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -629,9 +650,9 @@ func (k Keeper) GetAllValidators(ctx context.Context) (validators []stakingtypes // getAndIncrementPendingPacketsIdx returns the current pending packets index and increments it. // This index is used for implementing a FIFO queue of pending packets in the KV store. func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingPacketsIndexKey()) - if bz != nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PendingPacketsIndexKey()) + if err == nil && bz != nil { toReturn = sdk.BigEndianToUint64(bz) } toStore := toReturn + 1 @@ -641,8 +662,13 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint // DeleteHeadOfPendingPackets deletes the head of the pending packets queue. func (k Keeper) DeleteHeadOfPendingPackets(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PendingDataPacketsBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error deleting the head of pending packets: %v", err) + return + } defer iterator.Close() if !iterator.Valid() { return @@ -673,11 +699,17 @@ type ConsumerPacketDataWithIdx struct { // with indexes relevant to the pending packets queue. func (k Keeper) GetAllPendingPacketsWithIdx(ctx sdk.Context) []ConsumerPacketDataWithIdx { packets := []ConsumerPacketDataWithIdx{} - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + prefix := []byte{types.PendingDataPacketsBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all pending consumer packets: %v", err) + return []ConsumerPacketDataWithIdx{} + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { var packet ccv.ConsumerPacketData bz := iterator.Value() @@ -698,17 +730,22 @@ func (k Keeper) GetAllPendingPacketsWithIdx(ctx sdk.Context) []ConsumerPacketDat // DeletePendingDataPackets deletes pending data packets with given indexes func (k Keeper) DeletePendingDataPackets(ctx sdk.Context, idxs ...uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) for _, idx := range idxs { store.Delete(types.PendingDataPacketsKey(idx)) } } func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) + prefix := []byte{types.PendingDataPacketsBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error deleting all pending data packets: %v", err) + return + } keysToDel := [][]byte{} defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -723,7 +760,7 @@ func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { func (k Keeper) AppendPendingPacket(ctx sdk.Context, packetType ccv.ConsumerPacketDataType, data ccv.ExportedIsConsumerPacketData_Data) { idx := k.getAndIncrementPendingPacketsIdx(ctx) // for FIFO queue key := types.PendingDataPacketsKey(idx) - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) cpd := ccv.NewConsumerPacketData(packetType, data) bz, err := cpd.Marshal() if err != nil { @@ -734,11 +771,13 @@ func (k Keeper) AppendPendingPacket(ctx sdk.Context, packetType ccv.ConsumerPack } func (k Keeper) MarkAsPrevStandaloneChain(ctx sdk.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.PrevStandaloneChainKey(), []byte{}) } func (k Keeper) IsPrevStandaloneChain(ctx sdk.Context) bool { - store := ctx.KVStore(k.storeKey) - return store.Has(types.PrevStandaloneChainKey()) + store := k.storeService.OpenKVStore(ctx) + + exists, err := store.Has(types.PrevStandaloneChainKey()) + return err == nil && exists } diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 361bb2a62f..929082b9c8 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -28,13 +28,13 @@ func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subs func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { // deserialize packet data from old format var depreciatedType ccvtypes.ConsumerPacketDataList - store := ctx.KVStore(k.storeKey) - bz := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) + if err != nil || bz == nil { ctx.Logger().Info("no pending data packets to migrate") return } - err := depreciatedType.Unmarshal(bz) + err = depreciatedType.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong panic(fmt.Errorf("failed to unmarshal pending data packets: %w", err)) @@ -60,7 +60,7 @@ func PendingDataPacketsKeyOnlyForTesting() []byte { // Note: a better test of the old functionality would be to directly reference the old ICS version, // including the version of ccv.ConsumerPacketDataList has a list of ccv.ConsumerPacketData without indexes. func (k Keeper) SetPendingPacketsOnlyForTesting(ctx sdk.Context, packets ccvtypes.ConsumerPacketDataList) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := packets.Marshal() if err != nil { // This should never happen diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index 9bd0d1fa10..7950efc8bf 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -7,31 +7,31 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetParams returns the params for the consumer ccv module // NOTE: it is different from the GetParams method which is required to implement StakingKeeper interface -func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params { - return ccvtypes.NewParams( - k.GetEnabled(ctx), - k.GetBlocksPerDistributionTransmission(ctx), - k.GetDistributionTransmissionChannel(ctx), - k.GetProviderFeePoolAddrStr(ctx), - k.GetCCVTimeoutPeriod(ctx), - k.GetTransferTimeoutPeriod(ctx), - k.GetConsumerRedistributionFrac(ctx), - k.GetHistoricalEntries(ctx), - k.GetUnbondingPeriod(ctx), - k.GetSoftOptOutThreshold(ctx), - k.GetRewardDenoms(ctx), - k.GetProviderRewardDenoms(ctx), - ) +func (k Keeper) GetConsumerParams(ctx sdk.Context) (ccvtypes.Params, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ParametersKey()) + if err != nil { + return ccvtypes.Params{}, err //TODO @bermuell: check if default arguments or error handling should be done + } + var params ccvtypes.Params + k.cdc.MustUnmarshal(bz, ¶ms) + return params, nil } // SetParams sets the paramset for the consumer module -func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) { - k.paramStore.SetParamSet(ctx, ¶ms) +func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) error { + if err := params.Validate(); err != nil { + return err + } + store := k.storeService.OpenKVStore(ctx) + bz := k.cdc.MustMarshal(¶ms) + return store.Set(types.ParametersKey(), bz) } // GetParams implements StakingKeeper GetParams interface method @@ -44,98 +44,164 @@ func (k Keeper) GetParams(context.Context) (stakingtypes.Params, error) { // GetEnabled returns the enabled flag for the consumer module func (k Keeper) GetEnabled(ctx sdk.Context) bool { - var enabled bool - k.paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) - return enabled + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'enabled': %v", err) + return ccvtypes.Params{}.Enabled + } + return params.Enabled } func (k Keeper) GetBlocksPerDistributionTransmission(ctx sdk.Context) int64 { - var bpdt int64 - k.paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) - return bpdt + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'BlocksPerDistributionTransmission': %v", err) + return ccvtypes.Params{}.BlocksPerDistributionTransmission + } + + return params.BlocksPerDistributionTransmission } func (k Keeper) SetBlocksPerDistributionTransmission(ctx sdk.Context, bpdt int64) { - k.paramStore.Set(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, bpdt) + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error setting parameter 'BlocksPerDistributionTransmission': %v", err) + return + } + params.BlocksPerDistributionTransmission = bpdt + k.SetParams(ctx, params) } func (k Keeper) GetDistributionTransmissionChannel(ctx sdk.Context) string { - var s string - k.paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) - return s + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'DistributionTransmissionChannel': %v", err) + return ccvtypes.Params{}.DistributionTransmissionChannel + } + return params.DistributionTransmissionChannel } func (k Keeper) SetDistributionTransmissionChannel(ctx sdk.Context, channel string) { - k.paramStore.Set(ctx, ccvtypes.KeyDistributionTransmissionChannel, channel) + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error setting parameter 'DistributionTransmissionChannel': %v", err) + return + } + params.DistributionTransmissionChannel = channel + k.SetParams(ctx, params) } func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string { - var s string - k.paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) - return s + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'ProviderFeePoolAddrStr': %v", err) + return ccvtypes.Params{}.ProviderFeePoolAddrStr + } + return params.ProviderFeePoolAddrStr + } func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) { - k.paramStore.Set(ctx, ccvtypes.KeyProviderFeePoolAddrStr, addr) + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error setting parameter 'ProviderFeePoolAddrStr': %v", err) + return + } + params.ProviderFeePoolAddrStr = addr + k.SetParams(ctx, params) } // GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err) + return ccvtypes.Params{}.CcvTimeoutPeriod + } + return params.CcvTimeoutPeriod } // GetTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) - return p + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'TransferTimeoutPeriod': %v", err) + return ccvtypes.Params{}.TransferTimeoutPeriod + } + return params.TransferTimeoutPeriod + } // GetConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution // address during distribution events. The fraction is a string representing a // decimal number. For example "0.75" would represent 75%. func (k Keeper) GetConsumerRedistributionFrac(ctx sdk.Context) string { - var str string - k.paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) - return str + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'ConsumerRedistributionFraction': %v", err) + return ccvtypes.Params{}.ConsumerRedistributionFraction + } + return params.ConsumerRedistributionFraction + } // GetHistoricalEntries returns the number of historical info entries to persist in store func (k Keeper) GetHistoricalEntries(ctx sdk.Context) int64 { - var n int64 - k.paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) - return n + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'HistoricalEntries': %v", err) + return ccvtypes.Params{}.HistoricalEntries + } + return params.HistoricalEntries } // Only used to set an unbonding period in diff tests +// TODO @bermuell: move this to testutil func (k Keeper) SetUnbondingPeriod(ctx sdk.Context, period time.Duration) { - k.paramStore.Set(ctx, ccvtypes.KeyConsumerUnbondingPeriod, period) + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error setting parameter 'UnbondingPeriod': %v", err) + return + } + params.UnbondingPeriod = period + k.SetParams(ctx, params) } +// GetUnbondingPeriod returns the unbonding period of the consumer func (k Keeper) GetUnbondingPeriod(ctx sdk.Context) time.Duration { - var period time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) - return period + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err) + return ccvtypes.Params{}.UnbondingPeriod + } + return params.UnbondingPeriod } // GetSoftOptOutThreshold returns the percentage of validators at the bottom of the set // that can opt out of running the consumer chain func (k Keeper) GetSoftOptOutThreshold(ctx sdk.Context) string { - var str string - k.paramStore.Get(ctx, ccvtypes.KeySoftOptOutThreshold, &str) - return str + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'SoftOptOutThreshold': %v", err) + return ccvtypes.Params{}.SoftOptOutThreshold + } + return params.SoftOptOutThreshold } func (k Keeper) GetRewardDenoms(ctx sdk.Context) []string { - var denoms []string - k.paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) - return denoms + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'RewardDenoms': %v", err) + return ccvtypes.Params{}.RewardDenoms + } + return params.RewardDenoms } func (k Keeper) GetProviderRewardDenoms(ctx sdk.Context) []string { - var denoms []string - k.paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) - return denoms + params, err := k.GetConsumerParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err) + return ccvtypes.Params{}.ProviderRewardDenoms + } + return params.ProviderRewardDenoms } diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index 49b1816520..919980acde 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -33,14 +33,16 @@ func TestParams(t *testing.T) { provideRewardDenoms, ) // these are the default params, IBC suite independently sets enabled=true - params := consumerKeeper.GetConsumerParams(ctx) + params, err := consumerKeeper.GetConsumerParams(ctx) + require.NoError(t, err) require.Equal(t, expParams, params) newParams := ccv.NewParams(false, 1000, "channel-2", "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", 7*24*time.Hour, 25*time.Hour, "0.5", 500, 24*21*time.Hour, "0.05", []string{"untrn"}, []string{"uatom"}) consumerKeeper.SetParams(ctx, newParams) - params = consumerKeeper.GetConsumerParams(ctx) + params, err = consumerKeeper.GetConsumerParams(ctx) + require.NoError(t, err) require.Equal(t, newParams, params) consumerKeeper.SetBlocksPerDistributionTransmission(ctx, 10) diff --git a/x/ccv/consumer/keeper/soft_opt_out.go b/x/ccv/consumer/keeper/soft_opt_out.go index 41460e7917..c9c2607ac5 100644 --- a/x/ccv/consumer/keeper/soft_opt_out.go +++ b/x/ccv/consumer/keeper/soft_opt_out.go @@ -12,7 +12,7 @@ import ( // SetSmallestNonOptOutPower sets the smallest validator power that cannot soft opt out. func (k Keeper) SetSmallestNonOptOutPower(ctx sdk.Context, power uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.SmallestNonOptOutPowerKey(), sdk.Uint64ToBigEndian(power)) } @@ -67,9 +67,9 @@ func (k Keeper) UpdateSmallestNonOptOutPower(ctx sdk.Context) { // GetSmallestNonOptOutPower returns the smallest validator power that cannot soft opt out. func (k Keeper) GetSmallestNonOptOutPower(ctx sdk.Context) int64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.SmallestNonOptOutPowerKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.SmallestNonOptOutPowerKey()) + if err != nil || bz == nil { return 0 } return int64(binary.BigEndian.Uint64(bz)) diff --git a/x/ccv/consumer/keeper/throttle_retry.go b/x/ccv/consumer/keeper/throttle_retry.go index 4c4585cb1d..5d43e71beb 100644 --- a/x/ccv/consumer/keeper/throttle_retry.go +++ b/x/ccv/consumer/keeper/throttle_retry.go @@ -83,12 +83,12 @@ func (k Keeper) UpdateSlashRecordOnBounce(ctx sdktypes.Context) { } func (k Keeper) GetSlashRecord(ctx sdktypes.Context) (record consumertypes.SlashRecord, found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(consumertypes.SlashRecordKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(consumertypes.SlashRecordKey()) + if err != nil || bz == nil { return record, false } - err := record.Unmarshal(bz) + err = record.Unmarshal(bz) if err != nil { // This should never happen panic(fmt.Sprintf("could not unmarshal slash record: %v", err)) @@ -97,7 +97,7 @@ func (k Keeper) GetSlashRecord(ctx sdktypes.Context) (record consumertypes.Slash } func (k Keeper) SetSlashRecord(ctx sdktypes.Context, record consumertypes.SlashRecord) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := record.Marshal() if err != nil { // This should never happen @@ -107,6 +107,6 @@ func (k Keeper) SetSlashRecord(ctx sdktypes.Context, record consumertypes.SlashR } func (k Keeper) ClearSlashRecord(ctx sdktypes.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(consumertypes.SlashRecordKey()) } diff --git a/x/ccv/consumer/keeper/validators.go b/x/ccv/consumer/keeper/validators.go index ce2d726ca2..72dc077df8 100644 --- a/x/ccv/consumer/keeper/validators.go +++ b/x/ccv/consumer/keeper/validators.go @@ -207,11 +207,11 @@ func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) { // GetHistoricalInfo gets the historical info at a given height func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := sdkCtx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(sdkCtx) key := types.HistoricalInfoKey(height) - value := store.Get(key) - if value == nil { + value, err := store.Get(key) + if err != nil || value == nil { return stakingtypes.HistoricalInfo{}, stakingtypes.ErrNoHistoricalInfo } @@ -221,7 +221,7 @@ func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (stakingtyp // SetHistoricalInfo sets the historical info at a given height func (k Keeper) SetHistoricalInfo(ctx context.Context, height int64, hi *stakingtypes.HistoricalInfo) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := sdkCtx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(sdkCtx) key := types.HistoricalInfoKey(height) value := k.cdc.MustMarshal(hi) @@ -231,7 +231,7 @@ func (k Keeper) SetHistoricalInfo(ctx context.Context, height int64, hi *staking // DeleteHistoricalInfo deletes the historical info at a given height func (k Keeper) DeleteHistoricalInfo(ctx context.Context, height int64) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := sdkCtx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(sdkCtx) key := types.HistoricalInfoKey(height) store.Delete(key) diff --git a/x/ccv/provider/keeper/distribution.go b/x/ccv/provider/keeper/distribution.go index 2cf6ef08f6..c0c2b56d39 100644 --- a/x/ccv/provider/keeper/distribution.go +++ b/x/ccv/provider/keeper/distribution.go @@ -1,9 +1,8 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" - storetypes "cosmossdk.io/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ) @@ -25,31 +24,38 @@ func (k Keeper) SetConsumerRewardDenom( ctx sdk.Context, denom string, ) { - store := ctx.KVStore(k.storeKey) - store.Set(types.ConsumerRewardDenomsKey(denom), []byte{}) + store := k.storeService.OpenKVStore(ctx) + err := store.Set(types.ConsumerRewardDenomsKey(denom), []byte{}) + if err != nil { + k.Logger(ctx).Error("Error setting consumer reward denoms: %v", err) + } } func (k Keeper) ConsumerRewardDenomExists( ctx sdk.Context, denom string, ) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerRewardDenomsKey(denom)) - return bz != nil + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerRewardDenomsKey(denom)) + return err == nil && bz != nil } func (k Keeper) DeleteConsumerRewardDenom( ctx sdk.Context, denom string, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ConsumerRewardDenomsKey(denom)) } func (k Keeper) GetAllConsumerRewardDenoms(ctx sdk.Context) (consumerRewardDenoms []string) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ConsumerRewardDenomsBytePrefix}) - + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.ConsumerRewardDenomsBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("Error iterating over all consumer reward denoms: %v", err) + return + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { key := iterator.Key()[1:] diff --git a/x/ccv/provider/keeper/genesis.go b/x/ccv/provider/keeper/genesis.go index e86035170c..ff0c5994e7 100644 --- a/x/ccv/provider/keeper/genesis.go +++ b/x/ccv/provider/keeper/genesis.go @@ -151,7 +151,10 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { consumerAddrsToPrune = append(consumerAddrsToPrune, k.GetAllConsumerAddrsToPrune(ctx, chain.ChainId)...) } - params := k.GetParams(ctx) + params, err := k.GetParams(ctx) + if err != nil { + panic(fmt.Errorf("error getting provider parameters: %v", err)) + } return types.NewGenesisState( k.GetValidatorSetUpdateId(ctx), diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index e8119bef0a..5e0fca96ca 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -147,7 +147,9 @@ func TestInitAndExportGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := pk.GetSlashMeter(ctx) - replenishFraction, err := math.LegacyNewDecFromStr(pk.GetParams(ctx).SlashMeterReplenishFraction) + params, err := pk.GetParams(ctx) + require.NoError(t, err) + replenishFraction, err := math.LegacyNewDecFromStr(params.SlashMeterReplenishFraction) require.NoError(t, err) expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) @@ -173,7 +175,7 @@ func TestInitAndExportGenesis(t *testing.T) { require.True(t, found) require.Equal(t, provGenesis.ConsumerAdditionProposals[0], addProp) require.True(t, pk.PendingConsumerRemovalPropExists(ctx, cChainIDs[0], oneHourFromNow)) - require.Equal(t, provGenesis.Params, pk.GetParams(ctx)) + require.Equal(t, provGenesis.Params, params) gotConsTmPubKey, found := pk.GetValidatorConsumerPubKey(ctx, cChainIDs[0], provAddr) require.True(t, found) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 996ce651cd..1a430ae8f7 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -22,7 +22,6 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" 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" "cosmossdk.io/log" @@ -38,11 +37,9 @@ type Keeper struct { // should be the x/gov module account. authority string - storeKey storetypes.StoreKey // TODO: remove storeService store.KVStoreService cdc codec.BinaryCodec - paramSpace paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -61,7 +58,7 @@ type Keeper struct { // NewKeeper creates a new provider Keeper instance func NewKeeper( - cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, scopedKeeper ccv.ScopedKeeper, + cdc codec.BinaryCodec, storeService store.KVStoreService, scopedKeeper ccv.ScopedKeeper, channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper, connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper, stakingKeeper ccv.StakingKeeper, slashingKeeper ccv.SlashingKeeper, @@ -70,16 +67,10 @@ func NewKeeper( feeCollectorName, authority string, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, ) Keeper { - // set KeyTable if it has not already been set - if !paramSpace.HasKeyTable() { - paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) - } - k := Keeper{ cdc: cdc, - storeKey: key, + storeService: storeService, authority: authority, - paramSpace: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -114,19 +105,13 @@ func (k Keeper) ConsensusAddressCodec() addresscodec.Codec { return k.consensusAddressCodec } -// SetParamSpace sets the param space for the provider keeper. -// Note: this is only used for testing! -func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { - k.paramSpace = ps -} - // TODO: @MSalopek -> redo validation; some fields will be removed // Validates that the provider keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation - if reflect.ValueOf(k).NumField() != 18 { - panic("number of fields in provider keeper is not 18") + if reflect.ValueOf(k).NumField() != 16 { + panic("number of fields in provider keeper is not 16") } // TODO: @MSalopek -> validate once connected and AccountKeeper interface is updated @@ -140,24 +125,23 @@ func (k Keeper) mustValidateFields() { } ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 1 - ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 2 - ccv.PanicIfZeroOrNil(k.paramSpace, "paramSpace") // 3 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 - ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 8 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 9 - ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 10 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 11 - ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 12 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 13 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 + ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 2 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 + ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 7 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 + ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 9 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 10 + ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 11 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 12 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 // TODO: @MSalopek -> validate once connected - // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 18 + // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 17 } // Logger returns a module-specific logger. @@ -183,14 +167,22 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { // GetPort returns the portID for the CCV module. Used in ExportGenesis func (k Keeper) GetPort(ctx sdk.Context) string { - store := ctx.KVStore(k.storeKey) - return string(store.Get(types.PortKey())) + store := k.storeService.OpenKVStore(ctx) + port, err := store.Get(types.PortKey()) + if err != nil { + k.Logger(ctx).Error("error getting port ID: %v", err) + return "" + } + return string(port) } // SetPort sets the portID for the CCV module. Used in InitGenesis func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := ctx.KVStore(k.storeKey) - store.Set(types.PortKey(), []byte(portID)) + store := k.storeService.OpenKVStore(ctx) + err := store.Set(types.PortKey(), []byte(portID)) + if err != nil { + k.Logger(ctx).Error("error setting port ID: %v", err) + } } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function @@ -206,15 +198,15 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // SetChainToChannel sets the mapping from a consumer chainID to the CCV channel ID for that consumer chain. func (k Keeper) SetChainToChannel(ctx sdk.Context, chainID, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.ChainToChannelKey(chainID), []byte(channelID)) } // GetChainToChannel gets the CCV channelID for the given consumer chainID func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ChainToChannelKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ChainToChannelKey(chainID)) + if err != nil || bz == nil { return "", false } return string(bz), true @@ -222,7 +214,7 @@ func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool // DeleteChainToChannel deletes the CCV channel ID for the given consumer chain ID func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ChainToChannelKey(chainID)) } @@ -233,8 +225,13 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { // ChainToClientBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs. func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ChainToClientBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.ChainToClientBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting consumer chains: %v", err) + return []types.Chain{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -253,15 +250,15 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { // SetChannelToChain sets the mapping from the CCV channel ID to the consumer chainID. func (k Keeper) SetChannelToChain(ctx sdk.Context, channelID, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.ChannelToChainKey(channelID), []byte(chainID)) } // GetChannelToChain gets the consumer chainID for a given CCV channelID func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ChannelToChainKey(channelID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ChannelToChainKey(channelID)) + if err != nil || bz == nil { return "", false } return string(bz), true @@ -269,7 +266,7 @@ func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bo // DeleteChannelToChain deletes the consumer chain ID for a given CCV channelID func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ChannelToChainKey(channelID)) } @@ -281,8 +278,13 @@ func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { // ChannelToChainBytePrefix | channelID // Thus, the returned array is in ascending order of channelIDs. func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.ChannelToChain) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ChannelToChainBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.ChannelToChainBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting channel to chain mapping: %v", err) + return []types.ChannelToChain{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -300,7 +302,7 @@ func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.Channel } func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.GenesisState) error { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := gen.Marshal() if err != nil { return err @@ -311,9 +313,9 @@ func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.Gene } func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.GenesisState, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerGenesisKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerGenesisKey(chainID)) + if err != nil || bz == nil { return ccv.GenesisState{}, false } @@ -327,7 +329,7 @@ func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.Genesis } func (k Keeper) DeleteConsumerGenesis(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ConsumerGenesisKey(chainID)) } @@ -408,7 +410,7 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { // SetUnbondingOp sets the UnbondingOp by its unique ID func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := unbondingOp.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -422,9 +424,9 @@ func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { // GetUnbondingOp gets a UnbondingOp by its unique ID func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.UnbondingOpKey(id)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.UnbondingOpKey(id)) + if err != nil || bz == nil { return types.UnbondingOp{}, false } @@ -440,7 +442,7 @@ func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, b // DeleteUnbondingOp deletes a UnbondingOp given its ID func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.UnbondingOpKey(id)) } @@ -452,8 +454,13 @@ func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { // UnbondingOpBytePrefix | ID // Thus, the iteration is in ascending order of IDs. func (k Keeper) GetAllUnbondingOps(ctx sdk.Context) (ops []types.UnbondingOp) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.UnbondingOpBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.UnbondingOpBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all UnbondingOps: %v", err) + return []types.UnbondingOp{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -519,7 +526,7 @@ func removeStringFromSlice(slice []string, x string) (newSlice []string, numRemo // SetUnbondingOpIndex sets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64, ids []uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) vscUnbondingOps := types.VscUnbondingOps{ VscId: vscID, @@ -543,8 +550,13 @@ func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 // UnbondingOpIndexBytePrefix | len(chainID) | chainID | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (indexes []types.VscUnbondingOps) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID)) + store := k.storeService.OpenKVStore(ctx) + prefix := types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID) + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all unbonding indexes: %v", err) + return []types.VscUnbondingOps{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -567,10 +579,10 @@ func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (index // GetUnbondingOpIndex gets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) ([]uint64, bool) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) - bz := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) - if bz == nil { + bz, err := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) + if err != nil || bz == nil { return []uint64{}, false } @@ -587,7 +599,7 @@ func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 // DeleteUnbondingOpIndex deletes the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) DeleteUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.UnbondingOpIndexKey(chainID, vscID)) } @@ -613,9 +625,9 @@ func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valset // GetMaturedUnbondingOps returns the list of matured unbonding operation ids func (k Keeper) GetMaturedUnbondingOps(ctx sdk.Context) (ids []uint64) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.MaturedUnbondingOpsKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.MaturedUnbondingOpsKey()) + if err != nil || bz == nil { // Note that every call to ConsumeMaturedUnbondingOps // deletes the MaturedUnbondingOpsKey, which means that // the first call to GetMaturedUnbondingOps after that @@ -642,7 +654,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { Ids: append(existingIds, ids...), } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := maturedOps.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -655,7 +667,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { // ConsumeMaturedUnbondingOps empties and returns list of matured unbonding operation ids (if it exists) func (k Keeper) ConsumeMaturedUnbondingOps(ctx sdk.Context) []uint64 { ids := k.GetMaturedUnbondingOps(ctx) - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.MaturedUnbondingOpsKey()) return ids } @@ -699,7 +711,7 @@ func (k Keeper) IncrementValidatorSetUpdateId(ctx sdk.Context) { } func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) // Convert back into bytes for storage bz := make([]byte, 8) @@ -709,10 +721,10 @@ func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { } func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId uint64) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ValidatorSetUpdateIdKey()) + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ValidatorSetUpdateIdKey()) - if bz == nil { + if err != nil || bz == nil { validatorSetUpdateId = 0 } else { // Unmarshal @@ -724,7 +736,7 @@ func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId u // SetValsetUpdateBlockHeight sets the block height for a given valset update id func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, blockHeight uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, blockHeight) store.Set(types.ValsetUpdateBlockHeightKey(valsetUpdateId), heightBytes) @@ -732,9 +744,9 @@ func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, bloc // GetValsetUpdateBlockHeight gets the block height for a given valset update id func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) + if err != nil || bz == nil { return 0, false } return binary.BigEndian.Uint64(bz), true @@ -746,10 +758,15 @@ func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint6 // ValsetUpdateBlockHeightBytePrefix | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlockHeights []types.ValsetUpdateIdToHeight) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ValsetUpdateBlockHeightBytePrefix}) - + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.ValsetUpdateBlockHeightBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all block heights for valset updates: %v", err) + return []types.ValsetUpdateIdToHeight{} + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { valsetUpdateId := binary.BigEndian.Uint64(iterator.Key()[1:]) height := binary.BigEndian.Uint64(iterator.Value()) @@ -765,7 +782,7 @@ func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlo // DeleteValsetUpdateBlockHeight deletes the block height value for a given vaset update id func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) } @@ -774,7 +791,7 @@ func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId ui // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) sa := types.SlashAcks{ Addresses: acks, @@ -793,9 +810,9 @@ func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 func (k Keeper) GetSlashAcks(ctx sdk.Context, chainID string) []string { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.SlashAcksKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.SlashAcksKey(chainID)) + if err != nil || bz == nil { return nil } var acks types.SlashAcks @@ -814,14 +831,14 @@ func (k Keeper) ConsumeSlashAcks(ctx sdk.Context, chainID string) (acks []string if len(acks) < 1 { return } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.SlashAcksKey(chainID)) return } // DeleteSlashAcks deletes the slash acks for a given chain ID func (k Keeper) DeleteSlashAcks(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.SlashAcksKey(chainID)) } @@ -836,7 +853,7 @@ func (k Keeper) AppendSlashAck(ctx sdk.Context, chainID, // SetInitChainHeight sets the provider block height when the given consumer chain was initiated func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, height) @@ -845,9 +862,9 @@ func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint6 // GetInitChainHeight returns the provider block height when the given consumer chain was initiated func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.InitChainHeightKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.InitChainHeightKey(chainID)) + if err != nil || bz == nil { return 0, false } @@ -856,7 +873,7 @@ func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, boo // DeleteInitChainHeight deletes the block height value for which the given consumer chain's channel was established func (k Keeper) DeleteInitChainHeight(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.InitChainHeightKey(chainID)) } @@ -864,9 +881,9 @@ func (k Keeper) DeleteInitChainHeight(ctx sdk.Context, chainID string) { func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.ValidatorSetChangePacketData { var packets types.ValidatorSetChangePackets - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingVSCsKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PendingVSCsKey(chainID)) + if err != nil || bz == nil { return []ccv.ValidatorSetChangePacketData{} } if err := packets.Unmarshal(bz); err != nil { @@ -882,7 +899,7 @@ func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.Vali func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPackets ...ccv.ValidatorSetChangePacketData) { pds := append(k.GetPendingVSCPackets(ctx, chainID), newPackets...) - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) packets := types.ValidatorSetChangePackets{List: pds} buf, err := packets.Marshal() if err != nil { @@ -895,21 +912,21 @@ func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPack // DeletePendingVSCPackets deletes the list of pending ValidatorSetChange packets for chain ID func (k Keeper) DeletePendingVSCPackets(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.PendingVSCsKey(chainID)) } // SetConsumerClientId sets the client ID for the given chain ID func (k Keeper) SetConsumerClientId(ctx sdk.Context, chainID, clientID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.ChainToClientKey(chainID), []byte(clientID)) } // GetConsumerClientId returns the client ID for the given chain ID. func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bool) { - store := ctx.KVStore(k.storeKey) - clientIdBytes := store.Get(types.ChainToClientKey(chainID)) - if clientIdBytes == nil { + store := k.storeService.OpenKVStore(ctx) + clientIdBytes, err := store.Get(types.ChainToClientKey(chainID)) + if err != nil || clientIdBytes == nil { return "", false } return string(clientIdBytes), true @@ -917,13 +934,13 @@ func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bo // DeleteConsumerClientId removes from the store the clientID for the given chainID. func (k Keeper) DeleteConsumerClientId(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ChainToClientKey(chainID)) } // SetInitTimeoutTimestamp sets the init timeout timestamp for the given chain ID func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) tsBytes := make([]byte, 8) binary.BigEndian.PutUint64(tsBytes, ts) store.Set(types.InitTimeoutTimestampKey(chainID), tsBytes) @@ -932,9 +949,9 @@ func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint // GetInitTimeoutTimestamp returns the init timeout timestamp for the given chain ID. // This method is used only in testing. func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.InitTimeoutTimestampKey(chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.InitTimeoutTimestampKey(chainID)) + if err != nil || bz == nil { return 0, false } return binary.BigEndian.Uint64(bz), true @@ -942,7 +959,7 @@ func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64 // DeleteInitTimeoutTimestamp removes from the store the init timeout timestamp for the given chainID. func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.InitTimeoutTimestampKey(chainID)) } @@ -952,8 +969,13 @@ func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { // InitTimeoutTimestampBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs (NOT in timestamp order). func (k Keeper) GetAllInitTimeoutTimestamps(ctx sdk.Context) (initTimeoutTimestamps []types.InitTimeoutTimestamp) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.InitTimeoutTimestampBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.InitTimeoutTimestampBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all init timeout timestamps: %v", err) + return []types.InitTimeoutTimestamp{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -977,7 +999,7 @@ func (k Keeper) SetVscSendTimestamp( vscID uint64, timestamp time.Time, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) // Convert timestamp into bytes for storage timeBz := sdk.FormatTimeBytes(timestamp) @@ -989,10 +1011,10 @@ func (k Keeper) SetVscSendTimestamp( // // Note: This method is used only for testing. func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) (time.Time, bool) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) - timeBz := store.Get(types.VscSendingTimestampKey(chainID, vscID)) - if timeBz == nil { + timeBz, err := store.Get(types.VscSendingTimestampKey(chainID, vscID)) + if err != nil || timeBz == nil { return time.Time{}, false } @@ -1006,7 +1028,7 @@ func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint6 // DeleteVscSendTimestamp removes from the store a specific VSC send timestamp // for the given chainID and vscID. func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.VscSendingTimestampKey(chainID, vscID)) } @@ -1016,8 +1038,13 @@ func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID ui // VscSendTimestampBytePrefix | len(chainID) | chainID | vscID // Thus, the iteration is in ascending order of vscIDs, and as a result in send timestamp order. func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSendTimestamps []types.VscSendTimestamp) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) + store := k.storeService.OpenKVStore(ctx) + prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID) + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all vsc send timestamps: %v", err) + return []types.VscSendTimestamp{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -1045,8 +1072,13 @@ func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSen // DeleteVscSendTimestampsForConsumer deletes all VSC send timestamps for a given consumer chain func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChainID string) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID)) + store := k.storeService.OpenKVStore(ctx) + prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID) + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error deleting all VSC send timestamps: %v", err) + return + } defer iterator.Close() keysToDel := [][]byte{} @@ -1062,8 +1094,13 @@ func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChai // GetFirstVscSendTimestamp gets the vsc send timestamp with the lowest vscID for the given chainID. func (k Keeper) GetFirstVscSendTimestamp(ctx sdk.Context, chainID string) (vscSendTimestamp types.VscSendTimestamp, found bool) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) + store := k.storeService.OpenKVStore(ctx) + prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID) + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting first VSC send timestamps: %v", err) + return types.VscSendTimestamp{}, false + } defer iterator.Close() if iterator.Valid() { @@ -1096,7 +1133,7 @@ func (k Keeper) SetSlashLog( ctx sdk.Context, providerAddr types.ProviderConsAddress, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Set(types.SlashLogKey(providerAddr), []byte{}) } @@ -1106,9 +1143,9 @@ func (k Keeper) GetSlashLog( ctx sdk.Context, providerAddr types.ProviderConsAddress, ) (found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.SlashLogKey(providerAddr)) - return bz != nil + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.SlashLogKey(providerAddr)) + return err == nil && bz != nil } func (k Keeper) BondDenom(ctx sdk.Context) (string, error) { diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index 564a48f305..e07cf4f623 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -22,12 +22,12 @@ func (k Keeper) GetValidatorConsumerPubKey( chainID string, providerAddr types.ProviderConsAddress, ) (consumerKey tmprotocrypto.PublicKey, found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerValidatorsKey(chainID, providerAddr)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerValidatorsKey(chainID, providerAddr)) + if err != nil || bz == nil { return consumerKey, false } - err := consumerKey.Unmarshal(bz) + err = consumerKey.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the consumer key is assumed to be correctly serialized in SetValidatorConsumerPubKey. @@ -43,7 +43,7 @@ func (k Keeper) SetValidatorConsumerPubKey( providerAddr types.ProviderConsAddress, consumerKey tmprotocrypto.PublicKey, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := consumerKey.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -62,7 +62,7 @@ func (k Keeper) SetValidatorConsumerPubKey( // - in ascending order of providerAddresses, if chainID is not nil; // - in undetermined order, if chainID is nil. func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) (validatorConsumerPubKeys []types.ValidatorConsumerPubKey) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) var prefix []byte if chainID == nil { // iterate over the validators public keys assigned for all consumer chains @@ -71,8 +71,13 @@ func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) // iterate over the validators public keys assigned for chainID prefix = types.ChainIdWithLenKey(types.ConsumerValidatorsBytePrefix, *chainID) } - iterator := storetypes.KVStorePrefixIterator(store, prefix) + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting public keys of a all validators of chain %s: %v", chainID, err) + return + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type chainID, providerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.ConsumerValidatorsBytePrefix, iterator.Key()) @@ -102,7 +107,7 @@ func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) // DeleteValidatorConsumerPubKey deletes a validator's public key assigned for a consumer chain func (k Keeper) DeleteValidatorConsumerPubKey(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ConsumerValidatorsKey(chainID, providerAddr)) } @@ -113,9 +118,9 @@ func (k Keeper) GetValidatorByConsumerAddr( chainID string, consumerAddr types.ConsumerConsAddress, ) (providerAddr types.ProviderConsAddress, found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) + if err != nil || bz == nil { return providerAddr, false } providerAddr = types.NewProviderConsAddress(bz) @@ -130,7 +135,7 @@ func (k Keeper) SetValidatorByConsumerAddr( consumerAddr types.ConsumerConsAddress, providerAddr types.ProviderConsAddress, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) // Cons address is a type alias for a byte string, no marshaling needed bz := providerAddr.ToSdkConsAddr() store.Set(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr), bz) @@ -146,7 +151,7 @@ func (k Keeper) SetValidatorByConsumerAddr( // - in ascending order of consumerAddresses, if chainID is not nil; // - in undetermined order, if chainID is nil. func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) (validatorConsumerAddrs []types.ValidatorByConsumerAddr) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) var prefix []byte if chainID == nil { // iterate over the mappings from consensus addresses on all consumer chains @@ -155,8 +160,14 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) // iterate over the mappings from consensus addresses on chainID prefix = types.ChainIdWithLenKey(types.ValidatorsByConsumerAddrBytePrefix, *chainID) } - iterator := storetypes.KVStorePrefixIterator(store, prefix) + + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all validators by consumer address: %v", err) + return []types.ValidatorByConsumerAddr{} + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and consumer cons address in value bytes, marshaled as protobuf type chainID, consumerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.ValidatorsByConsumerAddrBytePrefix, iterator.Key()) @@ -181,7 +192,7 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) // DeleteValidatorByConsumerAddr deletes the mapping from a validator's consensus address on a consumer // to the validator's consensus address on the provider func (k Keeper) DeleteValidatorByConsumerAddr(ctx sdk.Context, chainID string, consumerAddr types.ConsumerConsAddress) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) } @@ -194,13 +205,13 @@ func (k Keeper) GetKeyAssignmentReplacement( providerAddr types.ProviderConsAddress, ) (prevCKey tmprotocrypto.PublicKey, power int64, found bool) { var pubKeyAndPower abci.ValidatorUpdate - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) + if err != nil || bz == nil { return pubKeyAndPower.PubKey, pubKeyAndPower.Power, false } - err := pubKeyAndPower.Unmarshal(bz) + err = pubKeyAndPower.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the public key and power are assumed to be correctly serialized in SetKeyAssignmentReplacement. @@ -219,7 +230,7 @@ func (k Keeper) SetKeyAssignmentReplacement( prevCKey tmprotocrypto.PublicKey, power int64, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) pubKeyAndPower := abci.ValidatorUpdate{PubKey: prevCKey, Power: power} bz, err := pubKeyAndPower.Marshal() if err != nil { @@ -239,10 +250,15 @@ func (k Keeper) SetKeyAssignmentReplacement( // KeyAssignmentReplacementsBytePrefix | len(chainID) | chainID | providerAddress // Thus, the iteration is in ascending order of providerAddresses. func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) (replacements []types.KeyAssignmentReplacement) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := types.ChainIdWithLenKey(types.KeyAssignmentReplacementsBytePrefix, chainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error getting all paris of previous assigned consumer keys: %v", err) + return []types.KeyAssignmentReplacement{} + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type _, providerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.KeyAssignmentReplacementsBytePrefix, iterator.Key()) @@ -274,7 +290,7 @@ func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) // for a provider validator for which a key assignment was received in this block. Both are // needed to update the validator's power on the consumer chain at the end of the current block. func (k Keeper) DeleteKeyAssignmentReplacement(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) } @@ -287,10 +303,10 @@ func (k Keeper) DeleteKeyAssignmentReplacement(ctx sdk.Context, chainID string, // s.t. hash(ValidatorConsumerPubKey(pAddr)) = cAddr // - or there exists a vscID in ConsumerAddrsToPrune s.t. cAddr in ConsumerAddrsToPrune(vscID) func (k Keeper) AppendConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscID uint64, consumerAddr types.ConsumerConsAddress) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) var consumerAddrsToPrune types.AddressList - if bz != nil { + if err == nil && bz != nil { err := consumerAddrsToPrune.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, @@ -299,7 +315,7 @@ func (k Keeper) AppendConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscI } } consumerAddrsToPrune.Addresses = append(consumerAddrsToPrune.Addresses, consumerAddr.ToSdkConsAddr()) - bz, err := consumerAddrsToPrune.Marshal() + bz, err = consumerAddrsToPrune.Marshal() if err != nil { // An error here would indicate something is very wrong, // consumerAddrsToPrune is instantiated in this method and should be able to be marshaled. @@ -315,12 +331,12 @@ func (k Keeper) GetConsumerAddrsToPrune( chainID string, vscID uint64, ) (consumerAddrsToPrune types.AddressList) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) + if err != nil || bz == nil { return } - err := consumerAddrsToPrune.Unmarshal(bz) + err = consumerAddrsToPrune.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the list of consumer addresses is assumed to be correctly serialized in AppendConsumerAddrsToPrune. @@ -335,10 +351,15 @@ func (k Keeper) GetConsumerAddrsToPrune( // ConsumerAddrsToPruneBytePrefix | len(chainID) | chainID | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (consumerAddrsToPrune []types.ConsumerAddrsToPrune) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := types.ChainIdWithLenKey(types.ConsumerAddrsToPruneBytePrefix, chainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error getting all consumer addresses to be pruned: %v", err) + return + } defer iterator.Close() + for ; iterator.Valid(); iterator.Next() { _, vscID, err := types.ParseChainIdAndUintIdKey(types.ConsumerAddrsToPruneBytePrefix, iterator.Key()) if err != nil { @@ -366,7 +387,7 @@ func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (con // DeleteConsumerAddrsToPrune deletes the list of consumer addresses mapped to a given VSC ID func (k Keeper) DeleteConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscID uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) store.Delete(types.ConsumerAddrsToPruneKey(chainID, vscID)) } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index a0bbc27679..f15ab5ffe4 100644 --- a/x/ccv/provider/keeper/params.go +++ b/x/ccv/provider/keeper/params.go @@ -8,100 +8,136 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetTemplateClient returns the template client for provider proposals func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState { - var cs ibctmtypes.ClientState - k.paramSpace.Get(ctx, types.KeyTemplateClient, &cs) - return &cs + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'TemplateClient': %v", err) + return types.Params{}.TemplateClient + } + return params.TemplateClient } // GetTrustingPeriodFraction returns a TrustingPeriodFraction // used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) string { - var f string - k.paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) - return f + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'TrustingPeriodFraction': %v", err) + return types.Params{}.TrustingPeriodFraction + } + return params.TrustingPeriodFraction + } // GetCCVTimeoutPeriod returns the timeout period for sent ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err) + return types.Params{}.CcvTimeoutPeriod + } + return params.CcvTimeoutPeriod } // GetInitTimeoutPeriod returns the init timeout period func (k Keeper) GetInitTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeyInitTimeoutPeriod, &p) - return p + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'InitTimeoutPeriod': %v", err) + return types.Params{}.InitTimeoutPeriod + } + return params.InitTimeoutPeriod } // GetVscTimeoutPeriod returns the vsc timeout period func (k Keeper) GetVscTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeyVscTimeoutPeriod, &p) - return p + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'VscTimeoutPeriod': %v", err) + return types.Params{}.VscTimeoutPeriod + } + return params.VscTimeoutPeriod } // SetVscTimeoutPeriod sets the vsc timeout period func (k Keeper) SetVscTimeoutPeriod(ctx sdk.Context, period time.Duration) { - k.paramSpace.Set(ctx, types.KeyVscTimeoutPeriod, period) + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error setting parameter 'VscTimeoutPeriod': %v", err) + return + } + params.VscTimeoutPeriod = period + k.SetParams(ctx, params) } // GetSlashMeterReplenishPeriod returns the period in which: // Once the slash meter becomes not-full, the slash meter is replenished after this period. func (k Keeper) GetSlashMeterReplenishPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) - return p + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishPeriod': %v", err) + return types.Params{}.SlashMeterReplenishPeriod + } + return params.SlashMeterReplenishPeriod } // GetSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished // to the slash meter every replenish period. This param also serves as a maximum fraction of total // voting power that the slash meter can hold. func (k Keeper) GetSlashMeterReplenishFraction(ctx sdk.Context) string { - var f string - k.paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) - return f + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishFraction': %v", err) + return types.Params{}.SlashMeterReplenishFraction + } + return params.SlashMeterReplenishFraction } // GetMaxThrottledPackets returns the maximum amount of throttled slash or vsc matured packets // that can be queued for a single consumer before the provider chain halts. func (k Keeper) GetMaxThrottledPackets(ctx sdk.Context) int64 { - var p int64 - k.paramSpace.Get(ctx, types.KeyMaxThrottledPackets, &p) - return p + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'MaxThrottledPackets': %v", err) + return types.Params{}.MaxThrottledPackets + } + return params.MaxThrottledPackets } func (k Keeper) GetConsumerRewardDenomRegistrationFee(ctx sdk.Context) sdk.Coin { // Due to difficulties doing migrations in coordinated upgrades, this param is hardcoded to 10 ATOM in v1.1.0-multiden. // The below code is the proper way to store the param. A future scheduled upgrade will // need to run migrations to add the param. This will allow us to change the fee by governance. - var c sdk.Coin - k.paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) - return c + params, err := k.GetParams(ctx) + if err != nil { + k.Logger(ctx).Error("error getting parameter 'ConsumerRewardDenomRegistrationFee': %v", err) + return types.Params{}.ConsumerRewardDenomRegistrationFee + } + return params.ConsumerRewardDenomRegistrationFee } -// GetParams returns the paramset for the provider module -func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams( - k.GetTemplateClient(ctx), - k.GetTrustingPeriodFraction(ctx), - k.GetCCVTimeoutPeriod(ctx), - k.GetInitTimeoutPeriod(ctx), - k.GetVscTimeoutPeriod(ctx), - k.GetSlashMeterReplenishPeriod(ctx), - k.GetSlashMeterReplenishFraction(ctx), - k.GetMaxThrottledPackets(ctx), - k.GetConsumerRewardDenomRegistrationFee(ctx), - ) +// GetParams returns the parameters for the provider module +func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.ParametersKey()) + if err != nil { + k.Logger(ctx).Error("error getting module parameters: %v", err) + return types.Params{}, nil //TODO @bermuell: check if default arguments or error handling should be done + } + var params types.Params + err = k.cdc.Unmarshal(bz, ¶ms) + return params, err } // SetParams sets the params for the provider module -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { - k.paramSpace.SetParamSet(ctx, ¶ms) +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { + store := k.storeService.OpenKVStore(ctx) + bz, err := k.cdc.Marshal(¶ms) + if err != nil { + return err + } + return store.Set(types.ParametersKey(), bz) } diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index ec938fffe7..c1ebf83124 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -25,7 +25,8 @@ func TestParams(t *testing.T) { defaultParams := providertypes.DefaultParams() providerKeeper.SetParams(ctx, defaultParams) - params := providerKeeper.GetParams(ctx) + params, err := providerKeeper.GetParams(ctx) + require.NoError(t, err) require.Equal(t, defaultParams, params) newParams := providertypes.NewParams( @@ -52,6 +53,7 @@ func TestParams(t *testing.T) { }, ) providerKeeper.SetParams(ctx, newParams) - params = providerKeeper.GetParams(ctx) + params, err = providerKeeper.GetParams(ctx) + require.NoError(t, err) require.Equal(t, newParams, params) } diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 8f90e14448..9d9e26e0c6 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -143,7 +143,11 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, prop *types.ConsumerAdditi k.SetConsumerClientId(ctx, chainID, clientID) // add the init timeout timestamp for this consumer chain - ts := ctx.BlockTime().Add(k.GetParams(ctx).InitTimeoutPeriod) + params, err := k.GetParams(ctx) + if err != nil { + return err + } + ts := ctx.BlockTime().Add(params.InitTimeoutPeriod) k.SetInitTimeoutTimestamp(ctx, chainID, uint64(ts.UnixNano())) k.Logger(ctx).Info("consumer chain registered (client created)", @@ -382,7 +386,7 @@ func (k Keeper) MakeConsumerGenesis( // Thus, if multiple consumer addition proposal for the same chain will pass at // the same time, then only the last one will be stored. func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, prop *types.ConsumerAdditionProposal) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := prop.Marshal() if err != nil { // An error here would indicate something is very wrong @@ -398,12 +402,12 @@ func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, prop *types.Cons func (k Keeper) GetPendingConsumerAdditionProp(ctx sdk.Context, spawnTime time.Time, chainID string, ) (prop types.ConsumerAdditionProposal, found bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingCAPKey(spawnTime, chainID)) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PendingCAPKey(spawnTime, chainID)) + if err != nil || bz == nil { return prop, false } - err := prop.Unmarshal(bz) + err = prop.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the ConsumerAdditionProp is assumed to be correctly serialized in SetPendingConsumerAdditionProp. @@ -451,8 +455,13 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) { // // Note: this method is split out from BeginBlockInit to be easily unit tested. func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecute []types.ConsumerAdditionProposal) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PendingCAPBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting the pending consumer proposals: %v", err) + return []types.ConsumerAdditionProposal{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -481,8 +490,13 @@ func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecu // Thus, the returned array is in spawnTime order. If two proposals have the same spawnTime, // then they are ordered by chainID. func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []types.ConsumerAdditionProposal) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PendingCAPBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting pending consumer addition proposals: %v", err) + return []types.ConsumerAdditionProposal{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -502,7 +516,7 @@ func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []typ // DeletePendingConsumerAdditionProps deletes the given consumer addition proposals func (k Keeper) DeletePendingConsumerAdditionProps(ctx sdk.Context, proposals ...types.ConsumerAdditionProposal) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) for _, p := range proposals { store.Delete(types.PendingCAPKey(p.SpawnTime, p.ChainId)) @@ -516,7 +530,7 @@ func (k Keeper) DeletePendingConsumerAdditionProps(ctx sdk.Context, proposals .. // Thus, if multiple removal addition proposal for the same chain will pass at // the same time, then only the last one will be stored. func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, prop *types.ConsumerRemovalProposal) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := prop.Marshal() if err != nil { // An error here would indicate something is very wrong @@ -530,16 +544,16 @@ func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, prop *types.Consu // // Note: this method is only used in testing func (k Keeper) PendingConsumerRemovalPropExists(ctx sdk.Context, chainID string, timestamp time.Time) bool { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.PendingCRPKey(timestamp, chainID)) + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(types.PendingCRPKey(timestamp, chainID)) - return bz != nil + return err == nil && bz != nil } // DeletePendingConsumerRemovalProps deletes the given pending consumer removal proposals. // This method should be called once the proposal has been acted upon. func (k Keeper) DeletePendingConsumerRemovalProps(ctx sdk.Context, proposals ...types.ConsumerRemovalProposal) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) for _, p := range proposals { store.Delete(types.PendingCRPKey(p.StopTime, p.ChainId)) @@ -589,8 +603,13 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum // store the (to be) executed consumer removal proposals in order propsToExecute := []types.ConsumerRemovalProposal{} - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PendingCRPBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting pending consumer removal proposals to be executed: %v", err) + return []types.ConsumerRemovalProposal{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -620,8 +639,13 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum // PendingCRPBytePrefix | stopTime.UnixNano() | chainID // Thus, the returned array is in stopTime order. func (k Keeper) GetAllPendingConsumerRemovalProps(ctx sdk.Context) (props []types.ConsumerRemovalProposal) { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{types.PendingCRPBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting pending cosumer removal proposals: %v", err) + return []types.ConsumerRemovalProposal{} + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 0d3ffa342f..75be344df9 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -514,6 +514,10 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { } } + params, err := k.GetParams(ctx) + if err != nil { + panic(fmt.Errorf("invalid provider parameters: %v", err)) + } for _, channelToChain := range k.GetAllChannelToChains(ctx) { // Check if the first vscSendTimestamp in iterator + VscTimeoutPeriod // exceed the current block time. @@ -522,7 +526,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { // Note: GetFirstVscSendTimestamp panics if the internal state is invalid vscSendTimestamp, found := k.GetFirstVscSendTimestamp(ctx, channelToChain.ChainId) if found { - timeoutTimestamp := vscSendTimestamp.Timestamp.Add(k.GetParams(ctx).VscTimeoutPeriod) + timeoutTimestamp := vscSendTimestamp.Timestamp.Add(params.VscTimeoutPeriod) if currentTime.After(timeoutTimestamp) { // vscTimeout expired // stop the consumer chain and release unbondings diff --git a/x/ccv/provider/keeper/throttle.go b/x/ccv/provider/keeper/throttle.go index 64a1e47e4e..cca808b26c 100644 --- a/x/ccv/provider/keeper/throttle.go +++ b/x/ccv/provider/keeper/throttle.go @@ -229,7 +229,7 @@ func (k Keeper) GetSlashMeterAllowance(ctx sdktypes.Context) math.Int { // between chains, whereas the chain-specific queue is used to coordinate the order of slash and vsc matured packets // relevant to each chain. func (k Keeper) QueueGlobalSlashEntry(ctx sdktypes.Context, entry providertypes.GlobalSlashEntry) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := providertypes.GlobalSlashEntryKey(entry) bz := entry.ProviderValConsAddr store.Set(key, bz) @@ -255,8 +255,13 @@ func (k Keeper) DeleteGlobalSlashEntriesForConsumer(ctx sdktypes.Context, consum // GlobalSlashEntryBytePrefix | uint64 recv time | ibc seq num | consumer chain id // Thus, the returned array is ordered by recv time, then ibc seq num. func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.GlobalSlashEntry { - store := ctx.KVStore(k.storeKey) - iterator := storetypes.KVStorePrefixIterator(store, []byte{providertypes.GlobalSlashEntryBytePrefix}) + store := k.storeService.OpenKVStore(ctx) + prefix := []byte{providertypes.GlobalSlashEntryBytePrefix} + iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) + if err != nil { + k.Logger(ctx).Error("error getting all global slash entries: %v", err) + return []providertypes.GlobalSlashEntry{} + } defer iterator.Close() entries := []providertypes.GlobalSlashEntry{} @@ -274,7 +279,7 @@ func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.G // DeleteGlobalSlashEntries deletes the given global entries from the global slash queue func (k Keeper) DeleteGlobalSlashEntries(ctx sdktypes.Context, entries ...providertypes.GlobalSlashEntry) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) for _, entry := range entries { store.Delete(providertypes.GlobalSlashEntryKey(entry)) } @@ -288,11 +293,11 @@ const ( // GetThrottledPacketDataSize returns the size of the throttled packet data queue for the given consumer chain func (k Keeper) GetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID string) uint64 { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) var size uint64 - bz := store.Get(key) - if bz == nil { + bz, err := store.Get(key) + if err != nil || bz == nil { size = 0 } else { size = sdktypes.BigEndianToUint64(bz) @@ -309,7 +314,7 @@ func (k Keeper) SetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID panic(fmt.Sprintf("throttled packet data queue for chain %s is too large: %d", consumerChainID, size)) } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) bz := sdktypes.Uint64ToBigEndian(size) store.Set(key, bz) @@ -353,7 +358,7 @@ func (k Keeper) QueueThrottledVSCMaturedPacketData( func (k Keeper) QueueThrottledPacketData( ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, ) error { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) var bz []byte var err error @@ -387,9 +392,13 @@ func (k Keeper) QueueThrottledPacketData( func (k Keeper) GetLeadingVSCMaturedData(ctx sdktypes.Context, consumerChainID string) ( vscMaturedData []ccvtypes.VSCMaturedPacketData, ibcSeqNums []uint64, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error getting leading VSC matured packets: %v", err) + return []ccvtypes.VSCMaturedPacketData{}, []uint64{} + } defer iterator.Close() // Iterate over the throttled packet data queue, @@ -437,9 +446,13 @@ func (k Keeper) GetSlashAndTrailingData(ctx sdktypes.Context, consumerChainID st // data after it has been handled. ibcSeqNums []uint64, ) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error getting first slash packet data: %v", err) + return false, slashData, []ccvtypes.VSCMaturedPacketData{}, []uint64{} + } defer iterator.Close() slashFound = false @@ -496,9 +509,13 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID rawOrderedData = []interface{}{} ibcSeqNums = []uint64{} - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error getting all throttled packets: %v", err) + return + } defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -537,9 +554,13 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID // DeleteAllPacketDataForConsumer deletes all queued packet data for the given consumer chain. func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consumerChainID string) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) + iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) + if err != nil { + k.Logger(ctx).Error("error deleting all queued packets for consumer chain %s: %v", consumerChainID, err) + return + } defer iterator.Close() keysToDel := [][]byte{} @@ -558,7 +579,7 @@ func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consu // DeleteThrottledPacketData deletes the given throttled packet data instances // (specified by their ibc seq number) from the chain-specific throttled packet data queue. func (k Keeper) DeleteThrottledPacketData(ctx sdktypes.Context, consumerChainID string, ibcSeqNumbers ...uint64) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) for _, ibcSeqNum := range ibcSeqNumbers { store.Delete(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) } @@ -572,15 +593,15 @@ func (k Keeper) DeleteThrottledPacketData(ctx sdktypes.Context, consumerChainID // // Note: the value of this int should always be in the range of tendermint's [-MaxVotingPower, MaxVotingPower] func (k Keeper) GetSlashMeter(ctx sdktypes.Context) math.Int { - store := ctx.KVStore(k.storeKey) - bz := store.Get(providertypes.SlashMeterKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(providertypes.SlashMeterKey()) + if err != nil || bz == nil { // Slash meter should be set as a part of InitGenesis and periodically updated by throttle logic, // there is no deletion method exposed, so nil bytes would indicate something is very wrong. panic("slash meter not set") } value := math.ZeroInt() - err := value.Unmarshal(bz) + err = value.Unmarshal(bz) if err != nil { // We should have obtained value bytes that were serialized in SetSlashMeter, // so an error here would indicate something is very wrong. @@ -607,7 +628,7 @@ func (k Keeper) SetSlashMeter(ctx sdktypes.Context, value math.Int) { if value.LT(math.NewInt(-tmtypes.MaxTotalVotingPower)) { panic("slash meter value cannot be less than negative tendermint's MaxTotalVotingPower") } - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) bz, err := value.Marshal() if err != nil { // A returned error for marshaling an int would indicate something is very wrong. @@ -621,9 +642,9 @@ func (k Keeper) SetSlashMeter(ctx sdktypes.Context, value math.Int) { // Note: this value is the next time the slash meter will be replenished IFF the slash meter is NOT full. // Otherwise this value will be updated in every future block until the slash meter becomes NOT full. func (k Keeper) GetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) time.Time { - store := ctx.KVStore(k.storeKey) - bz := store.Get(providertypes.SlashMeterReplenishTimeCandidateKey()) - if bz == nil { + store := k.storeService.OpenKVStore(ctx) + bz, err := store.Get(providertypes.SlashMeterReplenishTimeCandidateKey()) + if err != nil || bz == nil { // Slash meter replenish time candidate should be set as a part of InitGenesis and periodically updated by throttle logic, // there is no deletion method exposed, so nil bytes would indicate something is very wrong. panic("slash meter replenish time candidate not set") @@ -643,7 +664,7 @@ func (k Keeper) GetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) time.T // Note: this value is the next time the slash meter will be replenished IFF the slash meter is NOT full. // Otherwise this value will be updated in every future block until the slash meter becomes NOT full. func (k Keeper) SetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) { - store := ctx.KVStore(k.storeKey) + store := k.storeService.OpenKVStore(ctx) timeToStore := ctx.BlockTime().UTC().Add(k.GetSlashMeterReplenishPeriod(ctx)) store.Set(providertypes.SlashMeterReplenishTimeCandidateKey(), sdktypes.FormatTimeBytes(timeToStore)) } diff --git a/x/ccv/provider/module_test.go b/x/ccv/provider/module_test.go index ba3ec30b67..f446c35203 100644 --- a/x/ccv/provider/module_test.go +++ b/x/ccv/provider/module_test.go @@ -177,7 +177,9 @@ func TestInitGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := providerKeeper.GetSlashMeter(ctx) - replenishFraction, err := math.LegacyNewDecFromStr(providerKeeper.GetParams(ctx).SlashMeterReplenishFraction) + params, err := providerKeeper.GetParams(ctx) + require.NoError(t, err) + replenishFraction, err := math.LegacyNewDecFromStr(params.SlashMeterReplenishFraction) require.NoError(t, err) expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index 9a4cbdb149..3f9ed11fa2 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -55,11 +55,6 @@ var ( KeyConsumerRewardDenomRegistrationFee = []byte("ConsumerRewardDenomRegistrationFee") ) -// ParamKeyTable returns a key table with the necessary registered provider params -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // NewParams creates new provider parameters with provided arguments func NewParams( cs *ibctmtypes.ClientState, diff --git a/x/ccv/types/params.go b/x/ccv/types/params.go index d44ec68c80..7091e02b25 100644 --- a/x/ccv/types/params.go +++ b/x/ccv/types/params.go @@ -6,7 +6,6 @@ import ( "cosmossdk.io/math" sdktypes "github.com/cosmos/cosmos-sdk/types" - paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -57,11 +56,6 @@ var ( KeyProviderRewardDenoms = []byte("ProviderRewardDenoms") ) -// ParamKeyTable type declaration for parameters -func ParamKeyTable() paramtypes.KeyTable { - return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) -} - // NewParams creates new consumer parameters with provided arguments func NewParams(enabled bool, blocksPerDistributionTransmission int64, distributionTransmissionChannel, providerFeePoolAddrStr string, @@ -146,35 +140,6 @@ func (p Params) Validate() error { return nil } -// ParamSetPairs implements params.ParamSet -func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { - return paramtypes.ParamSetPairs{ - paramtypes.NewParamSetPair(KeyEnabled, p.Enabled, ValidateBool), - paramtypes.NewParamSetPair(KeyBlocksPerDistributionTransmission, - p.BlocksPerDistributionTransmission, ValidatePositiveInt64), - paramtypes.NewParamSetPair(KeyDistributionTransmissionChannel, - p.DistributionTransmissionChannel, ValidateDistributionTransmissionChannel), - paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr, - p.ProviderFeePoolAddrStr, ValidateProviderFeePoolAddrStr), - paramtypes.NewParamSetPair(KeyCCVTimeoutPeriod, - p.CcvTimeoutPeriod, ValidateDuration), - paramtypes.NewParamSetPair(KeyTransferTimeoutPeriod, - p.TransferTimeoutPeriod, ValidateDuration), - paramtypes.NewParamSetPair(KeyConsumerRedistributionFrac, - p.ConsumerRedistributionFraction, ValidateStringFraction), - paramtypes.NewParamSetPair(KeyHistoricalEntries, - p.HistoricalEntries, ValidatePositiveInt64), - paramtypes.NewParamSetPair(KeyConsumerUnbondingPeriod, - p.UnbondingPeriod, ValidateDuration), - paramtypes.NewParamSetPair(KeySoftOptOutThreshold, - p.SoftOptOutThreshold, ValidateSoftOptOutThreshold), - paramtypes.NewParamSetPair(KeyRewardDenoms, - p.RewardDenoms, ValidateDenoms), - paramtypes.NewParamSetPair(KeyProviderRewardDenoms, - p.ProviderRewardDenoms, ValidateDenoms), - } -} - func ValidateProviderFeePoolAddrStr(i interface{}) error { // Accept empty string as valid, since this will be the default value on genesis if i == "" { From ad4054650163d0001d5007258ebbd3cbb98c8f03 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Mon, 13 Nov 2023 11:44:36 +0100 Subject: [PATCH 4/8] Revert "Changed to store service" This reverts commit e47868f6631d4d497d23bf8ce5383ac92b80849d. --- app/consumer-democracy/app.go | 6 +- app/consumer/app.go | 6 +- app/provider/app.go | 3 +- tests/integration/channel_init.go | 5 +- tests/integration/distribution.go | 32 +-- tests/integration/throttle.go | 22 +- testutil/keeper/unit_test_helpers.go | 7 +- x/ccv/consumer/ibc_module_test.go | 6 +- x/ccv/consumer/keeper/distribution.go | 8 +- x/ccv/consumer/keeper/genesis.go | 6 +- x/ccv/consumer/keeper/genesis_test.go | 12 +- x/ccv/consumer/keeper/grpc_query.go | 5 +- x/ccv/consumer/keeper/keeper.go | 279 ++++++++++------------ x/ccv/consumer/keeper/migration.go | 10 +- x/ccv/consumer/keeper/params.go | 180 +++++--------- x/ccv/consumer/keeper/params_test.go | 6 +- x/ccv/consumer/keeper/soft_opt_out.go | 8 +- x/ccv/consumer/keeper/throttle_retry.go | 12 +- x/ccv/consumer/keeper/validators.go | 10 +- x/ccv/provider/keeper/distribution.go | 28 +-- x/ccv/provider/keeper/genesis.go | 5 +- x/ccv/provider/keeper/genesis_test.go | 6 +- x/ccv/provider/keeper/keeper.go | 303 +++++++++++------------- x/ccv/provider/keeper/key_assignment.go | 89 +++---- x/ccv/provider/keeper/params.go | 124 ++++------ x/ccv/provider/keeper/params_test.go | 6 +- x/ccv/provider/keeper/proposal.go | 64 ++--- x/ccv/provider/keeper/relay.go | 6 +- x/ccv/provider/keeper/throttle.go | 75 +++--- x/ccv/provider/module_test.go | 4 +- x/ccv/provider/types/params.go | 5 + x/ccv/types/params.go | 35 +++ 32 files changed, 559 insertions(+), 814 deletions(-) diff --git a/app/consumer-democracy/app.go b/app/consumer-democracy/app.go index 91d5ed333b..ed4e8d81fa 100644 --- a/app/consumer-democracy/app.go +++ b/app/consumer-democracy/app.go @@ -431,7 +431,8 @@ func New( // communication over IBC is not affected by these changes app.ConsumerKeeper = consumerkeeper.NewNonZeroKeeper( appCodec, - runtime.NewKVStoreService(keys[consumertypes.StoreKey]), + keys[consumertypes.StoreKey], + app.GetSubspace(consumertypes.ModuleName), ) app.IBCKeeper = ibckeeper.NewKeeper( @@ -447,7 +448,8 @@ func New( // Create CCV consumer and modules app.ConsumerKeeper = consumerkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[consumertypes.StoreKey]), + keys[consumertypes.StoreKey], + app.GetSubspace(consumertypes.ModuleName), scopedIBCConsumerKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/app/consumer/app.go b/app/consumer/app.go index 0029e75cf3..f6f354c777 100644 --- a/app/consumer/app.go +++ b/app/consumer/app.go @@ -357,7 +357,8 @@ func New( // communication over IBC is not affected by these changes app.ConsumerKeeper = ibcconsumerkeeper.NewNonZeroKeeper( appCodec, - runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]), + keys[ibcconsumertypes.StoreKey], + app.GetSubspace(ibcconsumertypes.ModuleName), ) app.IBCKeeper = ibckeeper.NewKeeper( @@ -373,7 +374,8 @@ func New( // initialize the actual consumer keeper app.ConsumerKeeper = ibcconsumerkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[ibcconsumertypes.StoreKey]), + keys[ibcconsumertypes.StoreKey], + app.GetSubspace(ibcconsumertypes.ModuleName), scopedIBCConsumerKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/app/provider/app.go b/app/provider/app.go index fa4912a186..00c775043e 100644 --- a/app/provider/app.go +++ b/app/provider/app.go @@ -436,7 +436,8 @@ func New( app.ProviderKeeper = icsproviderkeeper.NewKeeper( appCodec, - runtime.NewKVStoreService(keys[providertypes.StoreKey]), + keys[providertypes.StoreKey], + app.GetSubspace(providertypes.ModuleName), scopedIBCProviderKeeper, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.PortKeeper, diff --git a/tests/integration/channel_init.go b/tests/integration/channel_init.go index 0c67136896..e9a41c66f5 100644 --- a/tests/integration/channel_init.go +++ b/tests/integration/channel_init.go @@ -60,10 +60,7 @@ func (suite *CCVTestSuite) TestInitTimeout() { for i, tc := range testCases { providerKeeper := suite.providerApp.GetProviderKeeper() - params, err := providerKeeper.GetParams(suite.providerCtx()) - suite.Require().NoError(err) - initTimeout := params.InitTimeoutPeriod - + initTimeout := providerKeeper.GetParams(suite.providerCtx()).InitTimeoutPeriod chainID := suite.consumerChain.ChainID // check that the init timeout timestamp is set diff --git a/tests/integration/distribution.go b/tests/integration/distribution.go index ef072c9cb3..410837fb5b 100644 --- a/tests/integration/distribution.go +++ b/tests/integration/distribution.go @@ -28,8 +28,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() { s.providerChain.NextBlock() // register a consumer reward denom - params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) - s.Require().NoError(err) + params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) @@ -50,7 +49,7 @@ func (s *CCVTestSuite) TestRewardsDistribution() { consumerFeePoolAddr := consumerAccountKeeper.GetModuleAccount(s.consumerCtx(), authtypes.FeeCollectorName).GetAddress() feePoolTokensOld := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) - err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) + err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) feePoolTokens := consumerBankKeeper.GetAllBalances(s.consumerCtx(), consumerFeePoolAddr) s.Require().Equal(math.NewInt(100).Add(feePoolTokensOld.AmountOf(sdk.DefaultBondDenom)), feePoolTokens.AmountOf(sdk.DefaultBondDenom)) @@ -140,9 +139,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { s.providerChain.NextBlock() // Register denom on consumer chain - params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) - s.Require().NoError(err) - + params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) @@ -158,7 +155,7 @@ func (s *CCVTestSuite) TestSendRewardsRetries() { // fill fee pool fees := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, math.NewInt(100))) - err = consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), + err := consumerBankKeeper.SendCoinsFromAccountToModule(s.consumerCtx(), s.consumerChain.SenderAccount.GetAddress(), authtypes.FeeCollectorName, fees) s.Require().NoError(err) @@ -271,8 +268,7 @@ func (s *CCVTestSuite) TestEndBlockRD() { s.providerChain.NextBlock() if tc.denomRegistered { - params, err := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) - s.Require().NoError(err) + params := s.consumerApp.GetConsumerKeeper().GetConsumerParams(s.consumerCtx()) params.RewardDenoms = []string{sdk.DefaultBondDenom} s.consumerApp.GetConsumerKeeper().SetParams(s.consumerCtx(), params) } @@ -342,13 +338,12 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params, err := keeper.GetConsumerParams(ctx) - s.Require().NoError(err) + params := keeper.GetConsumerParams(ctx) params.RewardDenoms = []string{sdk.DefaultBondDenom} keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err = bankKeeper.SendCoinsFromAccountToModule( + err := bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, @@ -380,8 +375,7 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params, err := keeper.GetConsumerParams(ctx) - s.Require().NoError(err) + params := keeper.GetConsumerParams(ctx) params.RewardDenoms = []string{"uatom"} keeper.SetParams(ctx, params) @@ -397,14 +391,13 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params, err := keeper.GetConsumerParams(ctx) - s.Require().NoError(err) + params := keeper.GetConsumerParams(ctx) params.RewardDenoms = []string{sdk.DefaultBondDenom} params.DistributionTransmissionChannel = "" keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err = bankKeeper.SendCoinsFromAccountToModule( + err := bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, @@ -421,14 +414,13 @@ func (s *CCVTestSuite) TestSendRewardsToProvider() { s.SetupTransferChannel() // register a consumer reward denom - params, err := keeper.GetConsumerParams(ctx) - s.Require().NoError(err) + params := keeper.GetConsumerParams(ctx) params.RewardDenoms = []string{sdk.DefaultBondDenom} params.ProviderFeePoolAddrStr = "" keeper.SetParams(ctx, params) // send coins to the pool which is used for collect reward distributions to be sent to the provider - err = bankKeeper.SendCoinsFromAccountToModule( + err := bankKeeper.SendCoinsFromAccountToModule( ctx, s.consumerChain.SenderAccount.GetAddress(), consumertypes.ConsumerToSendToProviderName, diff --git a/tests/integration/throttle.go b/tests/integration/throttle.go index 1b5ad63752..73762b6b59 100644 --- a/tests/integration/throttle.go +++ b/tests/integration/throttle.go @@ -308,8 +308,7 @@ func (s *CCVTestSuite) TestPacketSpam() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = "0.75" // Allow 3/4 of validators to be jailed providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -377,8 +376,7 @@ func (s *CCVTestSuite) TestDoubleSignDoesNotAffectThrottling() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = "0.1" providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -471,8 +469,7 @@ func (s *CCVTestSuite) TestQueueOrdering() { // Explicitly set params, initialize slash meter providerKeeper := s.providerApp.GetProviderKeeper() - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = "0.05" // 5% total power can be jailed providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -709,8 +706,7 @@ func (s *CCVTestSuite) TestSlashMeterAllowanceChanges() { s.Require().Equal(int64(200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64()) // Now we change replenish fraction and assert new expected allowance. - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = "0.3" providerKeeper.SetParams(s.providerCtx(), params) s.Require().Equal(int64(1200), providerKeeper.GetSlashMeterAllowance(s.providerCtx()).Int64()) @@ -729,8 +725,7 @@ func (s *CCVTestSuite) TestSlashSameValidator() { providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should handled immediately (no throttling) - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -790,8 +785,7 @@ func (s CCVTestSuite) TestSlashAllValidators() { //nolint:govet // this is a tes providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no throttling) - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) @@ -945,9 +939,7 @@ func (s *CCVTestSuite) TestVscMaturedHandledPerBlockLimit() { providerKeeper := s.providerApp.GetProviderKeeper() // Set replenish fraction to 1.0 so that all sent packets should be handled immediately (no jail throttling) - params, err := providerKeeper.GetParams(s.providerCtx()) - s.Require().NoError(err) - + params := providerKeeper.GetParams(s.providerCtx()) params.SlashMeterReplenishFraction = fullSlashMeterString // needs to be const for linter providerKeeper.SetParams(s.providerCtx(), params) providerKeeper.InitializeSlashMeter(s.providerCtx()) diff --git a/testutil/keeper/unit_test_helpers.go b/testutil/keeper/unit_test_helpers.go index 59e7be67ae..d808689436 100644 --- a/testutil/keeper/unit_test_helpers.go +++ b/testutil/keeper/unit_test_helpers.go @@ -19,7 +19,6 @@ import ( cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" @@ -117,7 +116,8 @@ func NewMockedKeepers(ctrl *gomock.Controller) MockedKeepers { func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) providerkeeper.Keeper { return providerkeeper.NewKeeper( params.Cdc, - runtime.NewKVStoreService(params.StoreKey), + params.StoreKey, + *params.ParamsSubspace, mocks.MockScopedKeeper, mocks.MockChannelKeeper, mocks.MockPortKeeper, @@ -139,7 +139,8 @@ func NewInMemProviderKeeper(params InMemKeeperParams, mocks MockedKeepers) provi func NewInMemConsumerKeeper(params InMemKeeperParams, mocks MockedKeepers) consumerkeeper.Keeper { return consumerkeeper.NewKeeper( params.Cdc, - runtime.NewKVStoreService(params.StoreKey), + params.StoreKey, + *params.ParamsSubspace, mocks.MockScopedKeeper, mocks.MockChannelKeeper, mocks.MockPortKeeper, diff --git a/x/ccv/consumer/ibc_module_test.go b/x/ccv/consumer/ibc_module_test.go index 1005bca573..b84c30b117 100644 --- a/x/ccv/consumer/ibc_module_test.go +++ b/x/ccv/consumer/ibc_module_test.go @@ -1,7 +1,6 @@ package consumer_test import ( - "fmt" "testing" transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" @@ -227,10 +226,7 @@ func TestOnChanOpenAck(t *testing.T) { transfertypes.PortID, "", // signer unused ) - err := keeper.SetParams(params.ctx, ccv.DefaultParams()) - if err != nil { - panic(fmt.Sprintf("Setting params failed %v", err)) - } + transferChannelID := "" keeper.SetDistributionTransmissionChannel(params.ctx, transferChannelID) diff --git a/x/ccv/consumer/keeper/distribution.go b/x/ccv/consumer/keeper/distribution.go index b60bd61afe..64240990cb 100644 --- a/x/ccv/consumer/keeper/distribution.go +++ b/x/ccv/consumer/keeper/distribution.go @@ -204,10 +204,10 @@ func (k Keeper) AllowedRewardDenoms(ctx sdk.Context) []string { } func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmissionBlockHeight { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.LastDistributionTransmissionKey()) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.LastDistributionTransmissionKey()) ltbh := ccv.LastTransmissionBlockHeight{} - if err == nil && bz != nil { + if bz != nil { if err := ltbh.Unmarshal(bz); err != nil { panic(fmt.Errorf("failed to unmarshal LastTransmissionBlockHeight: %w", err)) } @@ -216,7 +216,7 @@ func (k Keeper) GetLastTransmissionBlockHeight(ctx sdk.Context) ccv.LastTransmis } func (k Keeper) SetLastTransmissionBlockHeight(ctx sdk.Context, ltbh ccv.LastTransmissionBlockHeight) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := ltbh.Marshal() if err != nil { panic(fmt.Errorf("failed to marshal LastTransmissionBlockHeight: %w", err)) diff --git a/x/ccv/consumer/keeper/genesis.go b/x/ccv/consumer/keeper/genesis.go index ca5c60515f..2ac38f650c 100644 --- a/x/ccv/consumer/keeper/genesis.go +++ b/x/ccv/consumer/keeper/genesis.go @@ -116,11 +116,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, state *ccv.GenesisState) []abci.Val // ExportGenesis returns the CCV consumer module's exported genesis func (k Keeper) ExportGenesis(ctx sdk.Context) (genesis *ccv.GenesisState) { - params, err := k.GetConsumerParams(ctx) - if err != nil { - panic(fmt.Sprintf("failed getting consumer parameters: %v", err)) - } - + params := k.GetConsumerParams(ctx) if !params.Enabled { return ccv.DefaultGenesisState() } diff --git a/x/ccv/consumer/keeper/genesis_test.go b/x/ccv/consumer/keeper/genesis_test.go index 7cae90b0d8..6bb67b10c3 100644 --- a/x/ccv/consumer/keeper/genesis_test.go +++ b/x/ccv/consumer/keeper/genesis_test.go @@ -125,9 +125,7 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs) require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address) - params, err := ck.GetConsumerParams(ctx) - require.NoError(t, err) - require.Equal(t, gs.Params, params) + require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) }, }, { "restart a chain without an established CCV channel", @@ -159,9 +157,7 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, defaultHeightValsetUpdateIDs) assertProviderClientID(t, ctx, &ck, provClientID) require.Equal(t, validator.Address.Bytes(), ck.GetAllCCValidator(ctx)[0].Address) - params, err := ck.GetConsumerParams(ctx) - require.NoError(t, err) - require.Equal(t, gs.Params, params) + require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) }, }, { "restart a chain with an established CCV channel", @@ -210,9 +206,7 @@ func TestInitGenesis(t *testing.T) { assertHeightValsetUpdateIDs(t, ctx, &ck, updatedHeightValsetUpdateIDs) assertProviderClientID(t, ctx, &ck, provClientID) - params, err := ck.GetConsumerParams(ctx) - require.NoError(t, err) - require.Equal(t, gs.Params, params) + require.Equal(t, gs.Params, ck.GetConsumerParams(ctx)) }, }, } diff --git a/x/ccv/consumer/keeper/grpc_query.go b/x/ccv/consumer/keeper/grpc_query.go index 7c0be1a7ab..80e6b695a9 100644 --- a/x/ccv/consumer/keeper/grpc_query.go +++ b/x/ccv/consumer/keeper/grpc_query.go @@ -36,10 +36,7 @@ func (k Keeper) QueryParams(c context.Context, //nolint:golint return nil, status.Errorf(codes.InvalidArgument, "empty request") } - p, err := k.GetConsumerParams(ctx) - if err != nil { - return nil, status.Errorf(codes.NotFound, "no consumer parameters found") - } + p := k.GetConsumerParams(ctx) return &types.QueryParamsResponse{Params: p}, nil } diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 624a4a2ebc..84167e61f8 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -19,6 +19,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" @@ -35,9 +36,10 @@ type Keeper struct { // should be the x/gov module account. authority string - storeService store.KVStoreService - cdc codec.BinaryCodec - //paramStore paramtypes.Subspace + storeKey storetypes.StoreKey // TODO: maybe needs to be removed? + storeService store.KVStoreService + cdc codec.BinaryCodec + paramStore paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -63,7 +65,7 @@ type Keeper struct { // NOTE: the feeCollectorName is in reference to the consumer-chain fee // collector (and not the provider chain) func NewKeeper( - cdc codec.BinaryCodec, storeService store.KVStoreService, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, scopedKeeper ccv.ScopedKeeper, channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper, connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper, @@ -72,10 +74,16 @@ func NewKeeper( feeCollectorName, authority string, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, ) Keeper { + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(ccv.ParamKeyTable()) + } + k := Keeper{ authority: authority, - storeService: storeService, + storeKey: key, cdc: cdc, + paramStore: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -96,57 +104,61 @@ func NewKeeper( return k } -// Returns a keeper with cdc, key it does not raise any panics during registration (eg with IBCKeeper). +// Returns a keeper with cdc, key and paramSpace set it does not raise any panics during registration (eg with IBCKeeper). // Used only in testing. -func NewNonZeroKeeper(cdc codec.BinaryCodec, storeService store.KVStoreService) Keeper { +func NewNonZeroKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace) Keeper { return Keeper{ - storeService: storeService, - cdc: cdc, + storeKey: key, + cdc: cdc, + paramStore: paramSpace, } } -func (k *Keeper) GetAuthority() string { - return k.authority -} - // SetStandaloneStakingKeeper sets the standalone staking keeper for the consumer chain. // This method should only be called for previously standalone chains that are now consumers. func (k *Keeper) SetStandaloneStakingKeeper(sk ccv.StakingKeeper) { k.standaloneStakingKeeper = sk } +// SetParamSpace sets the param space for the consumer keeper. +// Note: this is only used for testing! +func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { + k.paramStore = ps +} + // Validates that the consumer keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation // TODO: @MSalopek hangle this better - if reflect.ValueOf(k).NumField() != 18 { - panic(fmt.Sprintf("number of fields in consumer keeper is not 18 - have %d", reflect.ValueOf(k).NumField())) // incorrect number + if reflect.ValueOf(k).NumField() != 20 { + panic(fmt.Sprintf("number of fields in consumer keeper is not 19 - have %d", reflect.ValueOf(k).NumField())) // incorrect number } if k.validatorAddressCodec == nil || k.consensusAddressCodec == nil { panic("validator and/or consensus address codec are nil") } - // Note 16 / 20 fields will be validated, + // Note 17 / 20 fields will be validated, // hooks are explicitly set after the constructor, // stakingKeeper is optionally set after the constructor, - ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 1 + ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 1 ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 2 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 7 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 8 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 9 - ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 10 - ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 11 - ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 12 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 + ccv.PanicIfZeroOrNil(k.paramStore, "paramStore") // 3 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 9 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 10 + ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 11 + ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 12 + ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 13 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 } // Logger returns a module-specific logger. @@ -202,17 +214,13 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { // GetPort returns the portID for the transfer module. Used in ExportGenesis func (k Keeper) GetPort(ctx sdk.Context) string { - store := k.storeService.OpenKVStore(ctx) - port, err := store.Get(types.PortKey()) - if err != nil || port == nil { - return "" - } - return string(port) + store := ctx.KVStore(k.storeKey) + return string(store.Get(types.PortKey())) } // SetPort sets the portID for the CCV module. Used in InitGenesis func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.PortKey(), []byte(portID)) } @@ -229,15 +237,15 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // SetProviderClientID sets the clientID for the client to the provider. // Set in InitGenesis func (k Keeper) SetProviderClientID(ctx sdk.Context, clientID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.ProviderClientIDKey(), []byte(clientID)) } // GetProviderClientID gets the clientID for the client to the provider. func (k Keeper) GetProviderClientID(ctx sdk.Context) (string, bool) { - store := k.storeService.OpenKVStore(ctx) - clientIdBytes, err := store.Get(types.ProviderClientIDKey()) - if err != nil || clientIdBytes == nil { + store := ctx.KVStore(k.storeKey) + clientIdBytes := store.Get(types.ProviderClientIDKey()) + if clientIdBytes == nil { return "", false } return string(clientIdBytes), true @@ -245,15 +253,15 @@ func (k Keeper) GetProviderClientID(ctx sdk.Context) (string, bool) { // SetProviderChannel sets the channelID for the channel to the provider. func (k Keeper) SetProviderChannel(ctx sdk.Context, channelID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.ProviderChannelKey(), []byte(channelID)) } // GetProviderChannel gets the channelID for the channel to the provider. func (k Keeper) GetProviderChannel(ctx sdk.Context) (string, bool) { - store := k.storeService.OpenKVStore(ctx) - channelIdBytes, err := store.Get(types.ProviderChannelKey()) - if err != nil || len(channelIdBytes) == 0 { + store := ctx.KVStore(k.storeKey) + channelIdBytes := store.Get(types.ProviderChannelKey()) + if len(channelIdBytes) == 0 { return "", false } return string(channelIdBytes), true @@ -261,13 +269,13 @@ func (k Keeper) GetProviderChannel(ctx sdk.Context) (string, bool) { // DeleteProviderChannel deletes the channelID for the channel to the provider. func (k Keeper) DeleteProviderChannel(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ProviderChannelKey()) } // SetPendingChanges sets the pending validator set change packet that haven't been flushed to ABCI func (k Keeper) SetPendingChanges(ctx sdk.Context, updates ccv.ValidatorSetChangePacketData) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := updates.Marshal() if err != nil { // This should never happen @@ -278,9 +286,9 @@ func (k Keeper) SetPendingChanges(ctx sdk.Context, updates ccv.ValidatorSetChang // GetPendingChanges gets the pending changes that haven't been flushed over ABCI func (k Keeper) GetPendingChanges(ctx sdk.Context) (*ccv.ValidatorSetChangePacketData, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PendingChangesKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PendingChangesKey()) + if bz == nil { return nil, false } var data ccv.ValidatorSetChangePacketData @@ -294,14 +302,14 @@ func (k Keeper) GetPendingChanges(ctx sdk.Context) (*ccv.ValidatorSetChangePacke // DeletePendingChanges deletes the pending changes after they've been flushed to ABCI func (k Keeper) DeletePendingChanges(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.PendingChangesKey()) } func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.InitGenesisHeightKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.InitGenesisHeightKey()) + if bz == nil { panic("last standalone height not set") } height := sdk.BigEndianToUint64(bz) @@ -310,29 +318,29 @@ func (k Keeper) GetInitGenesisHeight(ctx sdk.Context) int64 { func (k Keeper) SetInitGenesisHeight(ctx sdk.Context, height int64) { bz := sdk.Uint64ToBigEndian(uint64(height)) - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.InitGenesisHeightKey(), bz) } func (k Keeper) IsPreCCV(ctx sdk.Context) bool { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PreCCVKey()) - return err == nil && bz != nil + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PreCCVKey()) + return bz != nil } func (k Keeper) SetPreCCVTrue(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz := sdk.Uint64ToBigEndian(uint64(1)) store.Set(types.PreCCVKey(), bz) } func (k Keeper) DeletePreCCV(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.PreCCVKey()) } func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.ValidatorUpdate) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) initialValSetState := ccv.GenesisState{ InitialValSet: initialValSet, } @@ -341,10 +349,10 @@ func (k Keeper) SetInitialValSet(ctx sdk.Context, initialValSet []tmtypes.Valida } func (k Keeper) GetInitialValSet(ctx sdk.Context) []tmtypes.ValidatorUpdate { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) initialValSet := ccv.GenesisState{} - bz, err := store.Get(types.InitialValSetKey()) - if err == nil && bz != nil { + bz := store.Get(types.InitialValSetKey()) + if bz != nil { k.cdc.MustUnmarshal(bz, &initialValSet) return initialValSet.InitialValSet } @@ -361,13 +369,8 @@ func (k Keeper) GetLastStandaloneValidators(ctx sdk.Context) ([]stakingtypes.Val // GetElapsedPacketMaturityTimes returns a slice of already elapsed PacketMaturityTimes, sorted by maturity times, // i.e., the slice contains the IDs of the matured VSCPackets. func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PacketMaturityTimeBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting elapsed PacketMaturityTimes: %v", err) - return []ccv.MaturingVSCPacket{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) defer iterator.Close() @@ -398,13 +401,8 @@ func (k Keeper) GetElapsedPacketMaturityTimes(ctx sdk.Context) (maturingVSCPacke // Thus, the returned array is in ascending order of maturityTimes. // If two entries have the same maturityTime, then they are ordered by vscID. func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets []ccv.MaturingVSCPacket) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PacketMaturityTimeBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all PacketMaturityTimes: %v", err) - return []ccv.MaturingVSCPacket{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PacketMaturityTimeBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -422,7 +420,7 @@ func (k Keeper) GetAllPacketMaturityTimes(ctx sdk.Context) (maturingVSCPackets [ // SetPacketMaturityTime sets the maturity time for a given received VSC packet id func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, vscId uint64, maturityTime time.Time) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) maturingVSCPacket := ccv.MaturingVSCPacket{ VscId: vscId, MaturityTime: maturityTime, @@ -440,14 +438,14 @@ func (k Keeper) SetPacketMaturityTime(ctx sdk.Context, vscId uint64, maturityTim // // Note: this method is only used in testing. func (k Keeper) PacketMaturityTimeExists(ctx sdk.Context, vscId uint64, maturityTime time.Time) bool { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PacketMaturityTimeKey(vscId, maturityTime)) - return err == nil && bz != nil + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PacketMaturityTimeKey(vscId, maturityTime)) + return bz != nil } // DeletePacketMaturityTimes deletes the packet maturity time for a given vscId and maturityTime func (k Keeper) DeletePacketMaturityTimes(ctx sdk.Context, vscId uint64, maturityTime time.Time) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.PacketMaturityTimeKey(vscId, maturityTime)) } @@ -476,7 +474,7 @@ func (k Keeper) VerifyProviderChain(ctx sdk.Context, connectionHops []string) er // SetHeightValsetUpdateID sets the valset update id for a given block height func (k Keeper) SetHeightValsetUpdateID(ctx sdk.Context, height, valsetUpdateId uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) valBytes := make([]byte, 8) binary.BigEndian.PutUint64(valBytes, valsetUpdateId) store.Set(types.HeightValsetUpdateIDKey(height), valBytes) @@ -484,9 +482,9 @@ func (k Keeper) SetHeightValsetUpdateID(ctx sdk.Context, height, valsetUpdateId // GetHeightValsetUpdateID gets the valset update id recorded for a given block height func (k Keeper) GetHeightValsetUpdateID(ctx sdk.Context, height uint64) uint64 { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.HeightValsetUpdateIDKey(height)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.HeightValsetUpdateIDKey(height)) + if bz == nil { return 0 } return binary.BigEndian.Uint64(bz) @@ -494,7 +492,7 @@ func (k Keeper) GetHeightValsetUpdateID(ctx sdk.Context, height uint64) uint64 { // DeleteHeightValsetUpdateID deletes the valset update id for a given block height func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.HeightValsetUpdateIDKey(height)) } @@ -504,13 +502,8 @@ func (k Keeper) DeleteHeightValsetUpdateID(ctx sdk.Context, height uint64) { // HeightValsetUpdateIDBytePrefix | height // Thus, the returned array is in ascending order of heights. func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUpdateIDs []ccv.HeightToValsetUpdateID) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.HeightValsetUpdateIDBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all heights to ValSet IDs: %v", err) - return []ccv.HeightToValsetUpdateID{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.HeightValsetUpdateIDBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -528,14 +521,14 @@ func (k Keeper) GetAllHeightToValsetUpdateIDs(ctx sdk.Context) (heightToValsetUp // OutstandingDowntime returns the outstanding downtime flag for a given validator func (k Keeper) OutstandingDowntime(ctx sdk.Context, address sdk.ConsAddress) bool { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.OutstandingDowntimeKey(address)) - return err == nil && bz != nil + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.OutstandingDowntimeKey(address)) + return bz != nil } // SetOutstandingDowntime sets the outstanding downtime flag for a given validator func (k Keeper) SetOutstandingDowntime(ctx sdk.Context, address sdk.ConsAddress) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.OutstandingDowntimeKey(address), []byte{}) } @@ -545,7 +538,7 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { if err != nil { return // TODO: this should panic with appropriate tests to validate the panic wont happen in normal cases. } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.OutstandingDowntimeKey(consAddr)) } @@ -555,13 +548,8 @@ func (k Keeper) DeleteOutstandingDowntime(ctx sdk.Context, consAddress string) { // OutstandingDowntimeBytePrefix | consAddress // Thus, the returned array is in ascending order of consAddresses. func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []ccv.OutstandingDowntime) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.OutstandingDowntimeBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting validator addresses of outstanding downtimes: %v", err) - return []ccv.OutstandingDowntime{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.OutstandingDowntimeBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -578,7 +566,7 @@ func (k Keeper) GetAllOutstandingDowntimes(ctx sdk.Context) (downtimes []ccv.Out // SetCCValidator sets a cross-chain validator under its validator address func (k Keeper) SetCCValidator(ctx sdk.Context, v types.CrossChainValidator) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz := k.cdc.MustMarshal(&v) store.Set(types.CrossChainValidatorKey(v.Address), bz) @@ -586,9 +574,9 @@ func (k Keeper) SetCCValidator(ctx sdk.Context, v types.CrossChainValidator) { // GetCCValidator returns a cross-chain validator for a given address func (k Keeper) GetCCValidator(ctx sdk.Context, addr []byte) (validator types.CrossChainValidator, found bool) { - store := k.storeService.OpenKVStore(ctx) - v, err := store.Get(types.CrossChainValidatorKey(addr)) - if err != nil || v == nil { + store := ctx.KVStore(k.storeKey) + v := store.Get(types.CrossChainValidatorKey(addr)) + if v == nil { return } k.cdc.MustUnmarshal(v, &validator) @@ -599,7 +587,7 @@ func (k Keeper) GetCCValidator(ctx sdk.Context, addr []byte) (validator types.Cr // DeleteCCValidator deletes a cross-chain validator for a given address func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.CrossChainValidatorKey(addr)) } @@ -609,15 +597,10 @@ func (k Keeper) DeleteCCValidator(ctx sdk.Context, addr []byte) { // CrossChainValidatorBytePrefix | address // Thus, the returned array is in ascending order of addresses. func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChainValidator) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.CrossChainValidatorBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all cross-chain validators: %v", err) - return []types.CrossChainValidator{} - } - defer iterator.Close() + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.CrossChainValidatorBytePrefix}) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { val := types.CrossChainValidator{} k.cdc.MustUnmarshal(iterator.Value(), &val) @@ -630,13 +613,9 @@ func (k Keeper) GetAllCCValidator(ctx sdk.Context) (validators []types.CrossChai // Implement from stakingkeeper interface func (k Keeper) GetAllValidators(ctx context.Context) (validators []stakingtypes.Validator, err error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := k.storeService.OpenKVStore(sdkCtx) + store := sdkCtx.KVStore(k.storeKey) - prefix := stakingtypes.ValidatorsKey - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - return nil, err - } + iterator := storetypes.KVStorePrefixIterator(store, stakingtypes.ValidatorsKey) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -650,9 +629,9 @@ func (k Keeper) GetAllValidators(ctx context.Context) (validators []stakingtypes // getAndIncrementPendingPacketsIdx returns the current pending packets index and increments it. // This index is used for implementing a FIFO queue of pending packets in the KV store. func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint64) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PendingPacketsIndexKey()) - if err == nil && bz != nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PendingPacketsIndexKey()) + if bz != nil { toReturn = sdk.BigEndianToUint64(bz) } toStore := toReturn + 1 @@ -662,13 +641,8 @@ func (k Keeper) getAndIncrementPendingPacketsIdx(ctx sdk.Context) (toReturn uint // DeleteHeadOfPendingPackets deletes the head of the pending packets queue. func (k Keeper) DeleteHeadOfPendingPackets(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PendingDataPacketsBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error deleting the head of pending packets: %v", err) - return - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) defer iterator.Close() if !iterator.Valid() { return @@ -699,17 +673,11 @@ type ConsumerPacketDataWithIdx struct { // with indexes relevant to the pending packets queue. func (k Keeper) GetAllPendingPacketsWithIdx(ctx sdk.Context) []ConsumerPacketDataWithIdx { packets := []ConsumerPacketDataWithIdx{} - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - prefix := []byte{types.PendingDataPacketsBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all pending consumer packets: %v", err) - return []ConsumerPacketDataWithIdx{} - } + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { var packet ccv.ConsumerPacketData bz := iterator.Value() @@ -730,22 +698,17 @@ func (k Keeper) GetAllPendingPacketsWithIdx(ctx sdk.Context) []ConsumerPacketDat // DeletePendingDataPackets deletes pending data packets with given indexes func (k Keeper) DeletePendingDataPackets(ctx sdk.Context, idxs ...uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) for _, idx := range idxs { store.Delete(types.PendingDataPacketsKey(idx)) } } func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) // Note: PendingDataPacketsBytePrefix is the correct prefix, NOT PendingDataPacketsByteKey. // See consistency with PendingDataPacketsKey(). - prefix := []byte{types.PendingDataPacketsBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error deleting all pending data packets: %v", err) - return - } + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingDataPacketsBytePrefix}) keysToDel := [][]byte{} defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -760,7 +723,7 @@ func (k Keeper) DeleteAllPendingDataPackets(ctx sdk.Context) { func (k Keeper) AppendPendingPacket(ctx sdk.Context, packetType ccv.ConsumerPacketDataType, data ccv.ExportedIsConsumerPacketData_Data) { idx := k.getAndIncrementPendingPacketsIdx(ctx) // for FIFO queue key := types.PendingDataPacketsKey(idx) - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) cpd := ccv.NewConsumerPacketData(packetType, data) bz, err := cpd.Marshal() if err != nil { @@ -771,13 +734,11 @@ func (k Keeper) AppendPendingPacket(ctx sdk.Context, packetType ccv.ConsumerPack } func (k Keeper) MarkAsPrevStandaloneChain(ctx sdk.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.PrevStandaloneChainKey(), []byte{}) } func (k Keeper) IsPrevStandaloneChain(ctx sdk.Context) bool { - store := k.storeService.OpenKVStore(ctx) - - exists, err := store.Has(types.PrevStandaloneChainKey()) - return err == nil && exists + store := ctx.KVStore(k.storeKey) + return store.Has(types.PrevStandaloneChainKey()) } diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 929082b9c8..361bb2a62f 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -28,13 +28,13 @@ func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subs func (k Keeper) MigrateConsumerPacketData(ctx sdk.Context) { // deserialize packet data from old format var depreciatedType ccvtypes.ConsumerPacketDataList - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get([]byte{consumertypes.PendingDataPacketsBytePrefix}) + if bz == nil { ctx.Logger().Info("no pending data packets to migrate") return } - err = depreciatedType.Unmarshal(bz) + err := depreciatedType.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong panic(fmt.Errorf("failed to unmarshal pending data packets: %w", err)) @@ -60,7 +60,7 @@ func PendingDataPacketsKeyOnlyForTesting() []byte { // Note: a better test of the old functionality would be to directly reference the old ICS version, // including the version of ccv.ConsumerPacketDataList has a list of ccv.ConsumerPacketData without indexes. func (k Keeper) SetPendingPacketsOnlyForTesting(ctx sdk.Context, packets ccvtypes.ConsumerPacketDataList) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := packets.Marshal() if err != nil { // This should never happen diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index 7950efc8bf..9bd0d1fa10 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -7,31 +7,31 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetParams returns the params for the consumer ccv module // NOTE: it is different from the GetParams method which is required to implement StakingKeeper interface -func (k Keeper) GetConsumerParams(ctx sdk.Context) (ccvtypes.Params, error) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ParametersKey()) - if err != nil { - return ccvtypes.Params{}, err //TODO @bermuell: check if default arguments or error handling should be done - } - var params ccvtypes.Params - k.cdc.MustUnmarshal(bz, ¶ms) - return params, nil +func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params { + return ccvtypes.NewParams( + k.GetEnabled(ctx), + k.GetBlocksPerDistributionTransmission(ctx), + k.GetDistributionTransmissionChannel(ctx), + k.GetProviderFeePoolAddrStr(ctx), + k.GetCCVTimeoutPeriod(ctx), + k.GetTransferTimeoutPeriod(ctx), + k.GetConsumerRedistributionFrac(ctx), + k.GetHistoricalEntries(ctx), + k.GetUnbondingPeriod(ctx), + k.GetSoftOptOutThreshold(ctx), + k.GetRewardDenoms(ctx), + k.GetProviderRewardDenoms(ctx), + ) } // SetParams sets the paramset for the consumer module -func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) error { - if err := params.Validate(); err != nil { - return err - } - store := k.storeService.OpenKVStore(ctx) - bz := k.cdc.MustMarshal(¶ms) - return store.Set(types.ParametersKey(), bz) +func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) { + k.paramStore.SetParamSet(ctx, ¶ms) } // GetParams implements StakingKeeper GetParams interface method @@ -44,164 +44,98 @@ func (k Keeper) GetParams(context.Context) (stakingtypes.Params, error) { // GetEnabled returns the enabled flag for the consumer module func (k Keeper) GetEnabled(ctx sdk.Context) bool { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'enabled': %v", err) - return ccvtypes.Params{}.Enabled - } - return params.Enabled + var enabled bool + k.paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) + return enabled } func (k Keeper) GetBlocksPerDistributionTransmission(ctx sdk.Context) int64 { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'BlocksPerDistributionTransmission': %v", err) - return ccvtypes.Params{}.BlocksPerDistributionTransmission - } - - return params.BlocksPerDistributionTransmission + var bpdt int64 + k.paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) + return bpdt } func (k Keeper) SetBlocksPerDistributionTransmission(ctx sdk.Context, bpdt int64) { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error setting parameter 'BlocksPerDistributionTransmission': %v", err) - return - } - params.BlocksPerDistributionTransmission = bpdt - k.SetParams(ctx, params) + k.paramStore.Set(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, bpdt) } func (k Keeper) GetDistributionTransmissionChannel(ctx sdk.Context) string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'DistributionTransmissionChannel': %v", err) - return ccvtypes.Params{}.DistributionTransmissionChannel - } - return params.DistributionTransmissionChannel + var s string + k.paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) + return s } func (k Keeper) SetDistributionTransmissionChannel(ctx sdk.Context, channel string) { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error setting parameter 'DistributionTransmissionChannel': %v", err) - return - } - params.DistributionTransmissionChannel = channel - k.SetParams(ctx, params) + k.paramStore.Set(ctx, ccvtypes.KeyDistributionTransmissionChannel, channel) } func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'ProviderFeePoolAddrStr': %v", err) - return ccvtypes.Params{}.ProviderFeePoolAddrStr - } - return params.ProviderFeePoolAddrStr - + var s string + k.paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) + return s } func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error setting parameter 'ProviderFeePoolAddrStr': %v", err) - return - } - params.ProviderFeePoolAddrStr = addr - k.SetParams(ctx, params) + k.paramStore.Set(ctx, ccvtypes.KeyProviderFeePoolAddrStr, addr) } // GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err) - return ccvtypes.Params{}.CcvTimeoutPeriod - } - return params.CcvTimeoutPeriod + var p time.Duration + k.paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p } // GetTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'TransferTimeoutPeriod': %v", err) - return ccvtypes.Params{}.TransferTimeoutPeriod - } - return params.TransferTimeoutPeriod - + var p time.Duration + k.paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) + return p } // GetConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution // address during distribution events. The fraction is a string representing a // decimal number. For example "0.75" would represent 75%. func (k Keeper) GetConsumerRedistributionFrac(ctx sdk.Context) string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'ConsumerRedistributionFraction': %v", err) - return ccvtypes.Params{}.ConsumerRedistributionFraction - } - return params.ConsumerRedistributionFraction - + var str string + k.paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) + return str } // GetHistoricalEntries returns the number of historical info entries to persist in store func (k Keeper) GetHistoricalEntries(ctx sdk.Context) int64 { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'HistoricalEntries': %v", err) - return ccvtypes.Params{}.HistoricalEntries - } - return params.HistoricalEntries + var n int64 + k.paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) + return n } // Only used to set an unbonding period in diff tests -// TODO @bermuell: move this to testutil func (k Keeper) SetUnbondingPeriod(ctx sdk.Context, period time.Duration) { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error setting parameter 'UnbondingPeriod': %v", err) - return - } - params.UnbondingPeriod = period - k.SetParams(ctx, params) + k.paramStore.Set(ctx, ccvtypes.KeyConsumerUnbondingPeriod, period) } -// GetUnbondingPeriod returns the unbonding period of the consumer func (k Keeper) GetUnbondingPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err) - return ccvtypes.Params{}.UnbondingPeriod - } - return params.UnbondingPeriod + var period time.Duration + k.paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) + return period } // GetSoftOptOutThreshold returns the percentage of validators at the bottom of the set // that can opt out of running the consumer chain func (k Keeper) GetSoftOptOutThreshold(ctx sdk.Context) string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'SoftOptOutThreshold': %v", err) - return ccvtypes.Params{}.SoftOptOutThreshold - } - return params.SoftOptOutThreshold + var str string + k.paramStore.Get(ctx, ccvtypes.KeySoftOptOutThreshold, &str) + return str } func (k Keeper) GetRewardDenoms(ctx sdk.Context) []string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'RewardDenoms': %v", err) - return ccvtypes.Params{}.RewardDenoms - } - return params.RewardDenoms + var denoms []string + k.paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) + return denoms } func (k Keeper) GetProviderRewardDenoms(ctx sdk.Context) []string { - params, err := k.GetConsumerParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'UnbondingPeriod': %v", err) - return ccvtypes.Params{}.ProviderRewardDenoms - } - return params.ProviderRewardDenoms + var denoms []string + k.paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) + return denoms } diff --git a/x/ccv/consumer/keeper/params_test.go b/x/ccv/consumer/keeper/params_test.go index 919980acde..49b1816520 100644 --- a/x/ccv/consumer/keeper/params_test.go +++ b/x/ccv/consumer/keeper/params_test.go @@ -33,16 +33,14 @@ func TestParams(t *testing.T) { provideRewardDenoms, ) // these are the default params, IBC suite independently sets enabled=true - params, err := consumerKeeper.GetConsumerParams(ctx) - require.NoError(t, err) + params := consumerKeeper.GetConsumerParams(ctx) require.Equal(t, expParams, params) newParams := ccv.NewParams(false, 1000, "channel-2", "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm", 7*24*time.Hour, 25*time.Hour, "0.5", 500, 24*21*time.Hour, "0.05", []string{"untrn"}, []string{"uatom"}) consumerKeeper.SetParams(ctx, newParams) - params, err = consumerKeeper.GetConsumerParams(ctx) - require.NoError(t, err) + params = consumerKeeper.GetConsumerParams(ctx) require.Equal(t, newParams, params) consumerKeeper.SetBlocksPerDistributionTransmission(ctx, 10) diff --git a/x/ccv/consumer/keeper/soft_opt_out.go b/x/ccv/consumer/keeper/soft_opt_out.go index c9c2607ac5..41460e7917 100644 --- a/x/ccv/consumer/keeper/soft_opt_out.go +++ b/x/ccv/consumer/keeper/soft_opt_out.go @@ -12,7 +12,7 @@ import ( // SetSmallestNonOptOutPower sets the smallest validator power that cannot soft opt out. func (k Keeper) SetSmallestNonOptOutPower(ctx sdk.Context, power uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.SmallestNonOptOutPowerKey(), sdk.Uint64ToBigEndian(power)) } @@ -67,9 +67,9 @@ func (k Keeper) UpdateSmallestNonOptOutPower(ctx sdk.Context) { // GetSmallestNonOptOutPower returns the smallest validator power that cannot soft opt out. func (k Keeper) GetSmallestNonOptOutPower(ctx sdk.Context) int64 { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.SmallestNonOptOutPowerKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.SmallestNonOptOutPowerKey()) + if bz == nil { return 0 } return int64(binary.BigEndian.Uint64(bz)) diff --git a/x/ccv/consumer/keeper/throttle_retry.go b/x/ccv/consumer/keeper/throttle_retry.go index 5d43e71beb..4c4585cb1d 100644 --- a/x/ccv/consumer/keeper/throttle_retry.go +++ b/x/ccv/consumer/keeper/throttle_retry.go @@ -83,12 +83,12 @@ func (k Keeper) UpdateSlashRecordOnBounce(ctx sdktypes.Context) { } func (k Keeper) GetSlashRecord(ctx sdktypes.Context) (record consumertypes.SlashRecord, found bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(consumertypes.SlashRecordKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(consumertypes.SlashRecordKey()) + if bz == nil { return record, false } - err = record.Unmarshal(bz) + err := record.Unmarshal(bz) if err != nil { // This should never happen panic(fmt.Sprintf("could not unmarshal slash record: %v", err)) @@ -97,7 +97,7 @@ func (k Keeper) GetSlashRecord(ctx sdktypes.Context) (record consumertypes.Slash } func (k Keeper) SetSlashRecord(ctx sdktypes.Context, record consumertypes.SlashRecord) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := record.Marshal() if err != nil { // This should never happen @@ -107,6 +107,6 @@ func (k Keeper) SetSlashRecord(ctx sdktypes.Context, record consumertypes.SlashR } func (k Keeper) ClearSlashRecord(ctx sdktypes.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(consumertypes.SlashRecordKey()) } diff --git a/x/ccv/consumer/keeper/validators.go b/x/ccv/consumer/keeper/validators.go index 72dc077df8..ce2d726ca2 100644 --- a/x/ccv/consumer/keeper/validators.go +++ b/x/ccv/consumer/keeper/validators.go @@ -207,11 +207,11 @@ func (k Keeper) UnbondingTime(ctx context.Context) (time.Duration, error) { // GetHistoricalInfo gets the historical info at a given height func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (stakingtypes.HistoricalInfo, error) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := k.storeService.OpenKVStore(sdkCtx) + store := sdkCtx.KVStore(k.storeKey) key := types.HistoricalInfoKey(height) - value, err := store.Get(key) - if err != nil || value == nil { + value := store.Get(key) + if value == nil { return stakingtypes.HistoricalInfo{}, stakingtypes.ErrNoHistoricalInfo } @@ -221,7 +221,7 @@ func (k Keeper) GetHistoricalInfo(ctx context.Context, height int64) (stakingtyp // SetHistoricalInfo sets the historical info at a given height func (k Keeper) SetHistoricalInfo(ctx context.Context, height int64, hi *stakingtypes.HistoricalInfo) { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := k.storeService.OpenKVStore(sdkCtx) + store := sdkCtx.KVStore(k.storeKey) key := types.HistoricalInfoKey(height) value := k.cdc.MustMarshal(hi) @@ -231,7 +231,7 @@ func (k Keeper) SetHistoricalInfo(ctx context.Context, height int64, hi *staking // DeleteHistoricalInfo deletes the historical info at a given height func (k Keeper) DeleteHistoricalInfo(ctx context.Context, height int64) error { sdkCtx := sdk.UnwrapSDKContext(ctx) - store := k.storeService.OpenKVStore(sdkCtx) + store := sdkCtx.KVStore(k.storeKey) key := types.HistoricalInfoKey(height) store.Delete(key) diff --git a/x/ccv/provider/keeper/distribution.go b/x/ccv/provider/keeper/distribution.go index c0c2b56d39..2cf6ef08f6 100644 --- a/x/ccv/provider/keeper/distribution.go +++ b/x/ccv/provider/keeper/distribution.go @@ -1,9 +1,10 @@ package keeper import ( - storetypes "cosmossdk.io/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + storetypes "cosmossdk.io/store/types" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ) @@ -24,38 +25,31 @@ func (k Keeper) SetConsumerRewardDenom( ctx sdk.Context, denom string, ) { - store := k.storeService.OpenKVStore(ctx) - err := store.Set(types.ConsumerRewardDenomsKey(denom), []byte{}) - if err != nil { - k.Logger(ctx).Error("Error setting consumer reward denoms: %v", err) - } + store := ctx.KVStore(k.storeKey) + store.Set(types.ConsumerRewardDenomsKey(denom), []byte{}) } func (k Keeper) ConsumerRewardDenomExists( ctx sdk.Context, denom string, ) bool { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ConsumerRewardDenomsKey(denom)) - return err == nil && bz != nil + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConsumerRewardDenomsKey(denom)) + return bz != nil } func (k Keeper) DeleteConsumerRewardDenom( ctx sdk.Context, denom string, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ConsumerRewardDenomsKey(denom)) } func (k Keeper) GetAllConsumerRewardDenoms(ctx sdk.Context) (consumerRewardDenoms []string) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.ConsumerRewardDenomsBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("Error iterating over all consumer reward denoms: %v", err) - return - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ConsumerRewardDenomsBytePrefix}) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { key := iterator.Key()[1:] diff --git a/x/ccv/provider/keeper/genesis.go b/x/ccv/provider/keeper/genesis.go index ff0c5994e7..e86035170c 100644 --- a/x/ccv/provider/keeper/genesis.go +++ b/x/ccv/provider/keeper/genesis.go @@ -151,10 +151,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { consumerAddrsToPrune = append(consumerAddrsToPrune, k.GetAllConsumerAddrsToPrune(ctx, chain.ChainId)...) } - params, err := k.GetParams(ctx) - if err != nil { - panic(fmt.Errorf("error getting provider parameters: %v", err)) - } + params := k.GetParams(ctx) return types.NewGenesisState( k.GetValidatorSetUpdateId(ctx), diff --git a/x/ccv/provider/keeper/genesis_test.go b/x/ccv/provider/keeper/genesis_test.go index 5e0fca96ca..e8119bef0a 100644 --- a/x/ccv/provider/keeper/genesis_test.go +++ b/x/ccv/provider/keeper/genesis_test.go @@ -147,9 +147,7 @@ func TestInitAndExportGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := pk.GetSlashMeter(ctx) - params, err := pk.GetParams(ctx) - require.NoError(t, err) - replenishFraction, err := math.LegacyNewDecFromStr(params.SlashMeterReplenishFraction) + replenishFraction, err := math.LegacyNewDecFromStr(pk.GetParams(ctx).SlashMeterReplenishFraction) require.NoError(t, err) expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) @@ -175,7 +173,7 @@ func TestInitAndExportGenesis(t *testing.T) { require.True(t, found) require.Equal(t, provGenesis.ConsumerAdditionProposals[0], addProp) require.True(t, pk.PendingConsumerRemovalPropExists(ctx, cChainIDs[0], oneHourFromNow)) - require.Equal(t, provGenesis.Params, params) + require.Equal(t, provGenesis.Params, pk.GetParams(ctx)) gotConsTmPubKey, found := pk.GetValidatorConsumerPubKey(ctx, cChainIDs[0], provAddr) require.True(t, found) diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 1a430ae8f7..996ce651cd 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -22,6 +22,7 @@ import ( storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" 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" "cosmossdk.io/log" @@ -37,9 +38,11 @@ type Keeper struct { // should be the x/gov module account. authority string + storeKey storetypes.StoreKey // TODO: remove storeService store.KVStoreService cdc codec.BinaryCodec + paramSpace paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -58,7 +61,7 @@ type Keeper struct { // NewKeeper creates a new provider Keeper instance func NewKeeper( - cdc codec.BinaryCodec, storeService store.KVStoreService, scopedKeeper ccv.ScopedKeeper, + cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace, scopedKeeper ccv.ScopedKeeper, channelKeeper ccv.ChannelKeeper, portKeeper ccv.PortKeeper, connectionKeeper ccv.ConnectionKeeper, clientKeeper ccv.ClientKeeper, stakingKeeper ccv.StakingKeeper, slashingKeeper ccv.SlashingKeeper, @@ -67,10 +70,16 @@ func NewKeeper( feeCollectorName, authority string, validatorAddressCodec, consensusAddressCodec addresscodec.Codec, ) Keeper { + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } + k := Keeper{ cdc: cdc, - storeService: storeService, + storeKey: key, authority: authority, + paramSpace: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -105,13 +114,19 @@ func (k Keeper) ConsensusAddressCodec() addresscodec.Codec { return k.consensusAddressCodec } +// SetParamSpace sets the param space for the provider keeper. +// Note: this is only used for testing! +func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { + k.paramSpace = ps +} + // TODO: @MSalopek -> redo validation; some fields will be removed // Validates that the provider keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation - if reflect.ValueOf(k).NumField() != 16 { - panic("number of fields in provider keeper is not 16") + if reflect.ValueOf(k).NumField() != 18 { + panic("number of fields in provider keeper is not 18") } // TODO: @MSalopek -> validate once connected and AccountKeeper interface is updated @@ -125,23 +140,24 @@ func (k Keeper) mustValidateFields() { } ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 1 - ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 2 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 - ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 7 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 - ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 9 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 10 - ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 11 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 12 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 + ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 2 + ccv.PanicIfZeroOrNil(k.paramSpace, "paramSpace") // 3 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 + ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 8 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 9 + ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 10 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 11 + ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 12 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 13 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 // TODO: @MSalopek -> validate once connected - // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 17 + // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 18 } // Logger returns a module-specific logger. @@ -167,22 +183,14 @@ func (k Keeper) BindPort(ctx sdk.Context, portID string) error { // GetPort returns the portID for the CCV module. Used in ExportGenesis func (k Keeper) GetPort(ctx sdk.Context) string { - store := k.storeService.OpenKVStore(ctx) - port, err := store.Get(types.PortKey()) - if err != nil { - k.Logger(ctx).Error("error getting port ID: %v", err) - return "" - } - return string(port) + store := ctx.KVStore(k.storeKey) + return string(store.Get(types.PortKey())) } // SetPort sets the portID for the CCV module. Used in InitGenesis func (k Keeper) SetPort(ctx sdk.Context, portID string) { - store := k.storeService.OpenKVStore(ctx) - err := store.Set(types.PortKey(), []byte(portID)) - if err != nil { - k.Logger(ctx).Error("error setting port ID: %v", err) - } + store := ctx.KVStore(k.storeKey) + store.Set(types.PortKey(), []byte(portID)) } // AuthenticateCapability wraps the scopedKeeper's AuthenticateCapability function @@ -198,15 +206,15 @@ func (k Keeper) ClaimCapability(ctx sdk.Context, cap *capabilitytypes.Capability // SetChainToChannel sets the mapping from a consumer chainID to the CCV channel ID for that consumer chain. func (k Keeper) SetChainToChannel(ctx sdk.Context, chainID, channelID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.ChainToChannelKey(chainID), []byte(channelID)) } // GetChainToChannel gets the CCV channelID for the given consumer chainID func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ChainToChannelKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ChainToChannelKey(chainID)) + if bz == nil { return "", false } return string(bz), true @@ -214,7 +222,7 @@ func (k Keeper) GetChainToChannel(ctx sdk.Context, chainID string) (string, bool // DeleteChainToChannel deletes the CCV channel ID for the given consumer chain ID func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ChainToChannelKey(chainID)) } @@ -225,13 +233,8 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) { // ChainToClientBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs. func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.ChainToClientBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting consumer chains: %v", err) - return []types.Chain{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ChainToClientBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -250,15 +253,15 @@ func (k Keeper) GetAllConsumerChains(ctx sdk.Context) (chains []types.Chain) { // SetChannelToChain sets the mapping from the CCV channel ID to the consumer chainID. func (k Keeper) SetChannelToChain(ctx sdk.Context, channelID, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.ChannelToChainKey(channelID), []byte(chainID)) } // GetChannelToChain gets the consumer chainID for a given CCV channelID func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ChannelToChainKey(channelID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ChannelToChainKey(channelID)) + if bz == nil { return "", false } return string(bz), true @@ -266,7 +269,7 @@ func (k Keeper) GetChannelToChain(ctx sdk.Context, channelID string) (string, bo // DeleteChannelToChain deletes the consumer chain ID for a given CCV channelID func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ChannelToChainKey(channelID)) } @@ -278,13 +281,8 @@ func (k Keeper) DeleteChannelToChain(ctx sdk.Context, channelID string) { // ChannelToChainBytePrefix | channelID // Thus, the returned array is in ascending order of channelIDs. func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.ChannelToChain) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.ChannelToChainBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting channel to chain mapping: %v", err) - return []types.ChannelToChain{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ChannelToChainBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -302,7 +300,7 @@ func (k Keeper) GetAllChannelToChains(ctx sdk.Context) (channels []types.Channel } func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.GenesisState) error { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := gen.Marshal() if err != nil { return err @@ -313,9 +311,9 @@ func (k Keeper) SetConsumerGenesis(ctx sdk.Context, chainID string, gen ccv.Gene } func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.GenesisState, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ConsumerGenesisKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConsumerGenesisKey(chainID)) + if bz == nil { return ccv.GenesisState{}, false } @@ -329,7 +327,7 @@ func (k Keeper) GetConsumerGenesis(ctx sdk.Context, chainID string) (ccv.Genesis } func (k Keeper) DeleteConsumerGenesis(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ConsumerGenesisKey(chainID)) } @@ -410,7 +408,7 @@ func (k Keeper) SetConsumerChain(ctx sdk.Context, channelID string) error { // SetUnbondingOp sets the UnbondingOp by its unique ID func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := unbondingOp.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -424,9 +422,9 @@ func (k Keeper) SetUnbondingOp(ctx sdk.Context, unbondingOp types.UnbondingOp) { // GetUnbondingOp gets a UnbondingOp by its unique ID func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.UnbondingOpKey(id)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.UnbondingOpKey(id)) + if bz == nil { return types.UnbondingOp{}, false } @@ -442,7 +440,7 @@ func (k Keeper) GetUnbondingOp(ctx sdk.Context, id uint64) (types.UnbondingOp, b // DeleteUnbondingOp deletes a UnbondingOp given its ID func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.UnbondingOpKey(id)) } @@ -454,13 +452,8 @@ func (k Keeper) DeleteUnbondingOp(ctx sdk.Context, id uint64) { // UnbondingOpBytePrefix | ID // Thus, the iteration is in ascending order of IDs. func (k Keeper) GetAllUnbondingOps(ctx sdk.Context) (ops []types.UnbondingOp) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.UnbondingOpBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all UnbondingOps: %v", err) - return []types.UnbondingOp{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.UnbondingOpBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -526,7 +519,7 @@ func removeStringFromSlice(slice []string, x string) (newSlice []string, numRemo // SetUnbondingOpIndex sets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64, ids []uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) vscUnbondingOps := types.VscUnbondingOps{ VscId: vscID, @@ -550,13 +543,8 @@ func (k Keeper) SetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 // UnbondingOpIndexBytePrefix | len(chainID) | chainID | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (indexes []types.VscUnbondingOps) { - store := k.storeService.OpenKVStore(ctx) - prefix := types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID) - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all unbonding indexes: %v", err) - return []types.VscUnbondingOps{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.UnbondingOpIndexBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -579,10 +567,10 @@ func (k Keeper) GetAllUnbondingOpIndexes(ctx sdk.Context, chainID string) (index // GetUnbondingOpIndex gets the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) ([]uint64, bool) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) - bz, err := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) - if err != nil || bz == nil { + bz := store.Get(types.UnbondingOpIndexKey(chainID, vscID)) + if bz == nil { return []uint64{}, false } @@ -599,7 +587,7 @@ func (k Keeper) GetUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint6 // DeleteUnbondingOpIndex deletes the IDs of unbonding operations that are waiting for // a VSCMaturedPacket with vscID from a consumer with chainID func (k Keeper) DeleteUnbondingOpIndex(ctx sdk.Context, chainID string, vscID uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.UnbondingOpIndexKey(chainID, vscID)) } @@ -625,9 +613,9 @@ func (k Keeper) GetUnbondingOpsFromIndex(ctx sdk.Context, chainID string, valset // GetMaturedUnbondingOps returns the list of matured unbonding operation ids func (k Keeper) GetMaturedUnbondingOps(ctx sdk.Context) (ids []uint64) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.MaturedUnbondingOpsKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.MaturedUnbondingOpsKey()) + if bz == nil { // Note that every call to ConsumeMaturedUnbondingOps // deletes the MaturedUnbondingOpsKey, which means that // the first call to GetMaturedUnbondingOps after that @@ -654,7 +642,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { Ids: append(existingIds, ids...), } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := maturedOps.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -667,7 +655,7 @@ func (k Keeper) AppendMaturedUnbondingOps(ctx sdk.Context, ids []uint64) { // ConsumeMaturedUnbondingOps empties and returns list of matured unbonding operation ids (if it exists) func (k Keeper) ConsumeMaturedUnbondingOps(ctx sdk.Context) []uint64 { ids := k.GetMaturedUnbondingOps(ctx) - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.MaturedUnbondingOpsKey()) return ids } @@ -711,7 +699,7 @@ func (k Keeper) IncrementValidatorSetUpdateId(ctx sdk.Context) { } func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) // Convert back into bytes for storage bz := make([]byte, 8) @@ -721,10 +709,10 @@ func (k Keeper) SetValidatorSetUpdateId(ctx sdk.Context, valUpdateID uint64) { } func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId uint64) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ValidatorSetUpdateIdKey()) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ValidatorSetUpdateIdKey()) - if err != nil || bz == nil { + if bz == nil { validatorSetUpdateId = 0 } else { // Unmarshal @@ -736,7 +724,7 @@ func (k Keeper) GetValidatorSetUpdateId(ctx sdk.Context) (validatorSetUpdateId u // SetValsetUpdateBlockHeight sets the block height for a given valset update id func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, blockHeight uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, blockHeight) store.Set(types.ValsetUpdateBlockHeightKey(valsetUpdateId), heightBytes) @@ -744,9 +732,9 @@ func (k Keeper) SetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId, bloc // GetValsetUpdateBlockHeight gets the block height for a given valset update id func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) (uint64, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) + if bz == nil { return 0, false } return binary.BigEndian.Uint64(bz), true @@ -758,15 +746,10 @@ func (k Keeper) GetValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint6 // ValsetUpdateBlockHeightBytePrefix | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlockHeights []types.ValsetUpdateIdToHeight) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.ValsetUpdateBlockHeightBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all block heights for valset updates: %v", err) - return []types.ValsetUpdateIdToHeight{} - } - defer iterator.Close() + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.ValsetUpdateBlockHeightBytePrefix}) + defer iterator.Close() for ; iterator.Valid(); iterator.Next() { valsetUpdateId := binary.BigEndian.Uint64(iterator.Key()[1:]) height := binary.BigEndian.Uint64(iterator.Value()) @@ -782,7 +765,7 @@ func (k Keeper) GetAllValsetUpdateBlockHeights(ctx sdk.Context) (valsetUpdateBlo // DeleteValsetUpdateBlockHeight deletes the block height value for a given vaset update id func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ValsetUpdateBlockHeightKey(valsetUpdateId)) } @@ -791,7 +774,7 @@ func (k Keeper) DeleteValsetUpdateBlockHeight(ctx sdk.Context, valsetUpdateId ui // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) sa := types.SlashAcks{ Addresses: acks, @@ -810,9 +793,9 @@ func (k Keeper) SetSlashAcks(ctx sdk.Context, chainID string, acks []string) { // TODO: SlashAcks should be persisted as a list of ConsumerConsAddr types, not strings. // See https://github.com/cosmos/interchain-security/issues/728 func (k Keeper) GetSlashAcks(ctx sdk.Context, chainID string) []string { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.SlashAcksKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.SlashAcksKey(chainID)) + if bz == nil { return nil } var acks types.SlashAcks @@ -831,14 +814,14 @@ func (k Keeper) ConsumeSlashAcks(ctx sdk.Context, chainID string) (acks []string if len(acks) < 1 { return } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.SlashAcksKey(chainID)) return } // DeleteSlashAcks deletes the slash acks for a given chain ID func (k Keeper) DeleteSlashAcks(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.SlashAcksKey(chainID)) } @@ -853,7 +836,7 @@ func (k Keeper) AppendSlashAck(ctx sdk.Context, chainID, // SetInitChainHeight sets the provider block height when the given consumer chain was initiated func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) heightBytes := make([]byte, 8) binary.BigEndian.PutUint64(heightBytes, height) @@ -862,9 +845,9 @@ func (k Keeper) SetInitChainHeight(ctx sdk.Context, chainID string, height uint6 // GetInitChainHeight returns the provider block height when the given consumer chain was initiated func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.InitChainHeightKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.InitChainHeightKey(chainID)) + if bz == nil { return 0, false } @@ -873,7 +856,7 @@ func (k Keeper) GetInitChainHeight(ctx sdk.Context, chainID string) (uint64, boo // DeleteInitChainHeight deletes the block height value for which the given consumer chain's channel was established func (k Keeper) DeleteInitChainHeight(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.InitChainHeightKey(chainID)) } @@ -881,9 +864,9 @@ func (k Keeper) DeleteInitChainHeight(ctx sdk.Context, chainID string) { func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.ValidatorSetChangePacketData { var packets types.ValidatorSetChangePackets - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PendingVSCsKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PendingVSCsKey(chainID)) + if bz == nil { return []ccv.ValidatorSetChangePacketData{} } if err := packets.Unmarshal(bz); err != nil { @@ -899,7 +882,7 @@ func (k Keeper) GetPendingVSCPackets(ctx sdk.Context, chainID string) []ccv.Vali func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPackets ...ccv.ValidatorSetChangePacketData) { pds := append(k.GetPendingVSCPackets(ctx, chainID), newPackets...) - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) packets := types.ValidatorSetChangePackets{List: pds} buf, err := packets.Marshal() if err != nil { @@ -912,21 +895,21 @@ func (k Keeper) AppendPendingVSCPackets(ctx sdk.Context, chainID string, newPack // DeletePendingVSCPackets deletes the list of pending ValidatorSetChange packets for chain ID func (k Keeper) DeletePendingVSCPackets(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.PendingVSCsKey(chainID)) } // SetConsumerClientId sets the client ID for the given chain ID func (k Keeper) SetConsumerClientId(ctx sdk.Context, chainID, clientID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.ChainToClientKey(chainID), []byte(clientID)) } // GetConsumerClientId returns the client ID for the given chain ID. func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bool) { - store := k.storeService.OpenKVStore(ctx) - clientIdBytes, err := store.Get(types.ChainToClientKey(chainID)) - if err != nil || clientIdBytes == nil { + store := ctx.KVStore(k.storeKey) + clientIdBytes := store.Get(types.ChainToClientKey(chainID)) + if clientIdBytes == nil { return "", false } return string(clientIdBytes), true @@ -934,13 +917,13 @@ func (k Keeper) GetConsumerClientId(ctx sdk.Context, chainID string) (string, bo // DeleteConsumerClientId removes from the store the clientID for the given chainID. func (k Keeper) DeleteConsumerClientId(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ChainToClientKey(chainID)) } // SetInitTimeoutTimestamp sets the init timeout timestamp for the given chain ID func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) tsBytes := make([]byte, 8) binary.BigEndian.PutUint64(tsBytes, ts) store.Set(types.InitTimeoutTimestampKey(chainID), tsBytes) @@ -949,9 +932,9 @@ func (k Keeper) SetInitTimeoutTimestamp(ctx sdk.Context, chainID string, ts uint // GetInitTimeoutTimestamp returns the init timeout timestamp for the given chain ID. // This method is used only in testing. func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.InitTimeoutTimestampKey(chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.InitTimeoutTimestampKey(chainID)) + if bz == nil { return 0, false } return binary.BigEndian.Uint64(bz), true @@ -959,7 +942,7 @@ func (k Keeper) GetInitTimeoutTimestamp(ctx sdk.Context, chainID string) (uint64 // DeleteInitTimeoutTimestamp removes from the store the init timeout timestamp for the given chainID. func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.InitTimeoutTimestampKey(chainID)) } @@ -969,13 +952,8 @@ func (k Keeper) DeleteInitTimeoutTimestamp(ctx sdk.Context, chainID string) { // InitTimeoutTimestampBytePrefix | chainID // Thus, the returned array is in ascending order of chainIDs (NOT in timestamp order). func (k Keeper) GetAllInitTimeoutTimestamps(ctx sdk.Context) (initTimeoutTimestamps []types.InitTimeoutTimestamp) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.InitTimeoutTimestampBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all init timeout timestamps: %v", err) - return []types.InitTimeoutTimestamp{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.InitTimeoutTimestampBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -999,7 +977,7 @@ func (k Keeper) SetVscSendTimestamp( vscID uint64, timestamp time.Time, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) // Convert timestamp into bytes for storage timeBz := sdk.FormatTimeBytes(timestamp) @@ -1011,10 +989,10 @@ func (k Keeper) SetVscSendTimestamp( // // Note: This method is used only for testing. func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) (time.Time, bool) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) - timeBz, err := store.Get(types.VscSendingTimestampKey(chainID, vscID)) - if err != nil || timeBz == nil { + timeBz := store.Get(types.VscSendingTimestampKey(chainID, vscID)) + if timeBz == nil { return time.Time{}, false } @@ -1028,7 +1006,7 @@ func (k Keeper) GetVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint6 // DeleteVscSendTimestamp removes from the store a specific VSC send timestamp // for the given chainID and vscID. func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.VscSendingTimestampKey(chainID, vscID)) } @@ -1038,13 +1016,8 @@ func (k Keeper) DeleteVscSendTimestamp(ctx sdk.Context, chainID string, vscID ui // VscSendTimestampBytePrefix | len(chainID) | chainID | vscID // Thus, the iteration is in ascending order of vscIDs, and as a result in send timestamp order. func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSendTimestamps []types.VscSendTimestamp) { - store := k.storeService.OpenKVStore(ctx) - prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID) - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all vsc send timestamps: %v", err) - return []types.VscSendTimestamp{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -1072,13 +1045,8 @@ func (k Keeper) GetAllVscSendTimestamps(ctx sdk.Context, chainID string) (vscSen // DeleteVscSendTimestampsForConsumer deletes all VSC send timestamps for a given consumer chain func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChainID string) { - store := k.storeService.OpenKVStore(ctx) - prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID) - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error deleting all VSC send timestamps: %v", err) - return - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, consumerChainID)) defer iterator.Close() keysToDel := [][]byte{} @@ -1094,13 +1062,8 @@ func (k Keeper) DeleteVscSendTimestampsForConsumer(ctx sdk.Context, consumerChai // GetFirstVscSendTimestamp gets the vsc send timestamp with the lowest vscID for the given chainID. func (k Keeper) GetFirstVscSendTimestamp(ctx sdk.Context, chainID string) (vscSendTimestamp types.VscSendTimestamp, found bool) { - store := k.storeService.OpenKVStore(ctx) - prefix := types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID) - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting first VSC send timestamps: %v", err) - return types.VscSendTimestamp{}, false - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, types.ChainIdWithLenKey(types.VscSendTimestampBytePrefix, chainID)) defer iterator.Close() if iterator.Valid() { @@ -1133,7 +1096,7 @@ func (k Keeper) SetSlashLog( ctx sdk.Context, providerAddr types.ProviderConsAddress, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Set(types.SlashLogKey(providerAddr), []byte{}) } @@ -1143,9 +1106,9 @@ func (k Keeper) GetSlashLog( ctx sdk.Context, providerAddr types.ProviderConsAddress, ) (found bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.SlashLogKey(providerAddr)) - return err == nil && bz != nil + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.SlashLogKey(providerAddr)) + return bz != nil } func (k Keeper) BondDenom(ctx sdk.Context) (string, error) { diff --git a/x/ccv/provider/keeper/key_assignment.go b/x/ccv/provider/keeper/key_assignment.go index e07cf4f623..564a48f305 100644 --- a/x/ccv/provider/keeper/key_assignment.go +++ b/x/ccv/provider/keeper/key_assignment.go @@ -22,12 +22,12 @@ func (k Keeper) GetValidatorConsumerPubKey( chainID string, providerAddr types.ProviderConsAddress, ) (consumerKey tmprotocrypto.PublicKey, found bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ConsumerValidatorsKey(chainID, providerAddr)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConsumerValidatorsKey(chainID, providerAddr)) + if bz == nil { return consumerKey, false } - err = consumerKey.Unmarshal(bz) + err := consumerKey.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the consumer key is assumed to be correctly serialized in SetValidatorConsumerPubKey. @@ -43,7 +43,7 @@ func (k Keeper) SetValidatorConsumerPubKey( providerAddr types.ProviderConsAddress, consumerKey tmprotocrypto.PublicKey, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := consumerKey.Marshal() if err != nil { // An error here would indicate something is very wrong, @@ -62,7 +62,7 @@ func (k Keeper) SetValidatorConsumerPubKey( // - in ascending order of providerAddresses, if chainID is not nil; // - in undetermined order, if chainID is nil. func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) (validatorConsumerPubKeys []types.ValidatorConsumerPubKey) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) var prefix []byte if chainID == nil { // iterate over the validators public keys assigned for all consumer chains @@ -71,13 +71,8 @@ func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) // iterate over the validators public keys assigned for chainID prefix = types.ChainIdWithLenKey(types.ConsumerValidatorsBytePrefix, *chainID) } - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting public keys of a all validators of chain %s: %v", chainID, err) - return - } + iterator := storetypes.KVStorePrefixIterator(store, prefix) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type chainID, providerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.ConsumerValidatorsBytePrefix, iterator.Key()) @@ -107,7 +102,7 @@ func (k Keeper) GetAllValidatorConsumerPubKeys(ctx sdk.Context, chainID *string) // DeleteValidatorConsumerPubKey deletes a validator's public key assigned for a consumer chain func (k Keeper) DeleteValidatorConsumerPubKey(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ConsumerValidatorsKey(chainID, providerAddr)) } @@ -118,9 +113,9 @@ func (k Keeper) GetValidatorByConsumerAddr( chainID string, consumerAddr types.ConsumerConsAddress, ) (providerAddr types.ProviderConsAddress, found bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) + if bz == nil { return providerAddr, false } providerAddr = types.NewProviderConsAddress(bz) @@ -135,7 +130,7 @@ func (k Keeper) SetValidatorByConsumerAddr( consumerAddr types.ConsumerConsAddress, providerAddr types.ProviderConsAddress, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) // Cons address is a type alias for a byte string, no marshaling needed bz := providerAddr.ToSdkConsAddr() store.Set(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr), bz) @@ -151,7 +146,7 @@ func (k Keeper) SetValidatorByConsumerAddr( // - in ascending order of consumerAddresses, if chainID is not nil; // - in undetermined order, if chainID is nil. func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) (validatorConsumerAddrs []types.ValidatorByConsumerAddr) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) var prefix []byte if chainID == nil { // iterate over the mappings from consensus addresses on all consumer chains @@ -160,14 +155,8 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) // iterate over the mappings from consensus addresses on chainID prefix = types.ChainIdWithLenKey(types.ValidatorsByConsumerAddrBytePrefix, *chainID) } - - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all validators by consumer address: %v", err) - return []types.ValidatorByConsumerAddr{} - } + iterator := storetypes.KVStorePrefixIterator(store, prefix) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and consumer cons address in value bytes, marshaled as protobuf type chainID, consumerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.ValidatorsByConsumerAddrBytePrefix, iterator.Key()) @@ -192,7 +181,7 @@ func (k Keeper) GetAllValidatorsByConsumerAddr(ctx sdk.Context, chainID *string) // DeleteValidatorByConsumerAddr deletes the mapping from a validator's consensus address on a consumer // to the validator's consensus address on the provider func (k Keeper) DeleteValidatorByConsumerAddr(ctx sdk.Context, chainID string, consumerAddr types.ConsumerConsAddress) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ValidatorsByConsumerAddrKey(chainID, consumerAddr)) } @@ -205,13 +194,13 @@ func (k Keeper) GetKeyAssignmentReplacement( providerAddr types.ProviderConsAddress, ) (prevCKey tmprotocrypto.PublicKey, power int64, found bool) { var pubKeyAndPower abci.ValidatorUpdate - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) + if bz == nil { return pubKeyAndPower.PubKey, pubKeyAndPower.Power, false } - err = pubKeyAndPower.Unmarshal(bz) + err := pubKeyAndPower.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the public key and power are assumed to be correctly serialized in SetKeyAssignmentReplacement. @@ -230,7 +219,7 @@ func (k Keeper) SetKeyAssignmentReplacement( prevCKey tmprotocrypto.PublicKey, power int64, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) pubKeyAndPower := abci.ValidatorUpdate{PubKey: prevCKey, Power: power} bz, err := pubKeyAndPower.Marshal() if err != nil { @@ -250,15 +239,10 @@ func (k Keeper) SetKeyAssignmentReplacement( // KeyAssignmentReplacementsBytePrefix | len(chainID) | chainID | providerAddress // Thus, the iteration is in ascending order of providerAddresses. func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) (replacements []types.KeyAssignmentReplacement) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.KeyAssignmentReplacementsBytePrefix, chainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error getting all paris of previous assigned consumer keys: %v", err) - return []types.KeyAssignmentReplacement{} - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { // TODO: store chainID and provider cons address in value bytes, marshaled as protobuf type _, providerAddrTmp, err := types.ParseChainIdAndConsAddrKey(types.KeyAssignmentReplacementsBytePrefix, iterator.Key()) @@ -290,7 +274,7 @@ func (k Keeper) GetAllKeyAssignmentReplacements(ctx sdk.Context, chainID string) // for a provider validator for which a key assignment was received in this block. Both are // needed to update the validator's power on the consumer chain at the end of the current block. func (k Keeper) DeleteKeyAssignmentReplacement(ctx sdk.Context, chainID string, providerAddr types.ProviderConsAddress) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.KeyAssignmentReplacementsKey(chainID, providerAddr)) } @@ -303,10 +287,10 @@ func (k Keeper) DeleteKeyAssignmentReplacement(ctx sdk.Context, chainID string, // s.t. hash(ValidatorConsumerPubKey(pAddr)) = cAddr // - or there exists a vscID in ConsumerAddrsToPrune s.t. cAddr in ConsumerAddrsToPrune(vscID) func (k Keeper) AppendConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscID uint64, consumerAddr types.ConsumerConsAddress) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) var consumerAddrsToPrune types.AddressList - if err == nil && bz != nil { + if bz != nil { err := consumerAddrsToPrune.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, @@ -315,7 +299,7 @@ func (k Keeper) AppendConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscI } } consumerAddrsToPrune.Addresses = append(consumerAddrsToPrune.Addresses, consumerAddr.ToSdkConsAddr()) - bz, err = consumerAddrsToPrune.Marshal() + bz, err := consumerAddrsToPrune.Marshal() if err != nil { // An error here would indicate something is very wrong, // consumerAddrsToPrune is instantiated in this method and should be able to be marshaled. @@ -331,12 +315,12 @@ func (k Keeper) GetConsumerAddrsToPrune( chainID string, vscID uint64, ) (consumerAddrsToPrune types.AddressList) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ConsumerAddrsToPruneKey(chainID, vscID)) + if bz == nil { return } - err = consumerAddrsToPrune.Unmarshal(bz) + err := consumerAddrsToPrune.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the list of consumer addresses is assumed to be correctly serialized in AppendConsumerAddrsToPrune. @@ -351,15 +335,10 @@ func (k Keeper) GetConsumerAddrsToPrune( // ConsumerAddrsToPruneBytePrefix | len(chainID) | chainID | vscID // Thus, the returned array is in ascending order of vscIDs. func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (consumerAddrsToPrune []types.ConsumerAddrsToPrune) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := types.ChainIdWithLenKey(types.ConsumerAddrsToPruneBytePrefix, chainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error getting all consumer addresses to be pruned: %v", err) - return - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() - for ; iterator.Valid(); iterator.Next() { _, vscID, err := types.ParseChainIdAndUintIdKey(types.ConsumerAddrsToPruneBytePrefix, iterator.Key()) if err != nil { @@ -387,7 +366,7 @@ func (k Keeper) GetAllConsumerAddrsToPrune(ctx sdk.Context, chainID string) (con // DeleteConsumerAddrsToPrune deletes the list of consumer addresses mapped to a given VSC ID func (k Keeper) DeleteConsumerAddrsToPrune(ctx sdk.Context, chainID string, vscID uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) store.Delete(types.ConsumerAddrsToPruneKey(chainID, vscID)) } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index f15ab5ffe4..a0bbc27679 100644 --- a/x/ccv/provider/keeper/params.go +++ b/x/ccv/provider/keeper/params.go @@ -8,136 +8,100 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetTemplateClient returns the template client for provider proposals func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'TemplateClient': %v", err) - return types.Params{}.TemplateClient - } - return params.TemplateClient + var cs ibctmtypes.ClientState + k.paramSpace.Get(ctx, types.KeyTemplateClient, &cs) + return &cs } // GetTrustingPeriodFraction returns a TrustingPeriodFraction // used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) string { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'TrustingPeriodFraction': %v", err) - return types.Params{}.TrustingPeriodFraction - } - return params.TrustingPeriodFraction - + var f string + k.paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) + return f } // GetCCVTimeoutPeriod returns the timeout period for sent ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'CcvTimeoutPeriod': %v", err) - return types.Params{}.CcvTimeoutPeriod - } - return params.CcvTimeoutPeriod + var p time.Duration + k.paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p } // GetInitTimeoutPeriod returns the init timeout period func (k Keeper) GetInitTimeoutPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'InitTimeoutPeriod': %v", err) - return types.Params{}.InitTimeoutPeriod - } - return params.InitTimeoutPeriod + var p time.Duration + k.paramSpace.Get(ctx, types.KeyInitTimeoutPeriod, &p) + return p } // GetVscTimeoutPeriod returns the vsc timeout period func (k Keeper) GetVscTimeoutPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'VscTimeoutPeriod': %v", err) - return types.Params{}.VscTimeoutPeriod - } - return params.VscTimeoutPeriod + var p time.Duration + k.paramSpace.Get(ctx, types.KeyVscTimeoutPeriod, &p) + return p } // SetVscTimeoutPeriod sets the vsc timeout period func (k Keeper) SetVscTimeoutPeriod(ctx sdk.Context, period time.Duration) { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error setting parameter 'VscTimeoutPeriod': %v", err) - return - } - params.VscTimeoutPeriod = period - k.SetParams(ctx, params) + k.paramSpace.Set(ctx, types.KeyVscTimeoutPeriod, period) } // GetSlashMeterReplenishPeriod returns the period in which: // Once the slash meter becomes not-full, the slash meter is replenished after this period. func (k Keeper) GetSlashMeterReplenishPeriod(ctx sdk.Context) time.Duration { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishPeriod': %v", err) - return types.Params{}.SlashMeterReplenishPeriod - } - return params.SlashMeterReplenishPeriod + var p time.Duration + k.paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) + return p } // GetSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished // to the slash meter every replenish period. This param also serves as a maximum fraction of total // voting power that the slash meter can hold. func (k Keeper) GetSlashMeterReplenishFraction(ctx sdk.Context) string { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'SlashMeterReplenishFraction': %v", err) - return types.Params{}.SlashMeterReplenishFraction - } - return params.SlashMeterReplenishFraction + var f string + k.paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) + return f } // GetMaxThrottledPackets returns the maximum amount of throttled slash or vsc matured packets // that can be queued for a single consumer before the provider chain halts. func (k Keeper) GetMaxThrottledPackets(ctx sdk.Context) int64 { - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'MaxThrottledPackets': %v", err) - return types.Params{}.MaxThrottledPackets - } - return params.MaxThrottledPackets + var p int64 + k.paramSpace.Get(ctx, types.KeyMaxThrottledPackets, &p) + return p } func (k Keeper) GetConsumerRewardDenomRegistrationFee(ctx sdk.Context) sdk.Coin { // Due to difficulties doing migrations in coordinated upgrades, this param is hardcoded to 10 ATOM in v1.1.0-multiden. // The below code is the proper way to store the param. A future scheduled upgrade will // need to run migrations to add the param. This will allow us to change the fee by governance. - params, err := k.GetParams(ctx) - if err != nil { - k.Logger(ctx).Error("error getting parameter 'ConsumerRewardDenomRegistrationFee': %v", err) - return types.Params{}.ConsumerRewardDenomRegistrationFee - } - return params.ConsumerRewardDenomRegistrationFee + var c sdk.Coin + k.paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) + return c } -// GetParams returns the parameters for the provider module -func (k Keeper) GetParams(ctx sdk.Context) (types.Params, error) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ParametersKey()) - if err != nil { - k.Logger(ctx).Error("error getting module parameters: %v", err) - return types.Params{}, nil //TODO @bermuell: check if default arguments or error handling should be done - } - var params types.Params - err = k.cdc.Unmarshal(bz, ¶ms) - return params, err +// GetParams returns the paramset for the provider module +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams( + k.GetTemplateClient(ctx), + k.GetTrustingPeriodFraction(ctx), + k.GetCCVTimeoutPeriod(ctx), + k.GetInitTimeoutPeriod(ctx), + k.GetVscTimeoutPeriod(ctx), + k.GetSlashMeterReplenishPeriod(ctx), + k.GetSlashMeterReplenishFraction(ctx), + k.GetMaxThrottledPackets(ctx), + k.GetConsumerRewardDenomRegistrationFee(ctx), + ) } // SetParams sets the params for the provider module -func (k Keeper) SetParams(ctx sdk.Context, params types.Params) error { - store := k.storeService.OpenKVStore(ctx) - bz, err := k.cdc.Marshal(¶ms) - if err != nil { - return err - } - return store.Set(types.ParametersKey(), bz) +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + k.paramSpace.SetParamSet(ctx, ¶ms) } diff --git a/x/ccv/provider/keeper/params_test.go b/x/ccv/provider/keeper/params_test.go index c1ebf83124..ec938fffe7 100644 --- a/x/ccv/provider/keeper/params_test.go +++ b/x/ccv/provider/keeper/params_test.go @@ -25,8 +25,7 @@ func TestParams(t *testing.T) { defaultParams := providertypes.DefaultParams() providerKeeper.SetParams(ctx, defaultParams) - params, err := providerKeeper.GetParams(ctx) - require.NoError(t, err) + params := providerKeeper.GetParams(ctx) require.Equal(t, defaultParams, params) newParams := providertypes.NewParams( @@ -53,7 +52,6 @@ func TestParams(t *testing.T) { }, ) providerKeeper.SetParams(ctx, newParams) - params, err = providerKeeper.GetParams(ctx) - require.NoError(t, err) + params = providerKeeper.GetParams(ctx) require.Equal(t, newParams, params) } diff --git a/x/ccv/provider/keeper/proposal.go b/x/ccv/provider/keeper/proposal.go index 9d9e26e0c6..8f90e14448 100644 --- a/x/ccv/provider/keeper/proposal.go +++ b/x/ccv/provider/keeper/proposal.go @@ -143,11 +143,7 @@ func (k Keeper) CreateConsumerClient(ctx sdk.Context, prop *types.ConsumerAdditi k.SetConsumerClientId(ctx, chainID, clientID) // add the init timeout timestamp for this consumer chain - params, err := k.GetParams(ctx) - if err != nil { - return err - } - ts := ctx.BlockTime().Add(params.InitTimeoutPeriod) + ts := ctx.BlockTime().Add(k.GetParams(ctx).InitTimeoutPeriod) k.SetInitTimeoutTimestamp(ctx, chainID, uint64(ts.UnixNano())) k.Logger(ctx).Info("consumer chain registered (client created)", @@ -386,7 +382,7 @@ func (k Keeper) MakeConsumerGenesis( // Thus, if multiple consumer addition proposal for the same chain will pass at // the same time, then only the last one will be stored. func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, prop *types.ConsumerAdditionProposal) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := prop.Marshal() if err != nil { // An error here would indicate something is very wrong @@ -402,12 +398,12 @@ func (k Keeper) SetPendingConsumerAdditionProp(ctx sdk.Context, prop *types.Cons func (k Keeper) GetPendingConsumerAdditionProp(ctx sdk.Context, spawnTime time.Time, chainID string, ) (prop types.ConsumerAdditionProposal, found bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PendingCAPKey(spawnTime, chainID)) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PendingCAPKey(spawnTime, chainID)) + if bz == nil { return prop, false } - err = prop.Unmarshal(bz) + err := prop.Unmarshal(bz) if err != nil { // An error here would indicate something is very wrong, // the ConsumerAdditionProp is assumed to be correctly serialized in SetPendingConsumerAdditionProp. @@ -455,13 +451,8 @@ func (k Keeper) BeginBlockInit(ctx sdk.Context) { // // Note: this method is split out from BeginBlockInit to be easily unit tested. func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecute []types.ConsumerAdditionProposal) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PendingCAPBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting the pending consumer proposals: %v", err) - return []types.ConsumerAdditionProposal{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -490,13 +481,8 @@ func (k Keeper) GetConsumerAdditionPropsToExecute(ctx sdk.Context) (propsToExecu // Thus, the returned array is in spawnTime order. If two proposals have the same spawnTime, // then they are ordered by chainID. func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []types.ConsumerAdditionProposal) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PendingCAPBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting pending consumer addition proposals: %v", err) - return []types.ConsumerAdditionProposal{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCAPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -516,7 +502,7 @@ func (k Keeper) GetAllPendingConsumerAdditionProps(ctx sdk.Context) (props []typ // DeletePendingConsumerAdditionProps deletes the given consumer addition proposals func (k Keeper) DeletePendingConsumerAdditionProps(ctx sdk.Context, proposals ...types.ConsumerAdditionProposal) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) for _, p := range proposals { store.Delete(types.PendingCAPKey(p.SpawnTime, p.ChainId)) @@ -530,7 +516,7 @@ func (k Keeper) DeletePendingConsumerAdditionProps(ctx sdk.Context, proposals .. // Thus, if multiple removal addition proposal for the same chain will pass at // the same time, then only the last one will be stored. func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, prop *types.ConsumerRemovalProposal) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := prop.Marshal() if err != nil { // An error here would indicate something is very wrong @@ -544,16 +530,16 @@ func (k Keeper) SetPendingConsumerRemovalProp(ctx sdk.Context, prop *types.Consu // // Note: this method is only used in testing func (k Keeper) PendingConsumerRemovalPropExists(ctx sdk.Context, chainID string, timestamp time.Time) bool { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.PendingCRPKey(timestamp, chainID)) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.PendingCRPKey(timestamp, chainID)) - return err == nil && bz != nil + return bz != nil } // DeletePendingConsumerRemovalProps deletes the given pending consumer removal proposals. // This method should be called once the proposal has been acted upon. func (k Keeper) DeletePendingConsumerRemovalProps(ctx sdk.Context, proposals ...types.ConsumerRemovalProposal) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) for _, p := range proposals { store.Delete(types.PendingCRPKey(p.StopTime, p.ChainId)) @@ -603,13 +589,8 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum // store the (to be) executed consumer removal proposals in order propsToExecute := []types.ConsumerRemovalProposal{} - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PendingCRPBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting pending consumer removal proposals to be executed: %v", err) - return []types.ConsumerRemovalProposal{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -639,13 +620,8 @@ func (k Keeper) GetConsumerRemovalPropsToExecute(ctx sdk.Context) []types.Consum // PendingCRPBytePrefix | stopTime.UnixNano() | chainID // Thus, the returned array is in stopTime order. func (k Keeper) GetAllPendingConsumerRemovalProps(ctx sdk.Context) (props []types.ConsumerRemovalProposal) { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{types.PendingCRPBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting pending cosumer removal proposals: %v", err) - return []types.ConsumerRemovalProposal{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{types.PendingCRPBytePrefix}) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 75be344df9..0d3ffa342f 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -514,10 +514,6 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { } } - params, err := k.GetParams(ctx) - if err != nil { - panic(fmt.Errorf("invalid provider parameters: %v", err)) - } for _, channelToChain := range k.GetAllChannelToChains(ctx) { // Check if the first vscSendTimestamp in iterator + VscTimeoutPeriod // exceed the current block time. @@ -526,7 +522,7 @@ func (k Keeper) EndBlockCCR(ctx sdk.Context) { // Note: GetFirstVscSendTimestamp panics if the internal state is invalid vscSendTimestamp, found := k.GetFirstVscSendTimestamp(ctx, channelToChain.ChainId) if found { - timeoutTimestamp := vscSendTimestamp.Timestamp.Add(params.VscTimeoutPeriod) + timeoutTimestamp := vscSendTimestamp.Timestamp.Add(k.GetParams(ctx).VscTimeoutPeriod) if currentTime.After(timeoutTimestamp) { // vscTimeout expired // stop the consumer chain and release unbondings diff --git a/x/ccv/provider/keeper/throttle.go b/x/ccv/provider/keeper/throttle.go index cca808b26c..64a1e47e4e 100644 --- a/x/ccv/provider/keeper/throttle.go +++ b/x/ccv/provider/keeper/throttle.go @@ -229,7 +229,7 @@ func (k Keeper) GetSlashMeterAllowance(ctx sdktypes.Context) math.Int { // between chains, whereas the chain-specific queue is used to coordinate the order of slash and vsc matured packets // relevant to each chain. func (k Keeper) QueueGlobalSlashEntry(ctx sdktypes.Context, entry providertypes.GlobalSlashEntry) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) key := providertypes.GlobalSlashEntryKey(entry) bz := entry.ProviderValConsAddr store.Set(key, bz) @@ -255,13 +255,8 @@ func (k Keeper) DeleteGlobalSlashEntriesForConsumer(ctx sdktypes.Context, consum // GlobalSlashEntryBytePrefix | uint64 recv time | ibc seq num | consumer chain id // Thus, the returned array is ordered by recv time, then ibc seq num. func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.GlobalSlashEntry { - store := k.storeService.OpenKVStore(ctx) - prefix := []byte{providertypes.GlobalSlashEntryBytePrefix} - iterator, err := store.Iterator(prefix, storetypes.PrefixEndBytes(prefix)) - if err != nil { - k.Logger(ctx).Error("error getting all global slash entries: %v", err) - return []providertypes.GlobalSlashEntry{} - } + store := ctx.KVStore(k.storeKey) + iterator := storetypes.KVStorePrefixIterator(store, []byte{providertypes.GlobalSlashEntryBytePrefix}) defer iterator.Close() entries := []providertypes.GlobalSlashEntry{} @@ -279,7 +274,7 @@ func (k Keeper) GetAllGlobalSlashEntries(ctx sdktypes.Context) []providertypes.G // DeleteGlobalSlashEntries deletes the given global entries from the global slash queue func (k Keeper) DeleteGlobalSlashEntries(ctx sdktypes.Context, entries ...providertypes.GlobalSlashEntry) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) for _, entry := range entries { store.Delete(providertypes.GlobalSlashEntryKey(entry)) } @@ -293,11 +288,11 @@ const ( // GetThrottledPacketDataSize returns the size of the throttled packet data queue for the given consumer chain func (k Keeper) GetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID string) uint64 { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) var size uint64 - bz, err := store.Get(key) - if err != nil || bz == nil { + bz := store.Get(key) + if bz == nil { size = 0 } else { size = sdktypes.BigEndianToUint64(bz) @@ -314,7 +309,7 @@ func (k Keeper) SetThrottledPacketDataSize(ctx sdktypes.Context, consumerChainID panic(fmt.Sprintf("throttled packet data queue for chain %s is too large: %d", consumerChainID, size)) } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) key := providertypes.ThrottledPacketDataSizeKey(consumerChainID) bz := sdktypes.Uint64ToBigEndian(size) store.Set(key, bz) @@ -358,7 +353,7 @@ func (k Keeper) QueueThrottledVSCMaturedPacketData( func (k Keeper) QueueThrottledPacketData( ctx sdktypes.Context, consumerChainID string, ibcSeqNum uint64, packetData interface{}, ) error { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) var bz []byte var err error @@ -392,13 +387,9 @@ func (k Keeper) QueueThrottledPacketData( func (k Keeper) GetLeadingVSCMaturedData(ctx sdktypes.Context, consumerChainID string) ( vscMaturedData []ccvtypes.VSCMaturedPacketData, ibcSeqNums []uint64, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error getting leading VSC matured packets: %v", err) - return []ccvtypes.VSCMaturedPacketData{}, []uint64{} - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() // Iterate over the throttled packet data queue, @@ -446,13 +437,9 @@ func (k Keeper) GetSlashAndTrailingData(ctx sdktypes.Context, consumerChainID st // data after it has been handled. ibcSeqNums []uint64, ) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error getting first slash packet data: %v", err) - return false, slashData, []ccvtypes.VSCMaturedPacketData{}, []uint64{} - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() slashFound = false @@ -509,13 +496,9 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID rawOrderedData = []interface{}{} ibcSeqNums = []uint64{} - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error getting all throttled packets: %v", err) - return - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() for ; iterator.Valid(); iterator.Next() { @@ -554,13 +537,9 @@ func (k Keeper) GetAllThrottledPacketData(ctx sdktypes.Context, consumerChainID // DeleteAllPacketDataForConsumer deletes all queued packet data for the given consumer chain. func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consumerChainID string) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) iteratorPrefix := providertypes.ChainIdWithLenKey(providertypes.ThrottledPacketDataBytePrefix, consumerChainID) - iterator, err := store.Iterator(iteratorPrefix, storetypes.PrefixEndBytes(iteratorPrefix)) - if err != nil { - k.Logger(ctx).Error("error deleting all queued packets for consumer chain %s: %v", consumerChainID, err) - return - } + iterator := storetypes.KVStorePrefixIterator(store, iteratorPrefix) defer iterator.Close() keysToDel := [][]byte{} @@ -579,7 +558,7 @@ func (k Keeper) DeleteThrottledPacketDataForConsumer(ctx sdktypes.Context, consu // DeleteThrottledPacketData deletes the given throttled packet data instances // (specified by their ibc seq number) from the chain-specific throttled packet data queue. func (k Keeper) DeleteThrottledPacketData(ctx sdktypes.Context, consumerChainID string, ibcSeqNumbers ...uint64) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) for _, ibcSeqNum := range ibcSeqNumbers { store.Delete(providertypes.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) } @@ -593,15 +572,15 @@ func (k Keeper) DeleteThrottledPacketData(ctx sdktypes.Context, consumerChainID // // Note: the value of this int should always be in the range of tendermint's [-MaxVotingPower, MaxVotingPower] func (k Keeper) GetSlashMeter(ctx sdktypes.Context) math.Int { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(providertypes.SlashMeterKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(providertypes.SlashMeterKey()) + if bz == nil { // Slash meter should be set as a part of InitGenesis and periodically updated by throttle logic, // there is no deletion method exposed, so nil bytes would indicate something is very wrong. panic("slash meter not set") } value := math.ZeroInt() - err = value.Unmarshal(bz) + err := value.Unmarshal(bz) if err != nil { // We should have obtained value bytes that were serialized in SetSlashMeter, // so an error here would indicate something is very wrong. @@ -628,7 +607,7 @@ func (k Keeper) SetSlashMeter(ctx sdktypes.Context, value math.Int) { if value.LT(math.NewInt(-tmtypes.MaxTotalVotingPower)) { panic("slash meter value cannot be less than negative tendermint's MaxTotalVotingPower") } - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) bz, err := value.Marshal() if err != nil { // A returned error for marshaling an int would indicate something is very wrong. @@ -642,9 +621,9 @@ func (k Keeper) SetSlashMeter(ctx sdktypes.Context, value math.Int) { // Note: this value is the next time the slash meter will be replenished IFF the slash meter is NOT full. // Otherwise this value will be updated in every future block until the slash meter becomes NOT full. func (k Keeper) GetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) time.Time { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(providertypes.SlashMeterReplenishTimeCandidateKey()) - if err != nil || bz == nil { + store := ctx.KVStore(k.storeKey) + bz := store.Get(providertypes.SlashMeterReplenishTimeCandidateKey()) + if bz == nil { // Slash meter replenish time candidate should be set as a part of InitGenesis and periodically updated by throttle logic, // there is no deletion method exposed, so nil bytes would indicate something is very wrong. panic("slash meter replenish time candidate not set") @@ -664,7 +643,7 @@ func (k Keeper) GetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) time.T // Note: this value is the next time the slash meter will be replenished IFF the slash meter is NOT full. // Otherwise this value will be updated in every future block until the slash meter becomes NOT full. func (k Keeper) SetSlashMeterReplenishTimeCandidate(ctx sdktypes.Context) { - store := k.storeService.OpenKVStore(ctx) + store := ctx.KVStore(k.storeKey) timeToStore := ctx.BlockTime().UTC().Add(k.GetSlashMeterReplenishPeriod(ctx)) store.Set(providertypes.SlashMeterReplenishTimeCandidateKey(), sdktypes.FormatTimeBytes(timeToStore)) } diff --git a/x/ccv/provider/module_test.go b/x/ccv/provider/module_test.go index f446c35203..ba3ec30b67 100644 --- a/x/ccv/provider/module_test.go +++ b/x/ccv/provider/module_test.go @@ -177,9 +177,7 @@ func TestInitGenesis(t *testing.T) { // Expect slash meter to be initialized to it's allowance value // (replenish fraction * mocked value defined above) slashMeter := providerKeeper.GetSlashMeter(ctx) - params, err := providerKeeper.GetParams(ctx) - require.NoError(t, err) - replenishFraction, err := math.LegacyNewDecFromStr(params.SlashMeterReplenishFraction) + replenishFraction, err := math.LegacyNewDecFromStr(providerKeeper.GetParams(ctx).SlashMeterReplenishFraction) require.NoError(t, err) expectedSlashMeterValue := math.NewInt(replenishFraction.MulInt(math.NewInt(100)).RoundInt64()) require.Equal(t, expectedSlashMeterValue, slashMeter) diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index 3f9ed11fa2..9a4cbdb149 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -55,6 +55,11 @@ var ( KeyConsumerRewardDenomRegistrationFee = []byte("ConsumerRewardDenomRegistrationFee") ) +// ParamKeyTable returns a key table with the necessary registered provider params +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + // NewParams creates new provider parameters with provided arguments func NewParams( cs *ibctmtypes.ClientState, diff --git a/x/ccv/types/params.go b/x/ccv/types/params.go index 7091e02b25..d44ec68c80 100644 --- a/x/ccv/types/params.go +++ b/x/ccv/types/params.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" sdktypes "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) @@ -56,6 +57,11 @@ var ( KeyProviderRewardDenoms = []byte("ProviderRewardDenoms") ) +// ParamKeyTable type declaration for parameters +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + // NewParams creates new consumer parameters with provided arguments func NewParams(enabled bool, blocksPerDistributionTransmission int64, distributionTransmissionChannel, providerFeePoolAddrStr string, @@ -140,6 +146,35 @@ func (p Params) Validate() error { return nil } +// ParamSetPairs implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyEnabled, p.Enabled, ValidateBool), + paramtypes.NewParamSetPair(KeyBlocksPerDistributionTransmission, + p.BlocksPerDistributionTransmission, ValidatePositiveInt64), + paramtypes.NewParamSetPair(KeyDistributionTransmissionChannel, + p.DistributionTransmissionChannel, ValidateDistributionTransmissionChannel), + paramtypes.NewParamSetPair(KeyProviderFeePoolAddrStr, + p.ProviderFeePoolAddrStr, ValidateProviderFeePoolAddrStr), + paramtypes.NewParamSetPair(KeyCCVTimeoutPeriod, + p.CcvTimeoutPeriod, ValidateDuration), + paramtypes.NewParamSetPair(KeyTransferTimeoutPeriod, + p.TransferTimeoutPeriod, ValidateDuration), + paramtypes.NewParamSetPair(KeyConsumerRedistributionFrac, + p.ConsumerRedistributionFraction, ValidateStringFraction), + paramtypes.NewParamSetPair(KeyHistoricalEntries, + p.HistoricalEntries, ValidatePositiveInt64), + paramtypes.NewParamSetPair(KeyConsumerUnbondingPeriod, + p.UnbondingPeriod, ValidateDuration), + paramtypes.NewParamSetPair(KeySoftOptOutThreshold, + p.SoftOptOutThreshold, ValidateSoftOptOutThreshold), + paramtypes.NewParamSetPair(KeyRewardDenoms, + p.RewardDenoms, ValidateDenoms), + paramtypes.NewParamSetPair(KeyProviderRewardDenoms, + p.ProviderRewardDenoms, ValidateDenoms), + } +} + func ValidateProviderFeePoolAddrStr(i interface{}) error { // Accept empty string as valid, since this will be the default value on genesis if i == "" { From 849d91378f874691479556977ef48cbe830c6bad Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Mon, 13 Nov 2023 16:33:13 +0100 Subject: [PATCH 5/8] use module's store instead of x/param parameter space --- x/ccv/consumer/keeper/keeper.go | 46 +++++------- x/ccv/consumer/keeper/params.go | 104 +++++++++++++--------------- x/ccv/provider/keeper/grpc_query.go | 5 +- x/ccv/provider/keeper/keeper.go | 43 +++++------- x/ccv/provider/keeper/msg_server.go | 4 +- x/ccv/provider/keeper/params.go | 74 +++++++++----------- 6 files changed, 119 insertions(+), 157 deletions(-) diff --git a/x/ccv/consumer/keeper/keeper.go b/x/ccv/consumer/keeper/keeper.go index 84167e61f8..c476db718d 100644 --- a/x/ccv/consumer/keeper/keeper.go +++ b/x/ccv/consumer/keeper/keeper.go @@ -39,7 +39,6 @@ type Keeper struct { storeKey storetypes.StoreKey // TODO: maybe needs to be removed? storeService store.KVStoreService cdc codec.BinaryCodec - paramStore paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -83,7 +82,6 @@ func NewKeeper( authority: authority, storeKey: key, cdc: cdc, - paramStore: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -108,9 +106,8 @@ func NewKeeper( // Used only in testing. func NewNonZeroKeeper(cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace) Keeper { return Keeper{ - storeKey: key, - cdc: cdc, - paramStore: paramSpace, + storeKey: key, + cdc: cdc, } } @@ -120,18 +117,12 @@ func (k *Keeper) SetStandaloneStakingKeeper(sk ccv.StakingKeeper) { k.standaloneStakingKeeper = sk } -// SetParamSpace sets the param space for the consumer keeper. -// Note: this is only used for testing! -func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { - k.paramStore = ps -} - // Validates that the consumer keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation // TODO: @MSalopek hangle this better - if reflect.ValueOf(k).NumField() != 20 { + if reflect.ValueOf(k).NumField() != 19 { panic(fmt.Sprintf("number of fields in consumer keeper is not 19 - have %d", reflect.ValueOf(k).NumField())) // incorrect number } @@ -139,26 +130,25 @@ func (k Keeper) mustValidateFields() { panic("validator and/or consensus address codec are nil") } - // Note 17 / 20 fields will be validated, + // Note 16 / 19 fields will be validated, // hooks are explicitly set after the constructor, // stakingKeeper is optionally set after the constructor, ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 1 ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 2 - ccv.PanicIfZeroOrNil(k.paramStore, "paramStore") // 3 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 9 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 10 - ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 11 - ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 12 - ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 13 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 7 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 8 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 9 + ccv.PanicIfZeroOrNil(k.authKeeper, "authKeeper") // 10 + ccv.PanicIfZeroOrNil(k.ibcTransferKeeper, "ibcTransferKeeper") // 11 + ccv.PanicIfZeroOrNil(k.ibcCoreKeeper, "ibcCoreKeeper") // 12 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 } // Logger returns a module-specific logger. diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index 9bd0d1fa10..ce680e4860 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -2,36 +2,34 @@ package keeper import ( "context" + "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types" ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetParams returns the params for the consumer ccv module // NOTE: it is different from the GetParams method which is required to implement StakingKeeper interface func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params { - return ccvtypes.NewParams( - k.GetEnabled(ctx), - k.GetBlocksPerDistributionTransmission(ctx), - k.GetDistributionTransmissionChannel(ctx), - k.GetProviderFeePoolAddrStr(ctx), - k.GetCCVTimeoutPeriod(ctx), - k.GetTransferTimeoutPeriod(ctx), - k.GetConsumerRedistributionFrac(ctx), - k.GetHistoricalEntries(ctx), - k.GetUnbondingPeriod(ctx), - k.GetSoftOptOutThreshold(ctx), - k.GetRewardDenoms(ctx), - k.GetProviderRewardDenoms(ctx), - ) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParametersKey()) + var params ccvtypes.Params + err := k.cdc.Unmarshal(bz, ¶ms) + if err != nil { + panic(fmt.Sprintf("error unmarshalling module parameters: %v:", err)) + } + return params } // SetParams sets the paramset for the consumer module func (k Keeper) SetParams(ctx sdk.Context, params ccvtypes.Params) { - k.paramStore.SetParamSet(ctx, ¶ms) + store := ctx.KVStore(k.storeKey) + bz := k.cdc.MustMarshal(¶ms) + store.Set(types.ParametersKey(), bz) } // GetParams implements StakingKeeper GetParams interface method @@ -44,98 +42,94 @@ func (k Keeper) GetParams(context.Context) (stakingtypes.Params, error) { // GetEnabled returns the enabled flag for the consumer module func (k Keeper) GetEnabled(ctx sdk.Context) bool { - var enabled bool - k.paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) - return enabled + params := k.GetConsumerParams(ctx) + return params.Enabled } func (k Keeper) GetBlocksPerDistributionTransmission(ctx sdk.Context) int64 { - var bpdt int64 - k.paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) - return bpdt + params := k.GetConsumerParams(ctx) + return params.BlocksPerDistributionTransmission } func (k Keeper) SetBlocksPerDistributionTransmission(ctx sdk.Context, bpdt int64) { - k.paramStore.Set(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, bpdt) + params := k.GetConsumerParams(ctx) + params.BlocksPerDistributionTransmission = bpdt + k.SetParams(ctx, params) } func (k Keeper) GetDistributionTransmissionChannel(ctx sdk.Context) string { - var s string - k.paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) - return s + params := k.GetConsumerParams(ctx) + return params.DistributionTransmissionChannel } func (k Keeper) SetDistributionTransmissionChannel(ctx sdk.Context, channel string) { - k.paramStore.Set(ctx, ccvtypes.KeyDistributionTransmissionChannel, channel) + params := k.GetConsumerParams(ctx) + params.DistributionTransmissionChannel = channel + k.SetParams(ctx, params) } func (k Keeper) GetProviderFeePoolAddrStr(ctx sdk.Context) string { - var s string - k.paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) - return s + params := k.GetConsumerParams(ctx) + return params.ProviderFeePoolAddrStr } func (k Keeper) SetProviderFeePoolAddrStr(ctx sdk.Context, addr string) { - k.paramStore.Set(ctx, ccvtypes.KeyProviderFeePoolAddrStr, addr) + params := k.GetConsumerParams(ctx) + params.ProviderFeePoolAddrStr = addr + k.SetParams(ctx, params) } // GetCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p + params := k.GetConsumerParams(ctx) + return params.CcvTimeoutPeriod } // GetTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets func (k Keeper) GetTransferTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) - return p + params := k.GetConsumerParams(ctx) + return params.TransferTimeoutPeriod } // GetConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution // address during distribution events. The fraction is a string representing a // decimal number. For example "0.75" would represent 75%. func (k Keeper) GetConsumerRedistributionFrac(ctx sdk.Context) string { - var str string - k.paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) - return str + params := k.GetConsumerParams(ctx) + return params.ConsumerRedistributionFraction } // GetHistoricalEntries returns the number of historical info entries to persist in store func (k Keeper) GetHistoricalEntries(ctx sdk.Context) int64 { - var n int64 - k.paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) - return n + params := k.GetConsumerParams(ctx) + return params.HistoricalEntries } // Only used to set an unbonding period in diff tests func (k Keeper) SetUnbondingPeriod(ctx sdk.Context, period time.Duration) { - k.paramStore.Set(ctx, ccvtypes.KeyConsumerUnbondingPeriod, period) + params := k.GetConsumerParams(ctx) + params.UnbondingPeriod = period + k.SetParams(ctx, params) } func (k Keeper) GetUnbondingPeriod(ctx sdk.Context) time.Duration { - var period time.Duration - k.paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) - return period + params := k.GetConsumerParams(ctx) + return params.UnbondingPeriod } // GetSoftOptOutThreshold returns the percentage of validators at the bottom of the set // that can opt out of running the consumer chain func (k Keeper) GetSoftOptOutThreshold(ctx sdk.Context) string { - var str string - k.paramStore.Get(ctx, ccvtypes.KeySoftOptOutThreshold, &str) - return str + params := k.GetConsumerParams(ctx) + return params.SoftOptOutThreshold } func (k Keeper) GetRewardDenoms(ctx sdk.Context) []string { - var denoms []string - k.paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) - return denoms + params := k.GetConsumerParams(ctx) + return params.RewardDenoms } func (k Keeper) GetProviderRewardDenoms(ctx sdk.Context) []string { - var denoms []string - k.paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) - return denoms + params := k.GetConsumerParams(ctx) + return params.ProviderRewardDenoms } diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 189796738f..4e896525cc 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -42,10 +42,7 @@ func (k Keeper) QueryParams(goCtx context.Context, req *types.QueryParamsRequest } ctx := sdk.UnwrapSDKContext(goCtx) - params, err := k.GetParams(ctx) - if err != nil { - return nil, status.Error(codes.NotFound, "no parameters found") - } + params := k.GetParams(ctx) return &types.QueryParamsResponse{Params: params}, nil } diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index 996ce651cd..605cfc0fd9 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -42,7 +42,6 @@ type Keeper struct { storeService store.KVStoreService cdc codec.BinaryCodec - paramSpace paramtypes.Subspace scopedKeeper ccv.ScopedKeeper channelKeeper ccv.ChannelKeeper portKeeper ccv.PortKeeper @@ -79,7 +78,6 @@ func NewKeeper( cdc: cdc, storeKey: key, authority: authority, - paramSpace: paramSpace, scopedKeeper: scopedKeeper, channelKeeper: channelKeeper, portKeeper: portKeeper, @@ -114,19 +112,13 @@ func (k Keeper) ConsensusAddressCodec() addresscodec.Codec { return k.consensusAddressCodec } -// SetParamSpace sets the param space for the provider keeper. -// Note: this is only used for testing! -func (k *Keeper) SetParamSpace(ctx sdk.Context, ps paramtypes.Subspace) { - k.paramSpace = ps -} - // TODO: @MSalopek -> redo validation; some fields will be removed // Validates that the provider keeper is initialized with non-zero and // non-nil values for all its fields. Otherwise this method will panic. func (k Keeper) mustValidateFields() { // Ensures no fields are missed in this validation - if reflect.ValueOf(k).NumField() != 18 { - panic("number of fields in provider keeper is not 18") + if reflect.ValueOf(k).NumField() != 17 { + panic("number of fields in provider keeper is not 17") } // TODO: @MSalopek -> validate once connected and AccountKeeper interface is updated @@ -141,23 +133,22 @@ func (k Keeper) mustValidateFields() { ccv.PanicIfZeroOrNil(k.cdc, "cdc") // 1 ccv.PanicIfZeroOrNil(k.storeKey, "storeKey") // 2 - ccv.PanicIfZeroOrNil(k.paramSpace, "paramSpace") // 3 - ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 4 - ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 5 - ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 6 - ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 7 - ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 8 - ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 9 - ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 10 - ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 11 - ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 12 - ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 13 - ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 14 - ccv.PanicIfZeroOrNil(k.authority, "authority") // 15 - ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 16 - ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 17 + ccv.PanicIfZeroOrNil(k.scopedKeeper, "scopedKeeper") // 3 + ccv.PanicIfZeroOrNil(k.channelKeeper, "channelKeeper") // 4 + ccv.PanicIfZeroOrNil(k.portKeeper, "portKeeper") // 5 + ccv.PanicIfZeroOrNil(k.connectionKeeper, "connectionKeeper") // 6 + ccv.PanicIfZeroOrNil(k.accountKeeper, "accountKeeper") // 7 + ccv.PanicIfZeroOrNil(k.clientKeeper, "clientKeeper") // 8 + ccv.PanicIfZeroOrNil(k.stakingKeeper, "stakingKeeper") // 9 + ccv.PanicIfZeroOrNil(k.slashingKeeper, "slashingKeeper") // 10 + ccv.PanicIfZeroOrNil(k.distributionKeeper, "distributionKeeper") // 11 + ccv.PanicIfZeroOrNil(k.bankKeeper, "bankKeeper") // 12 + ccv.PanicIfZeroOrNil(k.feeCollectorName, "feeCollectorName") // 13 + ccv.PanicIfZeroOrNil(k.authority, "authority") // 14 + ccv.PanicIfZeroOrNil(k.validatorAddressCodec, "validatorAddressCodec") // 15 + ccv.PanicIfZeroOrNil(k.consensusAddressCodec, "consensusAddressCodec") // 16 // TODO: @MSalopek -> validate once connected - // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 18 + // ccv.PanicIfZeroOrNil(k.storeService, "storeService") // 17 } // Logger returns a module-specific logger. diff --git a/x/ccv/provider/keeper/msg_server.go b/x/ccv/provider/keeper/msg_server.go index 2e8098cc5d..d96fd3dfb4 100644 --- a/x/ccv/provider/keeper/msg_server.go +++ b/x/ccv/provider/keeper/msg_server.go @@ -35,9 +35,7 @@ func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParam } ctx := sdk.UnwrapSDKContext(goCtx) - if err := k.Keeper.SetParams(ctx, msg.Params); err != nil { - return nil, err - } + k.Keeper.SetParams(ctx, msg.Params) return &types.MsgUpdateParamsResponse{}, nil } diff --git a/x/ccv/provider/keeper/params.go b/x/ccv/provider/keeper/params.go index a0bbc27679..5457465e88 100644 --- a/x/ccv/provider/keeper/params.go +++ b/x/ccv/provider/keeper/params.go @@ -1,6 +1,7 @@ package keeper import ( + "fmt" "time" ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -8,100 +9,91 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" - ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) // GetTemplateClient returns the template client for provider proposals func (k Keeper) GetTemplateClient(ctx sdk.Context) *ibctmtypes.ClientState { - var cs ibctmtypes.ClientState - k.paramSpace.Get(ctx, types.KeyTemplateClient, &cs) - return &cs + params := k.GetParams(ctx) + return params.TemplateClient } // GetTrustingPeriodFraction returns a TrustingPeriodFraction // used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction func (k Keeper) GetTrustingPeriodFraction(ctx sdk.Context) string { - var f string - k.paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) - return f + params := k.GetParams(ctx) + return params.TrustingPeriodFraction } // GetCCVTimeoutPeriod returns the timeout period for sent ibc packets func (k Keeper) GetCCVTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) - return p + params := k.GetParams(ctx) + return params.CcvTimeoutPeriod } // GetInitTimeoutPeriod returns the init timeout period func (k Keeper) GetInitTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeyInitTimeoutPeriod, &p) - return p + params := k.GetParams(ctx) + return params.InitTimeoutPeriod } // GetVscTimeoutPeriod returns the vsc timeout period func (k Keeper) GetVscTimeoutPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeyVscTimeoutPeriod, &p) - return p + params := k.GetParams(ctx) + return params.VscTimeoutPeriod } // SetVscTimeoutPeriod sets the vsc timeout period func (k Keeper) SetVscTimeoutPeriod(ctx sdk.Context, period time.Duration) { - k.paramSpace.Set(ctx, types.KeyVscTimeoutPeriod, period) + params := k.GetParams(ctx) + params.VscTimeoutPeriod = period + k.SetParams(ctx, params) } // GetSlashMeterReplenishPeriod returns the period in which: // Once the slash meter becomes not-full, the slash meter is replenished after this period. func (k Keeper) GetSlashMeterReplenishPeriod(ctx sdk.Context) time.Duration { - var p time.Duration - k.paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) - return p + params := k.GetParams(ctx) + return params.SlashMeterReplenishPeriod } // GetSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished // to the slash meter every replenish period. This param also serves as a maximum fraction of total // voting power that the slash meter can hold. func (k Keeper) GetSlashMeterReplenishFraction(ctx sdk.Context) string { - var f string - k.paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) - return f + params := k.GetParams(ctx) + return params.SlashMeterReplenishFraction } // GetMaxThrottledPackets returns the maximum amount of throttled slash or vsc matured packets // that can be queued for a single consumer before the provider chain halts. func (k Keeper) GetMaxThrottledPackets(ctx sdk.Context) int64 { - var p int64 - k.paramSpace.Get(ctx, types.KeyMaxThrottledPackets, &p) - return p + params := k.GetParams(ctx) + return params.MaxThrottledPackets } func (k Keeper) GetConsumerRewardDenomRegistrationFee(ctx sdk.Context) sdk.Coin { // Due to difficulties doing migrations in coordinated upgrades, this param is hardcoded to 10 ATOM in v1.1.0-multiden. // The below code is the proper way to store the param. A future scheduled upgrade will // need to run migrations to add the param. This will allow us to change the fee by governance. - var c sdk.Coin - k.paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) - return c + params := k.GetParams(ctx) + return params.ConsumerRewardDenomRegistrationFee } // GetParams returns the paramset for the provider module func (k Keeper) GetParams(ctx sdk.Context) types.Params { - return types.NewParams( - k.GetTemplateClient(ctx), - k.GetTrustingPeriodFraction(ctx), - k.GetCCVTimeoutPeriod(ctx), - k.GetInitTimeoutPeriod(ctx), - k.GetVscTimeoutPeriod(ctx), - k.GetSlashMeterReplenishPeriod(ctx), - k.GetSlashMeterReplenishFraction(ctx), - k.GetMaxThrottledPackets(ctx), - k.GetConsumerRewardDenomRegistrationFee(ctx), - ) + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ParametersKey()) + var params types.Params + err := k.cdc.Unmarshal(bz, ¶ms) + if err != nil { + panic(fmt.Sprintf("error unmarshalling module parameters: %v:", err)) + } + return params } // SetParams sets the params for the provider module 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.ParametersKey(), bz) } From 7e436b7552a86ef71ab8aa18e99f97933a6e83a1 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Tue, 14 Nov 2023 13:58:53 +0100 Subject: [PATCH 6/8] Added migration + tests --- x/ccv/consumer/keeper/legacy_params.go | 111 ++++++++++++++++++++++++ x/ccv/consumer/keeper/migration.go | 13 +++ x/ccv/consumer/keeper/migration_test.go | 34 ++++++++ x/ccv/consumer/module.go | 6 ++ x/ccv/provider/keeper/legacy_params.go | 95 ++++++++++++++++++++ x/ccv/provider/keeper/migration.go | 19 ++-- x/ccv/provider/keeper/migration_test.go | 41 +++++++++ x/ccv/provider/module.go | 7 +- 8 files changed, 313 insertions(+), 13 deletions(-) create mode 100644 x/ccv/consumer/keeper/legacy_params.go create mode 100644 x/ccv/provider/keeper/legacy_params.go create mode 100644 x/ccv/provider/keeper/migration_test.go diff --git a/x/ccv/consumer/keeper/legacy_params.go b/x/ccv/consumer/keeper/legacy_params.go new file mode 100644 index 0000000000..abbb2a8d35 --- /dev/null +++ b/x/ccv/consumer/keeper/legacy_params.go @@ -0,0 +1,111 @@ +package keeper + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" +) + +// Legacy: used for migration only! +// GetConsumerParamsLegacy returns the params for the consumer ccv module from x/param subspace +// which will be depreacted soon +func (k Keeper) GetConsumerParamsLegacy(ctx sdk.Context, paramSpace paramtypes.Subspace) ccvtypes.Params { + return ccvtypes.NewParams( + getEnabled(ctx, paramSpace), + getBlocksPerDistributionTransmission(ctx, paramSpace), + getDistributionTransmissionChannel(ctx, paramSpace), + getProviderFeePoolAddrStr(ctx, paramSpace), + getCCVTimeoutPeriod(ctx, paramSpace), + getTransferTimeoutPeriod(ctx, paramSpace), + getConsumerRedistributionFrac(ctx, paramSpace), + getHistoricalEntries(ctx, paramSpace), + getUnbondingPeriod(ctx, paramSpace), + getSoftOptOutThreshold(ctx, paramSpace), + getRewardDenoms(ctx, paramSpace), + getProviderRewardDenoms(ctx, paramSpace), + ) +} + +// getEnabled returns the enabled flag for the consumer module +func getEnabled(ctx sdk.Context, paramStore paramtypes.Subspace) bool { + var enabled bool + paramStore.Get(ctx, ccvtypes.KeyEnabled, &enabled) + return enabled +} + +func getBlocksPerDistributionTransmission(ctx sdk.Context, paramStore paramtypes.Subspace) int64 { + var bpdt int64 + paramStore.Get(ctx, ccvtypes.KeyBlocksPerDistributionTransmission, &bpdt) + return bpdt +} + +func getDistributionTransmissionChannel(ctx sdk.Context, paramStore paramtypes.Subspace) string { + var s string + paramStore.Get(ctx, ccvtypes.KeyDistributionTransmissionChannel, &s) + return s +} + +func getProviderFeePoolAddrStr(ctx sdk.Context, paramStore paramtypes.Subspace) string { + var s string + paramStore.Get(ctx, ccvtypes.KeyProviderFeePoolAddrStr, &s) + return s +} + +// getCCVTimeoutPeriod returns the timeout period for sent ccv related ibc packets +func getCCVTimeoutPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { + var p time.Duration + paramStore.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p +} + +// getTransferTimeoutPeriod returns the timeout period for sent transfer related ibc packets +func getTransferTimeoutPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { + var p time.Duration + paramStore.Get(ctx, ccvtypes.KeyTransferTimeoutPeriod, &p) + return p +} + +// getConsumerRedistributionFrac returns the fraction of tokens allocated to the consumer redistribution +// address during distribution events. The fraction is a string representing a +// decimal number. For example "0.75" would represent 75%. +func getConsumerRedistributionFrac(ctx sdk.Context, paramStore paramtypes.Subspace) string { + var str string + paramStore.Get(ctx, ccvtypes.KeyConsumerRedistributionFrac, &str) + return str +} + +// getHistoricalEntries returns the number of historical info entries to persist in store +func getHistoricalEntries(ctx sdk.Context, paramStore paramtypes.Subspace) int64 { + var n int64 + paramStore.Get(ctx, ccvtypes.KeyHistoricalEntries, &n) + return n +} + +func getUnbondingPeriod(ctx sdk.Context, paramStore paramtypes.Subspace) time.Duration { + var period time.Duration + paramStore.Get(ctx, ccvtypes.KeyConsumerUnbondingPeriod, &period) + return period +} + +// getSoftOptOutThreshold returns the percentage of validators at the bottom of the set +// that can opt out of running the consumer chain +func getSoftOptOutThreshold(ctx sdk.Context, paramStore paramtypes.Subspace) string { + var str string + paramStore.Get(ctx, ccvtypes.KeySoftOptOutThreshold, &str) + return str +} + +func getRewardDenoms(ctx sdk.Context, paramStore paramtypes.Subspace) []string { + var denoms []string + paramStore.Get(ctx, ccvtypes.KeyRewardDenoms, &denoms) + return denoms +} + +func getProviderRewardDenoms(ctx sdk.Context, paramStore paramtypes.Subspace) []string { + var denoms []string + paramStore.Get(ctx, ccvtypes.KeyProviderRewardDenoms, &denoms) + return denoms +} diff --git a/x/ccv/consumer/keeper/migration.go b/x/ccv/consumer/keeper/migration.go index 361bb2a62f..ffd581d208 100644 --- a/x/ccv/consumer/keeper/migration.go +++ b/x/ccv/consumer/keeper/migration.go @@ -21,6 +21,19 @@ func NewMigrator(ccvConsumerKeeper Keeper, ccvConsumerParamSpace paramtypes.Subs return Migrator{ccvConsumerKeeper: ccvConsumerKeeper, ccvConsumerParamSpace: ccvConsumerParamSpace} } +// MigrateParams migrates the consumers module's parameters from the x/params subspace to the +// consumer modules store. +func (m Migrator) MigrateParams(ctx sdk.Context) error { + params := m.ccvConsumerKeeper.GetConsumerParamsLegacy(ctx, m.ccvConsumerParamSpace) + err := params.Validate() + if err != nil { + return err + } + m.ccvConsumerKeeper.SetParams(ctx, params) + m.ccvConsumerKeeper.Logger(ctx).Info("successfully migrated provider parameters") + return nil +} + // MigrateConsumerPacketData migrates consumer packet data according to // https://github.com/cosmos/interchain-security/pull/1037 // diff --git a/x/ccv/consumer/keeper/migration_test.go b/x/ccv/consumer/keeper/migration_test.go index 7cb87665f0..387b8e1bb2 100644 --- a/x/ccv/consumer/keeper/migration_test.go +++ b/x/ccv/consumer/keeper/migration_test.go @@ -3,9 +3,13 @@ package keeper_test import ( "testing" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/stretchr/testify/require" testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" + + "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper" + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" ) @@ -61,3 +65,33 @@ func TestMigrateConsumerPacketData(t *testing.T) { require.Equal(t, uint64(88), obtainedPackets[1].GetVscMaturedPacketData().ValsetUpdateId) require.Equal(t, uint64(99), obtainedPackets[2].GetVscMaturedPacketData().ValsetUpdateId) } + +func TestMigrateParams(t *testing.T) { + params := testutil.NewInMemKeeperParams(t) + consumerKeeper, ctx, ctrl, _ := testutil.GetConsumerKeeperAndCtx(t, params) + defer ctrl.Finish() + + testCases := []struct { + name string + legacyParams func() paramtypes.Subspace + expetedParams ccvtypes.Params + }{ + { + "default params", + func() paramtypes.Subspace { + subspace := params.ParamsSubspace + defaultParams := ccvtypes.DefaultParams() + subspace.SetParamSet(ctx, &defaultParams) + return *subspace + }, + ccvtypes.DefaultParams(), + }, + } + for _, tc := range testCases { + migrator := keeper.NewMigrator(consumerKeeper, tc.legacyParams()) + err := migrator.MigrateParams(ctx) + require.NoError(t, err) + params := consumerKeeper.GetConsumerParams(ctx) + require.Equal(t, tc.expetedParams, params) + } +} diff --git a/x/ccv/consumer/module.go b/x/ccv/consumer/module.go index a3092345f0..594d38819a 100644 --- a/x/ccv/consumer/module.go +++ b/x/ccv/consumer/module.go @@ -113,6 +113,12 @@ func (AppModule) RegisterInvariants(ir sdk.InvariantRegistry) { // RegisterServices registers module services. func (am AppModule) RegisterServices(cfg module.Configurator) { consumertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) + + migrator := keeper.NewMigrator(am.keeper, am.paramSpace) + err := cfg.RegisterMigration(am.Name(), 1, migrator.MigrateParams) + if err != nil { + panic(err) + } } // InitGenesis performs genesis initialization for the consumer module. It returns diff --git a/x/ccv/provider/keeper/legacy_params.go b/x/ccv/provider/keeper/legacy_params.go new file mode 100644 index 0000000000..7758123d16 --- /dev/null +++ b/x/ccv/provider/keeper/legacy_params.go @@ -0,0 +1,95 @@ +package keeper + +import ( + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + ibctmtypes "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" + + ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types" +) + +// getTemplateClient returns the template client for provider proposals +func getTemplateClient(ctx sdk.Context, paramSpace paramtypes.Subspace) *ibctmtypes.ClientState { + var cs ibctmtypes.ClientState + paramSpace.Get(ctx, types.KeyTemplateClient, &cs) + return &cs +} + +// getTrustingPeriodFraction returns a TrustingPeriodFraction +// used to compute the provider IBC client's TrustingPeriod as UnbondingPeriod / TrustingPeriodFraction +func getTrustingPeriodFraction(ctx sdk.Context, paramSpace paramtypes.Subspace) string { + var f string + paramSpace.Get(ctx, types.KeyTrustingPeriodFraction, &f) + return f +} + +// getCCVTimeoutPeriod returns the timeout period for sent ibc packets +func getCCVTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { + var p time.Duration + paramSpace.Get(ctx, ccvtypes.KeyCCVTimeoutPeriod, &p) + return p +} + +// getInitTimeoutPeriod returns the init timeout period +func getInitTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { + var p time.Duration + paramSpace.Get(ctx, types.KeyInitTimeoutPeriod, &p) + return p +} + +// getVscTimeoutPeriod returns the vsc timeout period +func getVscTimeoutPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { + var p time.Duration + paramSpace.Get(ctx, types.KeyVscTimeoutPeriod, &p) + return p +} + +// getSlashMeterReplenishPeriod returns the period in which: +// Once the slash meter becomes not-full, the slash meter is replenished after this period. +func getSlashMeterReplenishPeriod(ctx sdk.Context, paramSpace paramtypes.Subspace) time.Duration { + var p time.Duration + paramSpace.Get(ctx, types.KeySlashMeterReplenishPeriod, &p) + return p +} + +// getSlashMeterReplenishFraction returns the string fraction of total voting power that is replenished +// to the slash meter every replenish period. This param also serves as a maximum fraction of total +// voting power that the slash meter can hold. +func getSlashMeterReplenishFraction(ctx sdk.Context, paramSpace paramtypes.Subspace) string { + var f string + paramSpace.Get(ctx, types.KeySlashMeterReplenishFraction, &f) + return f +} + +// getMaxThrottledPackets returns the maximum amount of throttled slash or vsc matured packets +// that can be queued for a single consumer before the provider chain halts. +func getMaxThrottledPackets(ctx sdk.Context, paramSpace paramtypes.Subspace) int64 { + var p int64 + paramSpace.Get(ctx, types.KeyMaxThrottledPackets, &p) + return p +} + +func getConsumerRewardDenomRegistrationFee(ctx sdk.Context, paramSpace paramtypes.Subspace) sdk.Coin { + var c sdk.Coin + paramSpace.Get(ctx, types.KeyConsumerRewardDenomRegistrationFee, &c) + return c +} + +// Legacy: Only for migration purposes. GetParamsLegacy returns the paramset for the provider +// module from a given param subspace +func GetParamsLegacy(ctx sdk.Context, paramspace paramtypes.Subspace) types.Params { + return types.NewParams( + getTemplateClient(ctx, paramspace), + getTrustingPeriodFraction(ctx, paramspace), + getCCVTimeoutPeriod(ctx, paramspace), + getInitTimeoutPeriod(ctx, paramspace), + getVscTimeoutPeriod(ctx, paramspace), + getSlashMeterReplenishPeriod(ctx, paramspace), + getSlashMeterReplenishFraction(ctx, paramspace), + getMaxThrottledPackets(ctx, paramspace), + getConsumerRewardDenomRegistrationFee(ctx, paramspace), + ) +} diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index 3b6db16463..336c5ebe69 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -3,25 +3,28 @@ package keeper import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" ) type Migrator struct { - keeper Keeper + keeper Keeper + legacySubspace paramtypes.Subspace } // NewMigrator returns a new Migrator. -func NewMigrator(keeper Keeper) Migrator { +func NewMigrator(keeper Keeper, subspace paramtypes.Subspace) Migrator { return Migrator{ - keeper: keeper, + keeper: keeper, + legacySubspace: subspace, } } // MigrateParams migrates the provider module's parameters from the x/params to self store. -func (m Migrator) MigrateParams(ctx sdk.Context, paramSpace paramtypes.Subspace) error { - var params types.Params - paramSpace.GetParamSet(ctx, ¶ms) - +func (m Migrator) MigrateParams(ctx sdk.Context) error { + params := GetParamsLegacy(ctx, m.legacySubspace) + err := params.Validate() + if err != nil { + return err + } m.keeper.SetParams(ctx, params) m.keeper.Logger(ctx).Info("successfully migrated provider parameters") return nil diff --git a/x/ccv/provider/keeper/migration_test.go b/x/ccv/provider/keeper/migration_test.go new file mode 100644 index 0000000000..0b6760ff27 --- /dev/null +++ b/x/ccv/provider/keeper/migration_test.go @@ -0,0 +1,41 @@ +package keeper_test + +import ( + "testing" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + testutil "github.com/cosmos/interchain-security/v3/testutil/keeper" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/keeper" + "github.com/cosmos/interchain-security/v3/x/ccv/provider/types" + "github.com/stretchr/testify/require" +) + +func TestMigrateParams(t *testing.T) { + params := testutil.NewInMemKeeperParams(t) + providerKeeper, ctx, ctrl, _ := testutil.GetProviderKeeperAndCtx(t, params) + defer ctrl.Finish() + + testCases := []struct { + name string + legacyParams func() paramtypes.Subspace + expetedParams types.Params + }{ + { + "default params", + func() paramtypes.Subspace { + subspace := params.ParamsSubspace + defaultParams := types.DefaultParams() + subspace.SetParamSet(ctx, &defaultParams) + return *subspace + }, + types.DefaultParams(), + }, + } + for _, tc := range testCases { + migrator := keeper.NewMigrator(providerKeeper, tc.legacyParams()) + err := migrator.MigrateParams(ctx) + require.NoError(t, err) + params := providerKeeper.GetParams(ctx) + require.Equal(t, tc.expetedParams, params) + } +} diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index 12eba7dab8..a6cc456ac9 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -120,11 +120,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { providertypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) providertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) - migrator := keeper.NewMigrator(*am.keeper) - err := cfg.RegisterMigration(am.Name(), 2, - func(ctx sdk.Context) error { - return migrator.MigrateParams(ctx, am.paramSpace) - }) + migrator := keeper.NewMigrator(*am.keeper, am.paramSpace) + err := cfg.RegisterMigration(am.Name(), 2, migrator.MigrateParams) if err != nil { panic(err) } From 3ae52c2ece62402ab2d179eb105beb6e419a043b Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Wed, 15 Nov 2023 11:47:41 +0100 Subject: [PATCH 7/8] Addressed review comments --- x/ccv/consumer/keeper/legacy_params.go | 2 +- x/ccv/consumer/keeper/params.go | 6 +----- x/ccv/consumer/types/keys.go | 3 ++- x/ccv/provider/client/cli/query.go | 10 +--------- x/ccv/provider/keeper/grpc_query.go | 8 ++++---- x/ccv/provider/types/keys.go | 3 ++- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/x/ccv/consumer/keeper/legacy_params.go b/x/ccv/consumer/keeper/legacy_params.go index abbb2a8d35..81b5f331ae 100644 --- a/x/ccv/consumer/keeper/legacy_params.go +++ b/x/ccv/consumer/keeper/legacy_params.go @@ -11,7 +11,7 @@ import ( // Legacy: used for migration only! // GetConsumerParamsLegacy returns the params for the consumer ccv module from x/param subspace -// which will be depreacted soon +// which will be deprecated soon func (k Keeper) GetConsumerParamsLegacy(ctx sdk.Context, paramSpace paramtypes.Subspace) ccvtypes.Params { return ccvtypes.NewParams( getEnabled(ctx, paramSpace), diff --git a/x/ccv/consumer/keeper/params.go b/x/ccv/consumer/keeper/params.go index ce680e4860..a9e52b7b30 100644 --- a/x/ccv/consumer/keeper/params.go +++ b/x/ccv/consumer/keeper/params.go @@ -2,7 +2,6 @@ package keeper import ( "context" - "fmt" "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,10 +17,7 @@ func (k Keeper) GetConsumerParams(ctx sdk.Context) ccvtypes.Params { store := ctx.KVStore(k.storeKey) bz := store.Get(types.ParametersKey()) var params ccvtypes.Params - err := k.cdc.Unmarshal(bz, ¶ms) - if err != nil { - panic(fmt.Sprintf("error unmarshalling module parameters: %v:", err)) - } + k.cdc.MustUnmarshal(bz, ¶ms) return params } diff --git a/x/ccv/consumer/types/keys.go b/x/ccv/consumer/types/keys.go index 379f52246c..6226bf61e2 100644 --- a/x/ccv/consumer/types/keys.go +++ b/x/ccv/consumer/types/keys.go @@ -106,7 +106,7 @@ const ( // SlashRecordByteKey is the single byte key storing the consumer's slash record. SlashRecordByteKey - // ParametersKey is the is the single byte key for storing consumer's parameters. + // ParametersKey is the single byte key for storing consumer's parameters. ParametersByteKey // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go @@ -116,6 +116,7 @@ const ( // Fully defined key func section // +// ParametersKey returns the key for the consumer parameters in the store func ParametersKey() []byte { return []byte{ParametersByteKey} } diff --git a/x/ccv/provider/client/cli/query.go b/x/ccv/provider/client/cli/query.go index 119ee90b82..6dabfefb8b 100644 --- a/x/ccv/provider/client/cli/query.go +++ b/x/ccv/provider/client/cli/query.go @@ -363,15 +363,7 @@ func CmdProviderParams() *cobra.Command { cmd := &cobra.Command{ Use: "params [flags]", Short: "Query values set as provider parameters", - /* Long: strings.TrimSpace( - fmt.Sprintf(`Returns the registered consumer reward denoms. - Example: - $ %s query provider registered-consumer-reward-denoms - `, - version.AppName, - ), - ), */ - Args: cobra.NoArgs, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { diff --git a/x/ccv/provider/keeper/grpc_query.go b/x/ccv/provider/keeper/grpc_query.go index 4e896525cc..09198e0e7d 100644 --- a/x/ccv/provider/keeper/grpc_query.go +++ b/x/ccv/provider/keeper/grpc_query.go @@ -230,9 +230,9 @@ func (k Keeper) QueryThrottledConsumerPacketData(goCtx context.Context, req *typ // getSlashPacketData fetches a slash packet data from the store using consumerChainId and ibcSeqNum (direct access) // If the returned bytes do not unmarshal to SlashPacketData, the data is considered not found. func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcSeqNum uint64) (ccvtypes.SlashPacketData, bool) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) - if err != nil || len(bz) == 0 { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.ThrottledPacketDataKey(consumerChainID, ibcSeqNum)) + if len(bz) == 0 { return ccvtypes.SlashPacketData{}, false } @@ -241,7 +241,7 @@ func (k Keeper) getSlashPacketData(ctx sdk.Context, consumerChainID string, ibcS } packet := ccvtypes.SlashPacketData{} - err = packet.Unmarshal(bz[1:]) + err := packet.Unmarshal(bz[1:]) if err != nil { // If the data cannot be unmarshaled, it is considered not found return ccvtypes.SlashPacketData{}, false diff --git a/x/ccv/provider/types/keys.go b/x/ccv/provider/types/keys.go index f34f29bc4c..643946258a 100644 --- a/x/ccv/provider/types/keys.go +++ b/x/ccv/provider/types/keys.go @@ -138,7 +138,7 @@ const ( // handled in the current block VSCMaturedHandledThisBlockBytePrefix - // ParametersKey is the is the single byte key for storing consumer's parameters. + // ParametersKey is the is the single byte key for storing provider's parameters. ParametersByteKey // NOTE: DO NOT ADD NEW BYTE PREFIXES HERE WITHOUT ADDING THEM TO getAllKeyPrefixes() IN keys_test.go @@ -148,6 +148,7 @@ const ( // Fully defined key func section // +// ParametersKey returns the key for the parameters of the provider module in the store func ParametersKey() []byte { return []byte{ParametersByteKey} } From bd021462a016cbc50b20d58826da085fb86b8f77 Mon Sep 17 00:00:00 2001 From: Bernd Mueller Date: Thu, 16 Nov 2023 15:59:14 +0100 Subject: [PATCH 8/8] Addressed comments --- x/ccv/consumer/module.go | 1 + x/ccv/provider/keeper/migration.go | 5 +++++ x/ccv/provider/module.go | 3 ++- x/ccv/provider/types/params.go | 3 +++ x/ccv/types/params.go | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/x/ccv/consumer/module.go b/x/ccv/consumer/module.go index 594d38819a..ffbce0eb72 100644 --- a/x/ccv/consumer/module.go +++ b/x/ccv/consumer/module.go @@ -115,6 +115,7 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { consumertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) migrator := keeper.NewMigrator(am.keeper, am.paramSpace) + // TODO: adapt 'fromVersion' and use MigrateXtoY() instead once merged with main err := cfg.RegisterMigration(am.Name(), 1, migrator.MigrateParams) if err != nil { panic(err) diff --git a/x/ccv/provider/keeper/migration.go b/x/ccv/provider/keeper/migration.go index 336c5ebe69..0d295fe531 100644 --- a/x/ccv/provider/keeper/migration.go +++ b/x/ccv/provider/keeper/migration.go @@ -18,6 +18,11 @@ func NewMigrator(keeper Keeper, subspace paramtypes.Subspace) Migrator { } } +// Migration from consensus version 2 to 3 +func (m Migrator) Migrate2to3(ctx sdk.Context) error { + return m.MigrateParams(ctx) +} + // MigrateParams migrates the provider module's parameters from the x/params to self store. func (m Migrator) MigrateParams(ctx sdk.Context) error { params := GetParamsLegacy(ctx, m.legacySubspace) diff --git a/x/ccv/provider/module.go b/x/ccv/provider/module.go index a6cc456ac9..74f340db24 100644 --- a/x/ccv/provider/module.go +++ b/x/ccv/provider/module.go @@ -121,7 +121,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { providertypes.RegisterQueryServer(cfg.QueryServer(), am.keeper) migrator := keeper.NewMigrator(*am.keeper, am.paramSpace) - err := cfg.RegisterMigration(am.Name(), 2, migrator.MigrateParams) + // TODO: check/adapt 'fromVersion' once v0.50 branch merged with main + err := cfg.RegisterMigration(am.Name(), 2, migrator.Migrate2to3) if err != nil { panic(err) } diff --git a/x/ccv/provider/types/params.go b/x/ccv/provider/types/params.go index 9a4cbdb149..b4ca06a314 100644 --- a/x/ccv/provider/types/params.go +++ b/x/ccv/provider/types/params.go @@ -44,6 +44,9 @@ const ( ) // Reflection based keys for params subspace +// Legacy: usage of x/params for parameters is deprecated. +// Use x/ccv/provider/keeper/params instead +// [DEPRECATED] var ( KeyTemplateClient = []byte("TemplateClient") KeyTrustingPeriodFraction = []byte("TrustingPeriodFraction") diff --git a/x/ccv/types/params.go b/x/ccv/types/params.go index d44ec68c80..0891591403 100644 --- a/x/ccv/types/params.go +++ b/x/ccv/types/params.go @@ -43,6 +43,7 @@ const ( ) // Reflection based keys for params subspace +// [DEPRECATED] var ( KeyEnabled = []byte("Enabled") KeyBlocksPerDistributionTransmission = []byte("BlocksPerDistributionTransmission")