diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b85b23eb..e78d050dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### 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. * [\#488](https://github.com/cosmos/relayer/pull/488) Fix state based relaying for acknowledgements. * [\#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. diff --git a/cmd/flags.go b/cmd/flags.go index 97ebcb028..4972bfe05 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -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 { @@ -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 +} diff --git a/cmd/raw.go b/cmd/raw.go index 7736a52ee..96bd16f50 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -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 { @@ -117,8 +127,8 @@ $ %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( @@ -126,7 +136,7 @@ $ %s tx raw clnt ibc-1 ibc-0 ibconeclient`, appName, appName)), chains[src], cmd) }, } - return cmd + return clientParameterFlags(cmd) } func connInit() *cobra.Command { diff --git a/cmd/tx.go b/cmd/tx.go index dca858042..34779d962 100644 --- a/cmd/tx.go +++ b/cmd/tx.go @@ -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 @@ -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 @@ -133,7 +144,7 @@ func createClientsCmd() *cobra.Command { }, } - return cmd + return clientParameterFlags(cmd) } func updateClientsCmd() *cobra.Command { @@ -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 @@ -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 @@ -264,7 +286,7 @@ $ %s tx conn demo-path --timeout 5s`, }, } - return retryFlag(timeoutFlag(cmd)) + return clientParameterFlags(retryFlag(timeoutFlag(cmd))) } func closeChannelCmd() *cobra.Command { @@ -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 @@ -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 @@ -378,7 +411,7 @@ $ %s tx connect demo-path`, }, } - return retryFlag(timeoutFlag(cmd)) + return clientParameterFlags(retryFlag(timeoutFlag(cmd))) } func linkThenStartCmd() *cobra.Command { diff --git a/relayer/chain.go b/relayer/chain.go index b7e6df55d..469b9ca8e 100644 --- a/relayer/chain.go +++ b/relayer/chain.go @@ -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 diff --git a/relayer/client.go b/relayer/client.go index 02ad52831..e9a323b56 100644 --- a/relayer/client.go +++ b/relayer/client.go @@ -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 @@ -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 @@ -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 diff --git a/test/relayer_akash_test.go b/test/relayer_akash_test.go index 25eb15f49..dda32ff3c 100644 --- a/test/relayer_akash_test.go +++ b/test/relayer_akash_test.go @@ -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) diff --git a/test/relayer_gaia_test.go b/test/relayer_gaia_test.go index c63eca44b..580c28d1b 100644 --- a/test/relayer_gaia_test.go +++ b/test/relayer_gaia_test.go @@ -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) @@ -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) @@ -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) @@ -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)