diff --git a/cmd/config/init/consts.go b/cmd/config/init/consts.go index 0615b9a9..2bcebb31 100644 --- a/cmd/config/init/consts.go +++ b/cmd/config/init/consts.go @@ -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: { diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 44d38e2e..4d2e126d 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -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", } diff --git a/relayer/clients.go b/relayer/clients.go new file mode 100644 index 00000000..a6c1e264 --- /dev/null +++ b/relayer/clients.go @@ -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 +} diff --git a/relayer/create_ibc_channel.go b/relayer/create_ibc_channel.go index e0f210ff..58055909 100644 --- a/relayer/create_ibc_channel.go +++ b/relayer/create_ibc_channel.go @@ -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..." @@ -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 } @@ -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") } diff --git a/sequencer/commands.go b/sequencer/commands.go new file mode 100644 index 00000000..482654bb --- /dev/null +++ b/sequencer/commands.go @@ -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 +}