Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ux): update prompts and rollapp status command #960

Merged
merged 6 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 }}'
Expand Down
7 changes: 4 additions & 3 deletions cmd/eibc/fulfill/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ 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"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"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 {
Expand Down Expand Up @@ -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()
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/eibc/fulfill/rollapps/rollapps.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
100 changes: 66 additions & 34 deletions cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
}()
}()
}
}
}

Expand Down
17 changes: 10 additions & 7 deletions cmd/rollapp/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions cmd/services/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cmd/tx/fund_faucet/fund_faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ 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"
"github.com/dymensionxyz/roller/relayer"
"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 {
Expand Down
2 changes: 0 additions & 2 deletions sequencer/sequencer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/utils/config"
"github.com/pterm/pterm"
)

type Sequencer struct {
Expand All @@ -26,7 +25,6 @@ var (
)

func GetInstance(rlpCfg config.RollappConfig) *Sequencer {
pterm.Info.Println("retrieving sequencer instance")
once.Do(
func() {
seq := &Sequencer{
Expand Down
52 changes: 35 additions & 17 deletions utils/dymint/dymint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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:
Expand Down Expand Up @@ -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, ""
}
Loading