diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 78fd6b0d..a42ca9cf 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,7 +18,9 @@ builds: flags: - -tags=cgo ldflags: - - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} + - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} + - -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} + - -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} - id: "roller-darwin-arm64" main: ./ binary: roller @@ -33,7 +35,9 @@ builds: flags: - -tags=cgo ldflags: - - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} + - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} + - -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} + - -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} - id: "roller-linux" main: ./ binary: roller @@ -48,7 +52,9 @@ builds: flags: - -tags=cgo ldflags: - - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} + - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} + - -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} + - -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} - id: "roller-linux-arm64" main: ./ binary: roller @@ -79,7 +85,9 @@ builds: - -tags=cgo - -buildmode=exe ldflags: - - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} + - -X github.com/dymensionxyz/roller/version.BuildVersion={{.Version}} + - -X github.com/dymensionxyz/roller/version.BuildCommit={{.Commit}} + - -X github.com/dymensionxyz/roller/version.BuildTime={{.Date}} archives: - name_template: '{{ .ProjectName }}_{{- title .Os }}_{{ .Arch }}' diff --git a/cmd/eibc/fulfill/order/order.go b/cmd/eibc/fulfill/order/order.go index 12ccdbbe..9ac1f788 100644 --- a/cmd/eibc/fulfill/order/order.go +++ b/cmd/eibc/fulfill/order/order.go @@ -3,6 +3,9 @@ package order import ( "fmt" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/utils/bash" @@ -10,8 +13,6 @@ import ( "github.com/dymensionxyz/roller/utils/eibc" "github.com/dymensionxyz/roller/utils/filesystem" "github.com/dymensionxyz/roller/utils/tx" - "github.com/pterm/pterm" - "github.com/spf13/cobra" ) func Cmd() *cobra.Command { @@ -51,7 +52,7 @@ func Cmd() *cobra.Command { percentage = args[1] } else { percentage, _ = pterm.DefaultInteractiveTextInput.WithDefaultText( - "provide an order id that you want to fulfill", + "provide the expected fee amount", ).Show() } diff --git a/cmd/eibc/fulfill/rollapps/rollapps.go b/cmd/eibc/fulfill/rollapps/rollapps.go index 975cd919..6f98ebff 100644 --- a/cmd/eibc/fulfill/rollapps/rollapps.go +++ b/cmd/eibc/fulfill/rollapps/rollapps.go @@ -1,10 +1,11 @@ package rollapps import ( + "github.com/spf13/cobra" + "github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/list" "github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/remove" "github.com/dymensionxyz/roller/cmd/eibc/fulfill/rollapps/set" - "github.com/spf13/cobra" ) func Cmd() *cobra.Command { diff --git a/cmd/rollapp/start/start.go b/cmd/rollapp/start/start.go index 3fef3bf0..9dfa9111 100644 --- a/cmd/rollapp/start/start.go +++ b/cmd/rollapp/start/start.go @@ -75,6 +75,9 @@ Consider using 'services' if you want to run a 'systemd' service instead. rollappConfig, strconv.Itoa(startRollappCmd.Process.Pid), showSequencerBalance, + true, + true, + true, ) err := createPidFile(RollappDirPath, startRollappCmd) if err != nil { @@ -93,55 +96,84 @@ Consider using 'services' if you want to run a 'systemd' service instead. return cmd } -func PrintOutput(rlpCfg config.RollappConfig, pid string, withBalance bool) { +func PrintOutput( + rlpCfg config.RollappConfig, + pid string, + withBalance, + withEndpoints, + withProcessInfo, + isHealthy bool, +) { + logPath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "rollapp.log") + rollappDirPath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp) + seq := sequencer.GetInstance(rlpCfg) - seqAddrData, err := sequencerutils.GetSequencerData(rlpCfg) - if err != nil { - return + + var msg string + if isHealthy { + msg = pterm.DefaultBasicText.WithStyle( + pterm. + FgGreen.ToStyle(), + ).Sprintf("💈 The Rollapp sequencer is running on your local machine!") + } else { + msg = pterm.DefaultBasicText.WithStyle( + pterm. + FgRed.ToStyle(), + ).Sprintf("❗ The Rollapp sequencer is in unhealthy state. Please check the logs for more information.") } - fmt.Println("💈 The Rollapp sequencer is running on your local machine!") + fmt.Println(msg) + pterm.Println() fmt.Printf( "💈 RollApp ID: %s\n", pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()). Sprintf(rlpCfg.RollappID), ) - pterm.DefaultSection.WithIndentCharacter("💈"). - Println("Endpoints:") - fmt.Printf("EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort) - fmt.Printf("Node RPC: http://0.0.0.0:%v\n", seq.RPCPort) - fmt.Printf("Rest API: http://0.0.0.0:%v\n", seq.APIPort) + if withEndpoints { + pterm.DefaultSection.WithIndentCharacter("💈"). + Println("Endpoints:") + fmt.Printf("EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort) + fmt.Printf("Node RPC: http://0.0.0.0:%v\n", seq.RPCPort) + fmt.Printf("Rest API: http://0.0.0.0:%v\n", seq.APIPort) + } pterm.DefaultSection.WithIndentCharacter("💈"). Println("Filesystem Paths:") - fmt.Println("Rollapp root dir: ", RollappDirPath) - fmt.Println("Log file path: ", LogPath) + fmt.Println("Rollapp root dir: ", rollappDirPath) + fmt.Println("Log file path: ", logPath) - pterm.DefaultSection.WithIndentCharacter("💈"). - Println("Process Info:") - fmt.Println("PID: ", pid) + if withProcessInfo { + pterm.DefaultSection.WithIndentCharacter("💈"). + Println("Process Info:") + fmt.Println("PID: ", pid) + } - pterm.DefaultSection.WithIndentCharacter("💈"). - Println("Wallet Info:") - fmt.Println("Sequencer Address:", seqAddrData[0].Address) - - if withBalance { - fmt.Println("Sequencer Balance:", seqAddrData[0].Balance.String()) - go func() { - for { - // nolint: gosimple - select { - default: - seqAddrData, err := sequencerutils.GetSequencerData(rlpCfg) - if err == nil { - // Clear the previous line and print the updated balance - fmt.Print("\033[1A\033[K") // Move cursor up one line and clear it - fmt.Println("Sequencer Balance:", seqAddrData[0].Balance.String()) + if isHealthy { + seqAddrData, err := sequencerutils.GetSequencerData(rlpCfg) + if err != nil { + return + } + pterm.DefaultSection.WithIndentCharacter("💈"). + Println("Wallet Info:") + fmt.Println("Sequencer Address:", seqAddrData[0].Address) + if withBalance { + fmt.Println("Sequencer Balance:", seqAddrData[0].Balance.String()) + go func() { + for { + // nolint: gosimple + select { + default: + seqAddrData, err := sequencerutils.GetSequencerData(rlpCfg) + if err == nil { + // Clear the previous line and print the updated balance + fmt.Print("\033[1A\033[K") // Move cursor up one line and clear it + fmt.Println("Sequencer Balance:", seqAddrData[0].Balance.String()) + } + time.Sleep(5 * time.Second) } - time.Sleep(5 * time.Second) } - } - }() + }() + } } } diff --git a/cmd/rollapp/status/status.go b/cmd/rollapp/status/status.go index 7eb486b2..2e9003be 100644 --- a/cmd/rollapp/status/status.go +++ b/cmd/rollapp/status/status.go @@ -10,9 +10,8 @@ import ( "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/rollapp/start" "github.com/dymensionxyz/roller/cmd/utils" - "github.com/dymensionxyz/roller/sequencer" "github.com/dymensionxyz/roller/utils/config/tomlconfig" - "github.com/dymensionxyz/roller/utils/errorhandling" + "github.com/dymensionxyz/roller/utils/dymint" ) func Cmd() *cobra.Command { @@ -21,14 +20,11 @@ func Cmd() *cobra.Command { Short: "Show the status of the sequencer on the local machine.", Run: func(cmd *cobra.Command, args []string) { home := cmd.Flag(utils.FlagNames.Home).Value.String() - rollappConfig, err := tomlconfig.LoadRollerConfig(home) + rollerConfig, err := tomlconfig.LoadRollerConfig(home) if err != nil { fmt.Println("failed to load config:", err) return } - errorhandling.PrettifyErrorIfExists(err) - seq := sequencer.GetInstance(rollappConfig) - fmt.Println(seq.GetSequencerStatus()) pidFilePath := filepath.Join(home, consts.ConfigDirName.Rollapp, "rollapp.pid") pid, err := os.ReadFile(pidFilePath) @@ -37,7 +33,14 @@ func Cmd() *cobra.Command { return } - start.PrintOutput(rollappConfig, string(pid), true) + ok, msg := dymint.IsRollappHealthy("http://localhost:26657/health") + if !ok { + start.PrintOutput(rollerConfig, string(pid), true, false, false, false) + fmt.Println("Unhealthy Message: ", msg) + return + } + + start.PrintOutput(rollerConfig, string(pid), true, true, true, true) }, } return cmd diff --git a/cmd/services/load/load.go b/cmd/services/load/load.go index 1aa0d19a..47694d6f 100644 --- a/cmd/services/load/load.go +++ b/cmd/services/load/load.go @@ -85,11 +85,11 @@ func Cmd(services []string, module string) *cobra.Command { pterm.Error.Println("failed to write launchctl file", err) return } - errorhandling.PrettifyErrorIfExists(err) - } - - return + pterm.Success.Printf( + "💈 Services %s been loaded successfully.\n", + strings.Join(services, ", "), + ) } else if runtime.GOOS == "linux" { for _, service := range services { serviceData := ServiceTemplateData{ @@ -123,8 +123,9 @@ func Cmd(services []string, module string) *cobra.Command { if module == "relayer" { schedule := "*/15 * * * *" // Run every hour command := fmt.Sprintf( - "%s tx flush hub-rollapp --max-msgs 100", + "%s tx flush hub-rollapp --max-msgs 100 --home %s", consts.Executables.Relayer, + filepath.Join(rollerData.Home, consts.ConfigDirName.Relayer), ) err := cronjobs.Add(schedule, command) diff --git a/cmd/tx/fund_faucet/fund_faucet.go b/cmd/tx/fund_faucet/fund_faucet.go index 5acb1529..fd65f0d8 100644 --- a/cmd/tx/fund_faucet/fund_faucet.go +++ b/cmd/tx/fund_faucet/fund_faucet.go @@ -7,6 +7,8 @@ import ( "os/exec" "path/filepath" + "github.com/spf13/cobra" + "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/tx/tx_utils" "github.com/dymensionxyz/roller/cmd/utils" @@ -14,7 +16,6 @@ import ( "github.com/dymensionxyz/roller/utils/bash" "github.com/dymensionxyz/roller/utils/config/tomlconfig" "github.com/dymensionxyz/roller/utils/errorhandling" - "github.com/spf13/cobra" ) var flagNames = struct { diff --git a/sequencer/sequencer_manager.go b/sequencer/sequencer_manager.go index 4f74a990..92e9aa8e 100644 --- a/sequencer/sequencer_manager.go +++ b/sequencer/sequencer_manager.go @@ -9,7 +9,6 @@ import ( "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/utils/config" - "github.com/pterm/pterm" ) type Sequencer struct { @@ -26,7 +25,6 @@ var ( ) func GetInstance(rlpCfg config.RollappConfig) *Sequencer { - pterm.Info.Println("retrieving sequencer instance") once.Do( func() { seq := &Sequencer{ diff --git a/utils/dymint/dymint.go b/utils/dymint/dymint.go index 3b7238ff..b31d4912 100644 --- a/utils/dymint/dymint.go +++ b/utils/dymint/dymint.go @@ -167,7 +167,8 @@ func UpdateDymintConfigForIBC(home string, t string, forceUpdate bool) error { } else { return errors.New( "unsupported platform: " + runtime.GOOS + - ", only linux and darwin are supported") + ", only linux and darwin are supported", + ) } WaitForHealthyRollApp("http://localhost:26657/health") } @@ -182,22 +183,6 @@ func WaitForHealthyRollApp(url string) { spinner, _ := pterm.DefaultSpinner.Start("waiting for rollapp to become healthy") - // if runtime.GOOS == "linux" { - // err := servicemanager.RestartSystemdService("rollapp") - // if err != nil { - // pterm.Error.Println(err) - // return - // } - // } else if runtime.GOOS == "darwin" { - // err := servicemanager.RestartLaunchctlService("rollapp") - // if err != nil { - // pterm.Error.Println(err) - // return - // } - // } else { - // return - // } - for { select { case <-timeout: @@ -234,3 +219,36 @@ func WaitForHealthyRollApp(url string) { } } } + +func IsRollappHealthy(url string) (bool, any) { + fmt.Println(url) + // nolint:gosec + resp, err := http.Get(url) + if err != nil { + fmt.Printf("Error making request: %v\n", err) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Printf("Error reading response body: %v\n", err) + } + // nolint:errcheck,gosec + resp.Body.Close() + + var response RollappHealthResponse + if json.Valid(body) { + err = json.Unmarshal(body, &response) + if err != nil { + msg := fmt.Sprintf("Error unmarshaling JSON: %v\n", err) + return false, msg + } + } else { + return false, "invalid json" + } + + if response.Result.IsHealthy { + return true, "" + } + + return false, "" +}