From adc8a839eac1b423855f93ddb4e50d161d3b6f3d Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Tue, 27 Jul 2021 11:38:33 +0200 Subject: [PATCH 1/5] Improved withdraw-all-rewards UX by forcing BroadcastMode to block if chunk size is not unlimited --- x/distribution/client/cli/tx.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 2b77a55ecea6..20bb98b7287c 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -167,6 +167,12 @@ $ %s tx distribution withdraw-all-rewards --from mykey } chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) + if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { + cmd.Println("Cannot use broadcast mode %s with chunk size that is not 0. Applying broadcast mode block", + clientCtx.BroadcastMode) + clientCtx.BroadcastMode = flags.BroadcastBlock + } + return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize) }, } From 5a69de4f58f568636aca28d6282d911a0e5586f7 Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Tue, 27 Jul 2021 11:47:29 +0200 Subject: [PATCH 2/5] Updated command documentation --- x/distribution/client/cli/tx.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 20bb98b7287c..b2da755ef310 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -126,11 +126,13 @@ func NewWithdrawAllRewardsCmd() *cobra.Command { Short: "withdraw all delegations rewards for a delegator", Long: strings.TrimSpace( fmt.Sprintf(`Withdraw all rewards for a single delegator. +Note that this command will not work if run using --%[2]s=%[3]s or --%[2]s=%[4]s and a chunk size greater than 0. +To make it work with those broadcast modes, you have to use --%[6]s=0, otherwise the broadcast mode %[5]s will be used instead. Example: -$ %s tx distribution withdraw-all-rewards --from mykey +$ %[1]s tx distribution withdraw-all-rewards --from mykey `, - version.AppName, + version.AppName, flags.FlagBroadcastMode, flags.BroadcastSync, flags.BroadcastAsync, flags.BroadcastBlock, FlagMaxMessagesPerTx, ), ), Args: cobra.NoArgs, From 3d7f6b836ad3b191ecbe43b0bf17bf2c071ff80f Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 28 Jul 2021 07:36:17 +0200 Subject: [PATCH 3/5] Updated how to handle withdraw-all-rewards with different broadcast modes --- x/distribution/client/cli/tx.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index b2da755ef310..09567630b899 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -126,13 +126,12 @@ func NewWithdrawAllRewardsCmd() *cobra.Command { Short: "withdraw all delegations rewards for a delegator", Long: strings.TrimSpace( fmt.Sprintf(`Withdraw all rewards for a single delegator. -Note that this command will not work if run using --%[2]s=%[3]s or --%[2]s=%[4]s and a chunk size greater than 0. -To make it work with those broadcast modes, you have to use --%[6]s=0, otherwise the broadcast mode %[5]s will be used instead. +Note that if you use this command with --%[2]s=%[3]s or --%[2]s=%[4]s, the %[5]s flag will automatically be set to 0. Example: $ %[1]s tx distribution withdraw-all-rewards --from mykey `, - version.AppName, flags.FlagBroadcastMode, flags.BroadcastSync, flags.BroadcastAsync, flags.BroadcastBlock, FlagMaxMessagesPerTx, + version.AppName, flags.FlagBroadcastMode, flags.BroadcastSync, flags.BroadcastAsync, FlagMaxMessagesPerTx, ), ), Args: cobra.NoArgs, @@ -170,9 +169,9 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { - cmd.Println("Cannot use broadcast mode %s with chunk size that is not 0. Applying broadcast mode block", - clientCtx.BroadcastMode) - clientCtx.BroadcastMode = flags.BroadcastBlock + cmd.Println("Cannot use broadcast mode %[1]s with %[2]s != 0. Forcing %[2]s to 0", + clientCtx.BroadcastMode, FlagMaxMessagesPerTx) + chunkSize = 0 } return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize) From 3ebce6fab57d00076f6216aa2884f3a13bebf91b Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 28 Jul 2021 11:52:22 +0200 Subject: [PATCH 4/5] Update x/distribution/client/cli/tx.go Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com> --- x/distribution/client/cli/tx.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 09567630b899..822821e24e4c 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -169,7 +169,7 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { - cmd.Println("Cannot use broadcast mode %[1]s with %[2]s != 0. Forcing %[2]s to 0", + cmd.Printf("Cannot use broadcast mode %[1]s with %[2]s != 0. Forcing %[2]s to 0", clientCtx.BroadcastMode, FlagMaxMessagesPerTx) chunkSize = 0 } From 5a40a2c20198bc49328c5615123982964c008765 Mon Sep 17 00:00:00 2001 From: Riccardo Montagnin Date: Wed, 28 Jul 2021 12:45:18 +0200 Subject: [PATCH 5/5] Added CHANGELOG entry --- CHANGELOG.md | 1 + x/distribution/client/cli/tx.go | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 274654745386..c1604ed6e20f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Client Breaking Changes * [\#9594](https://github.com/cosmos/cosmos-sdk/pull/9594) Remove legacy REST API. Please see the [REST Endpoints Migration guide](https://docs.cosmos.network/master/migrations/rest.html) to migrate to the new REST endpoints. +* [\#9781](https://github.com/cosmos/cosmos-sdk/pull/9781) Improve`withdraw-all-rewards` UX when broadcast mode `async` or `async` is used. ### CLI Breaking Changes diff --git a/x/distribution/client/cli/tx.go b/x/distribution/client/cli/tx.go index 09567630b899..ccbf5d8c6dbb 100644 --- a/x/distribution/client/cli/tx.go +++ b/x/distribution/client/cli/tx.go @@ -23,7 +23,7 @@ var ( ) const ( - MaxMessagesPerTxDefault = 5 + MaxMessagesPerTxDefault = 0 ) // NewTxCmd returns a root CLI command handler for all x/distribution transaction commands. @@ -169,9 +169,8 @@ $ %[1]s tx distribution withdraw-all-rewards --from mykey chunkSize, _ := cmd.Flags().GetInt(FlagMaxMessagesPerTx) if clientCtx.BroadcastMode != flags.BroadcastBlock && chunkSize > 0 { - cmd.Println("Cannot use broadcast mode %[1]s with %[2]s != 0. Forcing %[2]s to 0", + return fmt.Errorf("cannot use broadcast mode %[1]s with %[2]s != 0", clientCtx.BroadcastMode, FlagMaxMessagesPerTx) - chunkSize = 0 } return newSplitAndApply(tx.GenerateOrBroadcastTxCLI, clientCtx, cmd.Flags(), msgs, chunkSize)