Skip to content

Commit

Permalink
refactor: add rollapp start cmd (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Jul 16, 2024
1 parent 89dc1c6 commit db2fd80
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 84 deletions.
2 changes: 1 addition & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions cmd/rollapp/init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 4 additions & 0 deletions cmd/rollapp/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
31 changes: 14 additions & 17 deletions cmd/sequencer/start/start.go → cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sequnecer_start
package start

import (
"context"
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -51,8 +49,7 @@ func StartCmd() *cobra.Command {
select {}
},
}

return runCmd
return cmd
}

func printOutput(rlpCfg config.RollappConfig) {
Expand Down
2 changes: 0 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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())
Expand Down
12 changes: 6 additions & 6 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...)

Expand Down
17 changes: 0 additions & 17 deletions cmd/sequencer/sequencer.go

This file was deleted.

30 changes: 0 additions & 30 deletions cmd/sequencer/status/status.go

This file was deleted.

36 changes: 26 additions & 10 deletions cmd/utils/bash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"os/exec"
"sync"
"time"

"github.com/dymensionxyz/roller/config"
Expand Down Expand Up @@ -153,36 +154,51 @@ 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
if err := cmd.Wait(); err != nil {
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
Expand Down
2 changes: 1 addition & 1 deletion sequencer/sequencer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit db2fd80

Please sign in to comment.