Skip to content

Commit

Permalink
126 add optional override flag when establishing ibc connection (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored Jul 30, 2023
1 parent 27fe7d6 commit 8ddd173
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
13 changes: 8 additions & 5 deletions cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var oneDayRelayPriceRollapp = big.NewInt(1)

var connectionCh string

const (
flagOverride = "override"
)

func Start() *cobra.Command {
relayerStartCmd := &cobra.Command{
Use: "start",
Expand All @@ -39,14 +43,12 @@ func Start() *cobra.Command {
_, _, err = relayer.LoadChannels()
utils.PrettifyErrorIfExists(err)

//TODO: add override flag
if relayer.ChannelReady() {
override := cmd.Flag(flagOverride).Changed
if relayer.ChannelReady() && !override {
fmt.Println("💈 IBC transfer channel is already established!")
} else {
fmt.Println("💈 Establishing IBC transfer channel")

//FIXME: wrap in retries
_, err := relayer.CreateIBCChannel(logFileOption)
_, err := relayer.CreateIBCChannel(override, logFileOption)
utils.PrettifyErrorIfExists(err)
}

Expand All @@ -62,6 +64,7 @@ func Start() *cobra.Command {
},
}

relayerStartCmd.Flags().BoolP(flagOverride, "", false, "override the existing relayer clients and channels")
return relayerStartCmd
}

Expand Down
24 changes: 16 additions & 8 deletions relayer/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import (
)

// Creates an IBC channel between the hub and the client, and return the source channel ID.
func (r *Relayer) CreateIBCChannel(logFileOption utils.CommandOption) (ConnectionChannels, error) {
//TODO: add support for --override flag
createClientsCmd := r.getCreateClientsCmd()
func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOption) (ConnectionChannels, error) {
createClientsCmd := r.getCreateClientsCmd(override)
fmt.Println("💈 Creating clients...")
if err := utils.ExecBashCmd(createClientsCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
Expand All @@ -39,13 +38,13 @@ func (r *Relayer) CreateIBCChannel(logFileOption utils.CommandOption) (Connectio
return ConnectionChannels{}, err
}

createConnectionCmd := r.getCreateConnectionCmd()
createConnectionCmd := r.getCreateConnectionCmd(override)
fmt.Println("💈 Creating connection...")
if err := utils.ExecBashCmd(createConnectionCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
}

createChannelCmd := r.getCreateChannelCmd()
createChannelCmd := r.getCreateChannelCmd(override)
fmt.Println("💈 Creating channel...")
if err := utils.ExecBashCmd(createChannelCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
Expand Down Expand Up @@ -82,20 +81,29 @@ func (r *Relayer) CreateIBCChannel(logFileOption utils.CommandOption) (Connectio
}, nil
}

func (r *Relayer) getCreateClientsCmd() *exec.Cmd {
func (r *Relayer) getCreateClientsCmd(override bool) *exec.Cmd {
args := []string{"tx", "clients"}
args = append(args, r.getRelayerDefaultArgs()...)
if override {
args = append(args, "--override")
}
return exec.Command(consts.Executables.Relayer, args...)
}

func (r *Relayer) getCreateConnectionCmd() *exec.Cmd {
func (r *Relayer) getCreateConnectionCmd(override bool) *exec.Cmd {
args := []string{"tx", "connection", "-t", "300s"}
if override {
args = append(args, "--override")
}
args = append(args, r.getRelayerDefaultArgs()...)
return exec.Command(consts.Executables.Relayer, args...)
}

func (r *Relayer) getCreateChannelCmd() *exec.Cmd {
func (r *Relayer) getCreateChannelCmd(override bool) *exec.Cmd {
args := []string{"tx", "channel", "-t", "300s", "--override"}
if override {
args = append(args, "--override")
}
args = append(args, r.getRelayerDefaultArgs()...)
return exec.Command(consts.Executables.Relayer, args...)
}
Expand Down

0 comments on commit 8ddd173

Please sign in to comment.