Skip to content

Commit

Permalink
fix!: force genOrBroadcastFn even when max-msgs != 0
Browse files Browse the repository at this point in the history
If cli tx withdraw-all-rewards sends empty tx, the tx would be
rejected by validators because it has no msgs. However, the cli sends
empty tx only if one sets `--max-msgs=0` which means it does not split
the msgs. When you set `max-msgs` with any positive number, the cli
does not send any tx, which may confuse you because you cannot get the
feedback indicating the address has no delegations.
This patch addresses the problem, by forcing genOrBroadcastFn when the
number of total msgs generated is zero. It will provide the same user
experience with any `max-msgs`.
  • Loading branch information
0Tech committed Nov 2, 2021
1 parent 4f31170 commit 3a791e3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ func newSplitAndApply(
genOrBroadcastFn newGenerateOrBroadcastFunc, clientCtx client.Context,
fs *pflag.FlagSet, msgs []sdk.Msg, chunkSize int,
) error {

if chunkSize == 0 {
totalMessages := len(msgs)
if chunkSize == 0 || totalMessages == 0 {
return genOrBroadcastFn(clientCtx, fs, msgs...)
}

// split messages into slices of length chunkSize
totalMessages := len(msgs)
for i := 0; i < len(msgs); i += chunkSize {

sliceEnd := i + chunkSize
Expand Down
15 changes: 13 additions & 2 deletions x/distribution/client/cli/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,19 @@ import (
func Test_splitAndCall_NoMessages(t *testing.T) {
clientCtx := client.Context{}

err := newSplitAndApply(nil, clientCtx, nil, nil, 10)
assert.NoError(t, err, "")
// empty tx will always trigger genOrBroadcastFn
maxMsgsCases := []int{0, 1, 10}
calledCounter := 0
for _, maxMsgs := range maxMsgsCases {
err := newSplitAndApply(
func(clientCtx client.Context, fs *pflag.FlagSet, msgs ...sdk.Msg) error {
// dummy genOrBroadcastFn called once for each case
calledCounter++
return nil
}, clientCtx, nil, nil, maxMsgs)
assert.NoError(t, err, "")
}
assert.Equal(t, calledCounter, len(maxMsgsCases))
}

func Test_splitAndCall_Splitting(t *testing.T) {
Expand Down

0 comments on commit 3a791e3

Please sign in to comment.