Skip to content

Commit

Permalink
feat: update sequencer metadata (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Aug 20, 2024
1 parent 3febe76 commit 2166bc6
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/data_layer/celestia"
"github.com/dymensionxyz/roller/utils/bash"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/errorhandling"
Expand Down Expand Up @@ -86,7 +87,7 @@ func Cmd() *cobra.Command {

func addFlags(cmd *cobra.Command) {
cmd.Flags().
StringP(rpcEndpointFlag, "", "celestia-testnet-consensus.itrocket.net", "The DA rpc endpoint to connect to.")
StringP(rpcEndpointFlag, "", celestia.DefaultCelestiaStateNode, "The DA rpc endpoint to connect to.")
cmd.Flags().
StringP(metricsEndpointFlag, "", "", "The OTEL collector metrics endpoint to connect to.")
}
Expand Down
9 changes: 8 additions & 1 deletion cmd/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/dymensionxyz/roller/cmd/relayer/status"
"github.com/dymensionxyz/roller/cmd/services"
loadservices "github.com/dymensionxyz/roller/cmd/services/load"
restartservices "github.com/dymensionxyz/roller/cmd/services/restart"
startservices "github.com/dymensionxyz/roller/cmd/services/start"
)

Expand All @@ -19,7 +20,13 @@ func Cmd() *cobra.Command {
cmd.AddCommand(run.Cmd())
cmd.AddCommand(start.Cmd())
cmd.AddCommand(status.Cmd())
cmd.AddCommand(services.Cmd(loadservices.RelayerCmd(), startservices.RelayerCmd()))
cmd.AddCommand(
services.Cmd(
loadservices.RelayerCmd(),
startservices.RelayerCmd(),
restartservices.RelayerCmd(),
),
)

return cmd
}
20 changes: 20 additions & 0 deletions cmd/rollapp/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package config

import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/rollapp/config/set"
"github.com/dymensionxyz/roller/cmd/rollapp/config/show"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Update the relevant configuration values related to RollApp",
}

cmd.AddCommand(show.Cmd())
cmd.AddCommand(set.Cmd())

return cmd
}
116 changes: 116 additions & 0 deletions cmd/rollapp/config/set/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package set

