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: run da client on non-linux boxes with rollapp start #868

Merged
merged 1 commit into from
Aug 28, 2024
Merged
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
45 changes: 43 additions & 2 deletions cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package start

import (
"context"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"github.com/pterm/pterm"
Expand All @@ -14,6 +16,7 @@ import (
initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/sequencer"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/bash"
Expand All @@ -27,6 +30,8 @@ import (
var (
RollappDirPath string
LogPath string
DaLcEndpoint string
DaLogPath string
)

func Cmd() *cobra.Command {
Expand Down Expand Up @@ -70,6 +75,34 @@ Consider using 'services' if you want to run a 'systemd' service instead.
}, parseError,
utils.WithLogging(utils.GetSequencerLogPath(rollappConfig)),
)

// TODO: this is an ugly workaround to start a light client for those
// who run a rollapp locally on their non-linux boxes ( why would you )
// refactor and remove repetition with da-light-client start command
if runtime.GOOS != "linux" {
damanager := datalayer.NewDAManager(rollappConfig.DA.Backend, rollappConfig.Home)
startDALCCmd := damanager.GetStartDACmd()
if startDALCCmd == nil {
errorhandling.PrettifyErrorIfExists(
errors.New(
"DA doesn't need to run separately. It runs automatically with the app",
),
)
}

DaLcEndpoint = damanager.GetLightNodeEndpoint()
DaLogPath = utils.GetDALogFilePath(rollappConfig.Home)

defer cancel()
go bash.RunCmdAsync(
ctx,
startDALCCmd,
printDaOutput,
parseError,
utils.WithLogging(DaLogPath),
)
}

select {}
},
}
Expand All @@ -79,8 +112,10 @@ Consider using 'services' if you want to run a 'systemd' service instead.
func printOutput(rlpCfg config.RollappConfig, cmd *exec.Cmd) {
seq := sequencer.GetInstance(rlpCfg)
fmt.Println("💈 The Rollapp sequencer is running on your local machine!")
fmt.Printf("💈 RollApp ID: %s\n", pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()).
Sprintf(rlpCfg.RollappID))
fmt.Printf(
"💈 RollApp ID: %s\n", pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()).
Sprintf(rlpCfg.RollappID),
)
fmt.Println("💈 Endpoints:")

fmt.Printf("💈 EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort)
Expand All @@ -92,6 +127,12 @@ func printOutput(rlpCfg config.RollappConfig, cmd *exec.Cmd) {
fmt.Println("💈 PID: ", cmd.Process.Pid)
}

func printDaOutput() {
fmt.Println("💈 The data availability light node is running on your local machine!")
fmt.Printf("💈 Light node endpoint: %s\n", DaLcEndpoint)
fmt.Printf("💈 Log file path: %s\n", DaLogPath)
}

func createPidFile(path string, cmd *exec.Cmd) error {
pidPath := filepath.Join(path, "rollapp.pid")
file, err := os.Create(pidPath)
Expand Down
Loading