Skip to content

Commit

Permalink
Added handling for running two sequencers on the same machine for rol…
Browse files Browse the repository at this point in the history
…ler run
  • Loading branch information
ItayLevyOfficial committed Jun 12, 2023
1 parent b72030a commit f2552db
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package run

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

"bytes"

"strings"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
Expand All @@ -19,20 +24,36 @@ func RunCmd() *cobra.Command {
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
initconfig.OutputCleanError(err)
startRollappCmd := getStartRollapCmd(rollappConfig)
var stderr bytes.Buffer
startRollappCmd.Stderr = &stderr
err = startRollappCmd.Start()
initconfig.OutputCleanError(err)
if err != nil {
errMsg := parseError(stderr.String())
initconfig.OutputCleanError(errors.New(errMsg))
}
fmt.Println("💈 The Rollapp sequencer is running on your local machine!")
fmt.Println("💈 EVM RPC: http://0.0.0.0:8545")
fmt.Println("💈 Node RPC: http://0.0.0.0:26657")
fmt.Println("💈 Rest API: http://0.0.0.0:1317")
err = startRollappCmd.Wait()
initconfig.OutputCleanError(err)
if err != nil {
errMsg := parseError(stderr.String())
initconfig.OutputCleanError(errors.New(errMsg))
}
},
}
utils.AddGlobalFlags(runCmd)
return runCmd
}

func parseError(errMsg string) string {
lines := strings.Split(errMsg, "\n")
if len(lines) > 0 && lines[0] == "Error: failed to initialize database: resource temporarily unavailable" {
return "The Rollapp sequencer is already running. Only one sequencer can run on the machine at any given time."
}
return errMsg
}

func getStartRollapCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`, rollappConfig.LightNodeEndpoint)
rollappConfigDir := filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.Rollapp)
Expand Down

0 comments on commit f2552db

Please sign in to comment.