Skip to content

Commit

Permalink
Merge branch 'main' into itaylevyofficial/90-start-log-files
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 25, 2023
2 parents 0f82bd9 + b4c875e commit 06bff04
Show file tree
Hide file tree
Showing 28 changed files with 292 additions and 115 deletions.
17 changes: 17 additions & 0 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package initconfig

import (
"fmt"
"regexp"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
Expand All @@ -21,10 +22,20 @@ func addFlags(cmd *cobra.Command) {
if _, ok := Hubs[hubID]; !ok {
return fmt.Errorf("invalid hub ID: %s. %s", hubID, getAvailableHubsMessage())
}
rollappID := args[0]
if !validateRollAppID(rollappID) {
return fmt.Errorf("invalid RollApp ID '%s'. %s", rollappID, getValidRollappIdMessage())
}
return nil
}
}

func getValidRollappIdMessage() string {
return "A valid RollApp ID should follow the format 'rollapp-name_EIP155_version', where 'rollapp-name' is made up of" +
" lowercase English letters, 'EIP155_version' is a 1 to 5 digit number representing the EIP155 rollapp ID, and '" +
"version' is a 1 to 5 digit number representing the version. For example: 'mars_9721_1'"
}

func getDecimals(cmd *cobra.Command) uint64 {
decimals, err := cmd.Flags().GetUint64(FlagNames.Decimals)
if err != nil {
Expand Down Expand Up @@ -61,3 +72,9 @@ func GetInitConfig(initCmd *cobra.Command, args []string) utils.RollappConfig {
func getAvailableHubsMessage() string {
return fmt.Sprintf("Acceptable values are '%s', '%s' or '%s'", TestnetHubID, StagingHubID, LocalHubID)
}

func validateRollAppID(id string) bool {
pattern := `^[a-z]+_[0-9]{1,5}_[0-9]{1,5}$`
r, _ := regexp.Compile(pattern)
return r.MatchString(id)
}
13 changes: 8 additions & 5 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package initconfig

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"os"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
"os"
)

func InitCmd() *cobra.Command {
initCmd := &cobra.Command{
Use: "init <chain-id> <denom>",
Use: "init <rollapp-id> <denom>",
Short: "Initialize a RollApp configuration on your local machine.",
Long: fmt.Sprintf(`Initialize a RollApp configuration on your local machine.
%s
`, getValidRollappIdMessage()),
Run: func(cmd *cobra.Command, args []string) {
initConfig := GetInitConfig(cmd, args)
utils.PrettifyErrorIfExists(VerifyUniqueRollappID(initConfig.RollappID, initConfig))
Expand Down Expand Up @@ -44,7 +47,7 @@ func InitCmd() *cobra.Command {
addresses, err := generateKeys(initConfig)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
daAddress, err := utils.GetCelestiaAddress(filepath.Join(initConfig.Home, consts.ConfigDirName.DALightNode, consts.KeysDirName))
daAddress, err := utils.GetCelestiaAddress(initConfig.Home)
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.DALightNode] = daAddress
initializeRollappConfig(initConfig)
Expand Down
14 changes: 7 additions & 7 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func generateSequencersKeys(initConfig utils.RollappConfig) (map[string]string,
return addresses, nil
}

func getSequencerKeysConfig() []utils.KeyConfig {
return []utils.KeyConfig{
func getSequencerKeysConfig() []utils.CreateKeyConfig {
return []utils.CreateKeyConfig{
{
Dir: consts.ConfigDirName.Rollapp,
Dir: consts.ConfigDirName.HubKeys,
ID: consts.KeyNames.HubSequencer,
CoinType: consts.CoinTypes.Cosmos,
Prefix: consts.AddressPrefixes.Hub,
Expand All @@ -58,8 +58,8 @@ func getSequencerKeysConfig() []utils.KeyConfig {
}
}

func getRelayerKeysConfig(rollappConfig utils.RollappConfig) map[string]utils.KeyConfig {
return map[string]utils.KeyConfig{
func getRelayerKeysConfig(rollappConfig utils.RollappConfig) map[string]utils.CreateKeyConfig {
return map[string]utils.CreateKeyConfig{
consts.KeyNames.RollappRelayer: {
Dir: path.Join(rollappConfig.Home, consts.ConfigDirName.Relayer),
ID: consts.KeyNames.RollappRelayer,
Expand All @@ -75,7 +75,7 @@ func getRelayerKeysConfig(rollappConfig utils.RollappConfig) map[string]utils.Ke
}
}

func createAddressBinary(keyConfig utils.KeyConfig, binaryPath string, home string) (string, error) {
func createAddressBinary(keyConfig utils.CreateKeyConfig, binaryPath string, home string) (string, error) {
createKeyCommand := exec.Command(binaryPath, "keys", "add", keyConfig.ID, "--keyring-backend", "test",
"--keyring-dir", filepath.Join(home, keyConfig.Dir), "--output", "json")
out, err := utils.ExecBashCommand(createKeyCommand)
Expand Down Expand Up @@ -111,7 +111,7 @@ func generateRelayerKeys(rollappConfig utils.RollappConfig) (map[string]string,
return relayerAddresses, err
}

func getAddRlyKeyCmd(keyConfig utils.KeyConfig, chainID string) *exec.Cmd {
func getAddRlyKeyCmd(keyConfig utils.CreateKeyConfig, chainID string) *exec.Cmd {
return exec.Command(
consts.Executables.Relayer,
consts.KeysDirName,
Expand Down
23 changes: 2 additions & 21 deletions cmd/config/init/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,11 @@ package initconfig

import (
"fmt"
"os"

"github.com/dymensionxyz/roller/cmd/consts"
"github.com/olekukonko/tablewriter"
"github.com/dymensionxyz/roller/cmd/utils"
)

func printInitOutput(addresses map[string]string, rollappId string) {
fmt.Printf("💈 RollApp '%s' configuration files have been successfully generated on your local machine. Congratulations!\n\n", rollappId)

fmt.Printf("🔑 Addresses:\n\n")

data := [][]string{
{"Celestia", addresses[consts.KeyNames.DALightNode]},
{"Sequencer", addresses[consts.KeyNames.HubSequencer]},
{"Relayer, Hub", addresses[consts.KeyNames.HubRelayer]},
{"Relayer, RollApp", addresses[consts.KeyNames.RollappRelayer]},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetBorder(false)
table.AppendBulk(data)
table.Render()

utils.PrintAddresses(addresses)
fmt.Printf("\n🔔 Please fund these addresses to register and run the rollapp.\n")
}
3 changes: 2 additions & 1 deletion cmd/config/init/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
)

func initializeRollappConfig(initConfig utils.RollappConfig) {
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", consts.KeyNames.HubSequencer, "--chain-id", initConfig.RollappID, "--home", filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp))
initRollappCmd := exec.Command(initConfig.RollappBinary, "init", consts.KeyNames.HubSequencer, "--chain-id",
initConfig.RollappID, "--home", filepath.Join(initConfig.Home, consts.ConfigDirName.Rollapp))
err := initRollappCmd.Run()
if err != nil {
panic(err)
Expand Down
2 changes: 2 additions & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ var ConfigDirName = struct {
Rollapp string
Relayer string
DALightNode string
HubKeys string
}{
Rollapp: "rollapp",
Relayer: "relayer",
DALightNode: "da-light-node",
HubKeys: "hub-keys",
}

var CoinTypes = struct {
Expand Down
3 changes: 0 additions & 3 deletions cmd/da-light-client/da_light_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ func DALightClientCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "da-light-client",
Short: "Commands for running and managing the data availability light client.",

Run: func(cmd *cobra.Command, args []string) {
},
}
cmd.AddCommand(da_start.Cmd())
return cmd
Expand Down
19 changes: 14 additions & 5 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/spf13/cobra"
)

const rpcEndpointFlag = "--rpc-endpoint"

func Cmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "start",
Expand All @@ -18,28 +20,35 @@ func Cmd() *cobra.Command {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := utils.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getCelestiaCmd(rollappConfig)
rpcEndpoint := cmd.Flag(rpcEndpointFlag).Value.String()
startDACmd := getStartCelestiaLCCmd(rollappConfig, rpcEndpoint)
logFilePath := filepath.Join(rollappConfig.Home, consts.ConfigDirName.DALightNode, "light_client.log")
utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError, utils.WithLogging(logFilePath))
utils.RunBashCmdAsync(startDACmd, printOutput, parseError, utils.WithLogging(logFilePath))
},
}
utils.AddGlobalFlags(runCmd)
addFlags(runCmd)
return runCmd
}

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(rpcEndpointFlag, "", "consensus-full-arabica-8.celestia-arabica.com",
"The DA rpc endpoint to connect to.")
}

func printOutput() {
fmt.Println("💈 The data availability light node is running on your local machine!")
fmt.Println("💈 Light node endpoint: http://0.0.0.0:26659")
fmt.Println("💈 Light node endpoint: http://127.0.0.1:26659")
}

func parseError(errMsg string) string {
return errMsg
}

func getCelestiaCmd(rollappConfig utils.RollappConfig) *exec.Cmd {
func getStartCelestiaLCCmd(rollappConfig utils.RollappConfig, rpcEndpoint string) *exec.Cmd {
return exec.Command(
consts.Executables.Celestia, "light", "start",
"--core.ip", "consensus-full-arabica-8.celestia-arabica.com",
"--core.ip", rpcEndpoint,
"--node.store", filepath.Join(rollappConfig.Home, consts.ConfigDirName.DALightNode),
"--gateway",
"--gateway.addr", "127.0.0.1",
Expand Down
15 changes: 15 additions & 0 deletions cmd/keys/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package keys

import (
"github.com/dymensionxyz/roller/cmd/keys/list"
"github.com/spf13/cobra"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "keys",
Short: "Commands for managing the roller different keys.",
}
cmd.AddCommand(list.Cmd())
return cmd
}
45 changes: 45 additions & 0 deletions cmd/keys/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package list

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

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all the addresses of roller on the local machine.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := utils.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
daAddr, err := utils.GetCelestiaAddress(rollappConfig.Home)
utils.PrettifyErrorIfExists(err)
addresses := map[string]string{}
addresses[consts.KeyNames.DALightNode] = daAddr
hubSeqAddr, err := utils.GetAddressBinary(utils.GetKeyConfig{
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys),
ID: consts.KeyNames.HubSequencer,
}, consts.Executables.Dymension)
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.HubSequencer] = hubSeqAddr
rollappSeqAddr, err := utils.GetAddressBinary(utils.GetKeyConfig{
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
ID: consts.KeyNames.RollappSequencer,
}, consts.Executables.RollappEVM)
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.RollappSequencer] = rollappSeqAddr
hubRlyAddr, err := utils.GetRelayerAddress(rollappConfig.Home, rollappConfig.HubData.ID)
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.HubRelayer] = hubRlyAddr
rollappRlyAddr, err := utils.GetRelayerAddress(rollappConfig.Home, rollappConfig.RollappID)
utils.PrettifyErrorIfExists(err)
addresses[consts.KeyNames.RollappRelayer] = rollappRlyAddr
utils.PrintAddresses(addresses)
},
}
utils.AddGlobalFlags(cmd)
return cmd
}
2 changes: 1 addition & 1 deletion cmd/register/bash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func getCommonDymdTxFlags(rollappConfig utils.RollappConfig) []string {
txArgs := []string{
"--from", consts.KeyNames.HubSequencer,
"--keyring-backend", "test",
"--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
"--keyring-dir", filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys),
"--yes", "--broadcast-mode", "block", "--chain-id", rollappConfig.HubData.ID,
}
return append(commonFlags, txArgs...)
Expand Down
13 changes: 6 additions & 7 deletions cmd/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/spf13/cobra"
)

func RegisterCmd() *cobra.Command {
func Cmd() *cobra.Command {
registerCmd := &cobra.Command{
Use: "register",
Short: "Registers the rollapp and the sequencer to the Dymension hub.",
Expand Down Expand Up @@ -61,13 +61,12 @@ func handleStdErr(stderr bytes.Buffer, rollappConfig utils.RollappConfig) error
stderrStr := stderr.String()
if len(stderrStr) > 0 {
if strings.Contains(stderrStr, "key not found") {
sequencerAddress, err := utils.GetAddress(
utils.KeyConfig{
ID: consts.KeyNames.HubSequencer,
Prefix: consts.AddressPrefixes.Hub,
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp),
CoinType: consts.CoinTypes.Cosmos,
sequencerAddress, err := utils.GetAddressBinary(
utils.GetKeyConfig{
ID: consts.KeyNames.HubSequencer,
Dir: filepath.Join(rollappConfig.Home, consts.ConfigDirName.HubKeys),
},
consts.Executables.Dymension,
)
if err != nil {
return err
Expand Down
5 changes: 1 addition & 4 deletions cmd/relayer/start/create_ibc_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ func getLogFilePath(home string) string {
return filepath.Join(home, consts.ConfigDirName.Relayer, "relayer.log")
}

// Creates an IBC channel between the hub and the client, and return the source channel ID.
func createIBCChannelIfNeeded(rollappConfig utils.RollappConfig, logFileOption utils.CommandOption) (string, error) {
/**
Creates an IBC channel between the hub and the client, and return the source channel ID.
*/

createClientsCmd := getCreateClientsCmd(rollappConfig, rollappConfig.RollappID, rollappConfig.HubData.ID)
fmt.Println("Creating clients...")
if err := utils.ExecBashCmdWithOSOutput(createClientsCmd, logFileOption); err != nil {
Expand Down
6 changes: 2 additions & 4 deletions cmd/relayer/start/get_active_src_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"os/exec"
)

// GetSourceChannelForConnection Returns the open source channel for the given destination connection ID. If no open channel exists, it returns an
// empty string.
func GetSourceChannelForConnection(dstConnectionID string, rollappConfig utils.RollappConfig) (string, error) {
/**
Returns the open source channel for the given destination connection ID. If no open channel exists, it returns an
emtpy string.
*/
commonDymdFlags := utils.GetCommonDymdFlags(rollappConfig)
args := []string{"query", "ibc", "channel", "connections", dstConnectionID}
args = append(args, commonDymdFlags...)
Expand Down
5 changes: 2 additions & 3 deletions cmd/relayer/start/get_dst_connection_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ type Destination struct {
ConnectionID string `yaml:"connection-id"`
}

// GetDstConnectionIDFromYAMLFile Returns the destination connection ID if it been created already, an empty string otherwise.
func GetDstConnectionIDFromYAMLFile(filename string) (string, error) {
/**
Returns the destination connection ID if it been created already, an empty string otherwise.
*/

data, err := ioutil.ReadFile(filename)
if err != nil {
return "", err
Expand Down
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/dymensionxyz/roller/cmd/config"
da_light_client "github.com/dymensionxyz/roller/cmd/da-light-client"
"github.com/dymensionxyz/roller/cmd/keys"
"github.com/dymensionxyz/roller/cmd/register"
"github.com/dymensionxyz/roller/cmd/relayer"
"github.com/dymensionxyz/roller/cmd/sequencer"
Expand All @@ -30,8 +31,9 @@ func Execute() {
func init() {
rootCmd.AddCommand(config.ConfigCmd())
rootCmd.AddCommand(version.VersionCmd())
rootCmd.AddCommand(register.RegisterCmd())
rootCmd.AddCommand(register.Cmd())
rootCmd.AddCommand(da_light_client.DALightClientCmd())
rootCmd.AddCommand(sequencer.SequencerCmd())
rootCmd.AddCommand(relayer.Cmd())
rootCmd.AddCommand(keys.Cmd())
}
Loading

0 comments on commit 06bff04

Please sign in to comment.