diff --git a/ibc/relayer.go b/ibc/relayer.go index 3078c7c29..7322239c7 100644 --- a/ibc/relayer.go +++ b/ibc/relayer.go @@ -272,23 +272,36 @@ func (o Order) Validate() error { } // CreateClientOptions contains the configuration for creating a client. + +// a zero value is the same as not specifying the flag and will use the relayer defauls type CreateClientOptions struct { - TrustingPeriod string + TrustingPeriod string + TrustingPeriodPercentage int64 // only available for Go Relayer + MaxClockDrift string } // DefaultClientOpts returns the default settings for creating clients. -// These default options are usually determined by the relayer + +// empty values will use the relayer defaults func DefaultClientOpts() CreateClientOptions { - return CreateClientOptions{ - TrustingPeriod: "0", - } + return CreateClientOptions{} } func (opts CreateClientOptions) Validate() error { - _, err := time.ParseDuration(opts.TrustingPeriod) - if err != nil { - return err + if opts.TrustingPeriod != "" { + _, err := time.ParseDuration(opts.TrustingPeriod) + if err != nil { + return err + } } + + if opts.MaxClockDrift != "" { + _, err := time.ParseDuration(opts.MaxClockDrift) + if err != nil { + return err + } + } + return nil } diff --git a/ibc/relayer_test.go b/ibc/relayer_test.go index 333de7147..b1908bea7 100644 --- a/ibc/relayer_test.go +++ b/ibc/relayer_test.go @@ -34,3 +34,31 @@ func TestChannelOptsConfigured(t *testing.T) { } require.Error(t, opts.Validate()) } + +func TestClientOptsConfigured(t *testing.T) { + // Test the default client opts + opts := DefaultClientOpts() + require.NoError(t, opts.Validate()) + + // Test empty struct client opts + opts = CreateClientOptions{} + require.NoError(t, opts.Validate()) + + // Test partial client opts + opts = CreateClientOptions{ + MaxClockDrift: "5m", + } + require.NoError(t, opts.Validate()) + + // Test invalid MaxClockDrift + opts = CreateClientOptions{ + MaxClockDrift: "invalid duration", + } + require.Error(t, opts.Validate()) + + // Test invalid TrustingPeriod + opts = CreateClientOptions{ + TrustingPeriod: "invalid duration", + } + require.Error(t, opts.Validate()) +} diff --git a/relayer/hermes/hermes_relayer.go b/relayer/hermes/hermes_relayer.go index 3b3985e3a..d1fe0eae8 100644 --- a/relayer/hermes/hermes_relayer.go +++ b/relayer/hermes/hermes_relayer.go @@ -194,9 +194,12 @@ func (r *Relayer) UpdateClients(ctx context.Context, rep ibc.RelayerExecReporter func (r *Relayer) CreateClients(ctx context.Context, rep ibc.RelayerExecReporter, pathName string, opts ibc.CreateClientOptions) error { pathConfig := r.paths[pathName] chainACreateClientCmd := []string{hermes, "--json", "create", "client", "--host-chain", pathConfig.chainA.chainID, "--reference-chain", pathConfig.chainB.chainID} - if opts.TrustingPeriod != "0" { + if opts.TrustingPeriod != "" { chainACreateClientCmd = append(chainACreateClientCmd, "--trusting-period", opts.TrustingPeriod) } + if opts.MaxClockDrift != "" { + chainACreateClientCmd = append(chainACreateClientCmd, "--clock-drift", opts.MaxClockDrift) + } res := r.Exec(ctx, rep, chainACreateClientCmd, nil) if res.Err != nil { return res.Err @@ -209,9 +212,12 @@ func (r *Relayer) CreateClients(ctx context.Context, rep ibc.RelayerExecReporter pathConfig.chainA.clientID = chainAClientId chainBCreateClientCmd := []string{hermes, "--json", "create", "client", "--host-chain", pathConfig.chainB.chainID, "--reference-chain", pathConfig.chainA.chainID} - if opts.TrustingPeriod != "0" { + if opts.TrustingPeriod != "" { chainBCreateClientCmd = append(chainBCreateClientCmd, "--trusting-period", opts.TrustingPeriod) } + if opts.MaxClockDrift != "" { + chainBCreateClientCmd = append(chainBCreateClientCmd, "--clock-drift", opts.MaxClockDrift) + } res = r.Exec(ctx, rep, chainBCreateClientCmd, nil) if res.Err != nil { return res.Err diff --git a/relayer/rly/cosmos_relayer.go b/relayer/rly/cosmos_relayer.go index e0e35989f..efc03611f 100644 --- a/relayer/rly/cosmos_relayer.go +++ b/relayer/rly/cosmos_relayer.go @@ -139,18 +139,46 @@ func (commander) CreateChannel(pathName string, opts ibc.CreateChannelOptions, h } } -func (commander) CreateClients(pathName string, opts ibc.CreateClientOptions, homeDir string) []string { - return []string{ - "rly", "tx", "clients", pathName, "--client-tp", opts.TrustingPeriod, - "--home", homeDir, +func createClientOptsHelper(opts ibc.CreateClientOptions) []string { + var clientOptions []string + if opts.TrustingPeriod != "" { + clientOptions = append(clientOptions, "--client-tp", opts.TrustingPeriod) } + if opts.TrustingPeriodPercentage != 0 { + clientOptions = append(clientOptions, "--client-tp-percentage", fmt.Sprint(opts.TrustingPeriodPercentage)) + } + if opts.MaxClockDrift != "" { + clientOptions = append(clientOptions, "--max-clock-drift", opts.MaxClockDrift) + } + + return clientOptions } +func (commander) CreateClients(pathName string, opts ibc.CreateClientOptions, homeDir string) []string { + cmd := []string{"rly", "tx", "clients", pathName, "--home", homeDir} + + clientOptions := createClientOptsHelper(opts) + cmd = append(cmd, clientOptions...) + + return cmd +} + +<<<<<<< HEAD func (commander) CreateClient(srcChainID, dstChainID, pathName string, opts ibc.CreateClientOptions, homeDir string) []string { return []string{ "rly", "tx", "client", srcChainID, dstChainID, pathName, "--client-tp", opts.TrustingPeriod, "--home", homeDir, } +======= +// passing a value of 0 for customeClientTrustingPeriod will use default +func (commander) CreateClient(pathName, homeDir string, opts ibc.CreateClientOptions) []string { + cmd := []string{"rly", "tx", "client", pathName, "--home", homeDir} + + clientOptions := createClientOptsHelper(opts) + cmd = append(cmd, clientOptions...) + + return cmd +>>>>>>> 401a813 (Add create client options (#922)) } func (commander) CreateConnections(pathName string, homeDir string) []string { @@ -235,17 +263,20 @@ func (commander) GetClients(chainID, homeDir string) []string { } func (commander) LinkPath(pathName, homeDir string, channelOpts ibc.CreateChannelOptions, clientOpt ibc.CreateClientOptions) []string { - return []string{ + cmd := []string{ "rly", "tx", "link", pathName, "--src-port", channelOpts.SourcePortName, "--dst-port", channelOpts.DestPortName, "--order", channelOpts.Order.String(), "--version", channelOpts.Version, - "--client-tp", clientOpt.TrustingPeriod, "--debug", - "--home", homeDir, } + + clientOptions := createClientOptsHelper(clientOpt) + cmd = append(cmd, clientOptions...) + + return cmd } func (commander) RestoreKey(chainID, keyName, coinType, mnemonic, homeDir string) []string {