From 16afc9e72e2d993fb9441149ec276bc1cd5d5fbb Mon Sep 17 00:00:00 2001 From: omritoptix Date: Tue, 5 Sep 2023 17:12:33 +0200 Subject: [PATCH] Fixed connection-id missing key would cause relayer start to fail if active channels existed before. --- relayer/channels.go | 15 +++++++++++---- relayer/create_ibc_channel.go | 2 +- utils/errors.go | 11 +++++++++++ utils/yaml.go | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 utils/errors.go diff --git a/relayer/channels.go b/relayer/channels.go index b872a53f..b4fe4c21 100644 --- a/relayer/channels.go +++ b/relayer/channels.go @@ -7,11 +7,13 @@ import ( "path/filepath" "github.com/dymensionxyz/roller/cmd/consts" - "github.com/dymensionxyz/roller/cmd/utils" + cmdutils "github.com/dymensionxyz/roller/cmd/utils" + "github.com/dymensionxyz/roller/utils" ) +// TODO: Change to use the connection for fetching relevant channel using connection-channels rly command func (r *Relayer) LoadActiveChannel() (string, string, error) { - output, err := utils.ExecBashCommandWithStdout(r.queryChannelsRollappCmd()) + output, err := cmdutils.ExecBashCommandWithStdout(r.queryChannelsRollappCmd()) if err != nil { return "", "", err } @@ -27,7 +29,12 @@ func (r *Relayer) LoadActiveChannel() (string, string, error) { activeConnectionID, err = r.GetActiveConnection() if err != nil { - return "", "", err + if keyErr, ok := err.(*utils.KeyNotFoundError); ok { + r.logger.Printf("No active connection found. Key not found: %v", keyErr) + return "", "", nil + } else { + return "", "", err + } } if activeConnectionID == "" { return "", "", nil @@ -52,7 +59,7 @@ func (r *Relayer) LoadActiveChannel() (string, string, error) { // found STATE_OPEN channel // Check if the channel is open on the hub var res HubQueryResult - outputHub, err := utils.ExecBashCommandWithStdout(r.queryChannelsHubCmd(outputStruct.Counterparty.ChannelID)) + outputHub, err := cmdutils.ExecBashCommandWithStdout(r.queryChannelsHubCmd(outputStruct.Counterparty.ChannelID)) if err != nil { return "", "", err } diff --git a/relayer/create_ibc_channel.go b/relayer/create_ibc_channel.go index 0db0dce0..4c597a78 100644 --- a/relayer/create_ibc_channel.go +++ b/relayer/create_ibc_channel.go @@ -35,7 +35,7 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt utils.RunCommandEvery(ctx, updateClientsCmd.Path, updateClientsCmd.Args[1:], 20, utils.WithDiscardLogging()) //wait for block to be created - status = "Creating block..." + status = "Waiting for block creation..." fmt.Printf("💈 %s\n", status) if err := r.WriteRelayerStatus(status); err != nil { return ConnectionChannels{}, err diff --git a/utils/errors.go b/utils/errors.go new file mode 100644 index 00000000..eae287b8 --- /dev/null +++ b/utils/errors.go @@ -0,0 +1,11 @@ +package utils + +import "fmt" + +type KeyNotFoundError struct { + Key string +} + +func (e *KeyNotFoundError) Error() string { + return fmt.Sprintf("key not found: %s", e.Key) +} diff --git a/utils/yaml.go b/utils/yaml.go index fa5a573a..1e5b151b 100644 --- a/utils/yaml.go +++ b/utils/yaml.go @@ -27,7 +27,7 @@ func GetNestedValue(data map[interface{}]interface{}, keyPath []string) (interfa } value, ok := data[keyPath[0]] if !ok { - return nil, fmt.Errorf("key not found: %s", keyPath[0]) + return nil, &KeyNotFoundError{Key: keyPath[0]} } if len(keyPath) == 1 { return value, nil