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

allow splitting withdrawal txs #4384

Merged
merged 11 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .pending/improvements/sdk/4384-WithdrawalTxSplitting
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4384- Allow splitting withdrawal transaction in several chunks
39 changes: 35 additions & 4 deletions x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ var (
flagOnlyFromValidator = "only-from-validator"
flagIsValidator = "is-validator"
flagComission = "commission"
flagMaxMessagesPerTx = "max-msgs"
)

const (
MaxMessagesPerTxDefault = 5
jleni marked this conversation as resolved.
Show resolved Hide resolved
)

// GetTxCmd returns the transaction commands for this module
Expand All @@ -40,6 +45,28 @@ func GetTxCmd(storeKey string, cdc *amino.Codec) *cobra.Command {
return distTxCmd
}

func splitGenerateOrBroadcast(cliCtx context.CLIContext, txBldr authtxb.TxBuilder, msgs []sdk.Msg) error {
jleni marked this conversation as resolved.
Show resolved Hide resolved
chunkSize := viper.GetInt(flagMaxMessagesPerTx)
jleni marked this conversation as resolved.
Show resolved Hide resolved
totalMessages := len(msgs)
if chunkSize == 0 {
chunkSize = totalMessages
jleni marked this conversation as resolved.
Show resolved Hide resolved
}

for i := 0; i < len(msgs); i += chunkSize {
sliceEnd := i + chunkSize
if sliceEnd > totalMessages {
sliceEnd = totalMessages
}
msgChunk := msgs[i:sliceEnd]
err = utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgChunk)
if err != nil {
return err
}
}

return nil
}

// command to withdraw rewards
func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -68,16 +95,17 @@ $ <appcli> tx distr withdraw-rewards cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs
msgs = append(msgs, types.NewMsgWithdrawValidatorCommission(valAddr))
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgs)
return splitGenerateOrBroadcast(cliCtx, txBldr, msgs)
jleni marked this conversation as resolved.
Show resolved Hide resolved
},
}
cmd.Flags().Int(flagMaxMessagesPerTx, MaxMessagesPerTxDefault, "limit the number of messages per tx")
cmd.Flags().Bool(flagComission, false, "also withdraw validator's commission")
return cmd
}

// command to withdraw all rewards
func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "withdraw-all-rewards",
Short: "withdraw all delegations rewards for a delegator",
Long: strings.TrimSpace(`Withdraw all rewards for a single delegator:
Expand All @@ -98,9 +126,11 @@ $ <appcli> tx distr withdraw-all-rewards --from mykey
return err
}

return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, msgs)
return splitGenerateOrBroadcast(cliCtx, txBldr, msgs)
},
}
cmd.Flags().Int(flagMaxMessagesPerTx, MaxMessagesPerTxDefault, "limit the number of messages per tx [zero=unlimited]")
jleni marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}

// command to replace a delegator's withdrawal address
Expand All @@ -127,8 +157,9 @@ $ <appcli> tx set-withdraw-addr cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p --
}

msg := types.NewMsgSetWithdrawAddress(delAddr, withdrawAddr)
return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg})
return splitGenerateOrBroadcast(cliCtx, txBldr, []sdk.Msg{msg})
jleni marked this conversation as resolved.
Show resolved Hide resolved
},
}
cmd.Flags().Int(flagMaxMessagesPerTx, MaxMessagesPerTxDefault, "limit the number of messages per tx")
return cmd
}