Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add set functions to all rollapp ports #457

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions cmd/config/set/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import (
"path/filepath"
)

func setDA(rlpCfg config.RollappConfig, value config.DAType) error {
if value == rlpCfg.DA {
func setDA(rlpCfg config.RollappConfig, value string) error {
daValue := config.DAType(value)
if daValue == rlpCfg.DA {
return nil
}
supportedDas := []config.DAType{config.Celestia, config.Avail, config.Local}
if !config.IsValidDAType(string(value)) {
if !config.IsValidDAType(value) {
return fmt.Errorf("invalid DA type. Supported types are: %v", supportedDas)
}
return updateDaConfig(rlpCfg, value)
return updateDaConfig(rlpCfg, daValue)
}

func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error {
Expand Down
16 changes: 15 additions & 1 deletion cmd/config/set/lc_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"
)

func setLCRPC(cfg config.RollappConfig, value string) error {
func setLCGatewayPort(cfg config.RollappConfig, value string) error {
if err := validatePort(value); err != nil {
return err
}
Expand All @@ -22,3 +22,17 @@ func setLCRPC(cfg config.RollappConfig, value string) error {
}
return sequencer.UpdateDymintDAConfig(cfg)
}

func setLCRPCPort(cfg config.RollappConfig, value string) error {
if err := validatePort(value); err != nil {
return err
}
if cfg.DA != config.Celestia {
return errors.New("setting the LC RPC port is only supported for Celestia")
}
if err := utils.UpdateFieldInToml(filepath.Join(cfg.Home, consts.ConfigDirName.DALightNode, "config.toml"),
"RPC.Port", value); err != nil {
return err
}
return sequencer.UpdateDymintDAConfig(cfg)
}
24 changes: 24 additions & 0 deletions cmd/config/set/rollapp_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,27 @@ func updateRlpCfg(rlpCfg config.RollappConfig, newRpc string) error {
configFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "config.toml")
return utils.UpdateFieldInToml(configFilePath, "rpc.laddr", "tcp://0.0.0.0:"+newRpc)
}

func setJsonRpcPort(cfg config.RollappConfig, value string) error {
if err := validatePort(value); err != nil {
return err
}
appCfgFilePath := filepath.Join(cfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
return utils.UpdateFieldInToml(appCfgFilePath, "json-rpc.address", "0.0.0.0:"+value)
}

func setWSPort(cfg config.RollappConfig, value string) error {
if err := validatePort(value); err != nil {
return err
}
appCfgFilePath := filepath.Join(cfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
return utils.UpdateFieldInToml(appCfgFilePath, "json-rpc.ws-address", "0.0.0.0:"+value)
}

func setGRPCPort(cfg config.RollappConfig, value string) error {
if err := validatePort(value); err != nil {
return err
}
appCfgFilePath := filepath.Join(cfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
return utils.UpdateFieldInToml(appCfgFilePath, "grpc.address", "0.0.0.0:"+value)
}
34 changes: 20 additions & 14 deletions cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import (
"github.com/spf13/cobra"
)

var supportedKeys = []string{
"rollapp-rpc-port",
"lc-rpc-port",
"da",
var keyUpdateFuncs = map[string]func(cfg config.RollappConfig, value string) error{
"rollapp-rpc-port": setRollappRPC,
"lc-gateway-port": setLCGatewayPort,
"lc-rpc-port": setLCRPCPort,
"rollapp-jsonrpc-port": setJsonRpcPort,
"rollapp-ws-port": setWSPort,
"rollapp-grpc-port": setGRPCPort,
"da": setDA,
}

func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "set <key> <value>",
Short: fmt.Sprintf("Updates the specified key (supported keys: %v) in all relevant places within the roller configuration files.", supportedKeys),
Short: "Updates the specified key in all relevant places within the roller configuration files.",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
home := cmd.Flag(utils.FlagNames.Home).Value.String()
Expand All @@ -26,17 +30,19 @@ func Cmd() *cobra.Command {
}
key := args[0]
value := args[1]
switch key {
case "rollapp-rpc-port":
return setRollappRPC(rlpCfg, value)
case "lc-rpc-port":
return setLCRPC(rlpCfg, value)
case "da":
return setDA(rlpCfg, config.DAType(value))
default:
return fmt.Errorf("invalid key. Supported keys are: %v", supportedKeys)
if updateFunc, exists := keyUpdateFuncs[key]; exists {
return updateFunc(rlpCfg, value)
}
return fmt.Errorf("invalid key. Supported keys are: %v", getSupportedKeys())
},
}
return cmd
}

func getSupportedKeys() []string {
keys := make([]string, 0, len(keyUpdateFuncs))
for key := range keyUpdateFuncs {
keys = append(keys, key)
}
return keys
}