Skip to content

Commit

Permalink
Merge branch 'main' into itaylevyofficial/101-run-status
Browse files Browse the repository at this point in the history
# Conflicts:
#	.gitignore
  • Loading branch information
ItayLevyOfficial committed Jul 2, 2023
2 parents 70fc7d0 + 998f4e4 commit 337ab5d
Show file tree
Hide file tree
Showing 17 changed files with 135 additions and 41 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/.vscode
*
!*/
!*.*
build/
*.exe
\.*
/.vscode
/.idea
2 changes: 1 addition & 1 deletion cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func InitCmd() *cobra.Command {
},
Args: cobra.ExactArgs(2),
}
utils.AddGlobalFlags(initCmd)

addFlags(initCmd)
return initCmd
}
8 changes: 2 additions & 6 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ func Cmd() *cobra.Command {
utils.PrintInsufficientBalancesIfAny(insufficientBalances)
rpcEndpoint := cmd.Flag(rpcEndpointFlag).Value.String()
startDALCCmd := GetStartDACmd(rollappConfig, rpcEndpoint)
logFilePath := GetDALogFilePath(rollappConfig.Home)
logFilePath := utils.GetDALogFilePath(rollappConfig.Home)
utils.RunBashCmdAsync(startDALCCmd, printOutput, parseError, utils.WithLogging(logFilePath))
},
}
utils.AddGlobalFlags(runCmd)

addFlags(runCmd)
return runCmd
}
Expand Down Expand Up @@ -84,7 +84,3 @@ func GetStartDACmd(rollappConfig utils.RollappConfig, rpcEndpoint string) *exec.
"--p2p.network", "arabica",
)
}

func GetDALogFilePath(home string) string {
return filepath.Join(home, consts.ConfigDirName.DALightNode, "light_client.log")
}
60 changes: 60 additions & 0 deletions cmd/keys/export/export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package export

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
"os/exec"
"path/filepath"
"strings"
)

var supportedKeys = []string{
consts.KeysIds.HubSequencer,
consts.KeysIds.RollappSequencer,
}

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "export <key-id>",
Short: fmt.Sprintf("Exports the private key of the given key id. The supported keys are %s",
strings.Join(supportedKeys, ", ")),
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
config, err := utils.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)

keyID := args[0]
if keyID == consts.KeysIds.HubSequencer {
exportKeyCmd := getExportKeyCmdBinary(keyID, filepath.Join(home, consts.ConfigDirName.HubKeys),
consts.Executables.Dymension)
out, err := utils.ExecBashCommand(exportKeyCmd)
utils.PrettifyErrorIfExists(err)
fmt.Println(out.String())
} else if keyID == consts.KeysIds.RollappSequencer {
exportKeyCmd := getExportKeyCmdBinary(keyID, filepath.Join(home, consts.ConfigDirName.Rollapp),
config.RollappBinary)
out, err := utils.ExecBashCommand(exportKeyCmd)
utils.PrettifyErrorIfExists(err)
fmt.Println(out.String())
} else {
utils.PrettifyErrorIfExists(fmt.Errorf("invalid key id: %s. The supported keys are %s", keyID,
strings.Join(supportedKeys, ", ")))
}
},
Args: cobra.ExactArgs(1),
}

return cmd
}

func getExportKeyCmdBinary(keyID, keyringDir, binary string) *exec.Cmd {
flags := getExportKeyFlags(keyringDir)
cmdStr := fmt.Sprintf("yes | %s keys export %s %s", binary, keyID, flags)
return exec.Command("bash", "-c", cmdStr)
}

func getExportKeyFlags(keyringDir string) string {
return fmt.Sprintf("--keyring-backend test --keyring-dir %s --unarmored-hex --unsafe", keyringDir)
}
2 changes: 2 additions & 0 deletions cmd/keys/keys.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keys

import (
"github.com/dymensionxyz/roller/cmd/keys/export"
"github.com/dymensionxyz/roller/cmd/keys/list"
"github.com/spf13/cobra"
)
Expand All @@ -11,5 +12,6 @@ func Cmd() *cobra.Command {
Short: "Commands for managing the roller different keys.",
}
cmd.AddCommand(list.Cmd())
cmd.AddCommand(export.Cmd())
return cmd
}
2 changes: 1 addition & 1 deletion cmd/keys/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@ func Cmd() *cobra.Command {
utils.PrintAddresses(addresses)
},
}
utils.AddGlobalFlags(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Cmd() *cobra.Command {
printRegisterOutput(rollappConfig)
},
}
utils.AddGlobalFlags(registerCmd)

