From 6d9c6c0f78292918c0b4edd9162681256810104d Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 11:29:24 +0200 Subject: [PATCH 01/23] CNS-871: implemented iprpc provider reward --- proto/lavanet/lava/rewards/query.proto | 16 + scripts/cli_test.sh | 1 + testutil/common/tester.go | 9 +- x/rewards/client/cli/query.go | 1 + .../client/cli/query_iprpc_provider_reward.go | 43 ++ .../grpc_query_iprpc_provider_reward.go | 57 ++ x/rewards/types/query.pb.go | 490 ++++++++++++++++-- x/rewards/types/query.pb.gw.go | 101 ++++ 8 files changed, 671 insertions(+), 47 deletions(-) create mode 100644 x/rewards/client/cli/query_iprpc_provider_reward.go create mode 100644 x/rewards/keeper/grpc_query_iprpc_provider_reward.go diff --git a/proto/lavanet/lava/rewards/query.proto b/proto/lavanet/lava/rewards/query.proto index dd0ec78fe3..8f3bab30ef 100644 --- a/proto/lavanet/lava/rewards/query.proto +++ b/proto/lavanet/lava/rewards/query.proto @@ -5,6 +5,7 @@ import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; import "lavanet/lava/rewards/params.proto"; +import "lavanet/lava/rewards/iprpc.proto"; import "cosmos/base/v1beta1/coin.proto"; // this line is used by starport scaffolding # 1 @@ -31,6 +32,11 @@ service Query { rpc ShowIprpcData(QueryShowIprpcDataRequest) returns (QueryShowIprpcDataResponse) { option (google.api.http).get = "/lavanet/lava/rewards/show_iprpc_data"; } + + // ShowIprpcData queries for the iprpc data + rpc IprpcProviderReward(QueryIprpcProviderRewardRequest) returns (QueryIprpcProviderRewardResponse) { + option (google.api.http).get = "/lavanet/lava/rewards/iprpc_provider_reward/{provider}"; + } // this line is used by starport scaffolding # 2 } @@ -80,4 +86,14 @@ message QueryShowIprpcDataResponse { repeated string iprpc_subscriptions = 2; } +// QueryIprpcProviderRewardRequest is request type for the Query/IprpcProviderReward RPC method. +message QueryIprpcProviderRewardRequest { + string provider = 1; +} + +// QueryIprpcProviderRewardResponse is response type for the Query/IprpcProviderReward RPC method. +message QueryIprpcProviderRewardResponse { + repeated Specfund spec_funds = 1 [(gogoproto.nullable) = false]; +} + // this line is used by starport scaffolding # 3 \ No newline at end of file diff --git a/scripts/cli_test.sh b/scripts/cli_test.sh index 212e2db1b9..9ccd352adb 100755 --- a/scripts/cli_test.sh +++ b/scripts/cli_test.sh @@ -183,6 +183,7 @@ echo "Testing rewards q commands" trace lavad q rewards pools >/dev/null trace lavad q rewards block-reward >/dev/null trace lavad q rewards show-iprpc-data > /dev/null +trace lavad q rewards iprpc-provider-reward > /dev/null echo "Testing events command" trace lavad test events 30 10 --event lava_relay_payment --from alice --timeout 1s >/dev/null diff --git a/testutil/common/tester.go b/testutil/common/tester.go index b664e151ac..6e0f63232b 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -859,11 +859,18 @@ func (ts *Tester) QueryRewardsBlockReward() (*rewardstypes.QueryBlockRewardRespo return ts.Keepers.Rewards.BlockReward(ts.GoCtx, msg) } -func (ts *Tester) QueryShowIprpcData() (*rewardstypes.QueryShowIprpcDataResponse, error) { +func (ts *Tester) QueryRewardsShowIprpcData() (*rewardstypes.QueryShowIprpcDataResponse, error) { msg := &rewardstypes.QueryShowIprpcDataRequest{} return ts.Keepers.Rewards.ShowIprpcData(ts.GoCtx, msg) } +func (ts *Tester) QueryRewardsIprpcProviderReward(provider string) (*rewardstypes.QueryIprpcProviderRewardResponse, error) { + msg := &rewardstypes.QueryIprpcProviderRewardRequest{ + Provider: provider, + } + return ts.Keepers.Rewards.IprpcProviderReward(ts.GoCtx, msg) +} + // block/epoch helpers func (ts *Tester) BlockHeight() uint64 { diff --git a/x/rewards/client/cli/query.go b/x/rewards/client/cli/query.go index c109ab1701..0f9627ec93 100644 --- a/x/rewards/client/cli/query.go +++ b/x/rewards/client/cli/query.go @@ -28,6 +28,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryPools()) cmd.AddCommand(CmdQueryBlockReward()) cmd.AddCommand(CmdQueryShowIprpcData()) + cmd.AddCommand(CmdQueryIprpcProviderReward()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/rewards/client/cli/query_iprpc_provider_reward.go b/x/rewards/client/cli/query_iprpc_provider_reward.go new file mode 100644 index 0000000000..56e83ddaf4 --- /dev/null +++ b/x/rewards/client/cli/query_iprpc_provider_reward.go @@ -0,0 +1,43 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/lavanet/lava/x/rewards/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdQueryIprpcProviderReward() *cobra.Command { + cmd := &cobra.Command{ + Use: "iprpc-provider-reward [provider]", + Short: "Query for current IPRPC reward for a specific provider", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryIprpcProviderRewardRequest{ + Provider: args[0], + } + + res, err := queryClient.IprpcProviderReward(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/rewards/keeper/grpc_query_iprpc_provider_reward.go b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go new file mode 100644 index 0000000000..2a2cfd0ffc --- /dev/null +++ b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go @@ -0,0 +1,57 @@ +package keeper + +import ( + "context" + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/x/rewards/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) IprpcProviderReward(goCtx context.Context, req *types.QueryIprpcProviderRewardRequest) (*types.QueryIprpcProviderRewardResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + + // get current month IPRPC reward + id := k.GetIprpcRewardsCurrent(ctx) + iprpcReward, found := k.GetIprpcReward(ctx, id) + if !found { + return nil, fmt.Errorf("current month IPRPC reward does not exist") + } + + // go over all the IPRPC reward specs and get the provider's relative reward (by CU) + providerSpecFunds := []types.Specfund{} + for _, specFund := range iprpcReward.SpecFunds { + // get all spec basepays and count IPRPC CU + bps, _ := k.specProvidersBasePay(ctx, specFund.Spec) + providerIprpcCu := uint64(0) + totalIprpcCu := uint64(0) + providerBpIndex := types.BasePayIndex{Provider: req.Provider, ChainID: specFund.Spec} + for _, bp := range bps { + if bp.BasePayIndex.String() == providerBpIndex.String() { + providerIprpcCu = bp.IprpcCu + } + totalIprpcCu += bp.IprpcCu + } + + // get the provider's relative reward by CU + providerFund, isValid := specFund.Fund.SafeMulInt(sdk.NewIntFromUint64(providerIprpcCu)) + if !isValid { + continue + } + providerFund, isValid = providerFund.SafeQuoInt(sdk.NewIntFromUint64(totalIprpcCu)) + if !isValid { + continue + } + + // save the provider's reward + providerSpecFunds = append(providerSpecFunds, types.Specfund{Spec: specFund.Spec, Fund: providerFund}) + } + + return &types.QueryIprpcProviderRewardResponse{SpecFunds: providerSpecFunds}, nil +} diff --git a/x/rewards/types/query.pb.go b/x/rewards/types/query.pb.go index 76394786fd..4b720bf75f 100644 --- a/x/rewards/types/query.pb.go +++ b/x/rewards/types/query.pb.go @@ -446,6 +446,96 @@ func (m *QueryShowIprpcDataResponse) GetIprpcSubscriptions() []string { return nil } +// QueryIprpcProviderRewardRequest is request type for the Query/IprpcProviderReward RPC method. +type QueryIprpcProviderRewardRequest struct { + Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` +} + +func (m *QueryIprpcProviderRewardRequest) Reset() { *m = QueryIprpcProviderRewardRequest{} } +func (m *QueryIprpcProviderRewardRequest) String() string { return proto.CompactTextString(m) } +func (*QueryIprpcProviderRewardRequest) ProtoMessage() {} +func (*QueryIprpcProviderRewardRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_15bce9a904340007, []int{9} +} +func (m *QueryIprpcProviderRewardRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryIprpcProviderRewardRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryIprpcProviderRewardRequest.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 *QueryIprpcProviderRewardRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcProviderRewardRequest.Merge(m, src) +} +func (m *QueryIprpcProviderRewardRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryIprpcProviderRewardRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcProviderRewardRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryIprpcProviderRewardRequest proto.InternalMessageInfo + +func (m *QueryIprpcProviderRewardRequest) GetProvider() string { + if m != nil { + return m.Provider + } + return "" +} + +// QueryIprpcProviderRewardResponse is response type for the Query/IprpcProviderReward RPC method. +type QueryIprpcProviderRewardResponse struct { + SpecFunds []Specfund `protobuf:"bytes,1,rep,name=spec_funds,json=specFunds,proto3" json:"spec_funds"` +} + +func (m *QueryIprpcProviderRewardResponse) Reset() { *m = QueryIprpcProviderRewardResponse{} } +func (m *QueryIprpcProviderRewardResponse) String() string { return proto.CompactTextString(m) } +func (*QueryIprpcProviderRewardResponse) ProtoMessage() {} +func (*QueryIprpcProviderRewardResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_15bce9a904340007, []int{10} +} +func (m *QueryIprpcProviderRewardResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryIprpcProviderRewardResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryIprpcProviderRewardResponse.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 *QueryIprpcProviderRewardResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcProviderRewardResponse.Merge(m, src) +} +func (m *QueryIprpcProviderRewardResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryIprpcProviderRewardResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcProviderRewardResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryIprpcProviderRewardResponse proto.InternalMessageInfo + +func (m *QueryIprpcProviderRewardResponse) GetSpecFunds() []Specfund { + if m != nil { + return m.SpecFunds + } + return nil +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "lavanet.lava.rewards.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "lavanet.lava.rewards.QueryParamsResponse") @@ -456,57 +546,66 @@ func init() { proto.RegisterType((*QueryBlockRewardResponse)(nil), "lavanet.lava.rewards.QueryBlockRewardResponse") proto.RegisterType((*QueryShowIprpcDataRequest)(nil), "lavanet.lava.rewards.QueryShowIprpcDataRequest") proto.RegisterType((*QueryShowIprpcDataResponse)(nil), "lavanet.lava.rewards.QueryShowIprpcDataResponse") + proto.RegisterType((*QueryIprpcProviderRewardRequest)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardRequest") + proto.RegisterType((*QueryIprpcProviderRewardResponse)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardResponse") } func init() { proto.RegisterFile("lavanet/lava/rewards/query.proto", fileDescriptor_15bce9a904340007) } var fileDescriptor_15bce9a904340007 = []byte{ - // 718 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xc1, 0x4f, 0x13, 0x4f, - 0x18, 0xed, 0x42, 0x29, 0x30, 0xfc, 0x7e, 0x26, 0x0e, 0x24, 0x94, 0x05, 0x97, 0xba, 0x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7d, 0x31, 0x50, 0x31, - 0x0e, 0x15, 0xf3, 0x7d, 0x44, 0x03, 0x00, 0xfd, 0xe2, 0x87, 0x68, 0x91, 0x46, 0x11, 0x0f, 0x20, - 0x12, 0x5e, 0xde, 0xd6, 0x8b, 0x79, 0x22, 0x3b, 0xc2, 0x8b, 0x58, 0x4b, 0x56, 0xcb, 0x50, 0x5d, - 0xfd, 0x0b, 0xc9, 0x85, 0x3e, 0x05, 0xc0, 0x13, 0xd6, 0x92, 0xf6, 0x02, 0x9a, 0x07, 0xcf, 0xc0, - 0xea, 0x82, 0x99, 0xde, 0xbd, 0xec, 0xa1, 0xea, 0xe5, 0x23, 0xfd, 0x51, 0xee, 0xa1, 0x8a, 0x72, - 0xae, 0x43, 0x30, 0xe4, 0x46, 0x74, 0x02, 0x14, 0xdc, 0x5e, 0x44, 0x0b, 0x40, 0xba, 0xd7, 0xe1, - 0x47, 0x3b, 0x69, 0x96, 0x06, 0x8f, 0xa9, 0xa4, 0xbd, 0x8e, 0xef, 0x0c, 0x64, 0x16, 0x9d, 0xf6, - 0x6f, 0x62, 0x2a, 0x0e, 0x13, 0x2f, 0xe0, 0x42, 0x8e, 0xda, 0x76, 0x32, 0x0e, 0x93, 0x6d, 0x2e, - 0x24, 0x26, 0x68, 0x36, 0xcc, 0x09, 0x3d, 0xd1, 0xf5, 0x45, 0x90, 0x85, 0x29, 0x8c, 0x1b, 0xe4, - 0x69, 0xda, 0xc5, 0x70, 0xb4, 0x37, 0x78, 0xb2, 0xf5, 0xa5, 0x8c, 0x26, 0x40, 0x0b, 0x7e, 0x63, - 0xa0, 0x8a, 0x4a, 0x33, 0xae, 0x17, 0x5f, 0xfe, 0xe5, 0xe1, 0x31, 0xef, 0x8c, 0x80, 0x54, 0xb6, - 0xec, 0x95, 0xd7, 0x5f, 0x7f, 0x7d, 0x18, 0xb3, 0xf0, 0x12, 0x19, 0x32, 0xc9, 0xf8, 0x15, 0x9a, - 0x80, 0x5c, 0xe2, 0xd5, 0x61, 0xcc, 0x03, 0x73, 0x65, 0xd6, 0xff, 0x0d, 0xd4, 0x0a, 0x6e, 0x81, - 0x82, 0x1b, 0x78, 0xf1, 0x0a, 0x05, 0xd0, 0xf7, 0xa3, 0x81, 0x66, 0x06, 0xa2, 0x80, 0xd7, 0x87, - 0xd0, 0x5f, 0x4e, 0x93, 0xe9, 0x8c, 0x0a, 0xd7, 0x9a, 0xd6, 0x40, 0xd3, 0x0a, 0xb6, 0x8b, 0x35, - 0xc1, 0x98, 0x78, 0xea, 0x1f, 0xfe, 0x64, 0xa0, 0xff, 0x2f, 0x44, 0x06, 0x93, 0x21, 0xdd, 0x8a, - 0xa2, 0x67, 0x6e, 0x8c, 0x5e, 0xa0, 0x05, 0xae, 0x83, 0xc0, 0x55, 0x7c, 0xbb, 0x58, 0xa0, 0xe8, - 0xf0, 0x23, 0x4f, 0x45, 0xae, 0x49, 0x25, 0x6d, 0x3c, 0x3a, 0x39, 0xb3, 0x8c, 0xd3, 0x33, 0xcb, - 0xf8, 0x79, 0x66, 0x19, 0xef, 0xcf, 0xad, 0xd2, 0xe9, 0xb9, 0x55, 0xfa, 0x76, 0x6e, 0x95, 0x5e, - 0xac, 0x0e, 0x3c, 0x55, 0x17, 0xa8, 0x5e, 0xf6, 0xc9, 0xe0, 0xbd, 0xf2, 0x2b, 0xf0, 0x5a, 0xdf, - 0xfd, 0x13, 0x00, 0x00, 0xff, 0xff, 0xf0, 0xce, 0xcd, 0x6c, 0x8a, 0x06, 0x00, 0x00, + // 827 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xcf, 0x6f, 0xe3, 0x44, + 0x18, 0x8d, 0xfb, 0x23, 0x6d, 0xa7, 0x80, 0xc4, 0xa4, 0x52, 0x53, 0xb7, 0xb8, 0xc1, 0x14, 0x35, + 0x54, 0xaa, 0xa7, 0x2d, 0xa2, 0x20, 0x50, 0x91, 0x48, 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 0x36, 0xbe, 0xb8, 0xb9, 0xb3, 0x8c, 0xdb, 0x3b, 0xcb, 0x78, 0x76, 0x67, 0x19, + 0xbf, 0xdf, 0x5b, 0xa5, 0xdb, 0x7b, 0xab, 0xf4, 0xff, 0xbd, 0x55, 0xfa, 0x6e, 0x7b, 0xe8, 0x66, + 0x18, 0xa9, 0xfd, 0xfd, 0xa0, 0x3a, 0x5c, 0x0f, 0xad, 0x32, 0x5c, 0x8e, 0x1f, 0xbe, 0x0c, 0x00, + 0x00, 0xff, 0xff, 0x22, 0x23, 0xbb, 0x03, 0x1b, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -529,6 +628,8 @@ type QueryClient interface { BlockReward(ctx context.Context, in *QueryBlockRewardRequest, opts ...grpc.CallOption) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(ctx context.Context, in *QueryShowIprpcDataRequest, opts ...grpc.CallOption) (*QueryShowIprpcDataResponse, error) + // ShowIprpcData queries for the iprpc data + IprpcProviderReward(ctx context.Context, in *QueryIprpcProviderRewardRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardResponse, error) } type queryClient struct { @@ -575,6 +676,15 @@ func (c *queryClient) ShowIprpcData(ctx context.Context, in *QueryShowIprpcDataR return out, nil } +func (c *queryClient) IprpcProviderReward(ctx context.Context, in *QueryIprpcProviderRewardRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardResponse, error) { + out := new(QueryIprpcProviderRewardResponse) + err := c.cc.Invoke(ctx, "/lavanet.lava.rewards.Query/IprpcProviderReward", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Parameters queries the parameters of the module. @@ -585,6 +695,8 @@ type QueryServer interface { BlockReward(context.Context, *QueryBlockRewardRequest) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(context.Context, *QueryShowIprpcDataRequest) (*QueryShowIprpcDataResponse, error) + // ShowIprpcData queries for the iprpc data + IprpcProviderReward(context.Context, *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -603,6 +715,9 @@ func (*UnimplementedQueryServer) BlockReward(ctx context.Context, req *QueryBloc func (*UnimplementedQueryServer) ShowIprpcData(ctx context.Context, req *QueryShowIprpcDataRequest) (*QueryShowIprpcDataResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ShowIprpcData not implemented") } +func (*UnimplementedQueryServer) IprpcProviderReward(ctx context.Context, req *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IprpcProviderReward not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -680,6 +795,24 @@ func _Query_ShowIprpcData_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _Query_IprpcProviderReward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryIprpcProviderRewardRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).IprpcProviderReward(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lavanet.lava.rewards.Query/IprpcProviderReward", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).IprpcProviderReward(ctx, req.(*QueryIprpcProviderRewardRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "lavanet.lava.rewards.Query", HandlerType: (*QueryServer)(nil), @@ -700,6 +833,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "ShowIprpcData", Handler: _Query_ShowIprpcData_Handler, }, + { + MethodName: "IprpcProviderReward", + Handler: _Query_IprpcProviderReward_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lavanet/lava/rewards/query.proto", @@ -1001,6 +1138,73 @@ func (m *QueryShowIprpcDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } +func (m *QueryIprpcProviderRewardRequest) 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 *QueryIprpcProviderRewardRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryIprpcProviderRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Provider) > 0 { + i -= len(m.Provider) + copy(dAtA[i:], m.Provider) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Provider))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryIprpcProviderRewardResponse) 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 *QueryIprpcProviderRewardResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryIprpcProviderRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SpecFunds) > 0 { + for iNdEx := len(m.SpecFunds) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.SpecFunds[iNdEx].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 @@ -1130,6 +1334,34 @@ func (m *QueryShowIprpcDataResponse) Size() (n int) { return n } +func (m *QueryIprpcProviderRewardRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Provider) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryIprpcProviderRewardResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.SpecFunds) > 0 { + for _, e := range m.SpecFunds { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1874,6 +2106,172 @@ func (m *QueryShowIprpcDataResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryIprpcProviderRewardRequest) 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: QueryIprpcProviderRewardRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryIprpcProviderRewardRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Provider", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Provider = string(dAtA[iNdEx:postIndex]) + 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 (m *QueryIprpcProviderRewardResponse) 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: QueryIprpcProviderRewardResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryIprpcProviderRewardResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SpecFunds", 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 + } + m.SpecFunds = append(m.SpecFunds, Specfund{}) + if err := m.SpecFunds[len(m.SpecFunds)-1].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/rewards/types/query.pb.gw.go b/x/rewards/types/query.pb.gw.go index 946b59839e..7e0cc7f2c8 100644 --- a/x/rewards/types/query.pb.gw.go +++ b/x/rewards/types/query.pb.gw.go @@ -105,6 +105,60 @@ func local_request_Query_ShowIprpcData_0(ctx context.Context, marshaler runtime. } +func request_Query_IprpcProviderReward_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcProviderRewardRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["provider"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "provider") + } + + protoReq.Provider, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "provider", err) + } + + msg, err := client.IprpcProviderReward(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_IprpcProviderReward_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcProviderRewardRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["provider"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "provider") + } + + protoReq.Provider, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "provider", err) + } + + msg, err := server.IprpcProviderReward(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. @@ -203,6 +257,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_IprpcProviderReward_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_IprpcProviderReward_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_IprpcProviderReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -324,6 +401,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_IprpcProviderReward_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_IprpcProviderReward_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_IprpcProviderReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -335,6 +432,8 @@ var ( pattern_Query_BlockReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lavanet", "lava", "rewards", "block_reward"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_ShowIprpcData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lavanet", "lava", "rewards", "show_iprpc_data"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_IprpcProviderReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_provider_reward", "provider"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -345,4 +444,6 @@ var ( forward_Query_BlockReward_0 = runtime.ForwardResponseMessage forward_Query_ShowIprpcData_0 = runtime.ForwardResponseMessage + + forward_Query_IprpcProviderReward_0 = runtime.ForwardResponseMessage ) From fa40bcf5b66c0124108b6be90375946414fc7bba Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 11:38:36 +0200 Subject: [PATCH 02/23] CNS-871: fix query client context in all queries --- x/pairing/client/cli/query_effective_policy.go | 2 +- x/rewards/client/cli/query_block_reward.go | 2 +- x/rewards/client/cli/query_params.go | 6 ++++-- x/rewards/client/cli/query_pools.go | 2 +- x/rewards/client/cli/query_show_iprpc_data.go | 2 +- x/rewards/keeper/iprpc_data_test.go | 2 +- x/subscription/client/cli/query_list.go | 2 +- x/subscription/client/cli/query_list_projects.go | 2 +- x/subscription/client/cli/query_next_to_month_expiry.go | 2 +- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x/pairing/client/cli/query_effective_policy.go b/x/pairing/client/cli/query_effective_policy.go index 74a4dad791..b772915ead 100644 --- a/x/pairing/client/cli/query_effective_policy.go +++ b/x/pairing/client/cli/query_effective_policy.go @@ -21,7 +21,7 @@ func CmdEffectivePolicy() *cobra.Command { if len(args) > 1 { address = args[1] } else { - clientCtxForTx, err := client.GetClientTxContext(cmd) + clientCtxForTx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/rewards/client/cli/query_block_reward.go b/x/rewards/client/cli/query_block_reward.go index 12d7dbece9..55957e4dd0 100644 --- a/x/rewards/client/cli/query_block_reward.go +++ b/x/rewards/client/cli/query_block_reward.go @@ -17,7 +17,7 @@ func CmdQueryBlockReward() *cobra.Command { Short: "Query for amount of validator rewards for proposing a block", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/rewards/client/cli/query_params.go b/x/rewards/client/cli/query_params.go index 29c8fdf565..7efc38eb5a 100644 --- a/x/rewards/client/cli/query_params.go +++ b/x/rewards/client/cli/query_params.go @@ -15,8 +15,10 @@ func CmdQueryParams() *cobra.Command { Short: "shows the parameters of the module", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - clientCtx := client.GetClientContextFromCmd(cmd) - + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } queryClient := types.NewQueryClient(clientCtx) res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) diff --git a/x/rewards/client/cli/query_pools.go b/x/rewards/client/cli/query_pools.go index 7a2c7a25eb..9911dc7272 100644 --- a/x/rewards/client/cli/query_pools.go +++ b/x/rewards/client/cli/query_pools.go @@ -17,7 +17,7 @@ func CmdQueryPools() *cobra.Command { Short: "Query for validators and providers rewards pools information", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/rewards/client/cli/query_show_iprpc_data.go b/x/rewards/client/cli/query_show_iprpc_data.go index 4448e42323..c07c4a25bf 100644 --- a/x/rewards/client/cli/query_show_iprpc_data.go +++ b/x/rewards/client/cli/query_show_iprpc_data.go @@ -17,7 +17,7 @@ func CmdQueryShowIprpcData() *cobra.Command { Short: "Query for IPRPC data: min cost and IPRPC eligible subscriptions", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/rewards/keeper/iprpc_data_test.go b/x/rewards/keeper/iprpc_data_test.go index 330cb09879..f88cb59fbd 100644 --- a/x/rewards/keeper/iprpc_data_test.go +++ b/x/rewards/keeper/iprpc_data_test.go @@ -112,7 +112,7 @@ func TestIprpcDataValidation(t *testing.T) { _, err := ts.TxRewardsSetIprpcDataProposal(ts.Ctx, tt.authority, tt.cost, tt.subs) if tt.success { require.NoError(t, err) - res, err := ts.QueryShowIprpcData() + res, err := ts.QueryRewardsShowIprpcData() require.NoError(t, err) require.True(t, tt.cost.IsEqual(res.MinCost)) require.Equal(t, tt.subs, res.IprpcSubscriptions) diff --git a/x/subscription/client/cli/query_list.go b/x/subscription/client/cli/query_list.go index c60b5f03c3..6311b55f74 100644 --- a/x/subscription/client/cli/query_list.go +++ b/x/subscription/client/cli/query_list.go @@ -17,7 +17,7 @@ func CmdList() *cobra.Command { Short: "Query all current subscriptions", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/subscription/client/cli/query_list_projects.go b/x/subscription/client/cli/query_list_projects.go index 543ce42a08..b25ff1f3a8 100644 --- a/x/subscription/client/cli/query_list_projects.go +++ b/x/subscription/client/cli/query_list_projects.go @@ -19,7 +19,7 @@ func CmdListProjects() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) (err error) { reqSubscription := args[0] - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } diff --git a/x/subscription/client/cli/query_next_to_month_expiry.go b/x/subscription/client/cli/query_next_to_month_expiry.go index a8b99c110e..50a0143b30 100644 --- a/x/subscription/client/cli/query_next_to_month_expiry.go +++ b/x/subscription/client/cli/query_next_to_month_expiry.go @@ -17,7 +17,7 @@ func CmdNextToMonthExpiry() *cobra.Command { Short: "Query the subscriptions with the closest month expiry", Args: cobra.ExactArgs(0), RunE: func(cmd *cobra.Command, args []string) (err error) { - clientCtx, err := client.GetClientTxContext(cmd) + clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } From 754e215188fee5364ff1328e9afaaf8bc9340aad Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 11:57:26 +0200 Subject: [PATCH 03/23] CNS-871: scaffold query iprpc spec rewards --- proto/lavanet/lava/rewards/query.proto | 18 +- scripts/cli_test.sh | 1 + testutil/common/tester.go | 7 + x/rewards/client/cli/query.go | 1 + .../client/cli/query_iprpc_spec_reward.go | 48 ++ .../keeper/grpc_query_iprpc_spec_reward.go | 37 ++ x/rewards/types/query.pb.go | 543 ++++++++++++++++-- x/rewards/types/query.pb.gw.go | 101 ++++ 8 files changed, 700 insertions(+), 56 deletions(-) create mode 100644 x/rewards/client/cli/query_iprpc_spec_reward.go create mode 100644 x/rewards/keeper/grpc_query_iprpc_spec_reward.go diff --git a/proto/lavanet/lava/rewards/query.proto b/proto/lavanet/lava/rewards/query.proto index 8f3bab30ef..d4c6d9e89f 100644 --- a/proto/lavanet/lava/rewards/query.proto +++ b/proto/lavanet/lava/rewards/query.proto @@ -33,10 +33,15 @@ service Query { option (google.api.http).get = "/lavanet/lava/rewards/show_iprpc_data"; } - // ShowIprpcData queries for the iprpc data + // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) rpc IprpcProviderReward(QueryIprpcProviderRewardRequest) returns (QueryIprpcProviderRewardResponse) { option (google.api.http).get = "/lavanet/lava/rewards/iprpc_provider_reward/{provider}"; } + + // IprpcSpecReward queries for a spec's IPRPC reward + rpc IprpcSpecReward(QueryIprpcSpecRewardRequest) returns (QueryIprpcSpecRewardResponse) { + option (google.api.http).get = "/lavanet/lava/rewards/iprpc_spec_reward/{spec}"; + } // this line is used by starport scaffolding # 2 } @@ -96,4 +101,15 @@ message QueryIprpcProviderRewardResponse { repeated Specfund spec_funds = 1 [(gogoproto.nullable) = false]; } +// QueryIprpcSpecRewardRequest is request type for the Query/IprpcSpecReward RPC method. +message QueryIprpcSpecRewardRequest { + string spec = 1; +} + +// QueryIprpcSpecRewardResponse is response type for the Query/IprpcSpecReward RPC method. +message QueryIprpcSpecRewardResponse { + repeated IprpcReward iprpc_rewards = 1 [(gogoproto.nullable) = false]; + uint64 current_month_id = 2; +} + // this line is used by starport scaffolding # 3 \ No newline at end of file diff --git a/scripts/cli_test.sh b/scripts/cli_test.sh index 9ccd352adb..b14d7d6052 100755 --- a/scripts/cli_test.sh +++ b/scripts/cli_test.sh @@ -184,6 +184,7 @@ trace lavad q rewards pools >/dev/null trace lavad q rewards block-reward >/dev/null trace lavad q rewards show-iprpc-data > /dev/null trace lavad q rewards iprpc-provider-reward > /dev/null +trace lavad q rewards iprpc-spec-reward > /dev/null echo "Testing events command" trace lavad test events 30 10 --event lava_relay_payment --from alice --timeout 1s >/dev/null diff --git a/testutil/common/tester.go b/testutil/common/tester.go index 6e0f63232b..8b0f5807a3 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -871,6 +871,13 @@ func (ts *Tester) QueryRewardsIprpcProviderReward(provider string) (*rewardstype return ts.Keepers.Rewards.IprpcProviderReward(ts.GoCtx, msg) } +func (ts *Tester) QueryRewardsIprpcSpecReward(spec string) (*rewardstypes.QueryIprpcSpecRewardResponse, error) { + msg := &rewardstypes.QueryIprpcSpecRewardRequest{ + Spec: spec, + } + return ts.Keepers.Rewards.IprpcSpecReward(ts.GoCtx, msg) +} + // block/epoch helpers func (ts *Tester) BlockHeight() uint64 { diff --git a/x/rewards/client/cli/query.go b/x/rewards/client/cli/query.go index 0f9627ec93..b68b7c316c 100644 --- a/x/rewards/client/cli/query.go +++ b/x/rewards/client/cli/query.go @@ -29,6 +29,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryBlockReward()) cmd.AddCommand(CmdQueryShowIprpcData()) cmd.AddCommand(CmdQueryIprpcProviderReward()) + cmd.AddCommand(CmdQueryIprpcSpecReward()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/rewards/client/cli/query_iprpc_spec_reward.go b/x/rewards/client/cli/query_iprpc_spec_reward.go new file mode 100644 index 0000000000..f10ccdaddf --- /dev/null +++ b/x/rewards/client/cli/query_iprpc_spec_reward.go @@ -0,0 +1,48 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/lavanet/lava/x/rewards/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdQueryIprpcSpecReward() *cobra.Command { + cmd := &cobra.Command{ + Use: "iprpc-spec-reward {spec}", + Short: "Query for IPRPC rewards for a specific spec. If no spec is given, all IPRPC rewards will be shown", + Args: cobra.RangeArgs(0, 1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + var spec string + if len(args) > 0 { + spec = args[0] + } + + clientCtx, err := client.GetClientQueryContext(cmd) + if err != nil { + return err + } + + queryClient := types.NewQueryClient(clientCtx) + + params := &types.QueryIprpcSpecRewardRequest{ + Spec: spec, + } + + res, err := queryClient.IprpcSpecReward(cmd.Context(), params) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/rewards/keeper/grpc_query_iprpc_spec_reward.go b/x/rewards/keeper/grpc_query_iprpc_spec_reward.go new file mode 100644 index 0000000000..c3ad6acaea --- /dev/null +++ b/x/rewards/keeper/grpc_query_iprpc_spec_reward.go @@ -0,0 +1,37 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/x/rewards/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (k Keeper) IprpcSpecReward(goCtx context.Context, req *types.QueryIprpcSpecRewardRequest) (*types.QueryIprpcSpecRewardResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + + ctx := sdk.UnwrapSDKContext(goCtx) + iprpcRewards := k.GetAllIprpcReward(ctx) + currentMonthId := k.GetIprpcRewardsCurrent(ctx) + + if req.Spec == "" { + return &types.QueryIprpcSpecRewardResponse{IprpcRewards: iprpcRewards, CurrentMonthId: currentMonthId}, nil + } + + specIprpcRewards := []types.IprpcReward{} + for _, iprpcReward := range iprpcRewards { + for _, specFund := range iprpcReward.SpecFunds { + if specFund.Spec == req.Spec { + specIprpcReward := types.IprpcReward{Id: iprpcReward.Id, SpecFunds: []types.Specfund{specFund}} + specIprpcRewards = append(specIprpcRewards, specIprpcReward) + break + } + } + } + + return &types.QueryIprpcSpecRewardResponse{IprpcRewards: specIprpcRewards, CurrentMonthId: currentMonthId}, nil +} diff --git a/x/rewards/types/query.pb.go b/x/rewards/types/query.pb.go index 4b720bf75f..d404dd214a 100644 --- a/x/rewards/types/query.pb.go +++ b/x/rewards/types/query.pb.go @@ -536,6 +536,104 @@ func (m *QueryIprpcProviderRewardResponse) GetSpecFunds() []Specfund { return nil } +// QueryIprpcSpecRewardRequest is request type for the Query/IprpcSpecReward RPC method. +type QueryIprpcSpecRewardRequest struct { + Spec string `protobuf:"bytes,1,opt,name=spec,proto3" json:"spec,omitempty"` +} + +func (m *QueryIprpcSpecRewardRequest) Reset() { *m = QueryIprpcSpecRewardRequest{} } +func (m *QueryIprpcSpecRewardRequest) String() string { return proto.CompactTextString(m) } +func (*QueryIprpcSpecRewardRequest) ProtoMessage() {} +func (*QueryIprpcSpecRewardRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_15bce9a904340007, []int{11} +} +func (m *QueryIprpcSpecRewardRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryIprpcSpecRewardRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryIprpcSpecRewardRequest.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 *QueryIprpcSpecRewardRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcSpecRewardRequest.Merge(m, src) +} +func (m *QueryIprpcSpecRewardRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryIprpcSpecRewardRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcSpecRewardRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryIprpcSpecRewardRequest proto.InternalMessageInfo + +func (m *QueryIprpcSpecRewardRequest) GetSpec() string { + if m != nil { + return m.Spec + } + return "" +} + +// QueryIprpcSpecRewardResponse is response type for the Query/IprpcSpecReward RPC method. +type QueryIprpcSpecRewardResponse struct { + IprpcRewards []IprpcReward `protobuf:"bytes,1,rep,name=iprpc_rewards,json=iprpcRewards,proto3" json:"iprpc_rewards"` + CurrentMonthId uint64 `protobuf:"varint,2,opt,name=current_month_id,json=currentMonthId,proto3" json:"current_month_id,omitempty"` +} + +func (m *QueryIprpcSpecRewardResponse) Reset() { *m = QueryIprpcSpecRewardResponse{} } +func (m *QueryIprpcSpecRewardResponse) String() string { return proto.CompactTextString(m) } +func (*QueryIprpcSpecRewardResponse) ProtoMessage() {} +func (*QueryIprpcSpecRewardResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_15bce9a904340007, []int{12} +} +func (m *QueryIprpcSpecRewardResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryIprpcSpecRewardResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryIprpcSpecRewardResponse.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 *QueryIprpcSpecRewardResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcSpecRewardResponse.Merge(m, src) +} +func (m *QueryIprpcSpecRewardResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryIprpcSpecRewardResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcSpecRewardResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryIprpcSpecRewardResponse proto.InternalMessageInfo + +func (m *QueryIprpcSpecRewardResponse) GetIprpcRewards() []IprpcReward { + if m != nil { + return m.IprpcRewards + } + return nil +} + +func (m *QueryIprpcSpecRewardResponse) GetCurrentMonthId() uint64 { + if m != nil { + return m.CurrentMonthId + } + return 0 +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "lavanet.lava.rewards.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "lavanet.lava.rewards.QueryParamsResponse") @@ -548,64 +646,73 @@ func init() { proto.RegisterType((*QueryShowIprpcDataResponse)(nil), "lavanet.lava.rewards.QueryShowIprpcDataResponse") proto.RegisterType((*QueryIprpcProviderRewardRequest)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardRequest") proto.RegisterType((*QueryIprpcProviderRewardResponse)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardResponse") + proto.RegisterType((*QueryIprpcSpecRewardRequest)(nil), "lavanet.lava.rewards.QueryIprpcSpecRewardRequest") + proto.RegisterType((*QueryIprpcSpecRewardResponse)(nil), "lavanet.lava.rewards.QueryIprpcSpecRewardResponse") } func init() { proto.RegisterFile("lavanet/lava/rewards/query.proto", fileDescriptor_15bce9a904340007) } var fileDescriptor_15bce9a904340007 = []byte{ - // 827 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x55, 0xcf, 0x6f, 0xe3, 0x44, - 0x18, 0x8d, 0xfb, 0x23, 0x6d, 0xa7, 0x80, 0xc4, 0xa4, 0x52, 0x53, 0xb7, 0xb8, 0xc1, 0x14, 0x35, - 0x54, 0xaa, 0xa7, 0x2d, 0xa2, 0x20, 0x50, 0x91, 0x48, 0x11, 0x52, 0x25, 0x90, 0x5a, 0x87, 0x13, - 0x17, 0x6b, 0xe2, 0x4c, 0x12, 0xab, 0xb6, 0xc7, 0xf5, 0x4c, 0x5a, 0x2a, 0x84, 0x90, 0x40, 0x1c, - 0xb8, 0x21, 0xc1, 0x81, 0x2b, 0x57, 0xfe, 0x0e, 0x0e, 0x3d, 0x56, 0xe2, 0xc2, 0x69, 0x77, 0xd5, - 0xee, 0x5f, 0xb0, 0x7f, 0xc1, 0x6a, 0x3e, 0x8f, 0xb3, 0x89, 0xea, 0xa4, 0xd9, 0x93, 0xe3, 0x99, - 0xf7, 0xbe, 0xf7, 0xde, 0xf8, 0xfb, 0x32, 0xa8, 0x16, 0xd2, 0x4b, 0x1a, 0x33, 0x49, 0xd4, 0x93, - 0xa4, 0xec, 0x8a, 0xa6, 0x6d, 0x41, 0x2e, 0xfa, 0x2c, 0xbd, 0x76, 0x92, 0x94, 0x4b, 0x8e, 0x57, - 0x34, 0xc2, 0x51, 0x4f, 0x47, 0x23, 0xcc, 0x95, 0x2e, 0xef, 0x72, 0x00, 0x10, 0xf5, 0x2b, 0xc3, - 0x9a, 0x1b, 0x5d, 0xce, 0xbb, 0x21, 0x23, 0x34, 0x09, 0x08, 0x8d, 0x63, 0x2e, 0xa9, 0x0c, 0x78, - 0x2c, 0xf4, 0xee, 0x8e, 0xcf, 0x45, 0xc4, 0x05, 0x69, 0x51, 0xc1, 0x32, 0x09, 0x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77, 0x3e, 0x51, 0x0b, 0x55, 0x03, 0xb4, 0xad, 0x31, 0x71, 0x75, 0x00, 0x1d, - 0x38, 0xa3, 0xe0, 0x2d, 0xf4, 0x96, 0x0c, 0x22, 0xe6, 0x49, 0xee, 0xa5, 0xac, 0x13, 0x84, 0x61, - 0x75, 0xa6, 0x66, 0xd4, 0x67, 0xdd, 0x37, 0xd4, 0xea, 0xb7, 0xdc, 0x85, 0x35, 0xfc, 0x19, 0x32, - 0x99, 0x90, 0x41, 0x44, 0x25, 0x6b, 0x7b, 0xad, 0x90, 0xfb, 0xe7, 0x62, 0x88, 0x31, 0x0b, 0x8c, - 0xd5, 0x01, 0xa2, 0x01, 0x80, 0x01, 0xf9, 0x08, 0xad, 0xd3, 0x30, 0xe4, 0x3e, 0x34, 0x8d, 0xa7, - 0x64, 0xbd, 0x88, 0xc7, 0xb2, 0x27, 0xbc, 0x90, 0x75, 0x64, 0x75, 0x0e, 0xd8, 0xd5, 0x57, 0x10, - 0x65, 0xf4, 0x1b, 0x00, 0x7c, 0xcd, 0x3a, 0xd2, 0x5e, 0x43, 0xab, 0x90, 0x19, 0xaa, 0xba, 0x10, - 0x26, 0xff, 0x2e, 0x4d, 0x54, 0x7d, 0xb8, 0xa5, 0x0f, 0xe5, 0x63, 0x54, 0xce, 0x92, 0xeb, 0x26, - 0x98, 0xf0, 0x45, 0x74, 0x07, 0x64, 0x70, 0x7b, 0x1d, 0xad, 0x41, 0xd1, 0x66, 0x8f, 0x5f, 0x9d, - 0xa8, 0x16, 0xfd, 0x92, 0x4a, 0x9a, 0x2b, 0xfe, 0x66, 0x20, 0xb3, 0x68, 0x77, 0xf0, 0x25, 0x16, - 0xa3, 0x20, 0xf6, 0x7c, 0x2e, 0xe4, 0xb4, 0xb2, 0x0b, 0x51, 0x10, 0x1f, 0x73, 0x21, 0x31, 0x41, - 0x15, 0x98, 0x08, 0x4f, 0xf4, 0x5b, 0xc2, 0x4f, 0x83, 0x04, 0x06, 0x12, 0xfa, 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, 0xd8, 0xa0, 0xe8, 0xf1, 0x2b, 0x2f, 0x1b, 0x8d, 0xb6, 0x72, 0xf4, 0xaf, 0x81, - 0x2a, 0x05, 0x4d, 0x8b, 0x3f, 0x9a, 0x20, 0x3c, 0x7e, 0x46, 0xcc, 0xc3, 0xd7, 0xa5, 0x69, 0xd7, - 0x9f, 0x83, 0xeb, 0x4f, 0xf0, 0x21, 0x19, 0x7f, 0xbb, 0x79, 0xf9, 0xb4, 0xe9, 0xf3, 0x25, 0x3f, - 0xe4, 0x0b, 0x3f, 0x36, 0xbe, 0xb8, 0xb9, 0xb3, 0x8c, 0xdb, 0x3b, 0xcb, 0x78, 0x76, 0x67, 0x19, - 0xbf, 0xdf, 0x5b, 0xa5, 0xdb, 0x7b, 0xab, 0xf4, 0xff, 0xbd, 0x55, 0xfa, 0x6e, 0x7b, 0xe8, 0x66, - 0x18, 0xa9, 0xfd, 0xfd, 0xa0, 0x3a, 0x5c, 0x0f, 0xad, 0x32, 0x5c, 0x8e, 0x1f, 0xbe, 0x0c, 0x00, - 0x00, 0xff, 0xff, 0x22, 0x23, 0xbb, 0x03, 0x1b, 0x08, 0x00, 0x00, + // 936 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x6f, 0xdc, 0x44, + 0x14, 0x8e, 0x93, 0xcd, 0xaf, 0x97, 0xb6, 0xc0, 0x24, 0x52, 0x37, 0x4e, 0x70, 0xb6, 0x26, 0x28, + 0x4b, 0xa5, 0xd8, 0x49, 0x10, 0x01, 0x81, 0x8a, 0x44, 0x82, 0x90, 0x22, 0x15, 0xa9, 0x75, 0x38, + 0x71, 0xb1, 0x66, 0xbd, 0xb3, 0x1b, 0xab, 0xb6, 0xc7, 0xf5, 0xcc, 0x26, 0x54, 0xa8, 0x42, 0x02, + 0x71, 0xe0, 0x86, 0x84, 0x84, 0xb8, 0x72, 0xe5, 0xc4, 0x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xd4, + 0xbb, 0xfb, 0xa3, 0x05, 0xeb, 0xd5, 0x1c, 0x63, 0xec, 0x3e, 0xdc, 0xd4, 0x87, 0x65, 0xe4, 0x8d, + 0xb7, 0x3b, 0xd5, 0xde, 0x30, 0x8a, 0x8e, 0x60, 0xec, 0xdd, 0x88, 0x2f, 0x97, 0x04, 0x69, 0xc2, + 0xab, 0x51, 0xaf, 0x28, 0x58, 0x26, 0x75, 0x65, 0x86, 0x71, 0x1b, 0xdb, 0xa0, 0x16, 0xdc, 0x32, + 0xeb, 0x58, 0x8f, 0x47, 0xed, 0xbd, 0xdf, 0xe7, 0x61, 0x16, 0x8d, 0x91, 0x6f, 0x2c, 0x98, 0xd3, + 0x13, 0x84, 0x34, 0xab, 0x55, 0xaf, 0x0e, 0x2c, 0xfb, 0xad, 0x09, 0x90, 0x3a, 0x43, 0x77, 0xf3, + 0xeb, 0x3f, 0xfe, 0xfd, 0x61, 0xda, 0x21, 0xeb, 0xfe, 0x98, 0xf9, 0x4a, 0xbe, 0x82, 0x59, 0x9c, + 0x05, 0x64, 0x6b, 0x5c, 0xe4, 0x81, 0x59, 0x66, 0x37, 0xaf, 0x07, 0x1a, 0x07, 0x6f, 0xa0, 0x83, + 0xd7, 0xc9, 0xda, 0x08, 0x07, 0xa8, 0xfb, 0x93, 0x05, 0x4b, 0x03, 0xed, 0x47, 0xb6, 0xc7, 0x84, + 0xbf, 0xda, 0xc1, 0xb6, 0x37, 0x29, 0xdc, 0x78, 0xba, 0x8b, 0x9e, 0x36, 0x89, 0x5b, 0xed, 0x09, + 0x47, 0x93, 0xa9, 0x09, 0xf2, 0xb3, 0x05, 0x37, 0x87, 0xda, 0x94, 0xf8, 0x63, 0xd4, 0xaa, 0xda, + 0xdd, 0xde, 0x99, 0x9c, 0x60, 0x0c, 0x6e, 0xa3, 0xc1, 0x2d, 0xf2, 0x66, 0xb5, 0x41, 0x71, 0xc2, + 0xcf, 0x42, 0x5d, 0xb9, 0x6d, 0xe5, 0xe8, 0x37, 0x0b, 0x96, 0x2b, 0x1a, 0x90, 0xbc, 0x33, 0x46, + 0x78, 0x74, 0xbf, 0xdb, 0xfb, 0x2f, 0x4b, 0x33, 0xae, 0x3f, 0x44, 0xd7, 0xef, 0x91, 0x7d, 0x7f, + 0xf4, 0x4d, 0x1d, 0x96, 0x93, 0xc3, 0x9c, 0xaf, 0xff, 0x65, 0xb9, 0xf0, 0x94, 0xfc, 0x6a, 0xc1, + 0x2b, 0x2f, 0xb4, 0x2a, 0xd9, 0xbd, 0xce, 0xcb, 0x95, 0x51, 0x60, 0xef, 0xbd, 0x0c, 0xc5, 0x58, + 0xdf, 0x47, 0xeb, 0x3b, 0xc4, 0x1b, 0x67, 0x1d, 0x87, 0x58, 0x69, 0x5b, 0xfd, 0x78, 0x7a, 0xf0, + 0xd1, 0xb3, 0x73, 0xc7, 0x7a, 0x7e, 0xee, 0x58, 0xff, 0x9c, 0x3b, 0xd6, 0xf7, 0x17, 0xce, 0xd4, + 0xf3, 0x0b, 0x67, 0xea, 0xcf, 0x0b, 0x67, 0xea, 0xf3, 0xad, 0x81, 0x8b, 0x79, 0x28, 0xe6, 0x17, + 0xfd, 0xa8, 0x78, 0x3b, 0xb7, 0xe6, 0xf0, 0xbf, 0xc9, 0xdb, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, + 0x0c, 0x25, 0x99, 0x21, 0x9a, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -628,8 +735,10 @@ type QueryClient interface { BlockReward(ctx context.Context, in *QueryBlockRewardRequest, opts ...grpc.CallOption) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(ctx context.Context, in *QueryShowIprpcDataRequest, opts ...grpc.CallOption) (*QueryShowIprpcDataResponse, error) - // ShowIprpcData queries for the iprpc data + // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) IprpcProviderReward(ctx context.Context, in *QueryIprpcProviderRewardRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardResponse, error) + // IprpcSpecReward queries for a spec's IPRPC reward + IprpcSpecReward(ctx context.Context, in *QueryIprpcSpecRewardRequest, opts ...grpc.CallOption) (*QueryIprpcSpecRewardResponse, error) } type queryClient struct { @@ -685,6 +794,15 @@ func (c *queryClient) IprpcProviderReward(ctx context.Context, in *QueryIprpcPro return out, nil } +func (c *queryClient) IprpcSpecReward(ctx context.Context, in *QueryIprpcSpecRewardRequest, opts ...grpc.CallOption) (*QueryIprpcSpecRewardResponse, error) { + out := new(QueryIprpcSpecRewardResponse) + err := c.cc.Invoke(ctx, "/lavanet.lava.rewards.Query/IprpcSpecReward", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { // Parameters queries the parameters of the module. @@ -695,8 +813,10 @@ type QueryServer interface { BlockReward(context.Context, *QueryBlockRewardRequest) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(context.Context, *QueryShowIprpcDataRequest) (*QueryShowIprpcDataResponse, error) - // ShowIprpcData queries for the iprpc data + // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) IprpcProviderReward(context.Context, *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) + // IprpcSpecReward queries for a spec's IPRPC reward + IprpcSpecReward(context.Context, *QueryIprpcSpecRewardRequest) (*QueryIprpcSpecRewardResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. @@ -718,6 +838,9 @@ func (*UnimplementedQueryServer) ShowIprpcData(ctx context.Context, req *QuerySh func (*UnimplementedQueryServer) IprpcProviderReward(ctx context.Context, req *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method IprpcProviderReward not implemented") } +func (*UnimplementedQueryServer) IprpcSpecReward(ctx context.Context, req *QueryIprpcSpecRewardRequest) (*QueryIprpcSpecRewardResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IprpcSpecReward not implemented") +} func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) @@ -813,6 +936,24 @@ func _Query_IprpcProviderReward_Handler(srv interface{}, ctx context.Context, de return interceptor(ctx, in, info, handler) } +func _Query_IprpcSpecReward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryIprpcSpecRewardRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).IprpcSpecReward(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lavanet.lava.rewards.Query/IprpcSpecReward", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).IprpcSpecReward(ctx, req.(*QueryIprpcSpecRewardRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "lavanet.lava.rewards.Query", HandlerType: (*QueryServer)(nil), @@ -837,6 +978,10 @@ var _Query_serviceDesc = grpc.ServiceDesc{ MethodName: "IprpcProviderReward", Handler: _Query_IprpcProviderReward_Handler, }, + { + MethodName: "IprpcSpecReward", + Handler: _Query_IprpcSpecReward_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lavanet/lava/rewards/query.proto", @@ -1205,6 +1350,78 @@ func (m *QueryIprpcProviderRewardResponse) MarshalToSizedBuffer(dAtA []byte) (in return len(dAtA) - i, nil } +func (m *QueryIprpcSpecRewardRequest) 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 *QueryIprpcSpecRewardRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryIprpcSpecRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Spec) > 0 { + i -= len(m.Spec) + copy(dAtA[i:], m.Spec) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Spec))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QueryIprpcSpecRewardResponse) 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 *QueryIprpcSpecRewardResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryIprpcSpecRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.CurrentMonthId != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.CurrentMonthId)) + i-- + dAtA[i] = 0x10 + } + if len(m.IprpcRewards) > 0 { + for iNdEx := len(m.IprpcRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.IprpcRewards[iNdEx].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 @@ -1362,6 +1579,37 @@ func (m *QueryIprpcProviderRewardResponse) Size() (n int) { return n } +func (m *QueryIprpcSpecRewardRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Spec) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QueryIprpcSpecRewardResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if len(m.IprpcRewards) > 0 { + for _, e := range m.IprpcRewards { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + if m.CurrentMonthId != 0 { + n += 1 + sovQuery(uint64(m.CurrentMonthId)) + } + return n +} + func sovQuery(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -2272,6 +2520,191 @@ func (m *QueryIprpcProviderRewardResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *QueryIprpcSpecRewardRequest) 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: QueryIprpcSpecRewardRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryIprpcSpecRewardRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Spec", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + 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 ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Spec = string(dAtA[iNdEx:postIndex]) + 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 (m *QueryIprpcSpecRewardResponse) 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: QueryIprpcSpecRewardResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryIprpcSpecRewardResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field IprpcRewards", 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 + } + m.IprpcRewards = append(m.IprpcRewards, IprpcReward{}) + if err := m.IprpcRewards[len(m.IprpcRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentMonthId", wireType) + } + m.CurrentMonthId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CurrentMonthId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + 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/rewards/types/query.pb.gw.go b/x/rewards/types/query.pb.gw.go index 7e0cc7f2c8..2054cc9331 100644 --- a/x/rewards/types/query.pb.gw.go +++ b/x/rewards/types/query.pb.gw.go @@ -159,6 +159,60 @@ func local_request_Query_IprpcProviderReward_0(ctx context.Context, marshaler ru } +func request_Query_IprpcSpecReward_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcSpecRewardRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["spec"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "spec") + } + + protoReq.Spec, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "spec", err) + } + + msg, err := client.IprpcSpecReward(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_IprpcSpecReward_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcSpecRewardRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["spec"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "spec") + } + + protoReq.Spec, err = runtime.String(val) + + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "spec", err) + } + + msg, err := server.IprpcSpecReward(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. @@ -280,6 +334,29 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) + mux.Handle("GET", pattern_Query_IprpcSpecReward_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_IprpcSpecReward_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_IprpcSpecReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -421,6 +498,26 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) + mux.Handle("GET", pattern_Query_IprpcSpecReward_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_IprpcSpecReward_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_IprpcSpecReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -434,6 +531,8 @@ var ( pattern_Query_ShowIprpcData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lavanet", "lava", "rewards", "show_iprpc_data"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_IprpcProviderReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_provider_reward", "provider"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_IprpcSpecReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_spec_reward", "spec"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( @@ -446,4 +545,6 @@ var ( forward_Query_ShowIprpcData_0 = runtime.ForwardResponseMessage forward_Query_IprpcProviderReward_0 = runtime.ForwardResponseMessage + + forward_Query_IprpcSpecReward_0 = runtime.ForwardResponseMessage ) From b7ba787b62955511a064579c9bc16f019bcd5c28 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 13:55:44 +0200 Subject: [PATCH 04/23] CNS-872: fix for iprpc reward object update --- x/rewards/keeper/iprpc_reward.go | 13 +++---------- x/rewards/keeper/providers.go | 3 ++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/x/rewards/keeper/iprpc_reward.go b/x/rewards/keeper/iprpc_reward.go index b124b55e72..083e674908 100644 --- a/x/rewards/keeper/iprpc_reward.go +++ b/x/rewards/keeper/iprpc_reward.go @@ -86,16 +86,9 @@ func GetIprpcRewardIDFromBytes(bz []byte) uint64 { // PopIprpcReward gets the lowest id IprpcReward object and removes it func (k Keeper) PopIprpcReward(ctx sdk.Context) (types.IprpcReward, bool) { - // Get current IprpcReward - iprpcReward, found := k.GetIprpcReward(ctx, k.GetIprpcRewardsCurrent(ctx)) - if !found { - return types.IprpcReward{}, false - } - - // Remove the reward - k.RemoveIprpcReward(ctx, iprpcReward.Id) - - return iprpcReward, true + current := k.GetIprpcRewardsCurrent(ctx) + k.SetIprpcRewardsCurrent(ctx, current+1) + return k.GetIprpcReward(ctx, current) } // AddSpecFunds adds funds for a specific spec for of months. diff --git a/x/rewards/keeper/providers.go b/x/rewards/keeper/providers.go index 94eb41c3d3..48f09a2694 100644 --- a/x/rewards/keeper/providers.go +++ b/x/rewards/keeper/providers.go @@ -107,7 +107,8 @@ func (k Keeper) distributeMonthlyBonusRewards(ctx sdk.Context) { utils.LavaFormatError("current month iprpc reward not found", fmt.Errorf("did not reward providers IPRPC bonus")) return } - k.SetIprpcRewardsCurrent(ctx, iprpcReward.Id+1) + k.RemoveIprpcReward(ctx, iprpcReward.Id) + for _, specFund := range iprpcReward.SpecFunds { // collect details details := map[string]string{"spec": specFund.Spec, "rewards": specFund.Fund.String()} From 6b9cb8f069ff5a684e9bbfb78732dab10f2df56a Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 14:41:56 +0200 Subject: [PATCH 05/23] CNS-872: update pool test with iprpc pool --- x/rewards/keeper/pool_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/rewards/keeper/pool_test.go b/x/rewards/keeper/pool_test.go index f1fccf4c2c..ab18224d7a 100644 --- a/x/rewards/keeper/pool_test.go +++ b/x/rewards/keeper/pool_test.go @@ -37,8 +37,6 @@ import ( // 1. The allocation pool has the expected allocated funds minus one block reward // 2. The distribution pool has the expected monthly quota minus one block reward // 3. The fee collector has one block reward -// -// the validator got rewards func TestRewardsModuleSetup(t *testing.T) { ts := newTester(t, false) lifetime := int64(types.RewardsAllocationPoolsLifetime) @@ -64,6 +62,8 @@ func TestRewardsModuleSetup(t *testing.T) { require.Equal(t, allocationPoolBalance*(lifetime-1)/lifetime, pool.Balance.AmountOf(ts.BondDenom()).Int64()) case string(types.ValidatorsRewardsDistributionPoolName): require.Equal(t, (allocationPoolBalance/lifetime)-blockReward, pool.Balance.AmountOf(ts.BondDenom()).Int64()) + case string(types.IprpcPoolName): + require.True(t, pool.Balance.Empty()) } } From 8ae57c53215ff2bf60914a502c4281b43d9d1435 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 14:47:58 +0200 Subject: [PATCH 06/23] CNS-872: create small helper --- testutil/common/tester.go | 5 +++-- x/rewards/keeper/helpers_test.go | 5 +++++ x/rewards/keeper/iprpc_data_test.go | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/testutil/common/tester.go b/testutil/common/tester.go index 8b0f5807a3..708f4c1a14 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -610,9 +610,9 @@ func (ts *Tester) TxPairingUnfreezeProvider(addr, chainID string) (*pairingtypes return ts.Servers.PairingServer.UnfreezeProvider(ts.GoCtx, msg) } -func (ts *Tester) TxRewardsSetIprpcDataProposal(ctx sdk.Context, authority string, cost sdk.Coin, subs []string) (*rewardstypes.MsgSetIprpcDataResponse, error) { +func (ts *Tester) TxRewardsSetIprpcDataProposal(authority string, cost sdk.Coin, subs []string) (*rewardstypes.MsgSetIprpcDataResponse, error) { msg := rewardstypes.NewMsgSetIprpcData(authority, cost, subs) - return ts.Servers.RewardsServer.SetIprpcData(sdk.WrapSDKContext(ctx), msg) + return ts.Servers.RewardsServer.SetIprpcData(ts.GoCtx, msg) } // TxCreateValidator: implement 'tx staking createvalidator' and bond its tokens @@ -859,6 +859,7 @@ func (ts *Tester) QueryRewardsBlockReward() (*rewardstypes.QueryBlockRewardRespo return ts.Keepers.Rewards.BlockReward(ts.GoCtx, msg) } +// QueryRewardsShowIprpcData implements 'q rewards show-iprpc-data' func (ts *Tester) QueryRewardsShowIprpcData() (*rewardstypes.QueryShowIprpcDataResponse, error) { msg := &rewardstypes.QueryShowIprpcDataRequest{} return ts.Keepers.Rewards.ShowIprpcData(ts.GoCtx, msg) diff --git a/x/rewards/keeper/helpers_test.go b/x/rewards/keeper/helpers_test.go index e2d009ab50..ddff8d8474 100644 --- a/x/rewards/keeper/helpers_test.go +++ b/x/rewards/keeper/helpers_test.go @@ -6,6 +6,7 @@ import ( "cosmossdk.io/math" 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" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/lavanet/lava/testutil/common" testkeeper "github.com/lavanet/lava/testutil/keeper" @@ -66,6 +67,10 @@ func (ts *tester) getPoolBalance(pool rewardsTypes.Pool, denom string) math.Int return coins.AmountOf(denom) } +func (ts *tester) iprpcAuthority() string { + return authtypes.NewModuleAddress(govtypes.ModuleName).String() +} + // deductParticipationFees calculates the validators and community participation // fees and returns the providers reward after deducting them func (ts *tester) DeductParticipationFees(reward math.Int) (updatedReward math.Int, valParticipation math.Int, communityParticipation math.Int) { diff --git a/x/rewards/keeper/iprpc_data_test.go b/x/rewards/keeper/iprpc_data_test.go index f88cb59fbd..8d949565b1 100644 --- a/x/rewards/keeper/iprpc_data_test.go +++ b/x/rewards/keeper/iprpc_data_test.go @@ -109,7 +109,7 @@ func TestIprpcDataValidation(t *testing.T) { for _, tt := range template { t.Run(tt.name, func(t *testing.T) { - _, err := ts.TxRewardsSetIprpcDataProposal(ts.Ctx, tt.authority, tt.cost, tt.subs) + _, err := ts.TxRewardsSetIprpcDataProposal(tt.authority, tt.cost, tt.subs) if tt.success { require.NoError(t, err) res, err := ts.QueryRewardsShowIprpcData() From e287193bf6570b71e6696df67429056e700218bb Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 18:12:17 +0200 Subject: [PATCH 07/23] CNS-872: make mock bank keeper support multiple coins --- testutil/keeper/mock_keepers.go | 47 +++------------------------------ 1 file changed, 4 insertions(+), 43 deletions(-) diff --git a/testutil/keeper/mock_keepers.go b/testutil/keeper/mock_keepers.go index fbe2c741ce..e0cb927683 100644 --- a/testutil/keeper/mock_keepers.go +++ b/testutil/keeper/mock_keepers.go @@ -77,15 +77,9 @@ func (k mockBankKeeper) GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk } func (k mockBankKeeper) SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error { - // TODO support multiple coins moduleAcc := GetModuleAddress(recipientModule) - if amt.Len() > 1 { - return fmt.Errorf("mockbankkeeper dont support more than 1 coin") - } - coin := amt[0] - - accountCoin := k.GetBalance(ctx, senderAddr, coin.Denom) - if coin.Amount.GT(accountCoin.Amount) { + accountCoins := k.GetAllBalances(ctx, senderAddr) + if !accountCoins.IsAllGTE(amt) { return fmt.Errorf("not enough coins") } @@ -99,47 +93,14 @@ func (k mockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx sdk.Context, send } func (k mockBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error { - // TODO support multiple coins moduleAcc := GetModuleAddress(senderModule) - - if amt.Len() > 1 { - return fmt.Errorf("mockbankkeeper doesn't support more than 1 coin") - } - coin := amt[0] - - accountCoin := k.GetBalance(ctx, moduleAcc, coin.Denom) - if coin.Amount.GT(accountCoin.Amount) { - return fmt.Errorf("not enough coins") - } - - k.SubFromBalance(moduleAcc, amt) - - k.AddToBalance(recipientAddr, amt) - - return nil + return k.SendCoinsFromAccountToModule(ctx, moduleAcc, recipientAddr.String(), amt) } func (k mockBankKeeper) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error { - // TODO support multiple coins - senderModuleAcc := GetModuleAddress(senderModule) recipientModuleAcc := GetModuleAddress(recipientModule) - - if amt.Len() > 1 { - return fmt.Errorf("mockbankkeeper doesn't support more than 1 coin") - } - coin := amt[0] - - senderAccountCoin := k.GetBalance(ctx, senderModuleAcc, coin.Denom) - if coin.Amount.GT(senderAccountCoin.Amount) { - return fmt.Errorf("not enough coins") - } - - k.SubFromBalance(senderModuleAcc, amt) - - k.AddToBalance(recipientModuleAcc, amt) - - return nil + return k.SendCoinsFromAccountToModule(ctx, senderModuleAcc, recipientModuleAcc.String(), amt) } func (k mockBankKeeper) DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error { From bbf3f1106e6d34373f686eda6192ebe63383f4a2 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Thu, 15 Feb 2024 18:45:03 +0200 Subject: [PATCH 08/23] CNS-872: fix mock bank keeper --- testutil/keeper/mock_keepers.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/testutil/keeper/mock_keepers.go b/testutil/keeper/mock_keepers.go index e0cb927683..ab465c0e22 100644 --- a/testutil/keeper/mock_keepers.go +++ b/testutil/keeper/mock_keepers.go @@ -99,8 +99,7 @@ func (k mockBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModu func (k mockBankKeeper) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error { senderModuleAcc := GetModuleAddress(senderModule) - recipientModuleAcc := GetModuleAddress(recipientModule) - return k.SendCoinsFromAccountToModule(ctx, senderModuleAcc, recipientModuleAcc.String(), amt) + return k.SendCoinsFromAccountToModule(ctx, senderModuleAcc, recipientModule, amt) } func (k mockBankKeeper) DelegateCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error { From aaf6d4baa392fc1e00537201b84abafbe4418a33 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Sun, 18 Feb 2024 12:29:57 +0200 Subject: [PATCH 09/23] CNS-872: fix iprpc reward bug --- x/rewards/keeper/iprpc_reward.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/x/rewards/keeper/iprpc_reward.go b/x/rewards/keeper/iprpc_reward.go index 083e674908..067a009003 100644 --- a/x/rewards/keeper/iprpc_reward.go +++ b/x/rewards/keeper/iprpc_reward.go @@ -102,22 +102,24 @@ func (k Keeper) addSpecFunds(ctx sdk.Context, spec string, fund sdk.Coins, durat for i := startID; i < duration; i++ { iprpcReward, found := k.GetIprpcReward(ctx, i) if found { - // found IPRPC reward + // found IPRPC reward, find if spec exists + specIndex := -1 for i := 0; i < len(iprpcReward.SpecFunds); i++ { if iprpcReward.SpecFunds[i].Spec == spec { - iprpcReward.SpecFunds[i].Fund = iprpcReward.SpecFunds[i].Fund.Add(fund...) - k.SetIprpcReward(ctx, iprpcReward) - return + specIndex = i } } - // did not find spec in IPRPC reward -> create a new one - iprpcReward.SpecFunds = append(iprpcReward.SpecFunds, types.Specfund{Spec: spec, Fund: fund}) - k.SetIprpcReward(ctx, iprpcReward) + // update spec funds + if specIndex >= 0 { + iprpcReward.SpecFunds[specIndex].Fund = iprpcReward.SpecFunds[specIndex].Fund.Add(fund...) + } else { + iprpcReward.SpecFunds = append(iprpcReward.SpecFunds, types.Specfund{Spec: spec, Fund: fund}) + } } else { // did not find IPRPC reward -> create a new one iprpcReward.Id = i iprpcReward.SpecFunds = []types.Specfund{{Spec: spec, Fund: fund}} - k.SetIprpcReward(ctx, iprpcReward) } + k.SetIprpcReward(ctx, iprpcReward) } } From d21b0fc26bc68601c52a33181ec190bfd13dc8d7 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Mon, 19 Feb 2024 16:35:39 +0200 Subject: [PATCH 10/23] CNS-871: change popAllSpecBasepays to optionally delete --- x/rewards/keeper/base_pay.go | 6 ++++-- x/rewards/keeper/grpc_query_iprpc_provider_reward.go | 2 +- x/rewards/keeper/providers.go | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x/rewards/keeper/base_pay.go b/x/rewards/keeper/base_pay.go index e7639a2342..76c5ebfd50 100644 --- a/x/rewards/keeper/base_pay.go +++ b/x/rewards/keeper/base_pay.go @@ -54,7 +54,7 @@ func (k Keeper) SetAllBasePay(ctx sdk.Context, list []types.BasePayGenesis) { } } -func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string) (list []types.BasePayWithIndex) { +func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string, removeAfterPop bool) (list []types.BasePayWithIndex) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BasePayPrefix)) iterator := sdk.KVStorePrefixIterator(store, []byte(chainID)) @@ -64,7 +64,9 @@ func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string) (list []t var val types.BasePay k.cdc.MustUnmarshal(iterator.Value(), &val) list = append(list, types.BasePayWithIndex{BasePayIndex: types.BasePayKeyRecover(string(iterator.Key())), BasePay: val}) - store.Delete(iterator.Key()) + if removeAfterPop { + store.Delete(iterator.Key()) + } } return diff --git a/x/rewards/keeper/grpc_query_iprpc_provider_reward.go b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go index 2a2cfd0ffc..03e3aa8d6c 100644 --- a/x/rewards/keeper/grpc_query_iprpc_provider_reward.go +++ b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go @@ -28,7 +28,7 @@ func (k Keeper) IprpcProviderReward(goCtx context.Context, req *types.QueryIprpc providerSpecFunds := []types.Specfund{} for _, specFund := range iprpcReward.SpecFunds { // get all spec basepays and count IPRPC CU - bps, _ := k.specProvidersBasePay(ctx, specFund.Spec) + bps, _ := k.specProvidersBasePay(ctx, specFund.Spec, false) providerIprpcCu := uint64(0) totalIprpcCu := uint64(0) providerBpIndex := types.BasePayIndex{Provider: req.Provider, ChainID: specFund.Spec} diff --git a/x/rewards/keeper/providers.go b/x/rewards/keeper/providers.go index 762002580b..f0936bd0ba 100644 --- a/x/rewards/keeper/providers.go +++ b/x/rewards/keeper/providers.go @@ -58,7 +58,7 @@ func (k Keeper) distributeMonthlyBonusRewards(ctx sdk.Context) { specCuMap := map[string]types.SpecCuType{} // spec -> specCu for _, spec := range specs { // all providers basepays and the total basepay of the spec - basepays, totalbasepay := k.specProvidersBasePay(ctx, spec.ChainID) + basepays, totalbasepay := k.specProvidersBasePay(ctx, spec.ChainID, true) if len(basepays) == 0 { continue } @@ -250,8 +250,8 @@ func (k Keeper) specEmissionParts(ctx sdk.Context) (emissions []types.SpecEmissi return emissions } -func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string) ([]types.BasePayWithIndex, math.Int) { - basepays := k.popAllBasePayForChain(ctx, chainID) +func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string, removeAfterPop bool) ([]types.BasePayWithIndex, math.Int) { + basepays := k.popAllBasePayForChain(ctx, chainID, removeAfterPop) totalBasePay := math.ZeroInt() for _, basepay := range basepays { totalBasePay = totalBasePay.Add(basepay.Total) From 04b7f19a69305ec59855a892af01d340597c5d2c Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 21 Feb 2024 16:20:16 +0200 Subject: [PATCH 11/23] CNS-872: unit tests --- testutil/common/tester.go | 5 + x/rewards/keeper/helpers_test.go | 76 +++- x/rewards/keeper/iprpc_test.go | 642 +++++++++++++++++++++++++++++ x/rewards/keeper/providers_test.go | 66 +-- 4 files changed, 750 insertions(+), 39 deletions(-) create mode 100644 x/rewards/keeper/iprpc_test.go diff --git a/testutil/common/tester.go b/testutil/common/tester.go index 708f4c1a14..5ffdee65bf 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -615,6 +615,11 @@ func (ts *Tester) TxRewardsSetIprpcDataProposal(authority string, cost sdk.Coin, return ts.Servers.RewardsServer.SetIprpcData(ts.GoCtx, msg) } +func (ts *Tester) TxRewardsFundIprpc(creator string, spec string, duration uint64, fund sdk.Coins) (*rewardstypes.MsgFundIprpcResponse, error) { + msg := rewardstypes.NewMsgFundIprpc(creator, spec, duration, fund) + return ts.Servers.RewardsServer.FundIprpc(ts.GoCtx, msg) +} + // TxCreateValidator: implement 'tx staking createvalidator' and bond its tokens func (ts *Tester) TxCreateValidator(validator sigs.Account, amount math.Int) { consensusPowerTokens := ts.Keepers.StakingKeeper.TokensFromConsensusPower(ts.Ctx, 1) diff --git a/x/rewards/keeper/helpers_test.go b/x/rewards/keeper/helpers_test.go index ddff8d8474..05aaea3234 100644 --- a/x/rewards/keeper/helpers_test.go +++ b/x/rewards/keeper/helpers_test.go @@ -2,16 +2,18 @@ package keeper_test import ( "testing" + "time" "cosmossdk.io/math" 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" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + commontypes "github.com/lavanet/lava/common/types" "github.com/lavanet/lava/testutil/common" testkeeper "github.com/lavanet/lava/testutil/keeper" planstypes "github.com/lavanet/lava/x/plans/types" - rewardsTypes "github.com/lavanet/lava/x/rewards/types" + rewardstypes "github.com/lavanet/lava/x/rewards/types" spectypes "github.com/lavanet/lava/x/spec/types" "github.com/stretchr/testify/require" ) @@ -23,10 +25,20 @@ const ( feeCollectorName = authtypes.FeeCollectorName ) +var ( + ibcDenom string = "uibc" + minIprpcCost sdk.Coin = sdk.NewCoin(commontypes.TokenDenom, sdk.NewInt(100)) + iprpcFunds sdk.Coins = sdk.NewCoins( + sdk.NewCoin(commontypes.TokenDenom, sdk.NewInt(1100)), + sdk.NewCoin(ibcDenom, sdk.NewInt(500)), + ) + mockSpec2 string = "mock2" +) + type tester struct { common.Tester - plan planstypes.Plan - spec spectypes.Spec + plan planstypes.Plan + specs []spectypes.Spec } func newTester(t *testing.T, addValidator bool) *tester { @@ -39,14 +51,14 @@ func newTester(t *testing.T, addValidator bool) *tester { } ts.plan = common.CreateMockPlan() - coins := ts.Keepers.Rewards.TotalPoolTokens(ts.Ctx, rewardsTypes.ProviderRewardsDistributionPool) + coins := ts.Keepers.Rewards.TotalPoolTokens(ts.Ctx, rewardstypes.ProviderRewardsDistributionPool) _, monthlyProvidersPool := coins.Find(ts.BondDenom()) ts.plan.Price.Amount = monthlyProvidersPool.Amount.QuoRaw(5).AddRaw(5) ts.plan.PlanPolicy.EpochCuLimit = monthlyProvidersPool.Amount.Uint64() * 5 ts.plan.PlanPolicy.TotalCuLimit = monthlyProvidersPool.Amount.Uint64() * 5 ts.plan.PlanPolicy.MaxProvidersToPair = 5 ts.AddPlan(ts.plan.Index, ts.plan) - ts.spec = ts.AddSpec("mock", common.CreateMockSpec()).Spec("mock") + ts.specs = []spectypes.Spec{ts.AddSpec("mock", common.CreateMockSpec()).Spec("mock")} return ts } @@ -62,7 +74,7 @@ func (ts *tester) feeCollector() sdk.AccAddress { return testkeeper.GetModuleAddress(feeCollectorName) } -func (ts *tester) getPoolBalance(pool rewardsTypes.Pool, denom string) math.Int { +func (ts *tester) getPoolBalance(pool rewardstypes.Pool, denom string) math.Int { coins := ts.Keepers.Rewards.TotalPoolTokens(ts.Ctx, pool) return coins.AmountOf(denom) } @@ -71,6 +83,58 @@ func (ts *tester) iprpcAuthority() string { return authtypes.NewModuleAddress(govtypes.ModuleName).String() } +// setupForIprpcTests performs the following to set a proper env for iprpc tests: +// 0. it assumes that ts.newTester(t) was already executed +// 1. setting IPRPC data +// 2. fund the iprpc pool (optional, can specify if to fund from the next month) +func (ts *tester) setupForIprpcTests(fundIprpcPool bool) { + // add two consumers and buy subscriptions + consumerAcc, consumer := ts.AddAccount(common.CONSUMER, 0, testBalance*10000) + _, consumer2 := ts.AddAccount(common.CONSUMER, 1, testBalance*10000) + _, err := ts.TxSubscriptionBuy(consumer, consumer, ts.plan.Index, 5, true, false) + require.NoError(ts.T, err) + _, err = ts.TxSubscriptionBuy(consumer2, consumer2, ts.plan.Index, 5, true, false) + require.NoError(ts.T, err) + + // set iprpc data (only consumer is IPRPC eligible) + _, err = ts.TxRewardsSetIprpcDataProposal(ts.iprpcAuthority(), minIprpcCost, []string{consumer}) + require.NoError(ts.T, err) + + // create a new spec + spec2 := common.CreateMockSpec() + spec2.Index = mockSpec2 + spec2.Name = mockSpec2 + ts.specs = append(ts.specs, ts.AddSpec(mockSpec2, spec2).Spec(mockSpec2)) + + // add two providers and stake them both on the two specs + _, provider := ts.AddAccount(common.PROVIDER, 0, testBalance) + _, provider2 := ts.AddAccount(common.PROVIDER, 1, testBalance) + err = ts.StakeProvider(provider, ts.specs[0], testStake) + require.NoError(ts.T, err) + err = ts.StakeProvider(provider, ts.specs[1], testStake) + require.NoError(ts.T, err) + err = ts.StakeProvider(provider2, ts.specs[0], testStake) + require.NoError(ts.T, err) + err = ts.StakeProvider(provider2, ts.specs[1], testStake) + require.NoError(ts.T, err) + + ts.AdvanceEpoch() // apply pairing + + // reset time to the start of the month + startOfMonth := time.Date(ts.Ctx.BlockTime().Year(), ts.Ctx.BlockTime().Month(), 1, 0, 0, 0, 0, ts.Ctx.BlockTime().Location()) + ts.Ctx = ts.Ctx.WithBlockTime(startOfMonth) + ts.GoCtx = sdk.WrapSDKContext(ts.Ctx) + + if fundIprpcPool { + duration := uint64(1) + err = ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(sdk.NewIntFromUint64(duration))) + require.NoError(ts.T, err) + _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, duration, iprpcFunds) + require.NoError(ts.T, err) + ts.AdvanceMonths(1).AdvanceEpoch() // fund only fund for next month, so advance a month + } +} + // deductParticipationFees calculates the validators and community participation // fees and returns the providers reward after deducting them func (ts *tester) DeductParticipationFees(reward math.Int) (updatedReward math.Int, valParticipation math.Int, communityParticipation math.Int) { diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go new file mode 100644 index 0000000000..5d85a1abf6 --- /dev/null +++ b/x/rewards/keeper/iprpc_test.go @@ -0,0 +1,642 @@ +package keeper_test + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/lavanet/lava/testutil/common" + "github.com/lavanet/lava/utils/sigs" + rewardstypes "github.com/lavanet/lava/x/rewards/types" + "github.com/stretchr/testify/require" +) + +// TestFundIprpcTX tests the FundIprpc TX functionality in funding the IPRPC pool +// Scenarios: +// 1. fund IPRPC with different periods (1m,3m,12m) and different denominations (also combinations) +// -> pool balance and iprpc reward should be as expected +func TestFundIprpcTX(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) + + consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds) + require.NoError(ts.T, err) + + type fundIprpcData struct { + spec string + duration uint64 + fund sdk.Coins + } + + // we fund as follows (to all we add the min IPRPC price. the description below is the funds that go to the pool): + // - 10ulava, 1 month, mockspec + // - 50uibc, 1 month, mockspec + // - 90ulava + 30uibc, 3 months, mockspec2 + // - 130uibc, 3 months, mockspec + // - 10ulava + 120uibc, 12 months, mockspec2 + fundIprpcTXsData := []fundIprpcData{ + {spec: ts.specs[0].Index, duration: 1, fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(10+minIprpcCost.Amount.Int64())), + )}, + {spec: ts.specs[0].Index, duration: 1, fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(minIprpcCost.Amount.Int64())), + sdk.NewCoin(ibcDenom, math.NewInt(50)), + )}, + {spec: ts.specs[1].Index, duration: 3, fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(90+minIprpcCost.Amount.Int64()*3)), + sdk.NewCoin(ibcDenom, math.NewInt(30)), + )}, + {spec: ts.specs[0].Index, duration: 3, fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(minIprpcCost.Amount.Int64()*3)), + sdk.NewCoin(ibcDenom, math.NewInt(130)), + )}, + {spec: ts.specs[1].Index, duration: 12, fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(10+minIprpcCost.Amount.Int64()*12)), + sdk.NewCoin(ibcDenom, math.NewInt(120)), + )}, + } + + for _, txData := range fundIprpcTXsData { + _, err = ts.TxRewardsFundIprpc(consumer, txData.spec, txData.duration, txData.fund) + require.NoError(t, err) + } + + // Expected total IPRPC pool balance: 110ulava (=10+90+10) and 330uibc + iprpcTotalBalance := ts.Keepers.Rewards.TotalPoolTokens(ts.Ctx, rewardstypes.IprpcPoolName) + expectedIprpcTotalBalance := sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(110)), + sdk.NewCoin(ibcDenom, math.NewInt(330)), + ) + require.True(t, expectedIprpcTotalBalance.IsEqual(iprpcTotalBalance)) + + // Expected IPRPC rewards (by months, first month is skipped): + // 1. mockspec: 10ulava + 180uibc(=50+130), mockspec2: 100ulava(=10+90) + 150uibc(=30+120) + // 2. mockspec: 130uibc, mockspec2: 100ulava(=10+90) + 150uibc(=30+120) + // 3. mockspec: 130uibc, mockspec2: 100ulava(=10+90) + 150uibc(=30+120) + // 4-12. mockspec: nothing, mockspec2: 10ulava + 120uibc + iprpcRewards := ts.Keepers.Rewards.GetAllIprpcReward(ts.Ctx) + require.Len(t, iprpcRewards, 12) + for i := range iprpcRewards { + var expectedSpecFunds []rewardstypes.Specfund + switch i { + case 0: + // first month + expectedSpecFunds = []rewardstypes.Specfund{ + { + Spec: ts.specs[0].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(10)), + sdk.NewCoin(ibcDenom, math.NewInt(180)), + ), + }, + { + Spec: ts.specs[1].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(100)), + sdk.NewCoin(ibcDenom, math.NewInt(150)), + ), + }, + } + case 1: + // second month + expectedSpecFunds = []rewardstypes.Specfund{ + { + Spec: ts.specs[0].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ibcDenom, math.NewInt(130)), + ), + }, + { + Spec: ts.specs[1].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(100)), + sdk.NewCoin(ibcDenom, math.NewInt(150)), + ), + }, + } + case 2: + // 3rd month + expectedSpecFunds = []rewardstypes.Specfund{ + { + Spec: ts.specs[0].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ibcDenom, math.NewInt(130)), + ), + }, + { + Spec: ts.specs[1].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(100)), + sdk.NewCoin(ibcDenom, math.NewInt(150)), + ), + }, + } + default: + // rest of months (until 12) + expectedSpecFunds = []rewardstypes.Specfund{ + { + Spec: ts.specs[1].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), math.NewInt(10)), + sdk.NewCoin(ibcDenom, math.NewInt(120)), + ), + }, + } + } + require.Equal(t, i+1, int(iprpcRewards[i].Id)) + require.ElementsMatch(t, expectedSpecFunds, iprpcRewards[i].SpecFunds) + } +} + +// TestIprpcProviderRewardQuery tests the IprpcProviderReward query functionality +// Scenarios: +// 1. two providers provide different CU for two consumers, which only one is IPRPC eligible -> query should return expected reward +// 2. advance a month, fund the pool and check the query's output again (without sending relays -> provider rewards should be empty) +func TestIprpcProviderRewardQuery(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(true) // setup funds IPRPC for mock2 spec + + // get consumers and providers (note, only c1 is IPRPC eligible) + c1Acc, _ := ts.GetAccount(common.CONSUMER, 0) + c2Acc, _ := ts.GetAccount(common.CONSUMER, 1) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + _, p2 := ts.GetAccount(common.PROVIDER, 1) + + // send relays from both consumers to both providers + type relayInfo struct { + consumer sigs.Account + provider string + cu uint64 + } + relaysInfo := []relayInfo{ + {consumer: c1Acc, provider: p1, cu: 100}, + {consumer: c2Acc, provider: p1, cu: 150}, + {consumer: c1Acc, provider: p2, cu: 400}, + {consumer: c2Acc, provider: p2, cu: 450}, + } + for _, info := range relaysInfo { + msg := ts.SendRelay(info.provider, info.consumer, []string{ts.specs[1].Index}, info.cu) + _, err := ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &msg) + require.NoError(t, err) + } + + // check the IprpcProviderReward query + // p1 should get 1/5 of the reward and p2 4/5 of the reward (p1 relative serviced CU is 100/500) + // note: setupForIprpcTests() funds the IPRPC pool with 1000ulava and 500uibc + type providerRewards struct { + provider string + fund sdk.Coins + } + expectedProviderRewards := []providerRewards{ + {provider: p1, fund: iprpcFunds.Sub(minIprpcCost).QuoInt(sdk.NewInt(5))}, + {provider: p2, fund: iprpcFunds.Sub(minIprpcCost).MulInt(sdk.NewInt(4)).QuoInt(sdk.NewInt(5))}, + } + for _, expectedProviderReward := range expectedProviderRewards { + res, err := ts.QueryRewardsIprpcProviderReward(expectedProviderReward.provider) + require.NoError(t, err) + require.ElementsMatch(t, expectedProviderReward.fund, res.SpecFunds[0].Fund) // taking 0 index because there's a single spec + } + + // advance month to distribute monthly rewards + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + + // check that rewards were distributed as expected + for _, expectedProviderReward := range expectedProviderRewards { + res2, err := ts.QueryDualstakingDelegatorRewards(expectedProviderReward.provider, expectedProviderReward.provider, ts.specs[1].Index) + require.NoError(t, err) + require.True(t, res2.Rewards[0].Amount.IsEqual(expectedProviderReward.fund)) // taking 0 index because there are no delegators + } +} + +// TestIprpcSpecRewardQuery tests the IprpcSpecReward query functionality +// Scenarios: +// 0. assume IPRPC pool is funded with two denoms over different periods of vesting with two specs +// 1. query with no args should return all +// 2. query with arg should return the IPRPC rewards for the specific spec +// 3. advance a month, this month reward should transfer to next month -> query should return updated iprpc pool balance +// 4. make a provider provide service, advance a month to get his reward -> query should return updated iprpc pool balance +func TestIprpcSpecRewardQuery(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(true) // setup funds IPRPC for mock2 spec for 1 month and advances a month + + _, consumer := ts.GetAccount(common.CONSUMER, 0) + + // do another funding for mockspec and mock2 for 3 months + // Expected funds: + // first month: mock2 - 500uibc + 3000ulava, mockspec - 100000ulava + // second + third month: mock2 - 2000ulava, mockspec - 100000ulava + duration := int64(3) + minIprpcCostForFund := minIprpcCost.Amount.MulRaw(duration) + _, err := ts.TxRewardsFundIprpc(consumer, ts.specs[0].Index, uint64(duration), + sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000).Add(minIprpcCostForFund)))) + require.NoError(ts.T, err) + + _, err = ts.TxRewardsFundIprpc(consumer, ts.specs[1].Index, uint64(duration), + sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000).Add(minIprpcCostForFund)))) + require.NoError(ts.T, err) + + expectedResults := []rewardstypes.IprpcReward{ + { + Id: 1, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[1].Index, Fund: sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(500)), + sdk.NewCoin(ts.BondDenom(), sdk.NewInt(1000)))}, + }, + }, + { + Id: 2, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + {Spec: ts.specs[1].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000)))}, + }, + }, + { + Id: 3, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + {Spec: ts.specs[1].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000)))}, + }, + }, + { + Id: 4, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + {Spec: ts.specs[1].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000)))}, + }, + }, + } + + // query with no args + res, err := ts.QueryRewardsIprpcSpecReward("") + require.NoError(t, err) + require.ElementsMatch(t, expectedResults, res.IprpcRewards) + + // query with arg = mockspec + mockspecExpectedResults := []rewardstypes.IprpcReward{ + { + Id: 2, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + }, + }, + { + Id: 3, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + }, + }, + { + Id: 4, SpecFunds: []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + }, + }, + } + res, err = ts.QueryRewardsIprpcSpecReward(ts.specs[0].Index) + require.NoError(t, err) + require.ElementsMatch(t, mockspecExpectedResults, res.IprpcRewards) + + // advance a month with no providers getting rewarded this month's reward should transfer to the next month + // 2nd month expected funds: mockspec - 100000ulava, mock2 - 3000ulava(=2000+1000) and 500uibc + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + + afterMonthExpectedResults := expectedResults[1:] + afterMonthExpectedResults[0].SpecFunds = []rewardstypes.Specfund{ + {Spec: ts.specs[0].Index, Fund: sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000)))}, + {Spec: ts.specs[1].Index, Fund: sdk.NewCoins( + sdk.NewCoin(ts.BondDenom(), sdk.NewInt(3000)), + sdk.NewCoin(ibcDenom, sdk.NewInt(500)), + )}, + } + res, err = ts.QueryRewardsIprpcSpecReward("") + require.NoError(t, err) + require.Len(t, res.IprpcRewards, len(afterMonthExpectedResults)) + for i := range res.IprpcRewards { + require.Equal(t, afterMonthExpectedResults[i].Id, res.IprpcRewards[i].Id) + require.ElementsMatch(t, afterMonthExpectedResults[i].SpecFunds, res.IprpcRewards[i].SpecFunds) + } + + // make a provider provide some service to an IPRPC eligible subscription + c1Acc, _ := ts.GetAccount(common.CONSUMER, 0) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + relay := ts.SendRelay(p1, c1Acc, []string{ts.specs[1].Index}, 100) + _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) + require.NoError(t, err) + + // advance month to distribute monthly rewards + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + + // check that the latest iprpc object has been deleted + afterProviderServiceExpectedResults := afterMonthExpectedResults[1:] + res, err = ts.QueryRewardsIprpcSpecReward("") + require.NoError(t, err) + require.ElementsMatch(t, afterProviderServiceExpectedResults, res.IprpcRewards) +} + +// TestIprpcRewardObjectsUpdate tests that the IPRPC reward objects' management works as expected: +// Scenarios: +// 0. fund iprpc pool for 2 months, current should be 0 and first iprpc reward should be with id=1 (fund is always for the next month) +// 1. there is no service to eligible subscriptions, month passes -> current shouldn't increment and there should be no IPRPC object +// 2. provider provides service for eligible subscription, month passes -> current should increment by 1 and a new IPRPC reward should be created with id=current +func TestIprpcRewardObjectsUpdate(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) + consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) + + // fund iprpc pool + duration := uint64(2) + iprpcCost := sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) + fundForIprpc := iprpcFunds + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, fundForIprpc) + require.NoError(ts.T, err) + _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, duration, iprpcFunds) + require.NoError(ts.T, err) + + // check there are 2 iprpc reward object, and the first one is with id=1 + currentIprpcRewardId := ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + require.Equal(t, uint64(0), currentIprpcRewardId) + res, err := ts.QueryRewardsIprpcSpecReward(mockSpec2) + require.NoError(t, err) + require.Len(t, res.IprpcRewards, 2) + require.Equal(t, uint64(0), res.CurrentMonthId) + for i := range res.IprpcRewards { + require.Equal(t, uint64(i+1), res.IprpcRewards[i].Id) + require.True(t, fundForIprpc.Sub(iprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) + } + + // advance month to reach the first iprpc reward (first object is with id=1) + // there should still be the exact two objects as before + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + require.Equal(t, uint64(1), currentIprpcRewardId) + res, err = ts.QueryRewardsIprpcSpecReward(mockSpec2) + require.NoError(t, err) + require.Len(t, res.IprpcRewards, 2) + require.Equal(t, uint64(1), res.CurrentMonthId) + for i := range res.IprpcRewards { + require.Equal(t, uint64(i+1), res.IprpcRewards[i].Id) + require.True(t, fundForIprpc.Sub(iprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) + } + + // advance month without any provider service, there should be one IPRPC object with combined reward + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + require.Equal(t, uint64(2), currentIprpcRewardId) + res, err = ts.QueryRewardsIprpcSpecReward(mockSpec2) + require.NoError(t, err) + require.Len(t, res.IprpcRewards, 1) + require.Equal(t, uint64(2), res.CurrentMonthId) + require.True(t, fundForIprpc.Sub(iprpcCost).MulInt(sdk.NewInt(2)).IsEqual(res.IprpcRewards[0].SpecFunds[0].Fund)) + + // make a provider service an IPRPC eligible consumer and advance a month + // there should be no iprpc rewards objects + c1Acc, _ := ts.GetAccount(common.CONSUMER, 0) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + relay := ts.SendRelay(p1, c1Acc, []string{ts.specs[1].Index}, 100) + _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) + require.NoError(t, err) + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + res, err = ts.QueryRewardsIprpcSpecReward(mockSpec2) + require.NoError(t, err) + require.Len(t, res.IprpcRewards, 0) + require.Equal(t, uint64(3), res.CurrentMonthId) +} + +// TestIprpcMinCost tests that a fund TX fails if it doesn't have enough tokens to cover for the minimum IPRPC costs +// Scenarios: +// 1. fund TX with the minimum cost available -> TX success +// 2. assume min cost = 100ulava, fund TX with 50ulava and 200ibc -> TX fails (ibc "has enough funds") +// 3. fund TX without the minimum cost available -> TX fails +// 4. fund TX with the minimum cost but creator doesn't have enough balance for the funding -> TX fails +func TestIprpcMinCost(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) + consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdk.NewInt(500)))) + + _, poorConsumer := ts.AddAccount(common.CONSUMER, 1, minIprpcCost.Amount.Int64()-10) + + testCases := []struct { + name string + creator string + fund sdk.Coins + success bool + }{ + { + name: "Happy flow - creator with enough funds and above min iprpc cost", + creator: consumer, + fund: sdk.NewCoins(minIprpcCost.AddAmount(sdk.NewInt(10))), + success: true, + }, + { + name: "fund without min iprpc cost", + creator: consumer, + fund: sdk.NewCoins(minIprpcCost.SubAmount(sdk.NewInt(10))), + success: false, + }, + { + name: "fund with other denom above min iprpc cost", + creator: consumer, + fund: sdk.NewCoins(sdk.NewCoin(ibcDenom, minIprpcCost.Amount.AddRaw(10))), + success: false, + }, + { + name: "insufficient balance for fund", + creator: poorConsumer, + fund: sdk.NewCoins(minIprpcCost.AddAmount(sdk.NewInt(10))), + success: false, + }, + } + + for _, tt := range testCases { + t.Run(tt.name, func(t *testing.T) { + _, err = ts.TxRewardsFundIprpc(tt.creator, mockSpec2, 1, tt.fund) + if tt.success { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } +} + +// TestIprpcEligibleSubscriptions tests that IPRPC CU is counted only if serviced an eligible subscription +// Scenarios: +// 0. assume two providers: p1, p2 and two consumers: c1, c2. Only c1 is IPRPC eligible +// 1. p1 provides service for both consumers, p2 provides service for c1 -> IPRPC reward should divide equally between p1 and p2 +// 2. both providers provide service for c2 -> No IPRPC rewards should be given +func TestIprpcEligibleSubscriptions(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(true) // setup creates consumers and providers and funds IPRPC pool for mock2 spec + + c1Acc, c1 := ts.GetAccount(common.CONSUMER, 0) + c2Acc, _ := ts.GetAccount(common.CONSUMER, 1) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + _, p2 := ts.GetAccount(common.PROVIDER, 1) + + // p1 provides service for both consumers, p2 provides service for c1 + msg := ts.SendRelay(p1, c1Acc, []string{mockSpec2}, 100) + _, err := ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + msg = ts.SendRelay(p1, c2Acc, []string{mockSpec2}, 100) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + msg = ts.SendRelay(p2, c1Acc, []string{mockSpec2}, 100) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + // check expected reward for each provider, it should be equal (the service for c1 was equal) + res1, err := ts.QueryRewardsIprpcProviderReward(p1) + require.NoError(t, err) + res2, err := ts.QueryRewardsIprpcProviderReward(p2) + require.NoError(t, err) + require.True(t, res1.SpecFunds[0].Fund.IsEqual(res2.SpecFunds[0].Fund)) + require.True(t, iprpcFunds.Sub(minIprpcCost).QuoInt(sdk.NewInt(2)).IsEqual(res1.SpecFunds[0].Fund)) + + // fund the pool again (advance month to apply) + _, err = ts.TxRewardsFundIprpc(c1, mockSpec2, 1, sdk.NewCoins(minIprpcCost.AddAmount(sdk.NewInt(10)))) + require.NoError(ts.T, err) + ts.AdvanceMonths(1).AdvanceEpoch() + + // provide service only for c2 + msg = ts.SendRelay(p1, c2Acc, []string{mockSpec2}, 100) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + msg = ts.SendRelay(p2, c2Acc, []string{mockSpec2}, 100) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + // check none of the providers should get rewards + res1, err = ts.QueryRewardsIprpcProviderReward(p1) + require.NoError(t, err) + res2, err = ts.QueryRewardsIprpcProviderReward(p2) + require.NoError(t, err) + require.Len(t, res1.SpecFunds, 0) + require.Len(t, res2.SpecFunds, 0) +} + +// TestMultipleIprpcSpec checks that rewards are distributed correctly when multiple specs are configured in the IPRPC pool +// Scenarios: +// 0. IPRPC pool is funded for two specs for different periods and different denom (some are the same) +// 1. two providers provide service for consumer on 3 specs, two of them are the IPRPC ones -> they get rewarded relative to their serviced CU on each spec +func TestMultipleIprpcSpec(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) // creates consumers and providers staked on two stakes + + c1Acc, c1 := ts.GetAccount(common.CONSUMER, 0) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + _, p2 := ts.GetAccount(common.PROVIDER, 1) + + // add another spec and stake the providers + mockSpec3 := "mock3" + spec3 := common.CreateMockSpec() + spec3.Index = mockSpec3 + spec3.Name = mockSpec3 + ts.specs = append(ts.specs, ts.AddSpec(mockSpec3, spec3).Spec(mockSpec3)) + err := ts.StakeProvider(p1, ts.specs[2], testStake) + require.NoError(ts.T, err) + err = ts.StakeProvider(p2, ts.specs[2], testStake) + require.NoError(ts.T, err) + + // fund iprpc pool for mock2 spec for 1 months + duration := uint64(1) + iprpcCost := sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) + mock2Fund := sdk.NewCoin(ts.BondDenom(), sdk.NewInt(1700)) + _, err = ts.TxRewardsFundIprpc(c1, mockSpec2, duration, sdk.NewCoins(mock2Fund.Add(iprpcCost))) + require.NoError(t, err) + + // fund iprpc pool for mock3 spec for 3 months + duration = uint64(3) + iprpcCost = sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) + mock3Fund := sdk.NewCoin(ts.BondDenom(), sdk.NewInt(400)) + _, err = ts.TxRewardsFundIprpc(c1, mockSpec3, duration, sdk.NewCoins(mock3Fund.Add(iprpcCost))) + require.NoError(t, err) + + // advance month and epoch to apply pairing and iprpc fund + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + + // make both providers service the consumer on 3 specs, only 2 are funded by IPRPC + nonIprpcSpec := ts.specs[0].Index + type relayData struct { + provider string + spec string + cu uint64 + } + relaysData := []relayData{ + {provider: p1, spec: nonIprpcSpec, cu: 100}, + {provider: p1, spec: mockSpec2, cu: 200}, + {provider: p1, spec: mockSpec3, cu: 300}, + {provider: p2, spec: nonIprpcSpec, cu: 700}, + {provider: p2, spec: mockSpec2, cu: 200}, + {provider: p2, spec: mockSpec3, cu: 300}, + } + for _, rd := range relaysData { + msg := ts.SendRelay(rd.provider, c1Acc, []string{rd.spec}, rd.cu) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + } + + // p1 total CU: 600, p2 total CU: 1200 -> if the rewards were divided by total CU (wrong) the rewards ratio should've been 1:2 + // p1 total iprpc CU: 500, p2 total iprpc CU: 500 -> if the rewards were divided by total iprpc CU the rewards should be equal + res1, err := ts.QueryRewardsIprpcProviderReward(p1) + require.NoError(t, err) + res2, err := ts.QueryRewardsIprpcProviderReward(p2) + require.NoError(t, err) + require.Equal(t, len(res1.SpecFunds), len(res2.SpecFunds)) + responses := []*rewardstypes.QueryIprpcProviderRewardResponse{res1, res2} + for _, res := range responses { + for _, sf := range res.SpecFunds { + switch sf.Spec { + case mockSpec2: + expectedReward := sdk.NewCoins(mock2Fund).QuoInt(sdk.NewInt(2)) + require.True(t, expectedReward.IsEqual(sf.Fund)) + case mockSpec3: + expectedReward := sdk.NewCoins(mock3Fund).QuoInt(sdk.NewInt(2)) + require.True(t, expectedReward.IsEqual(sf.Fund)) + } + } + } +} + +// TestIprpcRewardWithZeroSubRewards checks that even if a subscription is free (providers won't get paid for their service) +// if the providers service an IPRPC eligible subscription, they get IPRPC rewards +// Scenarios: +// 0. consumer is IPRPC eligible and community tax = 100% -> provider won't get paid for its service +// 1. two providers provide service -> they get IPRPC reward relative to their serviced CU +func TestIprpcRewardWithZeroSubRewards(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(true) // create a consumer and buys subscription + funds iprpc + + c1Acc, _ := ts.GetAccount(common.CONSUMER, 0) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + _, p2 := ts.GetAccount(common.PROVIDER, 1) + + // make community participation percentage to be 100% to make the provider not get rewarded for its service later + distParams := distributiontypes.DefaultParams() + distParams.CommunityTax = sdk.OneDec() + err := ts.Keepers.Distribution.SetParams(ts.Ctx, distParams) + require.NoError(t, err) + + // make providers service the IPRPC eligible consumer + msg := ts.SendRelay(p1, c1Acc, []string{mockSpec2}, 100) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + msg = ts.SendRelay(p2, c1Acc, []string{mockSpec2}, 400) + _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) + require.NoError(t, err) + + // advance month to trigger monthly iprpc reward + blocksToSave to trigger sub rewards + ts.AdvanceMonths(1) + ts.AdvanceEpoch() + ts.AdvanceBlocks(ts.BlocksToSave() + 1) + + // check provider rewards (should be only expected IPRPC rewards) + p1ExpectedReward := iprpcFunds.Sub(minIprpcCost).QuoInt(sdk.NewInt(5)) + res1, err := ts.QueryDualstakingDelegatorRewards(p1, p1, mockSpec2) + require.NoError(t, err) + require.True(t, p1ExpectedReward.IsEqual(res1.Rewards[0].Amount)) + + p2ExpectedReward := p1ExpectedReward.MulInt(sdk.NewInt(4)) + res2, err := ts.QueryDualstakingDelegatorRewards(p2, p2, mockSpec2) + require.NoError(t, err) + require.True(t, p2ExpectedReward.IsEqual(res2.Rewards[0].Amount)) +} diff --git a/x/rewards/keeper/providers_test.go b/x/rewards/keeper/providers_test.go index c2ed44c47d..abbeba4e41 100644 --- a/x/rewards/keeper/providers_test.go +++ b/x/rewards/keeper/providers_test.go @@ -18,7 +18,7 @@ func TestZeroProvidersRewards(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -51,7 +51,7 @@ func TestBasicBoostProvidersRewards(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -62,7 +62,7 @@ func TestBasicBoostProvidersRewards(t *testing.T) { baserewards := uint64(100) // the rewards by the subscription will be limited by LIMIT_TOKEN_PER_CU - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, baserewards) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, baserewards) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -96,7 +96,7 @@ func TestSpecAllocationProvidersRewards(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -105,7 +105,7 @@ func TestSpecAllocationProvidersRewards(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -140,7 +140,7 @@ func TestProvidersDiminishingRewards(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -150,7 +150,7 @@ func TestProvidersDiminishingRewards(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) } @@ -189,7 +189,7 @@ func TestProvidersEndRewards(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -199,7 +199,7 @@ func TestProvidersEndRewards(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) } @@ -233,14 +233,14 @@ func TestProvidersEndRewards(t *testing.T) { // this means that no matter how much rewards the providers in this spec will get, they will get 0 bonus rewards func Test2SpecsZeroShares(t *testing.T) { ts := newTester(t, true) - spec2 := ts.spec + spec2 := ts.specs[0] spec2.Index = "mock2" spec2.Name = spec2.Index spec2.Shares = 0 ts.AddSpec(spec2.Index, spec2) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, 2*testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) err = ts.StakeProvider(providerAcc.Addr.String(), spec2, testBalance) @@ -252,7 +252,7 @@ func Test2SpecsZeroShares(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -287,7 +287,7 @@ func Test2SpecsZeroShares(t *testing.T) { require.NoError(t, err) require.Len(t, res.Rewards, 1) require.Equal(t, distBalance.QuoRaw(int64(ts.Keepers.Rewards.MaxRewardBoost(ts.Ctx))), res.Rewards[0].Amount.AmountOf(ts.BondDenom())) - require.Equal(t, res.Rewards[0].ChainId, ts.spec.Index) + require.Equal(t, res.Rewards[0].ChainId, ts.specs[0].Index) _, err = ts.TxDualstakingClaimRewards(providerAcc.Addr.String(), providerAcc.Addr.String()) require.NoError(t, err) } @@ -297,14 +297,14 @@ func Test2SpecsZeroShares(t *testing.T) { // the bonus for the provider with double the shares should be double than the other provider func Test2SpecsDoubleShares(t *testing.T) { ts := newTester(t, true) - spec2 := ts.spec + spec2 := ts.specs[0] spec2.Index = "mock2" spec2.Name = spec2.Index spec2.Shares *= 2 ts.AddSpec(spec2.Index, spec2) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, 2*testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) err = ts.StakeProvider(providerAcc.Addr.String(), spec2, testBalance) @@ -316,7 +316,7 @@ func Test2SpecsDoubleShares(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -360,15 +360,15 @@ func TestBonusRewards3Providers(t *testing.T) { ts := newTester(t, true) providerAcc1, _ := ts.AddAccount(common.PROVIDER, 1, 2*testBalance) - err := ts.StakeProvider(providerAcc1.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc1.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) providerAcc2, _ := ts.AddAccount(common.PROVIDER, 2, 2*testBalance) - err = ts.StakeProvider(providerAcc2.Addr.String(), ts.spec, 2*testBalance) + err = ts.StakeProvider(providerAcc2.Addr.String(), ts.specs[0], 2*testBalance) require.NoError(t, err) providerAcc3, _ := ts.AddAccount(common.PROVIDER, 3, 3*testBalance) - err = ts.StakeProvider(providerAcc3.Addr.String(), ts.spec, 3*testBalance) + err = ts.StakeProvider(providerAcc3.Addr.String(), ts.specs[0], 3*testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -377,15 +377,15 @@ func TestBonusRewards3Providers(t *testing.T) { _, err = ts.TxSubscriptionBuy(consumerAcc.Addr.String(), consumerAcc.Addr.String(), ts.plan.Index, 1, false, false) require.NoError(t, err) - msg := ts.SendRelay(providerAcc1.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()/2) + msg := ts.SendRelay(providerAcc1.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()/2) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) - msg = ts.SendRelay(providerAcc2.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()) + msg = ts.SendRelay(providerAcc2.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) - msg = ts.SendRelay(providerAcc3.Addr.String(), consumerAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()*2) + msg = ts.SendRelay(providerAcc3.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()*2) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -464,7 +464,7 @@ func TestValidatorsAndCommunityParticipation(t *testing.T) { // create provider+comsumer, send relay and send relay payment TX providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err = ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err = ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -475,7 +475,7 @@ func TestValidatorsAndCommunityParticipation(t *testing.T) { baserewards := uint64(100) // the rewards by the subscription will be limited by LIMIT_TOKEN_PER_CU - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, baserewards) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, baserewards) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -509,7 +509,7 @@ func TestValidatorsAndCommunityParticipation(t *testing.T) { func TestBonusReward49months(t *testing.T) { ts := newTester(t, true) providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -525,7 +525,7 @@ func TestBonusReward49months(t *testing.T) { baserewards := uint64(100) // the rewards by the subscription will be limited by LIMIT_TOKEN_PER_CU - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, baserewards) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, baserewards) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) @@ -559,7 +559,7 @@ func TestBonusRewardsEquall5Providers(t *testing.T) { for i := 0; i < count; i++ { providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) providerAccs = append(providerAccs, providerAcc) require.NoError(t, err) @@ -574,7 +574,7 @@ func TestBonusRewardsEquall5Providers(t *testing.T) { for _, providerAcc := range providerAccs { for _, consAcc := range consAccs { - msg := ts.SendRelay(providerAcc.Addr.String(), consAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()/uint64(count)/1000) + msg := ts.SendRelay(providerAcc.Addr.String(), consAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()/uint64(count)/1000) _, err := ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) } @@ -622,7 +622,7 @@ func TestBonusRewards5Providers(t *testing.T) { for i := 0; i < count; i++ { providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err := ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err := ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) providerAccs = append(providerAccs, providerAcc) require.NoError(t, err) @@ -635,13 +635,13 @@ func TestBonusRewards5Providers(t *testing.T) { for i := 1; i < 10; i++ { ts.AdvanceEpoch() - msg := ts.SendRelay(providerAccs[0].Addr.String(), consAccs[0], []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()/100) + msg := ts.SendRelay(providerAccs[0].Addr.String(), consAccs[0], []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()/100) _, err := ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) for _, providerAcc := range providerAccs[1:] { for _, consAcc := range consAccs[1:] { - msg := ts.SendRelay(providerAcc.Addr.String(), consAcc, []string{ts.spec.Index}, ts.plan.Price.Amount.Uint64()/uint64(count)/100) + msg := ts.SendRelay(providerAcc.Addr.String(), consAcc, []string{ts.specs[0].Index}, ts.plan.Price.Amount.Uint64()/uint64(count)/100) _, err := ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) } @@ -708,7 +708,7 @@ func TestCommunityTaxOne(t *testing.T) { // create provider+comsumer, send relay and send relay payment TX providerAcc, _ := ts.AddAccount(common.PROVIDER, 1, testBalance) - err = ts.StakeProvider(providerAcc.Addr.String(), ts.spec, testBalance) + err = ts.StakeProvider(providerAcc.Addr.String(), ts.specs[0], testBalance) require.NoError(t, err) ts.AdvanceEpoch() @@ -719,7 +719,7 @@ func TestCommunityTaxOne(t *testing.T) { baserewards := uint64(100) // the rewards by the subscription will be limited by LIMIT_TOKEN_PER_CU - msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.spec.Index}, baserewards) + msg := ts.SendRelay(providerAcc.Addr.String(), consumerAcc, []string{ts.specs[0].Index}, baserewards) _, err = ts.TxPairingRelayPayment(msg.Creator, msg.Relays...) require.NoError(t, err) From 481457792caa2bf6d4ee574d247b63344ff29307 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 21 Feb 2024 18:34:47 +0200 Subject: [PATCH 12/23] CNS-872: fix mock bank keeper --- testutil/keeper/mock_keepers.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/testutil/keeper/mock_keepers.go b/testutil/keeper/mock_keepers.go index ab465c0e22..d8512793d1 100644 --- a/testutil/keeper/mock_keepers.go +++ b/testutil/keeper/mock_keepers.go @@ -94,7 +94,14 @@ func (k mockBankKeeper) UndelegateCoinsFromModuleToAccount(ctx sdk.Context, send func (k mockBankKeeper) SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error { moduleAcc := GetModuleAddress(senderModule) - return k.SendCoinsFromAccountToModule(ctx, moduleAcc, recipientAddr.String(), amt) + accountCoins := k.GetAllBalances(ctx, moduleAcc) + if !accountCoins.IsAllGTE(amt) { + return fmt.Errorf("not enough coins") + } + + k.SubFromBalance(moduleAcc, amt) + k.AddToBalance(recipientAddr, amt) + return nil } func (k mockBankKeeper) SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error { From 374d197d5a0720e773a828b0c6a03f7dca7d4ef8 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Mon, 26 Feb 2024 14:11:44 +0200 Subject: [PATCH 13/23] CNS-871: change query name --- proto/lavanet/lava/rewards/query.proto | 12 +- testutil/common/tester.go | 6 +- x/rewards/client/cli/query.go | 2 +- ...query_iprpc_provider_reward_estimation.go} | 10 +- .../grpc_query_iprpc_provider_reward.go | 4 +- x/rewards/types/query.pb.go | 256 +++++++++--------- x/rewards/types/query.pb.gw.go | 28 +- 7 files changed, 163 insertions(+), 155 deletions(-) rename x/rewards/client/cli/{query_iprpc_provider_reward.go => query_iprpc_provider_reward_estimation.go} (65%) diff --git a/proto/lavanet/lava/rewards/query.proto b/proto/lavanet/lava/rewards/query.proto index d4c6d9e89f..6173e0c7d5 100644 --- a/proto/lavanet/lava/rewards/query.proto +++ b/proto/lavanet/lava/rewards/query.proto @@ -33,8 +33,8 @@ service Query { option (google.api.http).get = "/lavanet/lava/rewards/show_iprpc_data"; } - // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) - rpc IprpcProviderReward(QueryIprpcProviderRewardRequest) returns (QueryIprpcProviderRewardResponse) { + // IprpcProviderRewardEstimation queries for a provider's current IPRPC reward (relative to its serviced CU) + rpc IprpcProviderRewardEstimation(QueryIprpcProviderRewardEstimationRequest) returns (QueryIprpcProviderRewardEstimationResponse) { option (google.api.http).get = "/lavanet/lava/rewards/iprpc_provider_reward/{provider}"; } @@ -91,13 +91,13 @@ message QueryShowIprpcDataResponse { repeated string iprpc_subscriptions = 2; } -// QueryIprpcProviderRewardRequest is request type for the Query/IprpcProviderReward RPC method. -message QueryIprpcProviderRewardRequest { +// QueryIprpcProviderRewardEstimationRequest is request type for the Query/IprpcProviderRewardEstimation RPC method. +message QueryIprpcProviderRewardEstimationRequest { string provider = 1; } -// QueryIprpcProviderRewardResponse is response type for the Query/IprpcProviderReward RPC method. -message QueryIprpcProviderRewardResponse { +// QueryIprpcProviderRewardEstimationResponse is response type for the Query/IprpcProviderRewardEstimation RPC method. +message QueryIprpcProviderRewardEstimationResponse { repeated Specfund spec_funds = 1 [(gogoproto.nullable) = false]; } diff --git a/testutil/common/tester.go b/testutil/common/tester.go index 8b0f5807a3..4cae38c747 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -864,11 +864,11 @@ func (ts *Tester) QueryRewardsShowIprpcData() (*rewardstypes.QueryShowIprpcDataR return ts.Keepers.Rewards.ShowIprpcData(ts.GoCtx, msg) } -func (ts *Tester) QueryRewardsIprpcProviderReward(provider string) (*rewardstypes.QueryIprpcProviderRewardResponse, error) { - msg := &rewardstypes.QueryIprpcProviderRewardRequest{ +func (ts *Tester) QueryRewardsIprpcProviderRewardEstimation(provider string) (*rewardstypes.QueryIprpcProviderRewardEstimationResponse, error) { + msg := &rewardstypes.QueryIprpcProviderRewardEstimationRequest{ Provider: provider, } - return ts.Keepers.Rewards.IprpcProviderReward(ts.GoCtx, msg) + return ts.Keepers.Rewards.IprpcProviderRewardEstimation(ts.GoCtx, msg) } func (ts *Tester) QueryRewardsIprpcSpecReward(spec string) (*rewardstypes.QueryIprpcSpecRewardResponse, error) { diff --git a/x/rewards/client/cli/query.go b/x/rewards/client/cli/query.go index b68b7c316c..cf8b46c50d 100644 --- a/x/rewards/client/cli/query.go +++ b/x/rewards/client/cli/query.go @@ -28,7 +28,7 @@ func GetQueryCmd(queryRoute string) *cobra.Command { cmd.AddCommand(CmdQueryPools()) cmd.AddCommand(CmdQueryBlockReward()) cmd.AddCommand(CmdQueryShowIprpcData()) - cmd.AddCommand(CmdQueryIprpcProviderReward()) + cmd.AddCommand(CmdQueryIprpcProviderRewardEstimation()) cmd.AddCommand(CmdQueryIprpcSpecReward()) // this line is used by starport scaffolding # 1 diff --git a/x/rewards/client/cli/query_iprpc_provider_reward.go b/x/rewards/client/cli/query_iprpc_provider_reward_estimation.go similarity index 65% rename from x/rewards/client/cli/query_iprpc_provider_reward.go rename to x/rewards/client/cli/query_iprpc_provider_reward_estimation.go index 56e83ddaf4..09b7771a49 100644 --- a/x/rewards/client/cli/query_iprpc_provider_reward.go +++ b/x/rewards/client/cli/query_iprpc_provider_reward_estimation.go @@ -11,10 +11,10 @@ import ( var _ = strconv.Itoa(0) -func CmdQueryIprpcProviderReward() *cobra.Command { +func CmdQueryIprpcProviderRewardEstimation() *cobra.Command { cmd := &cobra.Command{ - Use: "iprpc-provider-reward [provider]", - Short: "Query for current IPRPC reward for a specific provider", + Use: "iprpc-provider-reward-estimation [provider]", + Short: "Query for current estimation of IPRPC reward for a specific provider", Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) (err error) { clientCtx, err := client.GetClientQueryContext(cmd) @@ -24,11 +24,11 @@ func CmdQueryIprpcProviderReward() *cobra.Command { queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryIprpcProviderRewardRequest{ + params := &types.QueryIprpcProviderRewardEstimationRequest{ Provider: args[0], } - res, err := queryClient.IprpcProviderReward(cmd.Context(), params) + res, err := queryClient.IprpcProviderRewardEstimation(cmd.Context(), params) if err != nil { return err } diff --git a/x/rewards/keeper/grpc_query_iprpc_provider_reward.go b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go index 03e3aa8d6c..633638d937 100644 --- a/x/rewards/keeper/grpc_query_iprpc_provider_reward.go +++ b/x/rewards/keeper/grpc_query_iprpc_provider_reward.go @@ -10,7 +10,7 @@ import ( "google.golang.org/grpc/status" ) -func (k Keeper) IprpcProviderReward(goCtx context.Context, req *types.QueryIprpcProviderRewardRequest) (*types.QueryIprpcProviderRewardResponse, error) { +func (k Keeper) IprpcProviderRewardEstimation(goCtx context.Context, req *types.QueryIprpcProviderRewardEstimationRequest) (*types.QueryIprpcProviderRewardEstimationResponse, error) { if req == nil { return nil, status.Error(codes.InvalidArgument, "invalid request") } @@ -53,5 +53,5 @@ func (k Keeper) IprpcProviderReward(goCtx context.Context, req *types.QueryIprpc providerSpecFunds = append(providerSpecFunds, types.Specfund{Spec: specFund.Spec, Fund: providerFund}) } - return &types.QueryIprpcProviderRewardResponse{SpecFunds: providerSpecFunds}, nil + return &types.QueryIprpcProviderRewardEstimationResponse{SpecFunds: providerSpecFunds}, nil } diff --git a/x/rewards/types/query.pb.go b/x/rewards/types/query.pb.go index d404dd214a..25737a1aca 100644 --- a/x/rewards/types/query.pb.go +++ b/x/rewards/types/query.pb.go @@ -446,23 +446,27 @@ func (m *QueryShowIprpcDataResponse) GetIprpcSubscriptions() []string { return nil } -// QueryIprpcProviderRewardRequest is request type for the Query/IprpcProviderReward RPC method. -type QueryIprpcProviderRewardRequest struct { +// QueryIprpcProviderRewardEstimationRequest is request type for the Query/IprpcProviderRewardEstimation RPC method. +type QueryIprpcProviderRewardEstimationRequest struct { Provider string `protobuf:"bytes,1,opt,name=provider,proto3" json:"provider,omitempty"` } -func (m *QueryIprpcProviderRewardRequest) Reset() { *m = QueryIprpcProviderRewardRequest{} } -func (m *QueryIprpcProviderRewardRequest) String() string { return proto.CompactTextString(m) } -func (*QueryIprpcProviderRewardRequest) ProtoMessage() {} -func (*QueryIprpcProviderRewardRequest) Descriptor() ([]byte, []int) { +func (m *QueryIprpcProviderRewardEstimationRequest) Reset() { + *m = QueryIprpcProviderRewardEstimationRequest{} +} +func (m *QueryIprpcProviderRewardEstimationRequest) String() string { + return proto.CompactTextString(m) +} +func (*QueryIprpcProviderRewardEstimationRequest) ProtoMessage() {} +func (*QueryIprpcProviderRewardEstimationRequest) Descriptor() ([]byte, []int) { return fileDescriptor_15bce9a904340007, []int{9} } -func (m *QueryIprpcProviderRewardRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryIprpcProviderRewardEstimationRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryIprpcProviderRewardRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryIprpcProviderRewardEstimationRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryIprpcProviderRewardRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryIprpcProviderRewardEstimationRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -472,42 +476,46 @@ func (m *QueryIprpcProviderRewardRequest) XXX_Marshal(b []byte, deterministic bo return b[:n], nil } } -func (m *QueryIprpcProviderRewardRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryIprpcProviderRewardRequest.Merge(m, src) +func (m *QueryIprpcProviderRewardEstimationRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcProviderRewardEstimationRequest.Merge(m, src) } -func (m *QueryIprpcProviderRewardRequest) XXX_Size() int { +func (m *QueryIprpcProviderRewardEstimationRequest) XXX_Size() int { return m.Size() } -func (m *QueryIprpcProviderRewardRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryIprpcProviderRewardRequest.DiscardUnknown(m) +func (m *QueryIprpcProviderRewardEstimationRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcProviderRewardEstimationRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryIprpcProviderRewardRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryIprpcProviderRewardEstimationRequest proto.InternalMessageInfo -func (m *QueryIprpcProviderRewardRequest) GetProvider() string { +func (m *QueryIprpcProviderRewardEstimationRequest) GetProvider() string { if m != nil { return m.Provider } return "" } -// QueryIprpcProviderRewardResponse is response type for the Query/IprpcProviderReward RPC method. -type QueryIprpcProviderRewardResponse struct { +// QueryIprpcProviderRewardEstimationResponse is response type for the Query/IprpcProviderRewardEstimation RPC method. +type QueryIprpcProviderRewardEstimationResponse struct { SpecFunds []Specfund `protobuf:"bytes,1,rep,name=spec_funds,json=specFunds,proto3" json:"spec_funds"` } -func (m *QueryIprpcProviderRewardResponse) Reset() { *m = QueryIprpcProviderRewardResponse{} } -func (m *QueryIprpcProviderRewardResponse) String() string { return proto.CompactTextString(m) } -func (*QueryIprpcProviderRewardResponse) ProtoMessage() {} -func (*QueryIprpcProviderRewardResponse) Descriptor() ([]byte, []int) { +func (m *QueryIprpcProviderRewardEstimationResponse) Reset() { + *m = QueryIprpcProviderRewardEstimationResponse{} +} +func (m *QueryIprpcProviderRewardEstimationResponse) String() string { + return proto.CompactTextString(m) +} +func (*QueryIprpcProviderRewardEstimationResponse) ProtoMessage() {} +func (*QueryIprpcProviderRewardEstimationResponse) Descriptor() ([]byte, []int) { return fileDescriptor_15bce9a904340007, []int{10} } -func (m *QueryIprpcProviderRewardResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryIprpcProviderRewardEstimationResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryIprpcProviderRewardResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryIprpcProviderRewardEstimationResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryIprpcProviderRewardResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryIprpcProviderRewardEstimationResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -517,19 +525,19 @@ func (m *QueryIprpcProviderRewardResponse) XXX_Marshal(b []byte, deterministic b return b[:n], nil } } -func (m *QueryIprpcProviderRewardResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryIprpcProviderRewardResponse.Merge(m, src) +func (m *QueryIprpcProviderRewardEstimationResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryIprpcProviderRewardEstimationResponse.Merge(m, src) } -func (m *QueryIprpcProviderRewardResponse) XXX_Size() int { +func (m *QueryIprpcProviderRewardEstimationResponse) XXX_Size() int { return m.Size() } -func (m *QueryIprpcProviderRewardResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryIprpcProviderRewardResponse.DiscardUnknown(m) +func (m *QueryIprpcProviderRewardEstimationResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryIprpcProviderRewardEstimationResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryIprpcProviderRewardResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryIprpcProviderRewardEstimationResponse proto.InternalMessageInfo -func (m *QueryIprpcProviderRewardResponse) GetSpecFunds() []Specfund { +func (m *QueryIprpcProviderRewardEstimationResponse) GetSpecFunds() []Specfund { if m != nil { return m.SpecFunds } @@ -644,8 +652,8 @@ func init() { proto.RegisterType((*QueryBlockRewardResponse)(nil), "lavanet.lava.rewards.QueryBlockRewardResponse") proto.RegisterType((*QueryShowIprpcDataRequest)(nil), "lavanet.lava.rewards.QueryShowIprpcDataRequest") proto.RegisterType((*QueryShowIprpcDataResponse)(nil), "lavanet.lava.rewards.QueryShowIprpcDataResponse") - proto.RegisterType((*QueryIprpcProviderRewardRequest)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardRequest") - proto.RegisterType((*QueryIprpcProviderRewardResponse)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardResponse") + proto.RegisterType((*QueryIprpcProviderRewardEstimationRequest)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardEstimationRequest") + proto.RegisterType((*QueryIprpcProviderRewardEstimationResponse)(nil), "lavanet.lava.rewards.QueryIprpcProviderRewardEstimationResponse") proto.RegisterType((*QueryIprpcSpecRewardRequest)(nil), "lavanet.lava.rewards.QueryIprpcSpecRewardRequest") proto.RegisterType((*QueryIprpcSpecRewardResponse)(nil), "lavanet.lava.rewards.QueryIprpcSpecRewardResponse") } @@ -653,66 +661,66 @@ func init() { func init() { proto.RegisterFile("lavanet/lava/rewards/query.proto", fileDescriptor_15bce9a904340007) } var fileDescriptor_15bce9a904340007 = []byte{ - // 936 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x56, 0xcf, 0x6f, 0xdc, 0x44, - 0x14, 0x8e, 0x93, 0xcd, 0xaf, 0x97, 0xb6, 0xc0, 0x24, 0x52, 0x37, 0x4e, 0x70, 0xb6, 0x26, 0x28, - 0x4b, 0xa5, 0xd8, 0x49, 0x10, 0x01, 0x81, 0x8a, 0x44, 0x82, 0x90, 0x22, 0x15, 0xa9, 0x75, 0x38, - 0x71, 0xb1, 0x66, 0xbd, 0xb3, 0x1b, 0xab, 0xb6, 0xc7, 0xf5, 0xcc, 0x26, 0x54, 0xa8, 0x42, 0x02, - 0x71, 0xe0, 0x86, 0x84, 0x84, 0xb8, 0x72, 0xe5, 0xc4, 0x1f, 0x81, 0x44, 0x8f, 0x95, 0xb8, 0x70, - 0x02, 0x94, 0xf0, 0x17, 0xf0, 0x17, 0xa0, 0x79, 0x33, 0xde, 0xec, 0x36, 0xde, 0xcd, 0xf6, 0x64, - 0xef, 0xcc, 0xf7, 0xbd, 0xef, 0x7b, 0xe3, 0xf7, 0xde, 0x2c, 0x34, 0x12, 0x7a, 0x4a, 0x33, 0x26, - 0x7d, 0xf5, 0xf4, 0x0b, 0x76, 0x46, 0x8b, 0xb6, 0xf0, 0x1f, 0xf7, 0x58, 0xf1, 0xc4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0x27, 0xe4, 0xa9, 0x84, 0x3c, 0x93, 0x90, 0x77, 0xc8, 0xe3, 0xec, 0x60, - 0x47, 0xe9, 0xfd, 0xf2, 0xf7, 0x46, 0xb3, 0x1b, 0xcb, 0x93, 0x5e, 0xcb, 0x8b, 0x78, 0xea, 0x9b, - 0xec, 0xf5, 0x63, 0x5b, 0xb4, 0x1f, 0xf9, 0xf2, 0x49, 0xce, 0x04, 0x12, 0x44, 0x50, 0xc6, 0x76, - 0xff, 0xb3, 0xca, 0x63, 0xd0, 0xee, 0xfa, 0xf9, 0xce, 0xe6, 0x6a, 0xa1, 0x6e, 0xa1, 0xb6, 0x33, - 0x22, 0x5d, 0x93, 0x80, 0x49, 0x58, 0x53, 0xc8, 0x26, 0xdc, 0x92, 0x71, 0xca, 0x42, 0xc9, 0xc3, - 0x82, 0x75, 0xe2, 0x24, 0xa9, 0x4f, 0x37, 0xac, 0xe6, 0x4c, 0x70, 0x43, 0xad, 0x7e, 0xc6, 0x03, - 0x5c, 0x23, 0x1f, 0x80, 0xcd, 0x84, 0x8c, 0x53, 0x2a, 0x59, 0x3b, 0x6c, 0x25, 0x3c, 0x7a, 0x24, - 0x06, 0x18, 0x33, 0xc8, 0xb8, 0xdd, 0x47, 0x1c, 0x20, 0xa0, 0x4f, 0xbe, 0x07, 0x6b, 0x34, 0x49, - 0x78, 0x84, 0x45, 0x13, 0x2a, 0xd9, 0x30, 0xe5, 0x99, 0x3c, 0x11, 0x61, 0xc2, 0x3a, 0xb2, 0x5e, - 0x43, 0x76, 0xfd, 0x12, 0xa2, 0x8c, 0x7e, 0x8a, 0x80, 0xfb, 0xac, 0x23, 0xdd, 0x55, 0xb8, 0x8d, - 0x39, 0x63, 0xd4, 0x00, 0x93, 0x29, 0xbf, 0xcb, 0x31, 0xd4, 0xaf, 0x6e, 0x99, 0x43, 0x79, 0x17, - 0xe6, 0x74, 0xe6, 0xa6, 0x08, 0xc6, 0x7c, 0x11, 0x53, 0x01, 0x1a, 0xee, 0x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, 0xef, 0xbd, 0x0c, 0xc5, 0x58, - 0xdf, 0x47, 0xeb, 0x3b, 0xc4, 0x1b, 0x67, 0x1d, 0x87, 0x58, 0x69, 0x5b, 0xfd, 0x78, 0x7a, 0xf0, - 0xd1, 0xb3, 0x73, 0xc7, 0x7a, 0x7e, 0xee, 0x58, 0xff, 0x9c, 0x3b, 0xd6, 0xf7, 0x17, 0xce, 0xd4, - 0xf3, 0x0b, 0x67, 0xea, 0xcf, 0x0b, 0x67, 0xea, 0xf3, 0xad, 0x81, 0x8b, 0x79, 0x28, 0xe6, 0x17, - 0xfd, 0xa8, 0x78, 0x3b, 0xb7, 0xe6, 0xf0, 0xbf, 0xc9, 0xdb, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, - 0x0c, 0x25, 0x99, 0x21, 0x9a, 0x09, 0x00, 0x00, + // 944 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x56, 0xcf, 0x6f, 0xdc, 0x44, + 0x14, 0x8e, 0x9b, 0xdf, 0x2f, 0x6d, 0x81, 0x49, 0xa4, 0x6e, 0x9c, 0xd4, 0x4d, 0x4d, 0x50, 0xb6, + 0x91, 0x62, 0x27, 0x41, 0x2a, 0x08, 0xc4, 0xaf, 0x84, 0x1f, 0x8a, 0x54, 0xa4, 0xd6, 0xe1, 0xc4, + 0xc5, 0x9a, 0xf5, 0xce, 0x6e, 0x46, 0xb5, 0x3d, 0x8e, 0x67, 0x36, 0xa1, 0x42, 0x15, 0x12, 0x88, + 0x03, 0x37, 0x24, 0x24, 0xc4, 0x95, 0x2b, 0x27, 0xfe, 0x8c, 0x1e, 0x2b, 0x71, 0xe1, 0x04, 0x28, + 0x81, 0x7f, 0x80, 0xbf, 0x00, 0xcd, 0x9b, 0xf1, 0x66, 0x43, 0x9c, 0xcd, 0xc2, 0xc9, 0xde, 0x99, + 0xef, 0xbd, 0xef, 0xfb, 0x66, 0xde, 0x7b, 0x5e, 0x58, 0x49, 0xe9, 0x11, 0xcd, 0x99, 0x0a, 0xf5, + 0x33, 0x2c, 0xd9, 0x31, 0x2d, 0xdb, 0x32, 0x3c, 0xec, 0xb1, 0xf2, 0x49, 0x50, 0x94, 0x42, 0x09, + 0xb2, 0x60, 0x11, 0x81, 0x7e, 0x06, 0x16, 0xe1, 0x2e, 0x74, 0x45, 0x57, 0x20, 0x20, 0xd4, 0x6f, + 0x06, 0xeb, 0x2e, 0x77, 0x85, 0xe8, 0xa6, 0x2c, 0xa4, 0x05, 0x0f, 0x69, 0x9e, 0x0b, 0x45, 0x15, + 0x17, 0xb9, 0xb4, 0xbb, 0xeb, 0x89, 0x90, 0x99, 0x90, 0x61, 0x8b, 0x4a, 0x66, 0x28, 0xc2, 0xa3, + 0xad, 0x16, 0x53, 0x74, 0x2b, 0x2c, 0x68, 0x97, 0xe7, 0x08, 0xb6, 0xd8, 0xbb, 0xb5, 0xba, 0x0a, + 0x5a, 0xd2, 0xac, 0x4a, 0x57, 0x2f, 0x9d, 0x17, 0x65, 0x91, 0x58, 0x84, 0x37, 0x48, 0x58, 0x51, + 0x25, 0x82, 0x5b, 0x12, 0x7f, 0x01, 0xc8, 0x23, 0x2d, 0xe3, 0x21, 0xa6, 0x8d, 0xd8, 0x61, 0x8f, + 0x49, 0xe5, 0x3f, 0x82, 0xf9, 0x73, 0xab, 0xb2, 0x10, 0xb9, 0x64, 0xe4, 0x0d, 0x98, 0x32, 0xf4, + 0x0d, 0x67, 0xc5, 0x69, 0xce, 0x6d, 0x2f, 0x07, 0x75, 0x07, 0x13, 0x98, 0xa8, 0x9d, 0x89, 0x67, + 0xbf, 0xdd, 0x19, 0x8b, 0x6c, 0x84, 0x3f, 0x0f, 0x2f, 0x99, 0x94, 0x42, 0xa4, 0x7d, 0x9e, 0xaf, + 0x1d, 0x98, 0xd1, 0x0b, 0x7b, 0x79, 0x47, 0x10, 0x02, 0x13, 0x39, 0xcd, 0x18, 0xe6, 0x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 0x1b, 0x3d, 0xbd, 0x4e, 0xee, 0x87, 0x97, 0x7f, 0xdb, 0xe3, 0x6a, 0xc2, 0xd8, 0xd3, 0x0f, 0x3f, + 0xaf, 0x16, 0x9e, 0x92, 0x9f, 0x1d, 0x78, 0xe1, 0x5f, 0x8d, 0x4c, 0xb6, 0xae, 0x52, 0x75, 0x61, + 0x50, 0xb8, 0xdb, 0xff, 0x25, 0xc4, 0x4a, 0xbf, 0x8f, 0xd2, 0x37, 0x49, 0x30, 0x4c, 0x3a, 0x8e, + 0xb8, 0x4a, 0xb6, 0xfe, 0xf1, 0x74, 0xe7, 0xbd, 0x67, 0x27, 0x9e, 0xf3, 0xfc, 0xc4, 0x73, 0xfe, + 0x38, 0xf1, 0x9c, 0x6f, 0x4f, 0xbd, 0xb1, 0xe7, 0xa7, 0xde, 0xd8, 0xaf, 0xa7, 0xde, 0xd8, 0xa7, + 0x6b, 0x03, 0x9f, 0xf2, 0x73, 0x39, 0x3f, 0xeb, 0x67, 0xc5, 0xef, 0x79, 0x6b, 0x0a, 0xff, 0xcd, + 0xbc, 0xfa, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x31, 0x49, 0xcb, 0x61, 0xcc, 0x09, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -735,8 +743,8 @@ type QueryClient interface { BlockReward(ctx context.Context, in *QueryBlockRewardRequest, opts ...grpc.CallOption) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(ctx context.Context, in *QueryShowIprpcDataRequest, opts ...grpc.CallOption) (*QueryShowIprpcDataResponse, error) - // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) - IprpcProviderReward(ctx context.Context, in *QueryIprpcProviderRewardRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardResponse, error) + // IprpcProviderRewardEstimation queries for a provider's current IPRPC reward (relative to its serviced CU) + IprpcProviderRewardEstimation(ctx context.Context, in *QueryIprpcProviderRewardEstimationRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardEstimationResponse, error) // IprpcSpecReward queries for a spec's IPRPC reward IprpcSpecReward(ctx context.Context, in *QueryIprpcSpecRewardRequest, opts ...grpc.CallOption) (*QueryIprpcSpecRewardResponse, error) } @@ -785,9 +793,9 @@ func (c *queryClient) ShowIprpcData(ctx context.Context, in *QueryShowIprpcDataR return out, nil } -func (c *queryClient) IprpcProviderReward(ctx context.Context, in *QueryIprpcProviderRewardRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardResponse, error) { - out := new(QueryIprpcProviderRewardResponse) - err := c.cc.Invoke(ctx, "/lavanet.lava.rewards.Query/IprpcProviderReward", in, out, opts...) +func (c *queryClient) IprpcProviderRewardEstimation(ctx context.Context, in *QueryIprpcProviderRewardEstimationRequest, opts ...grpc.CallOption) (*QueryIprpcProviderRewardEstimationResponse, error) { + out := new(QueryIprpcProviderRewardEstimationResponse) + err := c.cc.Invoke(ctx, "/lavanet.lava.rewards.Query/IprpcProviderRewardEstimation", in, out, opts...) if err != nil { return nil, err } @@ -813,8 +821,8 @@ type QueryServer interface { BlockReward(context.Context, *QueryBlockRewardRequest) (*QueryBlockRewardResponse, error) // ShowIprpcData queries for the iprpc data ShowIprpcData(context.Context, *QueryShowIprpcDataRequest) (*QueryShowIprpcDataResponse, error) - // IprpcProviderReward queries for a provider's current IPRPC reward (relative to its serviced CU) - IprpcProviderReward(context.Context, *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) + // IprpcProviderRewardEstimation queries for a provider's current IPRPC reward (relative to its serviced CU) + IprpcProviderRewardEstimation(context.Context, *QueryIprpcProviderRewardEstimationRequest) (*QueryIprpcProviderRewardEstimationResponse, error) // IprpcSpecReward queries for a spec's IPRPC reward IprpcSpecReward(context.Context, *QueryIprpcSpecRewardRequest) (*QueryIprpcSpecRewardResponse, error) } @@ -835,8 +843,8 @@ func (*UnimplementedQueryServer) BlockReward(ctx context.Context, req *QueryBloc func (*UnimplementedQueryServer) ShowIprpcData(ctx context.Context, req *QueryShowIprpcDataRequest) (*QueryShowIprpcDataResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ShowIprpcData not implemented") } -func (*UnimplementedQueryServer) IprpcProviderReward(ctx context.Context, req *QueryIprpcProviderRewardRequest) (*QueryIprpcProviderRewardResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method IprpcProviderReward not implemented") +func (*UnimplementedQueryServer) IprpcProviderRewardEstimation(ctx context.Context, req *QueryIprpcProviderRewardEstimationRequest) (*QueryIprpcProviderRewardEstimationResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method IprpcProviderRewardEstimation not implemented") } func (*UnimplementedQueryServer) IprpcSpecReward(ctx context.Context, req *QueryIprpcSpecRewardRequest) (*QueryIprpcSpecRewardResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method IprpcSpecReward not implemented") @@ -918,20 +926,20 @@ func _Query_ShowIprpcData_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } -func _Query_IprpcProviderReward_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryIprpcProviderRewardRequest) +func _Query_IprpcProviderRewardEstimation_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryIprpcProviderRewardEstimationRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).IprpcProviderReward(ctx, in) + return srv.(QueryServer).IprpcProviderRewardEstimation(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/lavanet.lava.rewards.Query/IprpcProviderReward", + FullMethod: "/lavanet.lava.rewards.Query/IprpcProviderRewardEstimation", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).IprpcProviderReward(ctx, req.(*QueryIprpcProviderRewardRequest)) + return srv.(QueryServer).IprpcProviderRewardEstimation(ctx, req.(*QueryIprpcProviderRewardEstimationRequest)) } return interceptor(ctx, in, info, handler) } @@ -975,8 +983,8 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Handler: _Query_ShowIprpcData_Handler, }, { - MethodName: "IprpcProviderReward", - Handler: _Query_IprpcProviderReward_Handler, + MethodName: "IprpcProviderRewardEstimation", + Handler: _Query_IprpcProviderRewardEstimation_Handler, }, { MethodName: "IprpcSpecReward", @@ -1283,7 +1291,7 @@ func (m *QueryShowIprpcDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, err return len(dAtA) - i, nil } -func (m *QueryIprpcProviderRewardRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryIprpcProviderRewardEstimationRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1293,12 +1301,12 @@ func (m *QueryIprpcProviderRewardRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryIprpcProviderRewardRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryIprpcProviderRewardEstimationRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryIprpcProviderRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryIprpcProviderRewardEstimationRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1313,7 +1321,7 @@ func (m *QueryIprpcProviderRewardRequest) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } -func (m *QueryIprpcProviderRewardResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryIprpcProviderRewardEstimationResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -1323,12 +1331,12 @@ func (m *QueryIprpcProviderRewardResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryIprpcProviderRewardResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryIprpcProviderRewardEstimationResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryIprpcProviderRewardResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryIprpcProviderRewardEstimationResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -1551,7 +1559,7 @@ func (m *QueryShowIprpcDataResponse) Size() (n int) { return n } -func (m *QueryIprpcProviderRewardRequest) Size() (n int) { +func (m *QueryIprpcProviderRewardEstimationRequest) Size() (n int) { if m == nil { return 0 } @@ -1564,7 +1572,7 @@ func (m *QueryIprpcProviderRewardRequest) Size() (n int) { return n } -func (m *QueryIprpcProviderRewardResponse) Size() (n int) { +func (m *QueryIprpcProviderRewardEstimationResponse) Size() (n int) { if m == nil { return 0 } @@ -2354,7 +2362,7 @@ func (m *QueryShowIprpcDataResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryIprpcProviderRewardRequest) Unmarshal(dAtA []byte) error { +func (m *QueryIprpcProviderRewardEstimationRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2377,10 +2385,10 @@ func (m *QueryIprpcProviderRewardRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryIprpcProviderRewardRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryIprpcProviderRewardEstimationRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryIprpcProviderRewardRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryIprpcProviderRewardEstimationRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: @@ -2436,7 +2444,7 @@ func (m *QueryIprpcProviderRewardRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryIprpcProviderRewardResponse) Unmarshal(dAtA []byte) error { +func (m *QueryIprpcProviderRewardEstimationResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -2459,10 +2467,10 @@ func (m *QueryIprpcProviderRewardResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryIprpcProviderRewardResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryIprpcProviderRewardEstimationResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryIprpcProviderRewardResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryIprpcProviderRewardEstimationResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: diff --git a/x/rewards/types/query.pb.gw.go b/x/rewards/types/query.pb.gw.go index 2054cc9331..f2d9d119e7 100644 --- a/x/rewards/types/query.pb.gw.go +++ b/x/rewards/types/query.pb.gw.go @@ -105,8 +105,8 @@ func local_request_Query_ShowIprpcData_0(ctx context.Context, marshaler runtime. } -func request_Query_IprpcProviderReward_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryIprpcProviderRewardRequest +func request_Query_IprpcProviderRewardEstimation_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcProviderRewardEstimationRequest var metadata runtime.ServerMetadata var ( @@ -127,13 +127,13 @@ func request_Query_IprpcProviderReward_0(ctx context.Context, marshaler runtime. return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "provider", err) } - msg, err := client.IprpcProviderReward(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.IprpcProviderRewardEstimation(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_IprpcProviderReward_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryIprpcProviderRewardRequest +func local_request_Query_IprpcProviderRewardEstimation_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryIprpcProviderRewardEstimationRequest var metadata runtime.ServerMetadata var ( @@ -154,7 +154,7 @@ func local_request_Query_IprpcProviderReward_0(ctx context.Context, marshaler ru return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "provider", err) } - msg, err := server.IprpcProviderReward(ctx, &protoReq) + msg, err := server.IprpcProviderRewardEstimation(ctx, &protoReq) return msg, metadata, err } @@ -311,7 +311,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_IprpcProviderReward_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_IprpcProviderRewardEstimation_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -322,7 +322,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_IprpcProviderReward_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_IprpcProviderRewardEstimation_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 { @@ -330,7 +330,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_IprpcProviderReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_IprpcProviderRewardEstimation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -478,7 +478,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_IprpcProviderReward_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_IprpcProviderRewardEstimation_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) @@ -487,14 +487,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_IprpcProviderReward_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_IprpcProviderRewardEstimation_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_IprpcProviderReward_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_IprpcProviderRewardEstimation_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -530,7 +530,7 @@ var ( pattern_Query_ShowIprpcData_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"lavanet", "lava", "rewards", "show_iprpc_data"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_IprpcProviderReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_provider_reward", "provider"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_IprpcProviderRewardEstimation_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_provider_reward", "provider"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_IprpcSpecReward_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3, 1, 0, 4, 1, 5, 4}, []string{"lavanet", "lava", "rewards", "iprpc_spec_reward", "spec"}, "", runtime.AssumeColonVerbOpt(false))) ) @@ -544,7 +544,7 @@ var ( forward_Query_ShowIprpcData_0 = runtime.ForwardResponseMessage - forward_Query_IprpcProviderReward_0 = runtime.ForwardResponseMessage + forward_Query_IprpcProviderRewardEstimation_0 = runtime.ForwardResponseMessage forward_Query_IprpcSpecReward_0 = runtime.ForwardResponseMessage ) From ce6e04119c4e5af6461872e00b727eaa23a5d43b Mon Sep 17 00:00:00 2001 From: oren-lava Date: Mon, 26 Feb 2024 15:59:44 +0200 Subject: [PATCH 14/23] CNS-872: fix lint --- x/rewards/keeper/iprpc_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 5d85a1abf6..1150b29581 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -187,7 +187,7 @@ func TestIprpcProviderRewardQuery(t *testing.T) { {provider: p2, fund: iprpcFunds.Sub(minIprpcCost).MulInt(sdk.NewInt(4)).QuoInt(sdk.NewInt(5))}, } for _, expectedProviderReward := range expectedProviderRewards { - res, err := ts.QueryRewardsIprpcProviderReward(expectedProviderReward.provider) + res, err := ts.QueryRewardsIprpcProviderRewardEstimation(expectedProviderReward.provider) require.NoError(t, err) require.ElementsMatch(t, expectedProviderReward.fund, res.SpecFunds[0].Fund) // taking 0 index because there's a single spec } @@ -482,9 +482,9 @@ func TestIprpcEligibleSubscriptions(t *testing.T) { require.NoError(t, err) // check expected reward for each provider, it should be equal (the service for c1 was equal) - res1, err := ts.QueryRewardsIprpcProviderReward(p1) + res1, err := ts.QueryRewardsIprpcProviderRewardEstimation(p1) require.NoError(t, err) - res2, err := ts.QueryRewardsIprpcProviderReward(p2) + res2, err := ts.QueryRewardsIprpcProviderRewardEstimation(p2) require.NoError(t, err) require.True(t, res1.SpecFunds[0].Fund.IsEqual(res2.SpecFunds[0].Fund)) require.True(t, iprpcFunds.Sub(minIprpcCost).QuoInt(sdk.NewInt(2)).IsEqual(res1.SpecFunds[0].Fund)) @@ -504,9 +504,9 @@ func TestIprpcEligibleSubscriptions(t *testing.T) { require.NoError(t, err) // check none of the providers should get rewards - res1, err = ts.QueryRewardsIprpcProviderReward(p1) + res1, err = ts.QueryRewardsIprpcProviderRewardEstimation(p1) require.NoError(t, err) - res2, err = ts.QueryRewardsIprpcProviderReward(p2) + res2, err = ts.QueryRewardsIprpcProviderRewardEstimation(p2) require.NoError(t, err) require.Len(t, res1.SpecFunds, 0) require.Len(t, res2.SpecFunds, 0) @@ -576,12 +576,12 @@ func TestMultipleIprpcSpec(t *testing.T) { // p1 total CU: 600, p2 total CU: 1200 -> if the rewards were divided by total CU (wrong) the rewards ratio should've been 1:2 // p1 total iprpc CU: 500, p2 total iprpc CU: 500 -> if the rewards were divided by total iprpc CU the rewards should be equal - res1, err := ts.QueryRewardsIprpcProviderReward(p1) + res1, err := ts.QueryRewardsIprpcProviderRewardEstimation(p1) require.NoError(t, err) - res2, err := ts.QueryRewardsIprpcProviderReward(p2) + res2, err := ts.QueryRewardsIprpcProviderRewardEstimation(p2) require.NoError(t, err) require.Equal(t, len(res1.SpecFunds), len(res2.SpecFunds)) - responses := []*rewardstypes.QueryIprpcProviderRewardResponse{res1, res2} + responses := []*rewardstypes.QueryIprpcProviderRewardEstimationResponse{res1, res2} for _, res := range responses { for _, sf := range res.SpecFunds { switch sf.Spec { From c73d48a27ac107815436d788293aa22307627574 Mon Sep 17 00:00:00 2001 From: Yarom Swisa Date: Tue, 5 Mar 2024 18:38:21 +0200 Subject: [PATCH 15/23] pr changes --- x/rewards/keeper/base_pay.go | 21 +++++++++++++++++---- x/rewards/keeper/providers.go | 10 ++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/x/rewards/keeper/base_pay.go b/x/rewards/keeper/base_pay.go index 76c5ebfd50..3e8d49d215 100644 --- a/x/rewards/keeper/base_pay.go +++ b/x/rewards/keeper/base_pay.go @@ -54,7 +54,7 @@ func (k Keeper) SetAllBasePay(ctx sdk.Context, list []types.BasePayGenesis) { } } -func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string, removeAfterPop bool) (list []types.BasePayWithIndex) { +func (k Keeper) getAllBasePayForChain(ctx sdk.Context, chainID string) (list []types.BasePayWithIndex) { store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BasePayPrefix)) iterator := sdk.KVStorePrefixIterator(store, []byte(chainID)) @@ -64,9 +64,22 @@ func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string, removeAft var val types.BasePay k.cdc.MustUnmarshal(iterator.Value(), &val) list = append(list, types.BasePayWithIndex{BasePayIndex: types.BasePayKeyRecover(string(iterator.Key())), BasePay: val}) - if removeAfterPop { - store.Delete(iterator.Key()) - } + } + + return +} + +func (k Keeper) popAllBasePayForChain(ctx sdk.Context, chainID string) (list []types.BasePayWithIndex) { + store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.BasePayPrefix)) + iterator := sdk.KVStorePrefixIterator(store, []byte(chainID)) + + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var val types.BasePay + k.cdc.MustUnmarshal(iterator.Value(), &val) + list = append(list, types.BasePayWithIndex{BasePayIndex: types.BasePayKeyRecover(string(iterator.Key())), BasePay: val}) + store.Delete(iterator.Key()) } return diff --git a/x/rewards/keeper/providers.go b/x/rewards/keeper/providers.go index 27118f9023..c0cca764c8 100644 --- a/x/rewards/keeper/providers.go +++ b/x/rewards/keeper/providers.go @@ -170,8 +170,14 @@ func (k Keeper) specEmissionParts(ctx sdk.Context) (emissions []types.SpecEmissi return emissions } -func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string, removeAfterPop bool) ([]types.BasePayWithIndex, math.Int) { - basepays := k.popAllBasePayForChain(ctx, chainID, removeAfterPop) +func (k Keeper) specProvidersBasePay(ctx sdk.Context, chainID string, pop bool) ([]types.BasePayWithIndex, math.Int) { + var basepays []types.BasePayWithIndex + if pop { + basepays = k.popAllBasePayForChain(ctx, chainID) + } else { + basepays = k.getAllBasePayForChain(ctx, chainID) + } + totalBasePay := math.ZeroInt() for _, basepay := range basepays { totalBasePay = totalBasePay.Add(basepay.Total) From 617a02df4b277921ff212c233d04022dff646e6b Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 11:55:21 +0200 Subject: [PATCH 16/23] CNS-872: small fix --- x/rewards/keeper/iprpc_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 1150b29581..f41c26bcb0 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -344,7 +344,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { require.NoError(ts.T, err) // check there are 2 iprpc reward object, and the first one is with id=1 - currentIprpcRewardId := ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + currentIprpcRewardId := ts.Keepers.Rewards.GetIprpcRewardsCurrentId(ts.Ctx) require.Equal(t, uint64(0), currentIprpcRewardId) res, err := ts.QueryRewardsIprpcSpecReward(mockSpec2) require.NoError(t, err) @@ -359,7 +359,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { // there should still be the exact two objects as before ts.AdvanceMonths(1) ts.AdvanceEpoch() - currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrentId(ts.Ctx) require.Equal(t, uint64(1), currentIprpcRewardId) res, err = ts.QueryRewardsIprpcSpecReward(mockSpec2) require.NoError(t, err) @@ -373,7 +373,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { // advance month without any provider service, there should be one IPRPC object with combined reward ts.AdvanceMonths(1) ts.AdvanceEpoch() - currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrent(ts.Ctx) + currentIprpcRewardId = ts.Keepers.Rewards.GetIprpcRewardsCurrentId(ts.Ctx) require.Equal(t, uint64(2), currentIprpcRewardId) res, err = ts.QueryRewardsIprpcSpecReward(mockSpec2) require.NoError(t, err) From 7f71d5db718bbd3f1e2fd8d662737223f3734ea0 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 12:24:11 +0200 Subject: [PATCH 17/23] CNS-872: unit test fix --- x/rewards/keeper/iprpc.go | 14 ++++++++++---- x/rewards/keeper/iprpc_test.go | 3 +++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/x/rewards/keeper/iprpc.go b/x/rewards/keeper/iprpc.go index 12006885a9..35c2a2fcb5 100644 --- a/x/rewards/keeper/iprpc.go +++ b/x/rewards/keeper/iprpc.go @@ -53,7 +53,7 @@ func (k Keeper) FundIprpc(ctx sdk.Context, creator string, duration uint64, fund } // add spec funds to next month IPRPC reward object - k.addSpecFunds(ctx, spec, fund, duration) + k.addSpecFunds(ctx, spec, fund, duration, true) return nil } @@ -62,7 +62,7 @@ func (k Keeper) FundIprpc(ctx sdk.Context, creator string, duration uint64, fund // so the IPRPC rewards transfer to the next month func (k Keeper) handleNoIprpcRewardToProviders(ctx sdk.Context, iprpcFunds []types.Specfund) { for _, fund := range iprpcFunds { - k.addSpecFunds(ctx, fund.Spec, fund.Fund, 1) + k.addSpecFunds(ctx, fund.Spec, fund.Fund, 1, false) } details := map[string]string{ @@ -91,8 +91,14 @@ func (k Keeper) countIprpcCu(specCuMap map[string]types.SpecCuType, iprpcCu uint // AddSpecFunds adds funds for a specific spec for of months. // This function is used by the fund-iprpc TX. -func (k Keeper) addSpecFunds(ctx sdk.Context, spec string, fund sdk.Coins, duration uint64) { - startID := k.GetIprpcRewardsCurrentId(ctx) + 1 // fund IPRPC only from the next month for months +// use fromNextMonth=true for normal IPRPC fund (should always start from next month) +// use fromNextMonth=false for IPRPC reward transfer for next month (when no providers are eligible for IPRPC rewards) +func (k Keeper) addSpecFunds(ctx sdk.Context, spec string, fund sdk.Coins, duration uint64, fromNextMonth bool) { + startID := k.GetIprpcRewardsCurrentId(ctx) + if fromNextMonth { + startID = startID + 1 // fund IPRPC only from the next month for months + } + for i := startID; i < startID+duration; i++ { iprpcReward, found := k.GetIprpcReward(ctx, i) if found { diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index f41c26bcb0..510d88d7fa 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -312,6 +312,9 @@ func TestIprpcSpecRewardQuery(t *testing.T) { relay := ts.SendRelay(p1, c1Acc, []string{ts.specs[1].Index}, 100) _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) require.NoError(t, err) + relay = ts.SendRelay(p1, c1Acc, []string{ts.specs[0].Index}, 100) + _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) + require.NoError(t, err) // advance month to distribute monthly rewards ts.AdvanceMonths(1) From 63298c12ad3dd0405fecba6b9b339c6ff9b7a735 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 12:29:18 +0200 Subject: [PATCH 18/23] CNS-872L lint fix --- x/rewards/keeper/iprpc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/rewards/keeper/iprpc.go b/x/rewards/keeper/iprpc.go index 35c2a2fcb5..812b00da10 100644 --- a/x/rewards/keeper/iprpc.go +++ b/x/rewards/keeper/iprpc.go @@ -96,7 +96,7 @@ func (k Keeper) countIprpcCu(specCuMap map[string]types.SpecCuType, iprpcCu uint func (k Keeper) addSpecFunds(ctx sdk.Context, spec string, fund sdk.Coins, duration uint64, fromNextMonth bool) { startID := k.GetIprpcRewardsCurrentId(ctx) if fromNextMonth { - startID = startID + 1 // fund IPRPC only from the next month for months + startID++ // fund IPRPC only from the next month for months } for i := startID; i < startID+duration; i++ { From 31124f597c84dd30ad7dd741dc939b332ea02370 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 12:47:01 +0200 Subject: [PATCH 19/23] CNS-872: fix unit tests --- x/rewards/keeper/iprpc_test.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 510d88d7fa..044249f0b2 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "fmt" "testing" "cosmossdk.io/math" @@ -45,15 +46,15 @@ func TestFundIprpcTX(t *testing.T) { sdk.NewCoin(ibcDenom, math.NewInt(50)), )}, {spec: ts.specs[1].Index, duration: 3, fund: sdk.NewCoins( - sdk.NewCoin(ts.BondDenom(), math.NewInt(90+minIprpcCost.Amount.Int64()*3)), + sdk.NewCoin(ts.BondDenom(), math.NewInt(90+minIprpcCost.Amount.Int64())), sdk.NewCoin(ibcDenom, math.NewInt(30)), )}, {spec: ts.specs[0].Index, duration: 3, fund: sdk.NewCoins( - sdk.NewCoin(ts.BondDenom(), math.NewInt(minIprpcCost.Amount.Int64()*3)), + sdk.NewCoin(ts.BondDenom(), math.NewInt(minIprpcCost.Amount.Int64())), sdk.NewCoin(ibcDenom, math.NewInt(130)), )}, {spec: ts.specs[1].Index, duration: 12, fund: sdk.NewCoins( - sdk.NewCoin(ts.BondDenom(), math.NewInt(10+minIprpcCost.Amount.Int64()*12)), + sdk.NewCoin(ts.BondDenom(), math.NewInt(10+minIprpcCost.Amount.Int64())), sdk.NewCoin(ibcDenom, math.NewInt(120)), )}, } @@ -222,13 +223,12 @@ func TestIprpcSpecRewardQuery(t *testing.T) { // first month: mock2 - 500uibc + 3000ulava, mockspec - 100000ulava // second + third month: mock2 - 2000ulava, mockspec - 100000ulava duration := int64(3) - minIprpcCostForFund := minIprpcCost.Amount.MulRaw(duration) _, err := ts.TxRewardsFundIprpc(consumer, ts.specs[0].Index, uint64(duration), - sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000).Add(minIprpcCostForFund)))) + sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(100000).Add(minIprpcCost.Amount)))) require.NoError(ts.T, err) _, err = ts.TxRewardsFundIprpc(consumer, ts.specs[1].Index, uint64(duration), - sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000).Add(minIprpcCostForFund)))) + sdk.NewCoins(sdk.NewCoin(ts.BondDenom(), sdk.NewInt(2000).Add(minIprpcCost.Amount)))) require.NoError(ts.T, err) expectedResults := []rewardstypes.IprpcReward{ @@ -261,6 +261,8 @@ func TestIprpcSpecRewardQuery(t *testing.T) { // query with no args res, err := ts.QueryRewardsIprpcSpecReward("") require.NoError(t, err) + fmt.Printf("expectedResults: %v\n", expectedResults) + fmt.Printf("res.IprpcRewards: %v\n", res.IprpcRewards) require.ElementsMatch(t, expectedResults, res.IprpcRewards) // query with arg = mockspec @@ -339,9 +341,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { // fund iprpc pool duration := uint64(2) - iprpcCost := sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) - fundForIprpc := iprpcFunds - err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, fundForIprpc) + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds) require.NoError(ts.T, err) _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, duration, iprpcFunds) require.NoError(ts.T, err) @@ -355,7 +355,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { require.Equal(t, uint64(0), res.CurrentMonthId) for i := range res.IprpcRewards { require.Equal(t, uint64(i+1), res.IprpcRewards[i].Id) - require.True(t, fundForIprpc.Sub(iprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) + require.True(t, iprpcFunds.Sub(minIprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) } // advance month to reach the first iprpc reward (first object is with id=1) @@ -370,7 +370,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { require.Equal(t, uint64(1), res.CurrentMonthId) for i := range res.IprpcRewards { require.Equal(t, uint64(i+1), res.IprpcRewards[i].Id) - require.True(t, fundForIprpc.Sub(iprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) + require.True(t, iprpcFunds.Sub(minIprpcCost).IsEqual(res.IprpcRewards[i].SpecFunds[0].Fund)) } // advance month without any provider service, there should be one IPRPC object with combined reward @@ -382,7 +382,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { require.NoError(t, err) require.Len(t, res.IprpcRewards, 1) require.Equal(t, uint64(2), res.CurrentMonthId) - require.True(t, fundForIprpc.Sub(iprpcCost).MulInt(sdk.NewInt(2)).IsEqual(res.IprpcRewards[0].SpecFunds[0].Fund)) + require.True(t, iprpcFunds.Sub(minIprpcCost).MulInt(sdk.NewInt(2)).IsEqual(res.IprpcRewards[0].SpecFunds[0].Fund)) // make a provider service an IPRPC eligible consumer and advance a month // there should be no iprpc rewards objects @@ -540,16 +540,14 @@ func TestMultipleIprpcSpec(t *testing.T) { // fund iprpc pool for mock2 spec for 1 months duration := uint64(1) - iprpcCost := sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) mock2Fund := sdk.NewCoin(ts.BondDenom(), sdk.NewInt(1700)) - _, err = ts.TxRewardsFundIprpc(c1, mockSpec2, duration, sdk.NewCoins(mock2Fund.Add(iprpcCost))) + _, err = ts.TxRewardsFundIprpc(c1, mockSpec2, duration, sdk.NewCoins(mock2Fund.Add(minIprpcCost))) require.NoError(t, err) // fund iprpc pool for mock3 spec for 3 months duration = uint64(3) - iprpcCost = sdk.NewCoin(ts.BondDenom(), minIprpcCost.Amount.MulRaw(int64(duration))) mock3Fund := sdk.NewCoin(ts.BondDenom(), sdk.NewInt(400)) - _, err = ts.TxRewardsFundIprpc(c1, mockSpec3, duration, sdk.NewCoins(mock3Fund.Add(iprpcCost))) + _, err = ts.TxRewardsFundIprpc(c1, mockSpec3, duration, sdk.NewCoins(mock3Fund.Add(minIprpcCost))) require.NoError(t, err) // advance month and epoch to apply pairing and iprpc fund From 38f4d486fe4d93846a44c5b356fa6345c0734a7c Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 13:43:48 +0200 Subject: [PATCH 20/23] CNS-872: iprpc unit tests fix --- x/rewards/keeper/iprpc_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 044249f0b2..4a357954b2 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -22,7 +22,7 @@ func TestFundIprpcTX(t *testing.T) { ts.setupForIprpcTests(false) consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) - err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds) + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(math.NewInt(12))) require.NoError(ts.T, err) type fundIprpcData struct { @@ -64,11 +64,17 @@ func TestFundIprpcTX(t *testing.T) { require.NoError(t, err) } - // Expected total IPRPC pool balance: 110ulava (=10+90+10) and 330uibc + // Expected total IPRPC pool balance (by TXs): + // 1. 10ulava + // 2. 50uibc + // 3. (90ulava + 30uibc) * 3 = 270ulava + 90uibc + // 4. 130uibc * 3 = 390uibc + // 5. (10ulava + 120uibc) * 12 = 120ulava + 1440uibc + // Total: 400ulava + 1970uibc iprpcTotalBalance := ts.Keepers.Rewards.TotalPoolTokens(ts.Ctx, rewardstypes.IprpcPoolName) expectedIprpcTotalBalance := sdk.NewCoins( - sdk.NewCoin(ts.BondDenom(), math.NewInt(110)), - sdk.NewCoin(ibcDenom, math.NewInt(330)), + sdk.NewCoin(ts.BondDenom(), math.NewInt(400)), + sdk.NewCoin(ibcDenom, math.NewInt(1970)), ) require.True(t, expectedIprpcTotalBalance.IsEqual(iprpcTotalBalance)) @@ -341,7 +347,7 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { // fund iprpc pool duration := uint64(2) - err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds) + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(math.NewInt(2))) require.NoError(ts.T, err) _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, duration, iprpcFunds) require.NoError(ts.T, err) From 85ba6891d7cb69e895c6500e8115b27858e3a3cb Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 14:51:44 +0200 Subject: [PATCH 21/23] CNS-872: PR fix --- testutil/common/tester.go | 4 ++++ x/rewards/keeper/helpers_test.go | 3 +++ x/rewards/keeper/iprpc_test.go | 9 +++++++++ 3 files changed, 16 insertions(+) diff --git a/testutil/common/tester.go b/testutil/common/tester.go index 02fea69170..d3e775421e 100644 --- a/testutil/common/tester.go +++ b/testutil/common/tester.go @@ -307,6 +307,10 @@ func (ts *Tester) GetBalance(accAddr sdk.AccAddress) int64 { return ts.Keepers.BankKeeper.GetBalance(ts.Ctx, accAddr, denom).Amount.Int64() } +func (ts *Tester) GetBalances(accAddr sdk.AccAddress) sdk.Coins { + return ts.Keepers.BankKeeper.GetAllBalances(ts.Ctx, accAddr) +} + func (ts *Tester) FindPlan(index string, block uint64) (planstypes.Plan, bool) { return ts.Keepers.Plans.FindPlan(ts.Ctx, index, block) } diff --git a/x/rewards/keeper/helpers_test.go b/x/rewards/keeper/helpers_test.go index 05aaea3234..6c9be49dfb 100644 --- a/x/rewards/keeper/helpers_test.go +++ b/x/rewards/keeper/helpers_test.go @@ -129,8 +129,11 @@ func (ts *tester) setupForIprpcTests(fundIprpcPool bool) { duration := uint64(1) err = ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(sdk.NewIntFromUint64(duration))) require.NoError(ts.T, err) + balanceBeforeFund := ts.GetBalances(consumerAcc.Addr) _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, duration, iprpcFunds) require.NoError(ts.T, err) + expectedBalanceAfterFund := balanceBeforeFund.Sub(iprpcFunds.MulInt(math.NewIntFromUint64(duration))...) + require.True(ts.T, ts.GetBalances(consumerAcc.Addr).IsEqual(expectedBalanceAfterFund)) ts.AdvanceMonths(1).AdvanceEpoch() // fund only fund for next month, so advance a month } } diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 4a357954b2..0d7c9e78b8 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -519,6 +519,15 @@ func TestIprpcEligibleSubscriptions(t *testing.T) { require.NoError(t, err) require.Len(t, res1.SpecFunds, 0) require.Len(t, res2.SpecFunds, 0) + + // advance another month and see there are still no rewards + ts.AdvanceMonths(1).AdvanceEpoch() + res1, err = ts.QueryRewardsIprpcProviderRewardEstimation(p1) + require.NoError(t, err) + res2, err = ts.QueryRewardsIprpcProviderRewardEstimation(p2) + require.NoError(t, err) + require.Len(t, res1.SpecFunds, 0) + require.Len(t, res2.SpecFunds, 0) } // TestMultipleIprpcSpec checks that rewards are distributed correctly when multiple specs are configured in the IPRPC pool From d24e2b9b06ce7e85d048887903e734174a6a55b2 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 16:58:46 +0200 Subject: [PATCH 22/23] CNS-872: added unit test --- x/rewards/keeper/iprpc_test.go | 51 ++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index 0d7c9e78b8..c4b2f7b3bd 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -1,7 +1,6 @@ package keeper_test import ( - "fmt" "testing" "cosmossdk.io/math" @@ -267,8 +266,6 @@ func TestIprpcSpecRewardQuery(t *testing.T) { // query with no args res, err := ts.QueryRewardsIprpcSpecReward("") require.NoError(t, err) - fmt.Printf("expectedResults: %v\n", expectedResults) - fmt.Printf("res.IprpcRewards: %v\n", res.IprpcRewards) require.ElementsMatch(t, expectedResults, res.IprpcRewards) // query with arg = mockspec @@ -405,6 +402,54 @@ func TestIprpcRewardObjectsUpdate(t *testing.T) { require.Equal(t, uint64(3), res.CurrentMonthId) } +// TestFundIprpcTwice tests the following scenario: +// IPRPC is funded for two months, advance month and fund again +// during this month, let provider serve and advance month again -> reward should be as the original funding +// advance again and serve -> reward should be from both funds (funding only starts from the next month) +func TestFundIprpcTwice(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) + consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) + _, p1 := ts.GetAccount(common.PROVIDER, 0) + + // fund iprpc pool + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(math.NewInt(2))) + require.NoError(ts.T, err) + _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, 2, iprpcFunds) + require.NoError(ts.T, err) + + // advance month and fund again + ts.AdvanceMonths(1).AdvanceEpoch() + err = ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(math.NewInt(2))) + require.NoError(ts.T, err) + _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, 2, iprpcFunds) + require.NoError(ts.T, err) + + // make a provider service an IPRPC eligible consumer and advance month + relay := ts.SendRelay(p1, consumerAcc, []string{ts.specs[1].Index}, 100) + _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) + ts.AdvanceEpoch() + require.NoError(t, err) + ts.AdvanceMonths(1).AdvanceEpoch() + + // check rewards - should be only from first funding (=iprpcFunds) + res, err := ts.QueryDualstakingDelegatorRewards(p1, p1, mockSpec2) + require.NoError(t, err) + require.True(t, iprpcFunds.Sub(minIprpcCost).IsEqual(res.Rewards[0].Amount)) + + // make a provider service an IPRPC eligible consumer and advance month again + relay = ts.SendRelay(p1, consumerAcc, []string{ts.specs[1].Index}, 100) + _, err = ts.Servers.PairingServer.RelayPayment(ts.GoCtx, &relay) + ts.AdvanceEpoch() + require.NoError(t, err) + ts.AdvanceMonths(1).AdvanceEpoch() + + // check rewards - should be only from first + second funding (=iprpcFunds*3) + res, err = ts.QueryDualstakingDelegatorRewards(p1, p1, mockSpec2) + require.NoError(t, err) + require.True(t, iprpcFunds.Sub(minIprpcCost).MulInt(math.NewInt(3)).IsEqual(res.Rewards[0].Amount)) +} + // TestIprpcMinCost tests that a fund TX fails if it doesn't have enough tokens to cover for the minimum IPRPC costs // Scenarios: // 1. fund TX with the minimum cost available -> TX success From 1a0e230004c9aa514fa8de5ebdd7b2bf5399c5d2 Mon Sep 17 00:00:00 2001 From: oren-lava Date: Wed, 6 Mar 2024 17:06:28 +0200 Subject: [PATCH 23/23] CNS-872: added min cost unit test --- x/rewards/keeper/iprpc_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/x/rewards/keeper/iprpc_test.go b/x/rewards/keeper/iprpc_test.go index c4b2f7b3bd..07486ddaf6 100644 --- a/x/rewards/keeper/iprpc_test.go +++ b/x/rewards/keeper/iprpc_test.go @@ -701,3 +701,17 @@ func TestIprpcRewardWithZeroSubRewards(t *testing.T) { require.NoError(t, err) require.True(t, p2ExpectedReward.IsEqual(res2.Rewards[0].Amount)) } + +// TestMinIprpcCostForSeveralMonths checks that if a user sends fund=1.1*minIprpcCost with duration=2 +// the TX succeeds (checks that the min iprpc cost check that per month there is enough funds) +func TestMinIprpcCostForSeveralMonths(t *testing.T) { + ts := newTester(t, true) + ts.setupForIprpcTests(false) + consumerAcc, consumer := ts.GetAccount(common.CONSUMER, 0) + + // fund iprpc pool + err := ts.Keepers.BankKeeper.AddToBalance(consumerAcc.Addr, iprpcFunds.MulInt(math.NewInt(3))) + require.NoError(ts.T, err) + _, err = ts.TxRewardsFundIprpc(consumer, mockSpec2, 2, iprpcFunds.MulInt(math.NewInt(110)).QuoInt(math.NewInt(100))) + require.NoError(ts.T, err) +}