diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index 4af80cec..a74d66fa 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -11,14 +11,15 @@ import ( "strings" "time" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/utils/archives" "github.com/dymensionxyz/roller/utils/bash" "github.com/dymensionxyz/roller/utils/dependencies" "github.com/dymensionxyz/roller/utils/rollapp" - "github.com/pterm/pterm" - "github.com/spf13/cobra" ) func Cmd() *cobra.Command { @@ -33,6 +34,8 @@ func Cmd() *cobra.Command { pterm.Error.Println("failed to add flags") return } + isMockFlagSet := cmd.Flags().Changed("mock") + shouldUseMockBackend, _ := cmd.Flags().GetBool("mock") var raID string if len(args) != 0 { @@ -43,13 +46,11 @@ func Cmd() *cobra.Command { ).Show() } - envs := []string{"mock", "playground"} - env, _ := pterm.DefaultInteractiveSelect. - WithDefaultText("select the environment you want to initialize for"). - WithOptions(envs). - Show() - hd := consts.Hubs[env] - if env == "mock" { + var hd consts.HubData + var env string + + if shouldUseMockBackend { + env := "mock" err := runInit(cmd, env, raID) if err != nil { fmt.Println("failed to run init: ", err) @@ -58,6 +59,23 @@ func Cmd() *cobra.Command { return } + if !isMockFlagSet && !shouldUseMockBackend { + envs := []string{"mock", "playground"} + env, _ = pterm.DefaultInteractiveSelect. + WithDefaultText("select the environment you want to initialize for"). + WithOptions(envs). + Show() + hd = consts.Hubs[env] + if env == "mock" { + err := runInit(cmd, env, raID) + if err != nil { + fmt.Println("failed to run init: ", err) + return + } + return + } + } + // ex binaries install dymdBinaryOptions := dependencies.Dependency{ Name: "dymension", @@ -153,6 +171,9 @@ func Cmd() *cobra.Command { ) }, } + + cmd.Flags().Bool("mock", false, "initialize the rollapp with mock backend") + return cmd } @@ -164,6 +185,14 @@ func installBinaries(bech32 string) error { return errors.New(errMsg) } + defer func() { + dir, err := os.UserHomeDir() + if err != nil { + return + } + _ = os.Chdir(dir) + }() + buildableDeps := map[string]dependencies.Dependency{ "rollapp": { Repository: "https://github.com/dymensionxyz/rollapp-evm.git", diff --git a/cmd/rollapp/setup/setup.go b/cmd/rollapp/setup/setup.go index 6f482654..1d1990b1 100644 --- a/cmd/rollapp/setup/setup.go +++ b/cmd/rollapp/setup/setup.go @@ -1,7 +1,6 @@ package setup import ( - "context" "encoding/json" "errors" "fmt" @@ -83,30 +82,14 @@ func Cmd() *cobra.Command { ) errorhandling.PrettifyErrorIfExists(err) - seq := sequencer.GetInstance(*rollappConfig) - startRollappCmd := seq.GetStartCmd() - - LogPath = filepath.Join( - rollappConfig.Home, - consts.ConfigDirName.Rollapp, - "rollapputils.log", - ) - RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) - if rollappConfig.HubData.ID == "mock" { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - go bash.RunCmdAsync( - ctx, startRollappCmd, func() { - printOutput(*rollappConfig, startRollappCmd) - err := createPidFile(RollappDirPath, startRollappCmd) - if err != nil { - pterm.Warning.Println("failed to create pid file") - } - }, parseError, - utils.WithLogging(utils.GetSequencerLogPath(*rollappConfig)), + pterm.Error.Println("setup is not required for mock backend") + pterm.Info.Printf( + "run %s instead to run the rollapp\n", + pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()). + Sprintf("roller rollapp start"), ) - select {} + return } getRaCmd := rollapp.GetRollappCmd(rollerData.RollappID, rollerData.HubData) diff --git a/cmd/rollapp/start/start.go b/cmd/rollapp/start/start.go index 9d8843b1..49297b04 100644 --- a/cmd/rollapp/start/start.go +++ b/cmd/rollapp/start/start.go @@ -79,7 +79,7 @@ Consider using 'services' if you want to run a 'systemd' service instead. // 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" { + if runtime.GOOS != "linux" && rollappConfig.HubData.ID != consts.MockHubID { damanager := datalayer.NewDAManager(rollappConfig.DA.Backend, rollappConfig.Home) startDALCCmd := damanager.GetStartDACmd() if startDALCCmd == nil { @@ -91,7 +91,6 @@ Consider using 'services' if you want to run a 'systemd' service instead. } DaLcEndpoint = damanager.GetLightNodeEndpoint() - DaLogPath = utils.GetDALogFilePath(rollappConfig.Home) defer cancel() go bash.RunCmdAsync( @@ -99,7 +98,6 @@ Consider using 'services' if you want to run a 'systemd' service instead. startDALCCmd, printDaOutput, parseError, - utils.WithLogging(DaLogPath), ) } diff --git a/data_layer/celestia/celestia.go b/data_layer/celestia/celestia.go index 4971c706..e0003529 100644 --- a/data_layer/celestia/celestia.go +++ b/data_layer/celestia/celestia.go @@ -347,7 +347,7 @@ func (c *Celestia) GetSequencerDAConfig(nt string) string { } return fmt.Sprintf( - `{"base_url": "%s", "timeout": 60000000000, "gas_prices":1.0, "gas_adjustment": 1.3, "namespace_id":"%s","auth_token":"%s","backoff":{"initial_delay":6000000000,"max_delay":6000000000,"growth_factor":2},"retry_attempts":4,"retry_delay":3000000000}`, + `{"base_url": "%s", "timeout": 60000000000, "gas_prices":0.02, "gas_adjustment": 1.3, "namespace_id":"%s","auth_token":"%s","backoff":{"initial_delay":6000000000,"max_delay":6000000000,"growth_factor":2},"retry_attempts":4,"retry_delay":3000000000}`, lcEndpoint, c.NamespaceID, authToken,