return registerCmd
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/relayer/start/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ func createIBCChannelIfNeeded(rollappConfig utils.RollappConfig, logFileOption u
return "", err
}
if dstConnectionId == "" {
// Before setting up the connection, we need to call update clients
updateClientsCmd := getUpdateClientsCmd(rollappConfig)
fmt.Println("Updating clients...")
if err := utils.ExecBashCmdWithOSOutput(updateClientsCmd, logFileOption); err != nil {
return "", err
}

createConnectionCmd := getCreateConnectionCmd(rollappConfig)
fmt.Println("Creating connection...")
if err := utils.ExecBashCmdWithOSOutput(createConnectionCmd, logFileOption); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/relayer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Start() *cobra.Command {
rollappConfig, err := utils.LoadConfigFromTOML(home)
VerifyRelayerBalances(rollappConfig)
utils.PrettifyErrorIfExists(err)
relayerLogFilePath := filepath.Join(home, consts.ConfigDirName.Relayer, "relayer.log")
relayerLogFilePath := utils.GetRelayerLogPath(rollappConfig)
logFileOption := utils.WithLogging(relayerLogFilePath)
srcChannelId, err := createIBCChannelIfNeeded(rollappConfig, logFileOption)
utils.PrettifyErrorIfExists(err)
Expand All @@ -39,7 +39,7 @@ func Start() *cobra.Command {
select {}
},
}
utils.AddGlobalFlags(relayerStartCmd)

return relayerStartCmd
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/dymensionxyz/roller/cmd/run"
"github.com/dymensionxyz/roller/cmd/utils"
"os"

"github.com/dymensionxyz/roller/cmd/config"
Expand Down Expand Up @@ -38,4 +39,5 @@ func init() {
rootCmd.AddCommand(relayer.Cmd())
rootCmd.AddCommand(keys.Cmd())
rootCmd.AddCommand(run.Cmd())
utils.AddGlobalFlags(rootCmd)
}
8 changes: 3 additions & 5 deletions cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
"os/exec"
"path/filepath"
"sync"
)

Expand Down Expand Up @@ -41,7 +40,7 @@ func Cmd() *cobra.Command {
logger.Println("killed them")
},
}
utils.AddGlobalFlags(cmd)

return cmd
}

Expand All @@ -55,15 +54,14 @@ func getStartRelayerCmd(config utils.RollappConfig) *exec.Cmd {
}

func runDaWithRestarts(rollappConfig utils.RollappConfig, serviceConfig utils.ServiceConfig) {
daLogFilePath := da_start.GetDALogFilePath(rollappConfig.Home)
daLogFilePath := utils.GetDALogFilePath(rollappConfig.Home)
startDALCCmd := da_start.GetStartDACmd(rollappConfig, consts.DefaultCelestiaRPC)
utils.RunServiceWithRestart(startDALCCmd, serviceConfig, utils.WithLogging(daLogFilePath))
}