import (
"fmt"
"path/filepath"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

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

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set <key> <new-value>",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
k := args[0]
v := args[1]
home := cmd.Flag(cmdutils.FlagNames.Home).Value.String()

dymintConfigPath := filepath.Join(
home,
consts.ConfigDirName.Rollapp,
"config",
"dymint.toml",
)
appConfigPath := filepath.Join(
home,
consts.ConfigDirName.Rollapp,
"config",
"app.toml",
)
// nice name, ik
configConfigPath := filepath.Join(
home,
consts.ConfigDirName.Rollapp,
"config",
"config.toml",
)

// TODO: refactor, each configurable value can be a struct
// containing config file path, key and the current value
switch k {
case "rollapp_minimum_gas_price":
cfg := appConfigPath
err := utils.UpdateFieldInToml(cfg, "minimum-gas-prices", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "rollapp_rpc_port":
cfg := configConfigPath
err := utils.UpdateFieldInToml(cfg, "rpc.laddr", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "rollapp_grpc_port":
cfg := appConfigPath
err := utils.UpdateFieldInToml(cfg, "grpc-web.address", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "rollapp_rest_api_port":
cfg := appConfigPath
err := utils.UpdateFieldInToml(cfg, "api.address", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "rollapp_json_rpc_port":
cfg := appConfigPath
err := utils.UpdateFieldInToml(cfg, "json-rpc.address", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "rollapp_ws_port":
cfg := appConfigPath
err := utils.UpdateFieldInToml(cfg, "json-rpc.ws-address", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "settlement_node_address":
cfg := dymintConfigPath
err := utils.UpdateFieldInToml(cfg, "settlement_node_address", v)
if err != nil {
pterm.Error.Printf("failed to update %s: %s", k, err)
return
}
case "da_node_address":
// Handle da_node_address
fmt.Printf("Setting DA node address to: %s\n", v)
// Add your logic here
default:
pterm.Error.Printf("unknown configuration key: %s\n", k)
return
}

pterm.Info.Println("next steps:")
pterm.Info.Println("if this was the only configuration value you wanted to update")
pterm.Info.Printf(
"run %s to restart the systemd services and apply the new values\n",
pterm.DefaultBasicText.WithStyle(pterm.FgYellow.ToStyle()).
Sprintf("roller rollapp services restart"),
)
},
}

return cmd
}
26 changes: 26 additions & 0 deletions cmd/rollapp/config/show/show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package show

import (
"github.com/pterm/pterm"
"github.com/spf13/cobra"

cmdutils "github.com/dymensionxyz/roller/cmd/utils"
configutils "github.com/dymensionxyz/roller/utils/config"
)

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show",
Run: func(cmd *cobra.Command, args []string) {
home := cmd.Flag(cmdutils.FlagNames.Home).Value.String()

err := configutils.ShowCurrentConfigurableValues(home)
if err != nil {
pterm.Error.Println("failed to retrieve configurable values: ", err)
return
}
},
}

return cmd
}
12 changes: 10 additions & 2 deletions cmd/rollapp/rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package rollapp
import (
"github.com/spf13/cobra"

"github.com/dymensionxyz/roller/cmd/rollapp/config"
initrollapp "github.com/dymensionxyz/roller/cmd/rollapp/init"
"github.com/dymensionxyz/roller/cmd/rollapp/run"
"github.com/dymensionxyz/roller/cmd/rollapp/sequencer"
"github.com/dymensionxyz/roller/cmd/rollapp/start"
"github.com/dymensionxyz/roller/cmd/rollapp/status"
"github.com/dymensionxyz/roller/cmd/services"
loadservices "github.com/dymensionxyz/roller/cmd/services/load"
restartservices "github.com/dymensionxyz/roller/cmd/services/restart"
startservices "github.com/dymensionxyz/roller/cmd/services/start"
)

Expand All @@ -22,10 +24,16 @@ func Cmd() *cobra.Command {
cmd.AddCommand(initrollapp.Cmd())
cmd.AddCommand(status.Cmd())
cmd.AddCommand(start.Cmd())
// cmd.AddCommand(config.Cmd())
cmd.AddCommand(config.Cmd())
cmd.AddCommand(run.Cmd())
cmd.AddCommand(sequencer.Cmd())
cmd.AddCommand(services.Cmd(loadservices.RollappCmd(), startservices.RollappCmd()))
cmd.AddCommand(
services.Cmd(
loadservices.RollappCmd(),
startservices.RollappCmd(),
restartservices.RollappCmd(),
),
)

return cmd
}
4 changes: 2 additions & 2 deletions cmd/services/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type ServiceTemplateData struct {
func RollappCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "load",
Short: "Loads the different rollapp services on the local machine",
Short: "Loads the different RollApp services on the local machine",
Run: func(cmd *cobra.Command, args []string) {
if runtime.GOOS != "linux" {
pterm.Error.Printf(
Expand Down Expand Up @@ -78,7 +78,7 @@ func RollappCmd() *cobra.Command {
func RelayerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "load",
Short: "Loads the different rollapp services on the local machine",
Short: "Loads the different RollApp services on the local machine",
Run: func(cmd *cobra.Command, args []string) {
if runtime.GOOS != "linux" {
pterm.Error.Printf(
Expand Down
63 changes: 63 additions & 0 deletions cmd/services/restart/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package restart

import (
"fmt"
"runtime"
"strings"

"github.com/pterm/pterm"
"github.com/spf13/cobra"

servicemanager "github.com/dymensionxyz/roller/utils/service_manager"
)

func RollappCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "restart",
Short: "Restarts the systemd services relevant to RollApp",
Run: func(cmd *cobra.Command, args []string) {
services := []string{"rollapp", "da-light-client"}
err := restartSystemdServices(services)
if err != nil {
pterm.Error.Println("failed to restart systemd services:", err)
return
}
},
}
return cmd
}

func RelayerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "restart",
Short: "Restarts the systemd services relevant to the relayer",
Run: func(cmd *cobra.Command, args []string) {
services := []string{"relayer"}
err := restartSystemdServices(services)
if err != nil {
pterm.Error.Println("failed to restart systemd services:", err)
return
}
},
}
return cmd
}

func restartSystemdServices(services []string) error {
if runtime.GOOS != "linux" {
return fmt.Errorf(
"the services commands are only available on linux machines",
)
}
for _, service := range services {
err := servicemanager.RestartSystemdService(fmt.Sprintf("%s.service", service))
if err != nil {
return fmt.Errorf("failed to start %s systemd service: %v", service, err)
}
}
pterm.Success.Printf(
"💈 Services %s started successfully.\n",
strings.Join(services, ", "),
)
return nil
}
3 changes: 2 additions & 1 deletion cmd/services/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package services

import "github.com/spf13/cobra"

func Cmd(loadCmd, startCmd *cobra.Command) *cobra.Command {
func Cmd(loadCmd, startCmd, restartCmd *cobra.Command) *cobra.Command {
cmd := &cobra.Command{
Use: "services [command]",
Short: "Commands for managing systemd services.",
}
cmd.AddCommand(loadCmd)
cmd.AddCommand(startCmd)
cmd.AddCommand(restartCmd)
return cmd
}
4 changes: 2 additions & 2 deletions cmd/services/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func RollappCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Loads the different rollapp services on the local machine",
Short: "Loads the different RollApp services on the local machine",
Run: func(cmd *cobra.Command, args []string) {
services := []string{"rollapp", "da-light-client"}
err := startSystemdServices(services)
Expand All @@ -37,7 +37,7 @@ func RollappCmd() *cobra.Command {
func RelayerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Loads the different rollapp services on the local machine",
Short: "Loads the different RollApp services on the local machine",
Run: func(cmd *cobra.Command, args []string) {
services := []string{"relayer"}
err := startSystemdServices(services)
Expand Down
7 changes: 5 additions & 2 deletions data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import (
// TODO: test how much is enough to run the LC for one day and set the minimum balance accordingly.
const (
DefaultCelestiaRestApiEndpoint = "https://api.celestia-mocha.com"
DefaultCelestiaRPC = "http://celestia-testnet-consensus.itrocket.net:26657"
DefaultCelestiaNetwork = "mocha"
DefaultCelestiaRPC = "http://mocha-4-consensus.mesa.newmetric.xyz:26657"

// https://docs.celestia.org/nodes/mocha-testnet#community-data-availability-da-grpc-endpoints-for-state-access
DefaultCelestiaStateNode = "full.consensus.mocha-4.celestia-mocha.com"
DefaultCelestiaNetwork = "mocha"
)

var lcMinBalance = big.NewInt(1)
Expand Down
Loading

0 comments on commit 2166bc6

Please sign in to comment.