Skip to content

Commit

Permalink
Run light client and sequencer works great
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial committed Jun 13, 2023
1 parent 513e5f1 commit 53602cb
Show file tree
Hide file tree
Showing 17 changed files with 318 additions and 97 deletions.
4 changes: 3 additions & 1 deletion cmd/config/init/DALightClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package initconfig
import (
"os/exec"
"path/filepath"

"github.com/dymensionxyz/roller/cmd/consts"
)

func initializeLightNodeConfig(initConfig InitConfig) error {
initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", "arabica", "--node.store", filepath.Join(initConfig.Home, ConfigDirName.DALightNode))
initLightNodeCmd := exec.Command(consts.Executables.Celestia, "light", "init", "--p2p.network", "arabica", "--node.store",
filepath.Join(initConfig.Home, ConfigDirName.DALightNode))
err := initLightNodeCmd.Run()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/config/init/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var KeyNames = struct {
HubSequencer: "hub_sequencer",
RollappSequencer: "rollapp_sequencer",
RollappRelayer: "relayer-rollapp-key",
DALightNode: "my-celes-key",
DALightNode: "my_celes_key",
HubRelayer: "relayer-hub-key",
}

Expand All @@ -45,7 +45,7 @@ var ConfigDirName = struct {
}{
Rollapp: "rollapp",
Relayer: "relayer",
DALightNode: "light-node",
DALightNode: "da-light-node",
}

const TestnetHubID = "35-C"
Expand Down
4 changes: 0 additions & 4 deletions cmd/config/init/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

func addFlags(cmd *cobra.Command) {
cmd.Flags().StringP(FlagNames.HubID, "", TestnetHubID, fmt.Sprintf("The ID of the Dymension hub. %s", getAvailableHubsMessage()))
cmd.Flags().StringP(FlagNames.DAEndpoint, "", "http://localhost:26659", "The data availability light node endpoint. Runs an Arabica Celestia light node if not provided")
cmd.Flags().StringP(FlagNames.RollappBinary, "", "", "The rollapp binary. Should be passed only if you built a custom rollapp")
cmd.Flags().Uint64P(FlagNames.Decimals, "", 18, "The number of decimal places a rollapp token supports")

Expand Down Expand Up @@ -46,19 +45,16 @@ func GetInitConfig(initCmd *cobra.Command, args []string) InitConfig {
rollappId := args[0]
denom := args[1]
home := initCmd.Flag(utils.FlagNames.Home).Value.String()
createLightNode := !initCmd.Flags().Changed(FlagNames.DAEndpoint)
rollappBinaryPath := getRollappBinaryPath(initCmd)
decimals := getDecimals(initCmd)
hubID := initCmd.Flag(FlagNames.HubID).Value.String()
return InitConfig{
Home: home,
RollappID: rollappId,
RollappBinary: rollappBinaryPath,
CreateDALightNode: createLightNode,
Denom: denom,
Decimals: decimals,
HubData: Hubs[hubID],
LightNodeEndpoint: initCmd.Flag(FlagNames.DAEndpoint).Value.String(),
}
}

Expand Down
27 changes: 14 additions & 13 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package initconfig
import (
"os"

"path/filepath"

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

type InitConfig struct {
Home string
RollappID string
RollappBinary string
CreateDALightNode bool
Denom string
Decimals uint64
HubData HubData
LightNodeEndpoint string
Home string
RollappID string
RollappBinary string
Denom string
Decimals uint64
HubData HubData
}

func InitCmd() *cobra.Command {
Expand All @@ -36,11 +36,9 @@ func InitCmd() *cobra.Command {
os.Exit(0)
}
}

addresses := initializeKeys(initConfig)
if initConfig.CreateDALightNode {
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
}
addresses, err := generateKeys(initConfig)
utils.PrettifyErrorIfExists(err)
utils.PrettifyErrorIfExists(initializeLightNodeConfig(initConfig))
initializeRollappConfig(initConfig)
utils.PrettifyErrorIfExists(initializeRollappGenesis(initConfig))
utils.PrettifyErrorIfExists(initializeRelayerConfig(ChainConfig{
Expand All @@ -55,6 +53,9 @@ func InitCmd() *cobra.Command {
AddressPrefix: AddressPrefixes.Hub,
}, initConfig))
utils.PrettifyErrorIfExists(WriteConfigToTOML(initConfig))
daLightNodeAddress, err := utils.GetCelestiaAddress(filepath.Join(initConfig.Home, ConfigDirName.DALightNode, KeysDirName))
utils.PrettifyErrorIfExists(err)
addresses[KeyNames.DALightNode] = daLightNodeAddress
printInitOutput(addresses, initConfig.RollappID)
},
Args: cobra.ExactArgs(2),
Expand Down
22 changes: 0 additions & 22 deletions cmd/config/init/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,32 +93,10 @@ func getDefaultKeysConfig(initConfig InitConfig) []KeyConfig {
ID: KeyNames.RollappRelayer,
CoinType: CoinTypes.EVM,
Prefix: AddressPrefixes.Rollapp,
}, {

Dir: path.Join(ConfigDirName.DALightNode, KeysDirName),
ID: KeyNames.DALightNode,
CoinType: CoinTypes.Cosmos,
Prefix: AddressPrefixes.DA,
},
}
}

func initializeKeys(initConfig InitConfig) map[string]string {
if initConfig.CreateDALightNode {
addresses, err := generateKeys(initConfig)
if err != nil {
panic(err)
}
return addresses
} else {
addresses, err := generateKeys(initConfig, KeyNames.DALightNode)
if err != nil {
panic(err)
}
return addresses
}
}

func GetAddress(keyConfig KeyConfig) (string, error) {
kr, err := keyring.New(
"",
Expand Down
30 changes: 26 additions & 4 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package consts

import "fmt"

const binsDir = "/usr/local/bin"

var internalBinsDir = fmt.Sprintf("%s/roller_bins", binsDir)

var Executables = struct {
Celestia string
RollappEVM string
Relayer string
Dymension string
CelKey string
}{
Celestia: fmt.Sprintf("%s/celestia", internalBinsDir),
CelKey: fmt.Sprintf("%s/cel-key", internalBinsDir),
RollappEVM: fmt.Sprintf("%s/rollapp_evm", binsDir),
Relayer: fmt.Sprintf("%s/rly", internalBinsDir),
Dymension: fmt.Sprintf("%s/dymd", internalBinsDir),
}

var KeyNames = struct {
HubSequencer string
RollappSequencer string
RollappRelayer string
DALightNode string
HubRelayer string
}{
Celestia: "/usr/local/bin/roller_bins/celestia",
RollappEVM: "/usr/local/bin/rollapp_evm",
Relayer: "/usr/local/bin/roller_bins/rly",
Dymension: "/usr/local/bin/roller_bins/dymd",
HubSequencer: "hub_sequencer",
RollappSequencer: "rollapp_sequencer",
RollappRelayer: "relayer-rollapp-key",
DALightNode: "my_celes_key",
HubRelayer: "relayer-hub-key",
}
18 changes: 18 additions & 0 deletions cmd/da-light-client/da_light_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package da_light_client

import (
da_start "github.com/dymensionxyz/roller/cmd/da-light-client/start"
"github.com/spf13/cobra"
)

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.StartCmd())
return cmd
}
49 changes: 49 additions & 0 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package start

import (
"fmt"
"os/exec"
"path/filepath"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
)

func StartCmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "start",
Short: "Runs the rollapp sequencer.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getCelestiaCmd(rollappConfig)
utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError)
},
}
utils.AddGlobalFlags(runCmd)
return runCmd
}

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")
}

