Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ibc clients creation stuck #639

Merged
merged 13 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to return the err, and ignore it by the caller
keep same standard as in GetActiveConnection

}

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

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
}
142 changes: 91 additions & 51 deletions relayer/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,22 @@ 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())
// 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
}
sendFundsCmd := seq.GetSendCmd(sequecerAddress)
utils.RunCommandEvery(ctx, sendFundsCmd.Path, sendFundsCmd.Args[1:], 20, utils.WithDiscardLogging())

//wait for block to be created
status := "Waiting for state update before creating the channel..."
status := "Validating rollapp height > 2 before creating clients..."
fmt.Printf("💈 %s\n", status)
if err := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
Expand All @@ -34,15 +44,59 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt
return ConnectionChannels{}, err
}

// Create client if it doesn't exist or override is true
clientsExist := false
if !override {
// Check if clients exist
clientsExist, err = r.CheckClientsExist()
if err != nil {
Copy link
Contributor

@mtsitrin mtsitrin Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore err as u don't won't to return here

return ConnectionChannels{}, err
}
}
if !clientsExist {
// 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if u set override=true in the createClients, this check is wrong.
if creating new client, u will must to create new connection as well

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

// 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 := r.WriteRelayerStatus(status); err != nil {
return ConnectionChannels{}, err
}
if err := utils.ExecBashCmd(createChannelCmd, logFileOption); err != nil {
return ConnectionChannels{}, err
}
status = "Validating channel established..."
Expand All @@ -51,7 +105,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 +123,50 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt
}, nil
}

// waitForValidRollappHeight waits for the rollapp height to be greater than 2 otherwise
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for the rollapp height on the hub to be greater than initial height not needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. because we open a connection optimistically so only the rollapp height is important.

// 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", "-t", "300s", "-d"}
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", "300s", "-r", "5", "-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
}
Loading