Skip to content

Commit

Permalink
fix: Read output ports from config files (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Aug 28, 2023
1 parent 487f0c8 commit 38a57c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/run/services_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func NewServicesInfoTable(rollappConfig config.RollappConfig, termWidth int) *wi
seq := sequencer.GetInstance(rollappConfig)
table.Rows = [][]string{
{"Name", "Log File", "Ports"},
{"Sequencer", utils.GetSequencerLogPath(rollappConfig), fmt.Sprintf("%v, 8545, 1317", seq.RPCPort)},
{"Sequencer", utils.GetSequencerLogPath(rollappConfig), fmt.Sprintf("%v, %v, %v", seq.RPCPort, seq.JsonRPCPort, seq.APIPort)},
{"Relayer", utils.GetRelayerLogPath(rollappConfig), ""},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/sequencer/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func printOutput(rlpCfg config.RollappConfig) {
fmt.Println("💈 The Rollapp sequencer is running on your local machine!")
fmt.Println("💈 Endpoints:")

fmt.Println("💈 EVM RPC: http://0.0.0.0:8545")
fmt.Printf("💈 EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort)
fmt.Printf("💈 Node RPC: http://0.0.0.0:%v\n", seq.RPCPort)
fmt.Println("💈 Rest API: http://0.0.0.0:1317")
fmt.Printf("💈 Rest API: http://0.0.0.0:%v\n", seq.APIPort)

fmt.Println("💈 Log file path: ", LogPath)
fmt.Println("💈 Rollapp root dir: ", RollappDirPath)
Expand Down
32 changes: 24 additions & 8 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func updateDaConfigInToml(rlpCfg config.RollappConfig, dymintCfg *toml.Tree) err
}

func SetAppConfig(rlpCfg config.RollappConfig) error {
appConfigFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
appConfigFilePath := filepath.Join(getSequencerConfigDir(rlpCfg.Home), "app.toml")
appCfg, err := toml.LoadFile(appConfigFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", appConfigFilePath, err)
Expand All @@ -90,7 +90,7 @@ func SetAppConfig(rlpCfg config.RollappConfig) error {
}

func SetTMConfig(rlpCfg config.RollappConfig) error {
configFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "config.toml")
configFilePath := filepath.Join(getSequencerConfigDir(rlpCfg.Home), "config.toml")
var tomlCfg, err = toml.LoadFile(configFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", configFilePath, err)
Expand All @@ -101,18 +101,25 @@ func SetTMConfig(rlpCfg config.RollappConfig) error {
return utils.WriteTomlTreeToFile(tomlCfg, configFilePath)
}

func (seq *Sequencer) ReadRPCPort() (string, error) {
func (seq *Sequencer) ReadPorts() error {
rpcAddr, err := seq.GetConfigValue("rpc.laddr")
if err != nil {
return "", err
return err
}
parts := strings.Split(rpcAddr, ":")
port := parts[len(parts)-1]
return port, nil
seq.RPCPort = getPortFromAddress(rpcAddr)
appCfg, err := toml.LoadFile(filepath.Join(getSequencerConfigDir(seq.RlpCfg.Home), "app.toml"))
if err != nil {
return err
}
jsonRpcAddr := appCfg.Get("json-rpc.address")
seq.JsonRPCPort = getPortFromAddress(fmt.Sprint(jsonRpcAddr))
apiAddr := appCfg.Get("api.address")
seq.APIPort = getPortFromAddress(fmt.Sprint(apiAddr))
return nil
}

func (seq *Sequencer) GetConfigValue(key string) (string, error) {
configFilePath := filepath.Join(seq.RlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "config.toml")
configFilePath := filepath.Join(getSequencerConfigDir(seq.RlpCfg.Home), "config.toml")
var tomlCfg, err = toml.LoadFile(configFilePath)
if err != nil {
return "", fmt.Errorf("failed to load %s: %v", configFilePath, err)
Expand All @@ -127,3 +134,12 @@ func (seq *Sequencer) GetConfigValue(key string) (string, error) {
func (seq *Sequencer) GetRPCEndpoint() string {
return "http://localhost:" + seq.RPCPort
}

func getSequencerConfigDir(rollerHome string) string {
return filepath.Join(rollerHome, consts.ConfigDirName.Rollapp, "config")
}

func getPortFromAddress(addr string) string {
parts := strings.Split(addr, ":")
return parts[len(parts)-1]
}
12 changes: 6 additions & 6 deletions sequencer/sequencer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (
)

type Sequencer struct {
RlpCfg config.RollappConfig
RPCPort string
logger *log.Logger
RlpCfg config.RollappConfig
RPCPort string
APIPort string
JsonRPCPort string
logger *log.Logger
}

var instance *Sequencer
Expand All @@ -25,11 +27,9 @@ func GetInstance(rlpCfg config.RollappConfig) *Sequencer {
logger: log.New(io.Discard, "", 0),
RlpCfg: rlpCfg,
}
rpcPort, err := seq.ReadRPCPort()
if err != nil {
if err := seq.ReadPorts(); err != nil {
panic(err)
}
seq.RPCPort = rpcPort
instance = seq
})
return instance
Expand Down

0 comments on commit 38a57c4

Please sign in to comment.