func parseError(errMsg string) string {
return errMsg
}

func getCelestiaCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
return exec.Command(
consts.Executables.Celestia, "light", "start",
"--core.ip", "consensus-full-arabica-8.celestia-arabica.com",
"--node.store", filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.DALightNode),
"--gateway",
"--gateway.addr", "127.0.0.1",
"--gateway.port", "26659",
"--p2p.network", "arabica",
)
}
6 changes: 4 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"os"

"github.com/dymensionxyz/roller/cmd/config"
da_light_client "github.com/dymensionxyz/roller/cmd/da-light-client"
"github.com/dymensionxyz/roller/cmd/register"
"github.com/dymensionxyz/roller/cmd/run"
"github.com/dymensionxyz/roller/cmd/sequencer"
"github.com/dymensionxyz/roller/cmd/version"
"github.com/spf13/cobra"
)
Expand All @@ -29,5 +30,6 @@ func init() {
rootCmd.AddCommand(config.ConfigCmd())
rootCmd.AddCommand(version.VersionCmd())
rootCmd.AddCommand(register.RegisterCmd())
rootCmd.AddCommand(run.RunCmd())
rootCmd.AddCommand(da_light_client.DALightClientCmd())
rootCmd.AddCommand(sequencer.SequencerCmd())
}
15 changes: 15 additions & 0 deletions cmd/sequencer/sequencer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sequencer

