Skip to content

Commit

Permalink
Add client parameter flags
Browse files Browse the repository at this point in the history
  • Loading branch information
--global authored and akhilkumarpilli committed Apr 12, 2021
1 parent f93962f commit ad042e0
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## [Unreleased]

### Relayer

* [\#491](https://github.com/cosmos/relayer/pull/491) Add client parameter flags to allow governance to update the client if expiry or misbehaviour freezing occurs.
* [\#474](https://github.com/cosmos/relayer/pull/474) Fix validator set mismatch when updating IBC client.
* [\#456](https://github.com/cosmos/relayer/pull/456) Fix bug which incorrectly set the timeout on a transfer.
* [\#455](https://github.com/cosmos/relayer/pull/455) Set default client parameter to allow governance to update the client if expiry or misbehaviour freezing occurs.
Expand Down
64 changes: 40 additions & 24 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,32 @@ import (
)

var (
flagHash = "hash"
flagURL = "url"
flagForce = "force"
flagVersion = "version"
flagSkip = "skip"
flagStrategy = "strategy"
flagTimeout = "timeout"
flagJSON = "json"
flagYAML = "yaml"
flagFile = "file"
flagPort = "port"
flagPath = "path"
flagListenAddr = "listen"
flagTx = "no-tx"
flagBlock = "no-block"
flagData = "data"
flagOrder = "unordered"
flagMaxTxSize = "max-tx-size"
flagMaxMsgLength = "max-msgs"
flagIBCDenoms = "ibc-denoms"
flagTimeoutHeightOffset = "timeout-height-offset"
flagTimeoutTimeOffset = "timeout-time-offset"
flagMaxRetries = "max-retries"
flagThresholdTime = "time-threshold"
flagHash = "hash"
flagURL = "url"
flagForce = "force"
flagVersion = "version"
flagSkip = "skip"
flagStrategy = "strategy"
flagTimeout = "timeout"
flagJSON = "json"
flagYAML = "yaml"
flagFile = "file"
flagPort = "port"
flagPath = "path"
flagListenAddr = "listen"
flagTx = "no-tx"
flagBlock = "no-block"
flagData = "data"
flagOrder = "unordered"
flagMaxTxSize = "max-tx-size"
flagMaxMsgLength = "max-msgs"
flagIBCDenoms = "ibc-denoms"
flagTimeoutHeightOffset = "timeout-height-offset"
flagTimeoutTimeOffset = "timeout-time-offset"
flagMaxRetries = "max-retries"
flagThresholdTime = "time-threshold"
flagUpdateAfterExpiry = "update-after-expiry"
flagUpdateAfterMisbehaviour = "update-after-misbehaviour"
)

func ibcDenomFlags(cmd *cobra.Command) *cobra.Command {
Expand Down Expand Up @@ -268,3 +270,17 @@ func updateTimeFlags(cmd *cobra.Command) *cobra.Command {
}
return cmd
}

func clientParameterFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagUpdateAfterExpiry, "e", true,
"allow governance to update the client if expiry occurs")
cmd.Flags().BoolP(flagUpdateAfterMisbehaviour, "m", true,
"allow governance to update the client if misbehaviour freezing occurs")
if err := viper.BindPFlag(flagUpdateAfterExpiry, cmd.Flags().Lookup(flagUpdateAfterExpiry)); err != nil {
panic(err)
}
if err := viper.BindPFlag(flagUpdateAfterMisbehaviour, cmd.Flags().Lookup(flagUpdateAfterMisbehaviour)); err != nil {
panic(err)
}
return cmd
}
16 changes: 13 additions & 3 deletions cmd/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ func createClientCmd() *cobra.Command {
$ %s transact raw client ibc-0 ibc-1 ibczeroclient
$ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
allowUpdateAfterExpiry, err := cmd.Flags().GetBool(flagUpdateAfterExpiry)
if err != nil {
return err
}

allowUpdateAfterMisbehaviour, err := cmd.Flags().GetBool(flagUpdateAfterMisbehaviour)
if err != nil {
return err
}

src, dst := args[0], args[1]
chains, err := config.Chains.Gets(src, dst)
if err != nil {
Expand Down Expand Up @@ -117,16 +127,16 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)),
dstHeader.GetHeight().(clienttypes.Height),
commitmenttypes.GetSDKSpecs(),
relayer.DefaultUpgradePath,
relayer.AllowUpdateAfterExpiry,
relayer.AllowUpdateAfterMisbehaviour,
allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour,
)

return sendAndPrint([]sdk.Msg{chains[src].CreateClient(
clientState, dstHeader)},
chains[src], cmd)
},
}
return cmd
return clientParameterFlags(cmd)
}