func runSequencerWithRestarts(rollappConfig utils.RollappConfig, serviceConfig utils.ServiceConfig) {
startRollappCmd := sequnecer_start.GetStartRollappCmd(rollappConfig, consts.DefaultDALCRPC)
utils.RunServiceWithRestart(startRollappCmd, serviceConfig, utils.WithLogging(
filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log")))
utils.RunServiceWithRestart(startRollappCmd, serviceConfig, utils.WithLogging(utils.GetSequencerLogPath(rollappConfig)))
}

func verifyBalances(rollappConfig utils.RollappConfig) {
Expand Down
23 changes: 23 additions & 0 deletions cmd/run/services_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package run

import (
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
)

func getServicesInfo(rollappConfig utils.RollappConfig, termWidth int) *widgets.Table {
table := widgets.NewTable()
table.RowStyles[0] = termui.NewStyle(termui.ColorWhite, termui.ColorClear, termui.ModifierBold)
table.SetRect(0, 13, termWidth, 22)
table.Title = "Services Info"
table.FillRow = true
table.ColumnWidths = []int{termWidth / 6, termWidth / 2, termWidth / 3}
table.Rows = [][]string{
{"Name", "Log File", "Ports"},
{"Sequencer", utils.GetSequencerLogPath(rollappConfig), "26657, 8545, 1317"},
{"Relayer", utils.GetRelayerLogPath(rollappConfig), ""},
{"DA Light Client", utils.GetDALogFilePath(rollappConfig.Home), "26659"},
}
return table
}
14 changes: 6 additions & 8 deletions cmd/run/services_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ func PrintServicesStatus(rollappConfig utils.RollappConfig) {
termWidth, _ := ui.TerminalDimensions()

p := buildUIParagraph(termWidth)
table := buildUITable(termWidth)
servicesStatusTable := buildUITable(termWidth)
servicesInfoTable := getServicesInfo(rollappConfig, termWidth)
serviceData := getInitialServiceData()

updateUITable(serviceData, table)
ui.Render(p, table)
updateUITable(serviceData, servicesStatusTable)
ui.Render(p, servicesStatusTable, servicesInfoTable)

events := ui.PollEvents()
ticker := time.NewTicker(time.Second * 1).C

config := ServiceStatusConfig{
rollappConfig: rollappConfig,
logger: logger,
table: table,
p: p,
table: servicesStatusTable,
}

eventLoop(events, ticker, config)
Expand All @@ -102,10 +102,9 @@ func eventLoop(events <-chan ui.Event, ticker <-chan time.Time, config ServiceSt
config.logger.Printf("Error: failed to fetch service data: %v", err)
} else {
config.logger.Printf("Fetched services data successfully %s", serviceData)

}
updateUITable(serviceData, config.table)
ui.Render(config.p, config.table)
ui.Render(config.table)
}
}
}
Expand All @@ -114,5 +113,4 @@ type ServiceStatusConfig struct {
rollappConfig utils.RollappConfig
logger *log.Logger
table *widgets.Table
p *widgets.Paragraph
}
8 changes: 3 additions & 5 deletions cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ func StartCmd() *cobra.Command {
utils.PrintInsufficientBalancesIfAny(sequencerInsufficientAddrs)
LightNodeEndpoint := cmd.Flag(FlagNames.DAEndpoint).Value.String()
startRollappCmd := GetStartRollappCmd(rollappConfig, LightNodeEndpoint)
utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError, utils.WithLogging(
filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log")))
utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError,
utils.WithLogging(utils.GetSequencerLogPath(rollappConfig)))
},
}
utils.AddGlobalFlags(runCmd)

runCmd.Flags().StringP(FlagNames.DAEndpoint, "", consts.DefaultDALCRPC,
"The data availability light node endpoint.")
return runCmd
Expand Down Expand Up @@ -90,7 +90,5 @@ func GetStartRollappCmd(rollappConfig utils.RollappConfig, lightNodeEndpoint str
"--log_level", "info",
"--max-log-size", "2000",
)

fmt.Println(cmd.String())
return cmd
}
3 changes: 2 additions & 1 deletion cmd/utils/global_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
)

func AddGlobalFlags(command *cobra.Command) {
command.Flags().StringP(FlagNames.Home, "", GetRollerRootDir(), "The directory of the roller config files")
command.PersistentFlags().StringP(
FlagNames.Home, "", GetRollerRootDir(), "The directory of the roller config files")
}

var FlagNames = struct {
Expand Down
13 changes: 13 additions & 0 deletions cmd/utils/log.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"github.com/dymensionxyz/roller/cmd/consts"
"gopkg.in/natefinch/lumberjack.v2"
"io"
"log"
Expand Down Expand Up @@ -32,3 +33,15 @@ func GetLogger(filepath string) *log.Logger {
logger := log.New(multiWriter, "", log.LstdFlags)
return logger
}

func GetSequencerLogPath(rollappConfig RollappConfig) string {
return filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log")
}

func GetRelayerLogPath(config RollappConfig) string {
return filepath.Join(config.Home, consts.ConfigDirName.Relayer, "relayer.log")
}

func GetDALogFilePath(home string) string {
return filepath.Join(home, consts.ConfigDirName.DALightNode, "light_client.log")
}
11 changes: 5 additions & 6 deletions test/config/init/init_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package initconfig_test

import (
"fmt"
"io/ioutil"
"path/filepath"
"testing"
Expand Down Expand Up @@ -39,13 +38,13 @@ func TestInitCmd(t *testing.T) {
assert := assert.New(t)
tempDir, err := ioutil.TempDir(os.TempDir(), "test")
tempDir = filepath.Join(tempDir, ".roller")
fmt.Println(tc.name, tempDir)
assert.NoError(err)
//defer func() {
// err := os.RemoveAll(tempDir)
// assert.NoError(err)
//}()
defer func() {
err := os.RemoveAll(tempDir)
assert.NoError(err)
}()
initCmd := initconfig.InitCmd()
utils.AddGlobalFlags(initCmd)
denom := "udym"
rollappID := "mars_1-1"
initCmd.SetArgs(append([]string{
Expand Down

0 comments on commit 337ab5d

Please sign in to comment.