diff --git a/proto/lavanet/lava/rewards/tx.proto b/proto/lavanet/lava/rewards/tx.proto index c89345cef4..1e4c23daee 100644 --- a/proto/lavanet/lava/rewards/tx.proto +++ b/proto/lavanet/lava/rewards/tx.proto @@ -11,6 +11,7 @@ option go_package = "github.com/lavanet/lava/x/rewards/types"; // Msg defines the Msg service. service Msg { rpc SetIprpcData(MsgSetIprpcData) returns (MsgSetIprpcDataResponse); + rpc FundIprpc(MsgFundIprpc) returns (MsgFundIprpcResponse); // this line is used by starport scaffolding # proto/tx/rpc } @@ -23,4 +24,17 @@ message MsgSetIprpcData { message MsgSetIprpcDataResponse { } +message MsgFundIprpc { + string creator = 1; + uint64 duration = 2; // vesting duration in months + repeated cosmos.base.v1beta1.Coin amounts = 3 [ + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins", + (gogoproto.nullable) = false + ]; // tokens to be distributed as reward + string spec = 4; // spec on which the providers get incentive +} + +message MsgFundIprpcResponse { +} + // this line is used by starport scaffolding # proto/tx/message \ No newline at end of file diff --git a/scripts/init_chain_commands.sh b/scripts/init_chain_commands.sh index 9dd6bb689c..9b3128f765 100755 --- a/scripts/init_chain_commands.sh +++ b/scripts/init_chain_commands.sh @@ -107,6 +107,10 @@ sleep_until_next_epoch HEALTH_FILE="config/health_examples/health_template.yml" create_health_config $HEALTH_FILE $(lavad keys show user1 -a) $(lavad keys show servicer2 -a) $(lavad keys show servicer3 -a) +lavad tx gov submit-legacy-proposal set-iprpc-data 1000000000ulava --min-cost 100ulava --add-subscriptions $(lavad keys show -a user1) --from alice -y +wait_count_blocks 1 +lavad tx gov vote $(latest_vote) yes -y --from alice --gas-adjustment "1.5" --gas "auto" --gas-prices $GASPRICE + if [[ "$1" != "--skip-providers" ]]; then . ${__dir}/setup_providers.sh echo "letting providers start and running health check" diff --git a/utils/time.go b/utils/time.go index c96dcf0ad9..88ae7fddc4 100644 --- a/utils/time.go +++ b/utils/time.go @@ -41,3 +41,15 @@ func NextMonth(date time.Time) time.Time { time.UTC, ) } + +func IsMiddleOfMonthPassed(date time.Time) bool { + // Get the total number of days in the current month + _, month, year := date.Date() + daysInMonth := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC).Day() + + // Calculate the middle day of the month + middleDay := daysInMonth / 2 + + // Check if the day of the given date is greater than the middle day + return date.Day() > middleDay +} diff --git a/x/rewards/client/cli/tx.go b/x/rewards/client/cli/tx.go index 3fe5071947..ff8d00261d 100644 --- a/x/rewards/client/cli/tx.go +++ b/x/rewards/client/cli/tx.go @@ -41,6 +41,7 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdFundIprpc()) // this line is used by starport scaffolding # 1 return cmd diff --git a/x/rewards/client/cli/tx_fund_iprpc.go b/x/rewards/client/cli/tx_fund_iprpc.go new file mode 100644 index 0000000000..c51c2abc59 --- /dev/null +++ b/x/rewards/client/cli/tx_fund_iprpc.go @@ -0,0 +1,60 @@ +package cli + +import ( + "strconv" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/x/rewards/types" + "github.com/spf13/cobra" +) + +var _ = strconv.Itoa(0) + +func CmdFundIprpc() *cobra.Command { + cmd := &cobra.Command{ + Use: "fund-iprpc [spec] [duration] [coins] --from ", + Short: `fund the IPRPC pool to a specific spec with ulava or IBC wrapped tokens. The tokens will be vested for months. + Note that the amount of coins you put is the monthly quota (it's not for the total period of time). + Also, the tokens must include duration*min_iprpc_cost of ulava tokens (min_iprpc_cost is shown with the show-iprpc-data command)`, + Example: `lavad tx rewards fund-iprpc ETH1 4 100000ulava,50000ibctoken --from alice + This command will transfer 4*100000ulava and 4*50000ibctoken to the IPRPC pool to be distributed for 4 months`, + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) (err error) { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + spec := args[0] + durationStr := args[1] + duration, err := strconv.ParseUint(durationStr, 10, 64) + if err != nil { + return err + } + + fundStr := args[2] + fund, err := sdk.ParseCoinsNormalized(fundStr) + if err != nil { + return err + } + + msg := types.NewMsgFundIprpc( + clientCtx.GetFromAddress().String(), + spec, + duration, + fund, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} diff --git a/x/rewards/handler.go b/x/rewards/handler.go index 068fa10b23..0692e0efcb 100644 --- a/x/rewards/handler.go +++ b/x/rewards/handler.go @@ -14,10 +14,15 @@ import ( func NewHandler(k keeper.Keeper) sdk.Handler { // this line is used by starport scaffolding # handler/msgServer + msgServer := keeper.NewMsgServerImpl(k) + return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { _ = ctx.WithEventManager(sdk.NewEventManager()) switch msg := msg.(type) { + case *types.MsgFundIprpc: + res, err := msgServer.FundIprpc(sdk.WrapSDKContext(ctx), msg) + return sdk.WrapServiceResult(ctx, res, err) // this line is used by starport scaffolding # 1 default: errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) diff --git a/x/rewards/keeper/iprpc.go b/x/rewards/keeper/iprpc.go index c0d57f4ce8..5a25ce96ad 100644 --- a/x/rewards/keeper/iprpc.go +++ b/x/rewards/keeper/iprpc.go @@ -2,12 +2,64 @@ package keeper import ( "fmt" + "strconv" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/lavanet/lava/utils" "github.com/lavanet/lava/x/rewards/types" ) +func (k Keeper) FundIprpc(ctx sdk.Context, creator string, duration uint64, fund sdk.Coins, spec string) error { + // verify spec exists and active + foundAndActive, _, _ := k.specKeeper.IsSpecFoundAndActive(ctx, spec) + if !foundAndActive { + return utils.LavaFormatWarning("spec not found or disabled", types.ErrFundIprpc) + } + + // check fund consists of minimum amount of ulava (min_iprpc_cost) + minIprpcFundCost := k.GetMinIprpcCost(ctx) + if fund.AmountOf(k.stakingKeeper.BondDenom(ctx)).LT(minIprpcFundCost.Amount) { + return utils.LavaFormatWarning("insufficient ulava tokens in fund. should be at least min iprpc cost * duration", types.ErrFundIprpc, + utils.LogAttr("min_iprpc_cost", k.GetMinIprpcCost(ctx).String()), + utils.LogAttr("duration", strconv.FormatUint(duration, 10)), + utils.LogAttr("fund_ulava_amount", fund.AmountOf(k.stakingKeeper.BondDenom(ctx))), + ) + } + + // check creator has enough balance + addr, err := sdk.AccAddressFromBech32(creator) + if err != nil { + return utils.LavaFormatWarning("invalid creator address", types.ErrFundIprpc) + } + + // send the minimum cost to the validators allocation pool (and subtract them from the fund) + minIprpcFundCostCoins := sdk.NewCoins(minIprpcFundCost).MulInt(sdk.NewIntFromUint64(duration)) + err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, string(types.ValidatorsRewardsAllocationPoolName), minIprpcFundCostCoins) + if err != nil { + return utils.LavaFormatError(types.ErrFundIprpc.Error()+"for funding validator allocation pool", err, + utils.LogAttr("creator", creator), + utils.LogAttr("min_iprpc_fund_cost", minIprpcFundCost.String()), + ) + } + fund = fund.Sub(minIprpcFundCost) + allFunds := fund.MulInt(math.NewIntFromUint64(duration)) + + // send the funds to the iprpc pool + err = k.bankKeeper.SendCoinsFromAccountToModule(ctx, addr, string(types.IprpcPoolName), allFunds) + if err != nil { + return utils.LavaFormatError(types.ErrFundIprpc.Error()+"for funding iprpc pool", err, + utils.LogAttr("creator", creator), + utils.LogAttr("fund", fund.String()), + ) + } + + // add spec funds to next month IPRPC reward object + k.addSpecFunds(ctx, spec, fund, duration) + + return nil +} + // handleNoIprpcRewardToProviders handles the situation in which there are no providers to send IPRPC rewards to // so the IPRPC rewards transfer to the next month func (k Keeper) handleNoIprpcRewardToProviders(ctx sdk.Context, iprpcFunds []types.Specfund) { @@ -95,6 +147,10 @@ func (k Keeper) distributeIprpcRewards(ctx sdk.Context, iprpcReward types.IprpcR if err != nil { continue } + if specCu.TotalCu == 0 { + // spec was not serviced by any provider, continue + continue + } // calculate provider IPRPC reward providerIprpcReward := specFund.Fund.MulInt(sdk.NewIntFromUint64(providerCU.CU)).QuoInt(sdk.NewIntFromUint64(specCu.TotalCu)) diff --git a/x/rewards/keeper/msg_server_fund_iprpc.go b/x/rewards/keeper/msg_server_fund_iprpc.go new file mode 100644 index 0000000000..d0e4e4a678 --- /dev/null +++ b/x/rewards/keeper/msg_server_fund_iprpc.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "context" + "strconv" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/utils" + "github.com/lavanet/lava/x/rewards/types" +) + +func (k msgServer) FundIprpc(goCtx context.Context, msg *types.MsgFundIprpc) (*types.MsgFundIprpcResponse, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + + err := msg.ValidateBasic() + if err != nil { + return &types.MsgFundIprpcResponse{}, err + } + + err = k.Keeper.FundIprpc(ctx, msg.Creator, msg.Duration, msg.Amounts, msg.Spec) + if err == nil { + logger := k.Keeper.Logger(ctx) + details := map[string]string{ + "spec": msg.Spec, + "duration": strconv.FormatUint(msg.Duration, 10), + "amounts": msg.Amounts.String(), + } + utils.LogLavaEvent(ctx, logger, types.FundIprpcEventName, details, "Funded IPRPC pool successfully") + } + + return &types.MsgFundIprpcResponse{}, err +} diff --git a/x/rewards/types/codec.go b/x/rewards/types/codec.go index 4a3fc0d903..8ec03098ef 100644 --- a/x/rewards/types/codec.go +++ b/x/rewards/types/codec.go @@ -11,6 +11,7 @@ import ( func RegisterCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgSetIprpcData{}, "rewards/MsgSetIprpcData", nil) + cdc.RegisterConcrete(&MsgFundIprpc{}, "rewards/MsgFundIprpc", nil) // this line is used by starport scaffolding # 2 } @@ -18,6 +19,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { // this line is used by starport scaffolding # 3 registry.RegisterImplementations((*sdk.Msg)(nil), &MsgSetIprpcData{}, + &MsgFundIprpc{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) } diff --git a/x/rewards/types/errors.go b/x/rewards/types/errors.go index 00faef99f3..f3d7d64317 100644 --- a/x/rewards/types/errors.go +++ b/x/rewards/types/errors.go @@ -8,5 +8,5 @@ import ( // x/rewards module sentinel errors var ( - ErrSample = sdkerrors.Register(ModuleName, 1100, "sample error") + ErrFundIprpc = sdkerrors.Register(ModuleName, 1, "fund iprpc TX failed") ) diff --git a/x/rewards/types/expected_keepers.go b/x/rewards/types/expected_keepers.go index d5deb5ef7d..e8b711b745 100644 --- a/x/rewards/types/expected_keepers.go +++ b/x/rewards/types/expected_keepers.go @@ -23,12 +23,14 @@ type BankKeeper interface { GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin SendCoinsFromModuleToModule(ctx sdk.Context, senderPool, recipientPool string, amt sdk.Coins) error GetAllBalances(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins + SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error // Methods imported from bank should be defined here } type SpecKeeper interface { GetAllChainIDs(ctx sdk.Context) (chainIDs []string) GetSpec(ctx sdk.Context, index string) (val spectypes.Spec, found bool) + IsSpecFoundAndActive(ctx sdk.Context, chainID string) (foundAndActive, found bool, providersType spectypes.Spec_ProvidersTypes) } type TimerStoreKeeper interface { diff --git a/x/rewards/types/message_fund_iprpc.go b/x/rewards/types/message_fund_iprpc.go new file mode 100644 index 0000000000..dbbd57e667 --- /dev/null +++ b/x/rewards/types/message_fund_iprpc.go @@ -0,0 +1,63 @@ +package types + +import ( + fmt "fmt" + + sdkerrors "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + legacyerrors "github.com/cosmos/cosmos-sdk/types/errors" +) + +const TypeMsgFundIprpc = "fund_iprpc" + +var _ sdk.Msg = &MsgFundIprpc{} + +func NewMsgFundIprpc(creator string, spec string, duration uint64, amounts sdk.Coins) *MsgFundIprpc { + return &MsgFundIprpc{ + Creator: creator, + Spec: spec, + Duration: duration, + Amounts: amounts, + } +} + +func (msg *MsgFundIprpc) Route() string { + return RouterKey +} + +func (msg *MsgFundIprpc) Type() string { + return TypeMsgFundIprpc +} + +func (msg *MsgFundIprpc) GetSigners() []sdk.AccAddress { + creator, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + panic(err) + } + return []sdk.AccAddress{creator} +} + +func (msg *MsgFundIprpc) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(msg) + return sdk.MustSortJSON(bz) +} + +func (msg *MsgFundIprpc) ValidateBasic() error { + _, err := sdk.AccAddressFromBech32(msg.Creator) + if err != nil { + return sdkerrors.Wrapf(legacyerrors.ErrInvalidAddress, "invalid creator address (%s)", err) + } + + unique := map[string]struct{}{} + for _, amount := range msg.Amounts { + if !amount.IsValid() { + return sdkerrors.Wrap(fmt.Errorf("invalid amount; invalid denom or negative amount. coin: %s", amount.String()), "") + } + if _, ok := unique[amount.Denom]; ok { + return sdkerrors.Wrap(fmt.Errorf("invalid coins, duplicated denom: %s", amount.Denom), "") + } + unique[amount.Denom] = struct{}{} + } + + return nil +} diff --git a/x/rewards/types/message_fund_iprpc_test.go b/x/rewards/types/message_fund_iprpc_test.go new file mode 100644 index 0000000000..b44c983b30 --- /dev/null +++ b/x/rewards/types/message_fund_iprpc_test.go @@ -0,0 +1,49 @@ +package types + +import ( + "testing" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/lavanet/lava/testutil/sample" + "github.com/stretchr/testify/require" +) + +func TestFundIprpc_ValidateBasic(t *testing.T) { + tests := []struct { + name string + msg MsgFundIprpc + valid bool + }{ + { + name: "valid", + msg: MsgFundIprpc{ + Creator: sample.AccAddress(), + Duration: 2, + Amounts: sdk.NewCoins(sdk.NewCoin("denom", math.OneInt())), + Spec: "spec", + }, + valid: true, + }, + { + name: "invalid creator address", + msg: MsgFundIprpc{ + Creator: "invalid_address", + Duration: 2, + Amounts: sdk.NewCoins(sdk.NewCoin("denom", math.OneInt())), + Spec: "spec", + }, + valid: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.msg.ValidateBasic() + if tt.valid { + require.NoError(t, err) + return + } + require.Error(t, err) + }) + } +} diff --git a/x/rewards/types/tx.pb.go b/x/rewards/types/tx.pb.go index e0886a5318..36a497f99f 100644 --- a/x/rewards/types/tx.pb.go +++ b/x/rewards/types/tx.pb.go @@ -6,6 +6,7 @@ package types import ( context "context" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" types "github.com/cosmos/cosmos-sdk/types" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" @@ -125,36 +126,149 @@ func (m *MsgSetIprpcDataResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgSetIprpcDataResponse proto.InternalMessageInfo +type MsgFundIprpc struct { + Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + Duration uint64 `protobuf:"varint,2,opt,name=duration,proto3" json:"duration,omitempty"` + Amounts github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amounts,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amounts"` + Spec string `protobuf:"bytes,4,opt,name=spec,proto3" json:"spec,omitempty"` +} + +func (m *MsgFundIprpc) Reset() { *m = MsgFundIprpc{} } +func (m *MsgFundIprpc) String() string { return proto.CompactTextString(m) } +func (*MsgFundIprpc) ProtoMessage() {} +func (*MsgFundIprpc) Descriptor() ([]byte, []int) { + return fileDescriptor_6a4c66e189226d78, []int{2} +} +func (m *MsgFundIprpc) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFundIprpc) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFundIprpc.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 *MsgFundIprpc) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFundIprpc.Merge(m, src) +} +func (m *MsgFundIprpc) XXX_Size() int { + return m.Size() +} +func (m *MsgFundIprpc) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFundIprpc.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFundIprpc proto.InternalMessageInfo + +func (m *MsgFundIprpc) GetCreator() string { + if m != nil { + return m.Creator + } + return "" +} + +func (m *MsgFundIprpc) GetDuration() uint64 { + if m != nil { + return m.Duration + } + return 0 +} + +func (m *MsgFundIprpc) GetAmounts() github_com_cosmos_cosmos_sdk_types.Coins { + if m != nil { + return m.Amounts + } + return nil +} + +func (m *MsgFundIprpc) GetSpec() string { + if m != nil { + return m.Spec + } + return "" +} + +type MsgFundIprpcResponse struct { +} + +func (m *MsgFundIprpcResponse) Reset() { *m = MsgFundIprpcResponse{} } +func (m *MsgFundIprpcResponse) String() string { return proto.CompactTextString(m) } +func (*MsgFundIprpcResponse) ProtoMessage() {} +func (*MsgFundIprpcResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_6a4c66e189226d78, []int{3} +} +func (m *MsgFundIprpcResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgFundIprpcResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgFundIprpcResponse.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 *MsgFundIprpcResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgFundIprpcResponse.Merge(m, src) +} +func (m *MsgFundIprpcResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgFundIprpcResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgFundIprpcResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgFundIprpcResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgSetIprpcData)(nil), "lavanet.lava.rewards.MsgSetIprpcData") proto.RegisterType((*MsgSetIprpcDataResponse)(nil), "lavanet.lava.rewards.MsgSetIprpcDataResponse") + proto.RegisterType((*MsgFundIprpc)(nil), "lavanet.lava.rewards.MsgFundIprpc") + proto.RegisterType((*MsgFundIprpcResponse)(nil), "lavanet.lava.rewards.MsgFundIprpcResponse") } func init() { proto.RegisterFile("lavanet/lava/rewards/tx.proto", fileDescriptor_6a4c66e189226d78) } var fileDescriptor_6a4c66e189226d78 = []byte{ - // 326 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x91, 0xcf, 0x4e, 0x3a, 0x31, - 0x10, 0xc7, 0xb7, 0x3f, 0x7e, 0x31, 0xa1, 0x12, 0x4d, 0x56, 0x12, 0x81, 0x68, 0x25, 0x24, 0x46, - 0x2e, 0xb6, 0x01, 0x9f, 0x40, 0xd0, 0x83, 0x07, 0x2e, 0xcb, 0xcd, 0x0b, 0xe9, 0x2e, 0xcd, 0xd2, - 0xe8, 0x76, 0x36, 0x3b, 0x05, 0xe1, 0x2d, 0x7c, 0x0b, 0x5f, 0x85, 0x23, 0x47, 0x4f, 0xc6, 0xc0, - 0x8b, 0x98, 0xfd, 0x63, 0x10, 0xe2, 0xc1, 0xd3, 0x4c, 0xe6, 0x3b, 0x9d, 0xf9, 0x74, 0xbe, 0xf4, - 0xfc, 0x59, 0xce, 0xa4, 0x51, 0x56, 0xa4, 0x51, 0x24, 0xea, 0x45, 0x26, 0x63, 0x14, 0x76, 0xce, - 0xe3, 0x04, 0x2c, 0xb8, 0xd5, 0x42, 0xe6, 0x69, 0xe4, 0x85, 0xdc, 0x60, 0x01, 0x60, 0x04, 0x28, - 0x7c, 0x89, 0x4a, 0xcc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xd8, 0x71, 0x70, 0xbe, 0xf5, - 0x70, 0x11, 0x2b, 0xf4, 0x0f, 0xb2, 0xdb, 0xdf, 0x7c, 0x05, 0x00, 0x00, 0xff, 0xff, 0x7e, 0xc1, - 0x85, 0x7c, 0xe8, 0x01, 0x00, 0x00, + // 443 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcd, 0x6e, 0xd4, 0x30, + 0x10, 0xc7, 0xd7, 0xec, 0x8a, 0xb2, 0x66, 0x05, 0x92, 0x59, 0x41, 0x1a, 0x41, 0xba, 0x8a, 0x84, + 0x88, 0x90, 0x6a, 0xd3, 0xf2, 0x04, 0xb4, 0x80, 0xc4, 0x61, 0x2f, 0xe9, 0x0d, 0x0e, 0x95, 0x93, + 0x58, 0xa9, 0x05, 0xb1, 0x23, 0x8f, 0x53, 0xda, 0xb7, 0xe0, 0x2d, 0x90, 0x78, 0x09, 0xae, 0x7b, + 0xec, 0x91, 0x13, 0xa0, 0xdd, 0x17, 0x41, 0x76, 0x92, 0xee, 0xb6, 0xe2, 0xeb, 0x34, 0x63, 0xff, + 0x67, 0xc6, 0xbf, 0x19, 0x0f, 0x7e, 0xf4, 0x81, 0x9f, 0x72, 0x25, 0x2c, 0x73, 0x96, 0x19, 0xf1, + 0x91, 0x9b, 0x02, 0x98, 0x3d, 0xa3, 0xb5, 0xd1, 0x56, 0x93, 0x69, 0x27, 0x53, 0x67, 0x69, 0x27, + 0x87, 0x51, 0xae, 0xa1, 0xd2, 0xc0, 0x32, 0x0e, 0x82, 0x9d, 0xee, 0x65, 0xc2, 0xf2, 0x3d, 0x96, + 0x6b, 0xa9, 0xda, 0xac, 0x70, 0x5a, 0xea, 0x52, 0x7b, 0x97, 0x39, 0xaf, 0xbd, 0x8d, 0x3f, 0x23, + 0x7c, 0x77, 0x0e, 0xe5, 0x91, 0xb0, 0x6f, 0x6a, 0x53, 0xe7, 0x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c9, 0xbc, 0x1f, 0xdf, 0xc7, 0xd3, 0xcd, 0x06, 0xfa, 0xce, 0xf6, 0x17, 0x08, 0x0f, 0xe7, 0x50, + 0x92, 0x02, 0x4f, 0xae, 0x7c, 0xd1, 0x63, 0xfa, 0xbb, 0x1d, 0xa0, 0xd7, 0x06, 0x14, 0xee, 0xfe, + 0x57, 0x58, 0xff, 0x1a, 0x79, 0x87, 0xc7, 0xeb, 0x19, 0xc6, 0x7f, 0xcc, 0xbd, 0x8c, 0x09, 0x9f, + 0xfe, 0x3b, 0xa6, 0x2f, 0x7e, 0xf0, 0x62, 0xb1, 0x8c, 0xd0, 0xc5, 0x32, 0x42, 0x3f, 0x97, 0x11, + 0xfa, 0xb4, 0x8a, 0x06, 0x17, 0xab, 0x68, 0xf0, 0x6d, 0x15, 0x0d, 0xde, 0x3e, 0xd9, 0x98, 0xe1, + 0x95, 0xcd, 0x3f, 0x5b, 0xef, 0xbe, 0x1b, 0x64, 0x76, 0xd3, 0xef, 0xec, 0xf3, 0x5f, 0x01, 0x00, + 0x00, 0xff, 0xff, 0x87, 0x10, 0x57, 0xff, 0x20, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -170,6 +284,7 @@ const _ = grpc.SupportPackageIsVersion4 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type MsgClient interface { SetIprpcData(ctx context.Context, in *MsgSetIprpcData, opts ...grpc.CallOption) (*MsgSetIprpcDataResponse, error) + FundIprpc(ctx context.Context, in *MsgFundIprpc, opts ...grpc.CallOption) (*MsgFundIprpcResponse, error) } type msgClient struct { @@ -189,9 +304,19 @@ func (c *msgClient) SetIprpcData(ctx context.Context, in *MsgSetIprpcData, opts return out, nil } +func (c *msgClient) FundIprpc(ctx context.Context, in *MsgFundIprpc, opts ...grpc.CallOption) (*MsgFundIprpcResponse, error) { + out := new(MsgFundIprpcResponse) + err := c.cc.Invoke(ctx, "/lavanet.lava.rewards.Msg/FundIprpc", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { SetIprpcData(context.Context, *MsgSetIprpcData) (*MsgSetIprpcDataResponse, error) + FundIprpc(context.Context, *MsgFundIprpc) (*MsgFundIprpcResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -201,6 +326,9 @@ type UnimplementedMsgServer struct { func (*UnimplementedMsgServer) SetIprpcData(ctx context.Context, req *MsgSetIprpcData) (*MsgSetIprpcDataResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method SetIprpcData not implemented") } +func (*UnimplementedMsgServer) FundIprpc(ctx context.Context, req *MsgFundIprpc) (*MsgFundIprpcResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FundIprpc not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -224,6 +352,24 @@ func _Msg_SetIprpcData_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Msg_FundIprpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgFundIprpc) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).FundIprpc(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/lavanet.lava.rewards.Msg/FundIprpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).FundIprpc(ctx, req.(*MsgFundIprpc)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "lavanet.lava.rewards.Msg", HandlerType: (*MsgServer)(nil), @@ -232,6 +378,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "SetIprpcData", Handler: _Msg_SetIprpcData_Handler, }, + { + MethodName: "FundIprpc", + Handler: _Msg_FundIprpc_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "lavanet/lava/rewards/tx.proto", @@ -309,6 +459,85 @@ func (m *MsgSetIprpcDataResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } +func (m *MsgFundIprpc) 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 *MsgFundIprpc) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFundIprpc) 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 = encodeVarintTx(dAtA, i, uint64(len(m.Spec))) + i-- + dAtA[i] = 0x22 + } + if len(m.Amounts) > 0 { + for iNdEx := len(m.Amounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.Duration != 0 { + i = encodeVarintTx(dAtA, i, uint64(m.Duration)) + i-- + dAtA[i] = 0x10 + } + if len(m.Creator) > 0 { + i -= len(m.Creator) + copy(dAtA[i:], m.Creator) + i = encodeVarintTx(dAtA, i, uint64(len(m.Creator))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgFundIprpcResponse) 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 *MsgFundIprpcResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgFundIprpcResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -350,6 +579,41 @@ func (m *MsgSetIprpcDataResponse) Size() (n int) { return n } +func (m *MsgFundIprpc) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Creator) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + if m.Duration != 0 { + n += 1 + sovTx(uint64(m.Duration)) + } + if len(m.Amounts) > 0 { + for _, e := range m.Amounts { + l = e.Size() + n += 1 + l + sovTx(uint64(l)) + } + } + l = len(m.Spec) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgFundIprpcResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -553,6 +817,223 @@ func (m *MsgSetIprpcDataResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgFundIprpc) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgFundIprpc: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFundIprpc: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Creator = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Duration", wireType) + } + m.Duration = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Duration |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Amounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Amounts = append(m.Amounts, types.Coin{}) + if err := m.Amounts[len(m.Amounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + 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 ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Spec = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgFundIprpcResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgFundIprpcResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgFundIprpcResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/subscription/keeper/cu_tracker.go b/x/subscription/keeper/cu_tracker.go index 2feae44f69..7622fdcd78 100644 --- a/x/subscription/keeper/cu_tracker.go +++ b/x/subscription/keeper/cu_tracker.go @@ -253,7 +253,7 @@ func (k Keeper) RewardAndResetCuTracker(ctx sdk.Context, cuTrackerTimerKeyBytes } else if rewardsRemainder.IsPositive() { { // sub expired (no need to update credit), send rewards remainder to the validators - pool := rewardstypes.ValidatorsRewardsDistributionPoolName + pool := rewardstypes.ValidatorsRewardsAllocationPoolName err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, string(pool), sdk.NewCoins(sdk.NewCoin(k.stakingKeeper.BondDenom(ctx), rewardsRemainder))) if err != nil { utils.LavaFormatError("failed sending remainder of rewards to the community pool", err,