func connInit() *cobra.Command {
Expand Down
45 changes: 39 additions & 6 deletions cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func createClientsCmd() *cobra.Command {
Args: cobra.ExactArgs(1),
Example: strings.TrimSpace(fmt.Sprintf(`$ %s transact clients demo-path`, appName)),
RunE: func(cmd *cobra.Command, args []string) error {
allowUpdateAfterExpiry, err := cmd.Flags().GetBool(flagUpdateAfterExpiry)
if err != nil {
return err
}

allowUpdateAfterMisbehaviour, err := cmd.Flags().GetBool(flagUpdateAfterMisbehaviour)
if err != nil {
return err
}

c, src, dst, err := config.ChainsFromPath(args[0])
if err != nil {
return err
Expand All @@ -122,7 +132,8 @@ func createClientsCmd() *cobra.Command {
return err
}

modified, err := c[src].CreateClients(c[dst])
modified, err := c[src].CreateClients(c[dst], allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour)
if modified {
if err := overWriteConfig(config); err != nil {
return err
Expand All @@ -133,7 +144,7 @@ func createClientsCmd() *cobra.Command {
},
}

return cmd
return clientParameterFlags(cmd)
}

func updateClientsCmd() *cobra.Command {
Expand Down Expand Up @@ -219,6 +230,16 @@ $ %s tx conn demo-path --timeout 5s`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
allowUpdateAfterExpiry, err := cmd.Flags().GetBool(flagUpdateAfterExpiry)
if err != nil {
return err
}

allowUpdateAfterMisbehaviour, err := cmd.Flags().GetBool(flagUpdateAfterMisbehaviour)
if err != nil {
return err
}

c, src, dst, err := config.ChainsFromPath(args[0])
if err != nil {
return err
Expand All @@ -243,7 +264,8 @@ $ %s tx conn demo-path --timeout 5s`,
}

// ensure that the clients exist
modified, err := c[src].CreateClients(c[dst])
modified, err := c[src].CreateClients(c[dst], allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour)
if modified {
if err := overWriteConfig(config); err != nil {
return err
Expand All @@ -264,7 +286,7 @@ $ %s tx conn demo-path --timeout 5s`,
},
}

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

func closeChannelCmd() *cobra.Command {
Expand Down Expand Up @@ -321,6 +343,16 @@ $ %s tx connect demo-path`,
appName, appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
allowUpdateAfterExpiry, err := cmd.Flags().GetBool(flagUpdateAfterExpiry)
if err != nil {
return err
}

allowUpdateAfterMisbehaviour, err := cmd.Flags().GetBool(flagUpdateAfterMisbehaviour)
if err != nil {
return err
}

c, src, dst, err := config.ChainsFromPath(args[0])
if err != nil {
return err
Expand All @@ -345,7 +377,8 @@ $ %s tx connect demo-path`,
}

// create clients if they aren't already created
modified, err := c[src].CreateClients(c[dst])
modified, err := c[src].CreateClients(c[dst], allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour)
if modified {
if err := overWriteConfig(config); err != nil {
return err
Expand Down Expand Up @@ -378,7 +411,7 @@ $ %s tx connect demo-path`,
},
}

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

func linkThenStartCmd() *cobra.Command {
Expand Down
3 changes: 0 additions & 3 deletions relayer/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ var (
rtyAtt = retry.Attempts(rtyAttNum)
rtyDel = retry.Delay(time.Millisecond * 400)
rtyErr = retry.LastErrorOnly(true)

AllowUpdateAfterExpiry = true
AllowUpdateAfterMisbehaviour = true
)

// Chain represents the necessary data for connecting to and indentifying a chain and its counterparites
Expand Down
11 changes: 6 additions & 5 deletions relayer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (

// CreateClients creates clients for src on dst and dst on src if the client ids are unspecified.
// TODO: de-duplicate code
func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) {
func (c *Chain) CreateClients(dst *Chain, allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour bool) (modified bool, err error) {
// Handle off chain light clients
if err := c.ValidateLightInitialized(); err != nil {
return false, err
Expand Down Expand Up @@ -50,8 +51,8 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) {
dstUpdateHeader.GetHeight().(clienttypes.Height),
commitmenttypes.GetSDKSpecs(),
DefaultUpgradePath,
AllowUpdateAfterExpiry,
AllowUpdateAfterMisbehaviour,
allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour,
)

// Check if an identical light client already exists
Expand Down Expand Up @@ -113,8 +114,8 @@ func (c *Chain) CreateClients(dst *Chain) (modified bool, err error) {
srcUpdateHeader.GetHeight().(clienttypes.Height),
commitmenttypes.GetSDKSpecs(),
DefaultUpgradePath,
AllowUpdateAfterExpiry,
AllowUpdateAfterMisbehaviour,
allowUpdateAfterExpiry,
allowUpdateAfterMisbehaviour,
)

// Check if an identical light client already exists
Expand Down
2 changes: 1 addition & 1 deletion test/relayer_akash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestAkashToGaiaStreamingRelayer(t *testing.T) {
require.NoError(t, err)

// create path
_, err = src.CreateClients(dst)
_, err = src.CreateClients(dst, true, true)
require.NoError(t, err)
testClientPair(t, src, dst)

Expand Down
8 changes: 4 additions & 4 deletions test/relayer_gaia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGaiaToGaiaStreamingRelayer(t *testing.T) {
require.NoError(t, err)

// create path
_, err = src.CreateClients(dst)
_, err = src.CreateClients(dst, true, true)
require.NoError(t, err)
testClientPair(t, src, dst)

Expand Down Expand Up @@ -120,7 +120,7 @@ func TestGaiaReuseIdentifiers(t *testing.T) {
require.NoError(t, err)

// create path
_, err = src.CreateClients(dst)
_, err = src.CreateClients(dst, true, true)
require.NoError(t, err)
testClientPair(t, src, dst)

Expand All @@ -143,7 +143,7 @@ func TestGaiaReuseIdentifiers(t *testing.T) {
dst.PathEnd.ConnectionID = ""
dst.PathEnd.ChannelID = ""

_, err = src.CreateClients(dst)
_, err = src.CreateClients(dst, true, true)
require.NoError(t, err)
testClientPair(t, src, dst)

Expand Down Expand Up @@ -171,7 +171,7 @@ func TestGaiaMisbehaviourMonitoring(t *testing.T) {
require.NoError(t, err)

// create path
_, err = src.CreateClients(dst)
_, err = src.CreateClients(dst, true, true)
require.NoError(t, err)
testClientPair(t, src, dst)

Expand Down

0 comments on commit ad042e0

Please sign in to comment.