Skip to content

Commit

Permalink
Add create client options (#922)
Browse files Browse the repository at this point in the history
* add create client options

* hermes

* remove comment

* fix comment

(cherry picked from commit 401a813)

# Conflicts:
#	relayer/rly/cosmos_relayer.go
  • Loading branch information
boojamya authored and mergify[bot] committed Feb 2, 2024
1 parent 4513200 commit 292af00
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 17 deletions.
29 changes: 21 additions & 8 deletions ibc/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
28 changes: 28 additions & 0 deletions ibc/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
10 changes: 8 additions & 2 deletions relayer/hermes/hermes_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
45 changes: 38 additions & 7 deletions relayer/rly/cosmos_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / lint

expected declaration, found '<<' (typecheck)

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: non-declaration statement outside function body

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: non-declaration statement outside function body

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: non-declaration statement outside function body

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: non-declaration statement outside function body

Check failure on line 166 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: non-declaration statement outside function body
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,
}
=======

Check failure on line 172 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected ==, expecting }

Check failure on line 172 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected ==, expecting }

Check failure on line 172 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected ==, expecting }

Check failure on line 172 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected ==, expecting }

Check failure on line 172 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected ==, expecting }
// 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))

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / lint

illegal character U+0023 '#' (typecheck)

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-conformance

syntax error: unexpected >>, expecting }

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-conformance

invalid character U+0023 '#'

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected >>, expecting }

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

invalid character U+0023 '#'

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

syntax error: unexpected >>, expecting }

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / unit-tests

invalid character U+0023 '#'

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

syntax error: unexpected >>, expecting }

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-cosmos-examples

invalid character U+0023 '#'

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

syntax error: unexpected >>, expecting }

Check failure on line 181 in relayer/rly/cosmos_relayer.go

View workflow job for this annotation

GitHub Actions / test-ibc-examples

invalid character U+0023 '#'
}

func (commander) CreateConnections(pathName string, homeDir string) []string {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 292af00

Please sign in to comment.