From ea235a1302712e58c7446b94a8feece30aef26df Mon Sep 17 00:00:00 2001 From: Yaroms <103432884+Yaroms@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:46:18 +0300 Subject: [PATCH] fix: CNS-fix-tracked-cu-query (#1639) * fix and remove warning * fix CLI * support mincost not mendatory * lint * fix cli name * add title and desc flags --------- Co-authored-by: Yarom Swisa --- x/epochstorage/keeper/stake_entries.go | 4 -- .../client/cli/query_spec_tracked_info.go | 16 ++++---- x/rewards/client/cli/tx.go | 41 +++++++++++++------ ...ard.go => grpc_query_spec_tracked_info.go} | 0 .../cli/query_estimated_validators_rewards.go | 2 +- .../keeper/grpc_query_tracked_usage.go | 2 +- 6 files changed, 38 insertions(+), 27 deletions(-) rename x/rewards/keeper/{grpc_query_provider_reward.go => grpc_query_spec_tracked_info.go} (100%) diff --git a/x/epochstorage/keeper/stake_entries.go b/x/epochstorage/keeper/stake_entries.go index cc8d0684d8..0c4a49630f 100644 --- a/x/epochstorage/keeper/stake_entries.go +++ b/x/epochstorage/keeper/stake_entries.go @@ -224,10 +224,6 @@ func (k Keeper) GetAllStakeEntriesCurrentForChainId(ctx sdk.Context, chainID str func (k Keeper) GetStakeEntryCurrentForChainIdByVault(ctx sdk.Context, chainID string, vault string) (val types.StakeEntry, found bool) { pk, err := k.stakeEntriesCurrent.Indexes.Index.MatchExact(ctx, collections.Join(chainID, vault)) if err != nil { - utils.LavaFormatWarning("GetStakeEntryCurrentForChainIdByVault: MatchExact with primary key failed", err, - utils.LogAttr("chain_id", chainID), - utils.LogAttr("vault", vault), - ) return types.StakeEntry{}, false } diff --git a/x/rewards/client/cli/query_spec_tracked_info.go b/x/rewards/client/cli/query_spec_tracked_info.go index d65543a0d6..3045bf1f72 100644 --- a/x/rewards/client/cli/query_spec_tracked_info.go +++ b/x/rewards/client/cli/query_spec_tracked_info.go @@ -28,18 +28,18 @@ func CmdSpecTrackedInfo() *cobra.Command { Args: cobra.RangeArgs(1, 2), RunE: func(cmd *cobra.Command, args []string) (err error) { - reqChainID := "" - if len(args) == 2 { - reqChainID = args[0] - } - clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } - reqProvider, err := utils.ParseCLIAddress(clientCtx, args[1]) - if err != nil { - return err + + reqChainID := args[0] + reqProvider := "" + if len(args) == 2 { + reqProvider, err = utils.ParseCLIAddress(clientCtx, args[1]) + if err != nil { + return err + } } queryClient := types.NewQueryClient(clientCtx) diff --git a/x/rewards/client/cli/tx.go b/x/rewards/client/cli/tx.go index 5d477b1e14..0849a7be87 100644 --- a/x/rewards/client/cli/tx.go +++ b/x/rewards/client/cli/tx.go @@ -27,6 +27,8 @@ const ( listSeparator = "," expeditedFlagName = "expedited" minIprpcCostFlagName = "min-cost" + titleFlagName = "title" + descriptionFlagName = "description" addIprpcSubscriptionsFlagName = "add-subscriptions" removeIprpcSubscriptionsFlagName = "remove-subscriptions" ) @@ -80,16 +82,6 @@ $ %s tx gov submit-legacy-proposal set-iprpc-data --min-cost 0ulava --add-subscr return err } - // get min cost - costStr, err := cmd.Flags().GetString(minIprpcCostFlagName) - if err != nil { - return err - } - cost, err := sdk.ParseCoinNormalized(costStr) - if err != nil { - return err - } - // get current iprpc subscriptions q := types.NewQueryClient(clientCtx) res, err := q.ShowIprpcData(context.Background(), &types.QueryShowIprpcDataRequest{}) @@ -98,6 +90,19 @@ $ %s tx gov submit-legacy-proposal set-iprpc-data --min-cost 0ulava --add-subscr } subs := res.IprpcSubscriptions + // get min cost + costStr, err := cmd.Flags().GetString(minIprpcCostFlagName) + if err != nil { + return err + } + cost := res.MinCost + if costStr != "" { + cost, err = sdk.ParseCoinNormalized(costStr) + if err != nil { + return err + } + } + // add from msg subsToAdd, err := cmd.Flags().GetStringSlice(addIprpcSubscriptionsFlagName) if err != nil { @@ -135,7 +140,16 @@ $ %s tx gov submit-legacy-proposal set-iprpc-data --min-cost 0ulava --add-subscr MinIprpcCost: cost, } - submitPropMsg, err := govv1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, from.String(), "", "Set IPRPC data", "Set IPRPC data", isExpedited) + title, err := cmd.Flags().GetString(titleFlagName) + if err != nil { + return err + } + + description, err := cmd.Flags().GetString(descriptionFlagName) + if err != nil { + return err + } + submitPropMsg, err := govv1.NewMsgSubmitProposal([]sdk.Msg{&msg}, deposit, from.String(), "", title, description, isExpedited) if err != nil { return err } @@ -143,10 +157,11 @@ $ %s tx gov submit-legacy-proposal set-iprpc-data --min-cost 0ulava --add-subscr return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), submitPropMsg) }, } - cmd.Flags().String(minIprpcCostFlagName, "0ulava", "set minimum iprpc cost") + cmd.Flags().String(minIprpcCostFlagName, "", "set minimum iprpc cost") + cmd.Flags().String(titleFlagName, "Set IPRPC data", "proposal title") + cmd.Flags().String(descriptionFlagName, "Set IPRPC data", "proposal description") cmd.Flags().StringSlice(addIprpcSubscriptionsFlagName, []string{}, "add iprpc eligible subscriptions") cmd.Flags().StringSlice(removeIprpcSubscriptionsFlagName, []string{}, "remove iprpc eligible subscriptions") cmd.Flags().Bool(expeditedFlagName, false, "set to true to make the spec proposal expedited") - cmd.MarkFlagRequired(minIprpcCostFlagName) return cmd } diff --git a/x/rewards/keeper/grpc_query_provider_reward.go b/x/rewards/keeper/grpc_query_spec_tracked_info.go similarity index 100% rename from x/rewards/keeper/grpc_query_provider_reward.go rename to x/rewards/keeper/grpc_query_spec_tracked_info.go diff --git a/x/subscription/client/cli/query_estimated_validators_rewards.go b/x/subscription/client/cli/query_estimated_validators_rewards.go index da08bf7803..1b805f8742 100644 --- a/x/subscription/client/cli/query_estimated_validators_rewards.go +++ b/x/subscription/client/cli/query_estimated_validators_rewards.go @@ -10,7 +10,7 @@ import ( func CmdEstimatedValidatorsRewards() *cobra.Command { cmd := &cobra.Command{ - Use: "estimated--validator-rewards [validator] {optional: amount/delegator}", + Use: "estimated-validator-rewards [validator] {optional: amount/delegator}", Short: "calculates the rewards estimation for a validator delegation", Long: `Query to estimate the rewards a delegator will get for 1 month from the validator, if used without optional args the calculations will be for the validator itself. optional args can be amount for new delegation or address for an existing one. diff --git a/x/subscription/keeper/grpc_query_tracked_usage.go b/x/subscription/keeper/grpc_query_tracked_usage.go index 255ba69de5..5312864f53 100644 --- a/x/subscription/keeper/grpc_query_tracked_usage.go +++ b/x/subscription/keeper/grpc_query_tracked_usage.go @@ -20,7 +20,7 @@ func (k Keeper) TrackedUsage(goCtx context.Context, req *types.QuerySubscription sub, _ := k.GetSubscription(ctx, req.Subscription) res.Subscription = &sub - res.Usage, res.TotalUsage = k.GetSubTrackedCuInfo(ctx, req.Subscription, uint64(ctx.BlockHeader().Height)) + res.Usage, res.TotalUsage = k.GetSubTrackedCuInfo(ctx, req.Subscription, sub.Block) return &res, nil }