diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 9e2bb6c4..c8962729 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -24,7 +24,7 @@ var Executables = struct { Eibc string }{ Roller: fmt.Sprintf("%s/roller", binsDir), - RollappEVM: fmt.Sprintf("%s/rollapp_evm", binsDir), + RollappEVM: fmt.Sprintf("%s/rollapp-evm", binsDir), Dymension: fmt.Sprintf("%s/dymd", binsDir), Celestia: fmt.Sprintf("%s/celestia", internalBinsDir), CelKey: fmt.Sprintf("%s/cel-key", internalBinsDir), diff --git a/cmd/rollapp/init/main.go b/cmd/rollapp/init/main.go index eef2b80f..cb79e2b6 100644 --- a/cmd/rollapp/init/main.go +++ b/cmd/rollapp/init/main.go @@ -221,6 +221,7 @@ func runInit(cmd *cobra.Command, args []string, configArchivePath string) error return err } + // genesis creator archive err = archives.ExtractFileFromNestedTar( configArchivePath, "genesis.json", diff --git a/cmd/rollapp/rollapp.go b/cmd/rollapp/rollapp.go index 2842425f..9eb69f8d 100644 --- a/cmd/rollapp/rollapp.go +++ b/cmd/rollapp/rollapp.go @@ -3,7 +3,9 @@ package rollapp import ( "github.com/spf13/cobra" + "github.com/dymensionxyz/roller/cmd/config" initrollapp "github.com/dymensionxyz/roller/cmd/rollapp/init" + "github.com/dymensionxyz/roller/cmd/rollapp/start" "github.com/dymensionxyz/roller/cmd/rollapp/status" ) @@ -15,6 +17,8 @@ func Cmd() *cobra.Command { cmd.AddCommand(initrollapp.Cmd) cmd.AddCommand(status.Cmd()) + cmd.AddCommand(config.Cmd()) + cmd.AddCommand(start.Cmd()) return cmd } diff --git a/cmd/sequencer/start/start.go b/cmd/rollapp/start/start.go similarity index 82% rename from cmd/sequencer/start/start.go rename to cmd/rollapp/start/start.go index 25305750..bee29d6a 100644 --- a/cmd/sequencer/start/start.go +++ b/cmd/rollapp/start/start.go @@ -1,4 +1,4 @@ -package sequnecer_start +package start import ( "context" @@ -7,12 +7,12 @@ import ( "path/filepath" "strings" - "github.com/dymensionxyz/roller/sequencer" + "github.com/spf13/cobra" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/config" - "github.com/spf13/cobra" + "github.com/dymensionxyz/roller/sequencer" ) // TODO: Test sequencing on 35-C and update the price @@ -23,25 +23,23 @@ var ( LogPath string ) -func StartCmd() *cobra.Command { - runCmd := &cobra.Command{ +func Cmd() *cobra.Command { + cmd := &cobra.Command{ Use: "start", - Short: "Runs the rollapp sequencer.", + 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 := config.LoadConfigFromTOML(home) utils.PrettifyErrorIfExists(err) - utils.RequireMigrateIfNeeded(rollappConfig) - LogPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log") - RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) - sequencerInsufficientAddrs, err := utils.GetSequencerInsufficientAddrs( - rollappConfig, - OneDaySequencePrice, - ) - utils.PrettifyErrorIfExists(err) - utils.PrintInsufficientBalancesIfAny(sequencerInsufficientAddrs, rollappConfig) + seq := sequencer.GetInstance(rollappConfig) startRollappCmd := seq.GetStartCmd() + + c := seq.GetStartCmd() + fmt.Println(c.String()) + LogPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log") + RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() go utils.RunBashCmdAsync(ctx, startRollappCmd, func() { @@ -51,8 +49,7 @@ func StartCmd() *cobra.Command { select {} }, } - - return runCmd + return cmd } func printOutput(rlpCfg config.RollappConfig) { diff --git a/cmd/root.go b/cmd/root.go index 65176559..6dc21e96 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -13,7 +13,6 @@ import ( "github.com/dymensionxyz/roller/cmd/relayer" "github.com/dymensionxyz/roller/cmd/rollapp" "github.com/dymensionxyz/roller/cmd/run" - "github.com/dymensionxyz/roller/cmd/sequencer" "github.com/dymensionxyz/roller/cmd/services" "github.com/dymensionxyz/roller/cmd/tx" "github.com/dymensionxyz/roller/cmd/utils" @@ -39,7 +38,6 @@ func init() { rootCmd.AddCommand(config.Cmd()) rootCmd.AddCommand(version.Cmd()) rootCmd.AddCommand(da_light_client.DALightClientCmd()) - rootCmd.AddCommand(sequencer.SequencerCmd()) rootCmd.AddCommand(relayer.Cmd()) rootCmd.AddCommand(keys.Cmd()) rootCmd.AddCommand(run.Cmd()) diff --git a/cmd/run/run.go b/cmd/run/run.go index 541ec76b..6755dfc8 100644 --- a/cmd/run/run.go +++ b/cmd/run/run.go @@ -6,17 +6,17 @@ import ( "os/exec" "sync" - "github.com/dymensionxyz/roller/data_layer/celestia" - "github.com/dymensionxyz/roller/relayer" - "github.com/dymensionxyz/roller/sequencer" + "github.com/spf13/cobra" relayer_start "github.com/dymensionxyz/roller/cmd/relayer/start" - sequnecer_start "github.com/dymensionxyz/roller/cmd/sequencer/start" + rollapp_start "github.com/dymensionxyz/roller/cmd/rollapp/start" "github.com/dymensionxyz/roller/cmd/utils" "github.com/dymensionxyz/roller/config" datalayer "github.com/dymensionxyz/roller/data_layer" + "github.com/dymensionxyz/roller/data_layer/celestia" + "github.com/dymensionxyz/roller/relayer" + "github.com/dymensionxyz/roller/sequencer" servicemanager "github.com/dymensionxyz/roller/utils/service_manager" - "github.com/spf13/cobra" ) var flagNames = struct { @@ -139,7 +139,7 @@ func verifyBalances(rollappConfig config.RollappConfig) { utils.PrettifyErrorIfExists(err) sequencerInsufficientBalances, err := utils.GetSequencerInsufficientAddrs( - rollappConfig, sequnecer_start.OneDaySequencePrice) + rollappConfig, rollapp_start.OneDaySequencePrice) utils.PrettifyErrorIfExists(err) insufficientBalances = append(insufficientBalances, sequencerInsufficientBalances...) diff --git a/cmd/sequencer/sequencer.go b/cmd/sequencer/sequencer.go deleted file mode 100644 index fc4bab47..00000000 --- a/cmd/sequencer/sequencer.go +++ /dev/null @@ -1,17 +0,0 @@ -package sequencer - -import ( - sequnecer_start "github.com/dymensionxyz/roller/cmd/sequencer/start" - "github.com/dymensionxyz/roller/cmd/sequencer/status" - "github.com/spf13/cobra" -) - -func SequencerCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "sequencer", - Short: "Commands for running and managing the RollApp sequnecer.", - } - cmd.AddCommand(sequnecer_start.StartCmd()) - cmd.AddCommand(status.Cmd()) - return cmd -} diff --git a/cmd/sequencer/status/status.go b/cmd/sequencer/status/status.go deleted file mode 100644 index e8395036..00000000 --- a/cmd/sequencer/status/status.go +++ /dev/null @@ -1,30 +0,0 @@ -package status - -import ( - "fmt" - - "github.com/spf13/cobra" - - "github.com/dymensionxyz/roller/cmd/utils" - "github.com/dymensionxyz/roller/config" - "github.com/dymensionxyz/roller/sequencer" -) - -func Cmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "status", - 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 := config.LoadConfigFromTOML(home) - if err != nil { - fmt.Println("failed to load config:", err) - return - } - utils.PrettifyErrorIfExists(err) - seq := sequencer.GetInstance(rollappConfig) - fmt.Println(seq.GetSequencerStatus(rollappConfig)) - }, - } - return cmd -} diff --git a/cmd/utils/bash_commands.go b/cmd/utils/bash_commands.go index 84f6f69a..4080547e 100644 --- a/cmd/utils/bash_commands.go +++ b/cmd/utils/bash_commands.go @@ -8,6 +8,7 @@ import ( "fmt" "io" "os/exec" + "sync" "time" "github.com/dymensionxyz/roller/config" @@ -153,23 +154,39 @@ func ExecBashCmdFollow(cmd *exec.Cmd) error { return err } - // Create a channel to capture any errors from stdout or stderr - errChan := make(chan error, 1) + // Use a WaitGroup to wait for both stdout and stderr to be processed + var wg sync.WaitGroup + wg.Add(2) + + // Channel to capture any errors from stdout or stderr + errChan := make(chan error, 2) go func() { + defer wg.Done() scanner := bufio.NewScanner(stdout) for scanner.Scan() { fmt.Println(scanner.Text()) } - errChan <- scanner.Err() + if err := scanner.Err(); err != nil { + errChan <- err + } }() go func() { + defer wg.Done() scanner := bufio.NewScanner(stderr) for scanner.Scan() { fmt.Println(scanner.Text()) } - errChan <- scanner.Err() + if err := scanner.Err(); err != nil { + errChan <- err + } + }() + + // Wait for both stdout and stderr goroutines to finish + go func() { + wg.Wait() + close(errChan) }() // Wait for the command to finish @@ -177,12 +194,11 @@ func ExecBashCmdFollow(cmd *exec.Cmd) error { return err } - // Check if there was any error in the goroutines - if err := <-errChan; err != nil { - return err - } - if err := <-errChan; err != nil { - return err + // Check if there were any errors in the goroutines + for err := range errChan { + if err != nil { + return err + } } return nil diff --git a/sequencer/sequencer_manager.go b/sequencer/sequencer_manager.go index 62d49179..68f416ef 100644 --- a/sequencer/sequencer_manager.go +++ b/sequencer/sequencer_manager.go @@ -41,7 +41,7 @@ func GetInstance(rlpCfg config.RollappConfig) *Sequencer { func (seq *Sequencer) GetStartCmd() *exec.Cmd { rollappConfigDir := filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp) cmd := exec.Command( - seq.RlpCfg.RollappBinary, + consts.Executables.RollappEVM, "start", "--home", rollappConfigDir, "--log-file", filepath.Join(rollappConfigDir, "rollapp.log"),