Skip to content

Commit

Permalink
Implemented error handling for roller run
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 19, 2023
1 parent 825a385 commit a353b32
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"os/exec"
"path/filepath"

"errors"

"bytes"

"strings"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
Expand All @@ -22,30 +28,46 @@ func RunCmd() *cobra.Command {
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getStartRollapCmd(rollappConfig, cmd.Flag(daLightClientEndpointFlag).Value.String())
var stderr bytes.Buffer
startRollappCmd.Stderr = &stderr
startRollappErr := startRollappCmd.Start()
if startRollappErr != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
utils.PrettifyErrorIfExists(startRollappErr)
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()
utils.PrettifyErrorIfExists(err)
if err != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
},
}
addFlags(runCmd)
utils.AddGlobalFlags(runCmd)
addFlags(runCmd)
return runCmd
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(daLightClientEndpointFlag, "", "http://localhost:26659", "The DA light client endpoint.")
}
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, daLightClientEndpoint string) *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]}`, daLightClientEndpoint)
func getStartRollapCmd(rollappConfig initconfig.InitConfig, daEndpoint string) *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]}`, daEndpoint)
rollappConfigDir := filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp)
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "2000000udym"}`,
rollappConfig.HubData.RPC_URL, rollappConfig.RollappID, consts.KeyNames.HubSequencer, rollappConfigDir)
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "2000000udym"}`, rollappConfig.HubData.RPC_URL, rollappConfig.RollappID,
consts.KeyNames.HubSequencer, rollappConfigDir)

return exec.Command(
rollappConfig.RollappBinary, "start",
Expand Down

0 comments on commit a353b32

Please sign in to comment.