Skip to content

Commit

Permalink
fix: ibc clients creation stuck (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
omritoptix committed Dec 17, 2023
1 parent b985f25 commit b60d9e1
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 63 deletions.
6 changes: 3 additions & 3 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ var Hubs = map[string]config.HubData{
GAS_PRICE: "0.25",
},
FroopylandHubName: {
API_URL: "https://froopyland.api.silknodes.io:443",
API_URL: "https://froopyland.blockpi.network:443/lcd/v1/public",
ID: "froopyland_100-1",
RPC_URL: "https://froopyland.rpc.silknodes.io:443",
ARCHIVE_RPC_URL: "https://froopy-archive.rpc.silknodes.io:443",
RPC_URL: "https://froopyland.blockpi.network:443/rpc/v1/public",
ARCHIVE_RPC_URL: "https://froopyland.blockpi.network:443/rpc/v1/public",
GAS_PRICE: "0.25",
},
LocalHubName: {
Expand Down
6 changes: 3 additions & 3 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ var SpinnerMsgs = struct {
}

var FroopylandHubData = config.HubData{
API_URL: "https://froopyland.api.silknodes.io:443",
API_URL: "https://froopyland.blockpi.network:443/lcd/v1/public",
ID: FroopylandHubID,
RPC_URL: "https://froopyland.rpc.silknodes.io:443",
ARCHIVE_RPC_URL: "https://froopy-archive.rpc.silknodes.io:443",
RPC_URL: "https://froopyland.blockpi.network:443/rpc/v1/public",
ARCHIVE_RPC_URL: "https://froopyland.blockpi.network:443/rpc/v1/public",
GAS_PRICE: "0.25",
}

Expand Down
32 changes: 32 additions & 0 deletions relayer/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package relayer

import (
"github.com/dymensionxyz/roller/cmd/consts"
roller_utils "github.com/dymensionxyz/roller/utils"
)

func (r *Relayer) CheckClientsExist() (bool, error) {
rlyCfg, err := ReadRlyConfig(r.Home)
if err != nil {
return false, err

}
clientIDRollapp_raw, err := roller_utils.GetNestedValue(rlyCfg, []string{"paths", consts.DefaultRelayerPath, "dst", "client-id"})
if err != nil {
return false, err
}

clientIDHub_raw, err := roller_utils.GetNestedValue(rlyCfg, []string{"paths", consts.DefaultRelayerPath, "src", "client-id"})
if err != nil {
return false, err
}

clientIDRollapp := clientIDRollapp_raw.(string)
clientIDHub := clientIDHub_raw.(string)

if clientIDRollapp == "" || clientIDHub == "" {
r.logger.Printf("can't find clients in the config for both rollapp and hub")
return false, nil
}
return true, nil
}
151 changes: 94 additions & 57 deletions relayer/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,80 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

//after successful update clients, keep running in the background
updateClientsCmd := r.GetUpdateClientsCmd()
utils.RunCommandEvery(ctx, updateClientsCmd.Path, updateClientsCmd.Args[1:], 20, utils.WithDiscardLogging())

//wait for block to be created
status := "Waiting for state update before creating the channel..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
// Run send funds command from sequencer to itself to make sure the chain is
// progressing for connection and channel creation.
// replaced update clients to avoid account sequence mismatch and
// premature heights updates e.g "TrustedHeight {1 x} must be less than header height {1 y}"
sequecerAddress, err := utils.GetAddressBinary(utils.KeyConfig{
Dir: filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeysIds.RollappSequencer,
}, seq.RlpCfg.RollappBinary)
if err != nil {
return ConnectionChannels{}, err
}
if err := waitForValidRollappHeight(seq); err != nil {
return ConnectionChannels{}, err
sendFundsCmd := seq.GetSendCmd(sequecerAddress)
utils.RunCommandEvery(ctx, sendFundsCmd.Path, sendFundsCmd.Args[1:], 5, utils.WithDiscardLogging())

var status string

// Create client if it doesn't exist or override is true
clientsExist := false
if !override {
// Check if clients exist
clientsExist, _ = r.CheckClientsExist()
}
if !clientsExist {
//wait for block to be created
status = "Validating rollapp height > 2 before creating clients..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
}
if err := waitForValidRollappHeight(seq); err != nil {
return ConnectionChannels{}, err
}
// We always pass override otherwise this command hangs if there are too many clients
// in the hub as it iterates all to check if this client exists
createClientsCmd := r.getCreateClientsCmd(true)
status = "Creating clients..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
}
if err := utils.ExecBashCmd(createClientsCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
}
}

// Sleep for a few seconds to make sure the clients are created
// otherwise the connection creation attempt fails
time.Sleep(10 * time.Second)

connectionID, _ := r.GetActiveConnection()
if connectionID == "" || override {
status = "Creating connection..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
}
createConnectionCmd := r.getCreateConnectionCmd(override)
if err := utils.ExecBashCmd(createConnectionCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
}
}

