Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: force genOrBroadcastFn even when max-msgs != 0 #10477

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would be broadcast a tx with 0 msgs if it's going to be rejected by the node? Shouldn't we just throw an error early?

}

// 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