diff --git a/cmd/config/set/da.go b/cmd/config/set/da.go index 0a38a2a4..41706883 100644 --- a/cmd/config/set/da.go +++ b/cmd/config/set/da.go @@ -17,9 +17,9 @@ func setDA(rlpCfg config.RollappConfig, value string) error { if daValue == rlpCfg.DA { return nil } - supportedDas := []config.DAType{config.Celestia, config.Avail, config.Local} + if !config.IsValidDAType(value) { - return fmt.Errorf("invalid DA type. Supported types are: %v", supportedDas) + return fmt.Errorf("invalid DA type. Supported types are: %v", config.SupportedDas) } return updateDaConfig(rlpCfg, daValue) } diff --git a/cmd/relayer/start/start.go b/cmd/relayer/start/start.go index 5cba62c2..0609e959 100644 --- a/cmd/relayer/start/start.go +++ b/cmd/relayer/start/start.go @@ -3,6 +3,7 @@ package start import ( "context" "fmt" + "github.com/dymensionxyz/roller/sequencer" "math/big" "github.com/dymensionxyz/roller/cmd/consts" @@ -48,7 +49,8 @@ func Start() *cobra.Command { fmt.Println("💈 IBC transfer channel is already established!") } else { fmt.Println("💈 Establishing IBC transfer channel") - _, err := rly.CreateIBCChannel(override, logFileOption) + seq := sequencer.GetInstance(rollappConfig) + _, err := rly.CreateIBCChannel(override, logFileOption, seq) utils.PrettifyErrorIfExists(err) } diff --git a/config/config.go b/config/config.go index 091c5354..78a7d96a 100644 --- a/config/config.go +++ b/config/config.go @@ -24,6 +24,8 @@ const ( Avail DAType = "avail" ) +var SupportedDas = []DAType{Celestia, Avail, Local} + type RollappConfig struct { Home string RollappID string @@ -68,7 +70,7 @@ func (c RollappConfig) Validate() error { } if !IsValidDAType(string(c.DA)) { - return fmt.Errorf("invalid DA type: %s", c.DA) + return fmt.Errorf("invalid DA type: %s. supported types %s", c.DA, SupportedDas) } if !IsValidVMType(string(c.VMType)) { diff --git a/relayer/create_ibc_channel.go b/relayer/create_ibc_channel.go index b55ddf6d..af75804a 100644 --- a/relayer/create_ibc_channel.go +++ b/relayer/create_ibc_channel.go @@ -3,15 +3,19 @@ package relayer import ( "context" "fmt" + "github.com/dymensionxyz/roller/sequencer" "os/exec" "path/filepath" + "strconv" + "time" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" ) -// Creates an IBC channel between the hub and the client, and return the source channel ID. -func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOption) (ConnectionChannels, error) { +// CreateIBCChannel Creates an IBC channel between the hub and the client, and return the source channel ID. +func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOption, seq *sequencer.Sequencer, +) (ConnectionChannels, error) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -25,16 +29,23 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt return ConnectionChannels{}, err } - //after succesfull update clients, keep running in the background + //after successful update clients, keep running in the background updateClientsCmd := r.GetUpdateClientsCmd() utils.RunCommandEvery(ctx, updateClientsCmd.Path, updateClientsCmd.Args[1:], 10, utils.WithDiscardLogging()) - - createConnectionCmd := r.getCreateConnectionCmd(override) + status = "Creating block..." + fmt.Printf("💈 %s\n", status) + if err := r.WriteRelayerStatus(status); err != nil { + return ConnectionChannels{}, err + } + if err := waitForValidRollappHeight(seq); err != nil { + return ConnectionChannels{}, err + } 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 } @@ -73,6 +84,62 @@ func (r *Relayer) CreateIBCChannel(override bool, logFileOption utils.CommandOpt }, nil } +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 + } + 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 hub height to be greater than 2, current height: %d\n", hubHeight) + continue + } + if hubHeight <= initialHubHeight { + fmt.Printf("💈 Waiting for hub height to be greater than initial height,"+ + " initial height: %d,current height: %d\n", initialHubHeight, hubHeight) + continue + } + rollappHeightStr, err := seq.GetRollappHeight() + if err != nil { + fmt.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()) + 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) + } + return nil + } +} + func (r *Relayer) getCreateClientsCmd(override bool) *exec.Cmd { args := []string{"tx", "clients"} args = append(args, r.getRelayerDefaultArgs()...) diff --git a/sequencer/status.go b/sequencer/status.go index 99e51dc1..d685c447 100644 --- a/sequencer/status.go +++ b/sequencer/status.go @@ -30,7 +30,7 @@ type Response struct { Result Result `json:"result"` } -func (seq *Sequencer) getRollappHeight() (string, error) { +func (seq *Sequencer) GetRollappHeight() (string, error) { rollappRPCEndpoint := seq.GetRPCEndpoint() resp, err := http.Get(fmt.Sprintf("%s/status", rollappRPCEndpoint)) if err != nil { @@ -60,7 +60,7 @@ type HubResponse struct { } `json:"stateInfo"` } -func (seq *Sequencer) getHubHeight() (string, error) { +func (seq *Sequencer) GetHubHeight() (string, error) { cmd := exec.Command(consts.Executables.Dymension, "q", "rollapp", "state", seq.RlpCfg.RollappID, "--output", "json", "--node", seq.RlpCfg.HubData.RPC_URL) out, err := utils.ExecBashCommandWithStdout(cmd) @@ -83,7 +83,7 @@ func (seq *Sequencer) getHubHeight() (string, error) { } func (seq *Sequencer) GetSequencerStatus(config.RollappConfig) string { // TODO: Make sure the sequencer status endpoint is being changed after block production is paused. - rolHeight, err := seq.getRollappHeight() + rolHeight, err := seq.GetRollappHeight() if err != nil { seq.logger.Println(err) } @@ -92,7 +92,7 @@ func (seq *Sequencer) GetSequencerStatus(config.RollappConfig) string { } else if rolHeight == "-2" { return "Unhealthy" } else { - hubHeight, err := seq.getHubHeight() + hubHeight, err := seq.GetHubHeight() if err != nil { seq.logger.Println(err) return fmt.Sprintf("Active, Height: %s", rolHeight)