Skip to content

Commit

Permalink
Add flag for amount of retries (cosmos#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
akhilkumarpilli committed Jan 18, 2021
1 parent 978a993 commit 565ce8f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
9 changes: 9 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
flagIBCDenoms = "ibc-denoms"
flagTimeoutHeightOffset = "timeout-height-offset"
flagTimeoutTimeOffset = "timeout-time-offset"
flagMaxRetries = "max-retries"
)

func ibcDenomFlags(cmd *cobra.Command) *cobra.Command {
Expand Down Expand Up @@ -249,3 +250,11 @@ func getAddInputs(cmd *cobra.Command) (file string, url string, err error) {

return
}

func retryFlag(cmd *cobra.Command) *cobra.Command {
cmd.Flags().Uint64P(flagMaxRetries, "r", 3, "maximum retries after failed message send")
if err := viper.BindPFlag(flagMaxRetries, cmd.Flags().Lookup(flagMaxRetries)); err != nil {
panic(err)
}
return cmd
}
30 changes: 21 additions & 9 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ $ %s tx con demo-path -o 3s`, appName, appName, appName)),
return err
}

retries, err := cmd.Flags().GetUint64(flagMaxRetries)
if err != nil {
return err
}

// ensure that keys exist
if _, err = c[src].GetAddress(); err != nil {
return err
Expand All @@ -196,8 +201,7 @@ $ %s tx con demo-path -o 3s`, appName, appName, appName)),
return err
}

// TODO: make '3' be a flag, maximum retries after failed message send
modified, err := c[src].CreateOpenConnections(c[dst], 3, to)
modified, err := c[src].CreateOpenConnections(c[dst], retries, to)
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
Expand All @@ -208,7 +212,7 @@ $ %s tx con demo-path -o 3s`, appName, appName, appName)),
},
}

return timeoutFlag(cmd)
return retryFlag(timeoutFlag(cmd))
}

func createChannelCmd() *cobra.Command {
Expand All @@ -234,6 +238,11 @@ $ %s tx ch demo-path -o 3s`, appName, appName, appName)),
return err
}

retries, err := cmd.Flags().GetUint64(flagMaxRetries)
if err != nil {
return err
}

// ensure that keys exist
if _, err = c[src].GetAddress(); err != nil {
return err
Expand All @@ -242,8 +251,7 @@ $ %s tx ch demo-path -o 3s`, appName, appName, appName)),
return err
}

// TODO: make '3' a flag, max retries after failed message send
modified, err := c[src].CreateOpenChannels(c[dst], 3, to)
modified, err := c[src].CreateOpenChannels(c[dst], retries, to)
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
Expand All @@ -255,7 +263,7 @@ $ %s tx ch demo-path -o 3s`, appName, appName, appName)),
},
}

return timeoutFlag(cmd)
return retryFlag(timeoutFlag(cmd))
}

func closeChannelCmd() *cobra.Command {
Expand Down Expand Up @@ -319,6 +327,11 @@ $ %s tx pth demo-path`, appName, appName, appName, appName, appName)),
return err
}

retries, err := cmd.Flags().GetUint64(flagMaxRetries)
if err != nil {
return err
}

// ensure that keys exist
if _, err = c[src].GetAddress(); err != nil {
return err
Expand All @@ -337,9 +350,8 @@ $ %s tx pth demo-path`, appName, appName, appName, appName, appName)),
return err
}

// TODO: make '3' a flag, maximum retries after failed message send
// create connection if it isn't already created
modified, err = c[src].CreateOpenConnections(c[dst], 3, to)
modified, err = c[src].CreateOpenConnections(c[dst], retries, to)
if modified {
if err := overWriteConfig(cmd, config); err != nil {
return err
Expand All @@ -360,7 +372,7 @@ $ %s tx pth demo-path`, appName, appName, appName, appName, appName)),
},
}

return timeoutFlag(cmd)
return retryFlag(timeoutFlag(cmd))
}

func linkThenStartCmd() *cobra.Command {
Expand Down

0 comments on commit 565ce8f

Please sign in to comment.