diff --git a/cmd/config/set/da.go b/cmd/config/set/da.go index 4d77ca99..06e7bb87 100644 --- a/cmd/config/set/da.go +++ b/cmd/config/set/da.go @@ -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 { diff --git a/cmd/config/set/lc_rpc.go b/cmd/config/set/lc_rpc.go index e4fe73b0..b9d96864 100644 --- a/cmd/config/set/lc_rpc.go +++ b/cmd/config/set/lc_rpc.go @@ -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 } @@ -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) +} diff --git a/cmd/config/set/rollapp_rpc.go b/cmd/config/set/rollapp_rpc.go index bda34b0e..bd50850b 100644 --- a/cmd/config/set/rollapp_rpc.go +++ b/cmd/config/set/rollapp_rpc.go @@ -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) +} diff --git a/cmd/config/set/set.go b/cmd/config/set/set.go index bdecfd3c..ed333cae 100644 --- a/cmd/config/set/set.go +++ b/cmd/config/set/set.go @@ -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 ", - 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() @@ -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 +}