var src, dst string

// Sleep for a few seconds to make sure the connection is created
time.Sleep(15 * time.Second)
// we ran create channel with override, as it not recovarable anyway
createLinkCmd := r.getCreateLinkCmd(override)
status = "Creating link..."
createChannelCmd := r.getCreateChannelCmd(true)
status = "Creating channel..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
}
if err := utils.ExecBashCmd(createLinkCmd, logFileOption); err != nil {
if err := utils.ExecBashCmd(createChannelCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
}
status = "Validating channel established..."
Expand All @@ -51,7 +102,7 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt
return ConnectionChannels{}, err
}

src, dst, err := r.LoadActiveChannel()
src, dst, err = r.LoadActiveChannel()
if err != nil {
return ConnectionChannels{}, err
}
Expand All @@ -69,64 +120,50 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt
}, nil
}

// waitForValidRollappHeight waits for the rollapp height to be greater than 2 otherwise
// it will fail to create clients.
func waitForValidRollappHeight(seq *sequencer.Sequencer) error {
initialHubHeightStr, err := seq.GetHubHeight()
if err != nil {
return err
}
initialHubHeight, err := strconv.Atoi(initialHubHeightStr)
if err != nil {
return err
}
initialRollappHeightStr, err := seq.GetRollappHeight()
if err != nil {
return err
}
initialRollappHeight, err := strconv.Atoi(initialRollappHeightStr)
if err != nil {
return err
}
logger := utils.GetRollerLogger(seq.RlpCfg.Home)
for {
time.Sleep(30 * time.Second)
hubHeightStr, err := seq.GetHubHeight()
if err != nil {
fmt.Printf("💈 Error getting rollapp hub height, %s", err.Error())
continue
}
hubHeight, err := strconv.Atoi(hubHeightStr)
if err != nil {
fmt.Printf("💈 Error converting hub height to int, %s", err.Error())
continue
}
if hubHeight < 3 {
fmt.Printf("💈 Waiting for the rollapp height on the hub to be greater than 2, current height: %d\n", hubHeight)
continue
}
if hubHeight <= initialHubHeight {
fmt.Printf("💈 Waiting for the rollapp height on the hub to be greater than initial height,"+
" initial height: %d, current height: %d\n", initialHubHeight, hubHeight)
continue
}
time.Sleep(10 * time.Second)
rollappHeightStr, err := seq.GetRollappHeight()
if err != nil {
fmt.Printf("💈 Error getting rollapp height, %s", err.Error())
logger.Printf("💈 Error getting rollapp height, %s", err.Error())
continue
}
rollappHeight, err := strconv.Atoi(rollappHeightStr)
if err != nil {
fmt.Printf("💈 Error converting rollapp height to int, %s", err.Error())
logger.Printf("💈 Error converting rollapp height to int, %s", err.Error())
continue
}
if rollappHeight <= initialRollappHeight {
fmt.Printf("💈 Waiting for rollapp height to be greater than initial height,"+
" initial height: %d,current height: %d\n", initialRollappHeight, rollappHeight)
if rollappHeight <= 2 {
logger.Printf("💈 Waiting for rollapp height to be greater than 2")
continue
}
return nil
}
}

func (r *Relayer) getCreateLinkCmd(override bool) *exec.Cmd {
args := []string{"tx", "link", "-t", "300s", "--src-port", "transfer", "--dst-port", "transfer", "--version", "ics20-1"}
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(override bool) *exec.Cmd {
args := []string{"tx", "connection"}
if override {
args = append(args, "--override")
}
args = append(args, r.getRelayerDefaultArgs()...)
return exec.Command(consts.Executables.Relayer, args...)
}

func (r *Relayer) getCreateChannelCmd(override bool) *exec.Cmd {
args := []string{"tx", "channel", "-t", "60s", "-d"}
if override {
args = append(args, "--override")
}
Expand Down
23 changes: 23 additions & 0 deletions sequencer/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sequencer

import (
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
)

// TODO(FIXME): Assumptions on rollapp price and keyring backend
func (seq *Sequencer) GetSendCmd(destAddress string) *exec.Cmd {
rollappConfigDir := filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp)
cmd := exec.Command(
seq.RlpCfg.RollappBinary,
"tx", "bank", "send",
consts.KeysIds.RollappSequencer, destAddress, "1"+seq.RlpCfg.Denom,
"--home", rollappConfigDir,
"--broadcast-mode", "block",
"--keyring-backend", "test",
"--yes",
)
return cmd
}

0 comments on commit b60d9e1

Please sign in to comment.