import (
sequnecer_start "github.com/dymensionxyz/roller/cmd/sequencer/start"
"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())
return cmd
}
52 changes: 26 additions & 26 deletions cmd/run/run.go β†’ cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,48 @@
package run
package sequnecer_start

import (
"errors"
"fmt"
"os/exec"
"path/filepath"

"bytes"

"strings"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/spf13/cobra"
)

func RunCmd() *cobra.Command {
func StartCmd() *cobra.Command {
runCmd := &cobra.Command{
Use: "run",
Use: "start",
Short: "Runs the rollapp sequencer.",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
rollappConfig, err := initconfig.LoadConfigFromTOML(home)
utils.PrettifyErrorIfExists(err)
startRollappCmd := getStartRollapCmd(rollappConfig)
var stderr bytes.Buffer
startRollappCmd.Stderr = &stderr
err = startRollappCmd.Start()
if err != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
fmt.Println("πŸ’ˆ The Rollapp sequencer is running on your local machine!")
fmt.Println("πŸ’ˆ EVM RPC: http://0.0.0.0:8545")
fmt.Println("πŸ’ˆ Node RPC: http://0.0.0.0:26657")
fmt.Println("πŸ’ˆ Rest API: http://0.0.0.0:1317")
err = startRollappCmd.Wait()
if err != nil {
errMsg := parseError(stderr.String())
utils.PrettifyErrorIfExists(errors.New(errMsg))
}
LightNodeEndpoint := cmd.Flag(FlagNames.DAEndpoint).Value.String()
startRollappCmd := getStartRollapCmd(rollappConfig, LightNodeEndpoint)
utils.RunBashCmdAsync(startRollappCmd, printOutput, parseError)
},
}
utils.AddGlobalFlags(runCmd)
runCmd.Flags().StringP(FlagNames.DAEndpoint, "", "http://localhost:26659", "The data availability light node endpoint.")
return runCmd
}

var FlagNames = struct {
DAEndpoint string
}{
DAEndpoint: "da-endpoint",
}

func printOutput() {
fmt.Println("πŸ’ˆ The Rollapp sequencer is running on your local machine!")
fmt.Println("πŸ’ˆ EVM RPC: http://0.0.0.0:8545")
fmt.Println("πŸ’ˆ Node RPC: http://0.0.0.0:26657")
fmt.Println("πŸ’ˆ Rest API: http://0.0.0.0:1317")
}

func parseError(errMsg string) string {
lines := strings.Split(errMsg, "\n")
if len(lines) > 0 && lines[0] == "Error: failed to initialize database: resource temporarily unavailable" {
Expand All @@ -54,10 +51,13 @@ func parseError(errMsg string) string {
return errMsg
}

func getStartRollapCmd(rollappConfig initconfig.InitConfig) *exec.Cmd {
daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`, rollappConfig.LightNodeEndpoint)
func getStartRollapCmd(rollappConfig initconfig.InitConfig, lightNodeEndpoint string) *exec.Cmd {
daConfig := fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "fee":20000, "gas_limit": 20000000, "namespace_id":[0,0,0,0,0,0,255,255]}`,
lightNodeEndpoint)
rollappConfigDir := filepath.Join(rollappConfig.Home, initconfig.ConfigDirName.Rollapp)
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "2000000udym"}`, rollappConfig.HubData.RPC_URL, rollappConfig.RollappID, initconfig.

// TODO: Update the gas_fees to 2000000udym before 35-c launch.
settlementConfig := fmt.Sprintf(`{"node_address": "%s", "rollapp_id": "%s", "dym_account_name": "%s", "keyring_home_dir": "%s", "keyring_backend":"test", "gas_fees": "0udym"}`, rollappConfig.HubData.RPC_URL, rollappConfig.RollappID, initconfig.
KeyNames.HubSequencer, rollappConfigDir)

return exec.Command(
Expand Down
Loading

0 comments on commit 53602cb

Please sign in to comment.