Skip to content

Commit

Permalink
Revert "feat: Add command to modify DA light client rpc port (#369)"
Browse files Browse the repository at this point in the history
This reverts commit c082e0d.
  • Loading branch information
omritoptix authored Aug 15, 2023
1 parent d82be95 commit 353d449
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 179 deletions.
1 change: 1 addition & 0 deletions cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func runInit(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

daAddress, err := damanager.GetDAAccountAddress()
if err != nil {
return err
Expand Down
24 changes: 0 additions & 24 deletions cmd/config/set/lc_rpc.go

This file was deleted.

16 changes: 13 additions & 3 deletions cmd/config/set/rollapp_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package set
import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/utils"
"github.com/pelletier/go-toml"
"gopkg.in/yaml.v2"
"os"
"path/filepath"
Expand Down Expand Up @@ -71,10 +72,19 @@ func setNestedValue(data map[interface{}]interface{}, keyPath []string, value st

func updateRlpClientCfg(rlpCfg config.RollappConfig, newRpcPort string) error {
configFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "client.toml")
return utils.UpdateFieldInToml(configFilePath, "node", "tcp://localhost:"+newRpcPort)
return updateFieldInToml(configFilePath, "node", "tcp://localhost:"+newRpcPort)
}

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)
return updateFieldInToml(configFilePath, "rpc.laddr", "tcp://0.0.0.0:"+newRpc)
}

func updateFieldInToml(tmlFilePath, key, value string) error {
var tomlCfg, err = toml.LoadFile(tmlFilePath)
if err != nil {
return fmt.Errorf("failed to load %s: %v", tmlFilePath, err)
}
tomlCfg.Set(key, value)
return utils.WriteTomlTreeToFile(tomlCfg, tmlFilePath)
}
3 changes: 0 additions & 3 deletions cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

var supportedKeys = []string{
"rollapp-rpc-port",
"lc-rpc-port",
}

func Cmd() *cobra.Command {
Expand All @@ -28,8 +27,6 @@ func Cmd() *cobra.Command {
switch key {
case "rollapp-rpc-port":
return setRollappRPC(rlpCfg, value)
case "lc-rpc-port":
return setLCRPC(rlpCfg, value)
default:
return fmt.Errorf("invalid key. Supported keys are: %v", supportedKeys)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const (
KeysDirName = "keys"
DefaultRelayerPath = "hub-rollapp"
DefaultRollappRPC = "http://localhost:26657"
DefaultDALCRPC = "http://localhost:26659"
)

// TODO: Check DA LC write price on arabica and update this value.
Expand Down
1 change: 0 additions & 1 deletion cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func Cmd() *cobra.Command {
utils.PrettifyErrorIfExists(errors.New("metrics endpoint can only be set for celestia"))
}
damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home)

insufficientBalances, err := damanager.CheckDABalance()
utils.PrettifyErrorIfExists(err)
utils.PrintInsufficientBalancesIfAny(insufficientBalances, rollappConfig)
Expand Down
8 changes: 2 additions & 6 deletions cmd/run/services_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/dymensionxyz/roller/sequencer"
"github.com/gizak/termui/v3"
"github.com/gizak/termui/v3/widgets"
"strings"

datalayer "github.com/dymensionxyz/roller/data_layer"
)
Expand All @@ -27,11 +26,8 @@ func NewServicesInfoTable(rollappConfig config.RollappConfig, termWidth int) *wi
}

damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home)
lcEndPoint := damanager.GetLightNodeEndpoint()
if lcEndPoint != "" {
parts := strings.Split(lcEndPoint, ":")
port := parts[len(parts)-1]
table.Rows = append(table.Rows, []string{"DA Light Client", utils.GetDALogFilePath(rollappConfig.Home), port})
if damanager.GetLightNodeEndpoint() != "" {
table.Rows = append(table.Rows, []string{"DA Light Client", utils.GetDALogFilePath(rollappConfig.Home), "26659"})
}
return table
}
22 changes: 22 additions & 0 deletions cmd/utils/toml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package utils

import (
"github.com/pelletier/go-toml"
"os"
)

func WriteTomlTreeToFile(tomlConfig *toml.Tree, path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
_, err = file.WriteString(tomlConfig.String())
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
return nil
}
45 changes: 14 additions & 31 deletions data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,33 @@ package celestia
import (
"encoding/json"
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
globalutils "github.com/dymensionxyz/roller/utils"
"math/big"
"os/exec"
"path/filepath"

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

// TODO: test how much is enough to run the LC for one day and set the minimum balance accordingly.
const (
gatewayAddr = "0.0.0.0"
gatewayPort = "26659"
CelestiaRestApiEndpoint = "https://api-arabica-9.consensus.celestia-arabica.com"
DefaultCelestiaRPC = "consensus-full-arabica-9.celestia-arabica.com"
DefaultCelestiaNetwork = "arabica"
)

var (
lcMinBalance = big.NewInt(1)
LCEndpoint = fmt.Sprintf("http://%s:%s", gatewayAddr, gatewayPort)
)

type Celestia struct {
Root string
rpcEndpoint string
metricsEndpoint string
RPCPort string
}

func NewCelestia(home string) *Celestia {
return &Celestia{
Root: home,
}
}

func (c2 *Celestia) GetPrivateKey() (string, error) {
Expand All @@ -49,10 +45,9 @@ func (c2 *Celestia) SetMetricsEndpoint(endpoint string) {
c2.metricsEndpoint = endpoint
}

func (c *Celestia) GetStatus(rlpCfg config.RollappConfig) string {
logger := utils.GetRollerLogger(rlpCfg.Home)
lcEndpoint := c.GetLightNodeEndpoint()
out, err := utils.RestQueryJson(fmt.Sprintf("%s/balance", lcEndpoint))
func (c2 *Celestia) GetStatus(c config.RollappConfig) string {
logger := utils.GetRollerLogger(c.Home)
out, err := utils.RestQueryJson(fmt.Sprintf("%s/balance", consts.DefaultDALCRPC))
const stoppedMsg = "Stopped, Restarting..."
if err != nil {
logger.Println("Error querying balance", err)
Expand All @@ -76,21 +71,8 @@ func (c *Celestia) GetStatus(rlpCfg config.RollappConfig) string {
}
}

func (c *Celestia) getRPCPort() string {
if c.RPCPort != "" {
return c.RPCPort
}
port, err := globalutils.GetKeyFromTomlFile(filepath.Join(c.Root, consts.ConfigDirName.DALightNode, "config.toml"),
"Gateway.Port")
if err != nil {
panic(err)
}
c.RPCPort = port
return port
}

func (c *Celestia) GetLightNodeEndpoint() string {
return fmt.Sprintf("http://localhost:%s", c.getRPCPort())
return LCEndpoint
}

// GetDAAccountAddress implements datalayer.DataLayer.
Expand Down Expand Up @@ -188,6 +170,8 @@ func (c *Celestia) GetStartDACmd() *exec.Cmd {
"--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode),
"--gateway",
"--gateway.deprecated-endpoints",
"--gateway.addr", gatewayAddr,
"--gateway.port", gatewayPort,
"--p2p.network", DefaultCelestiaNetwork,
}
if c.metricsEndpoint != "" {
Expand All @@ -207,7 +191,6 @@ func (c *Celestia) GetNetworkName() string {
}

func (c *Celestia) GetSequencerDAConfig() string {
lcEndpoint := c.GetLightNodeEndpoint()
return fmt.Sprintf(`{"base_url": "%s", "timeout": 60000000000, "gas_prices":0.1, "gas_adjustment": 1.3, "namespace_id":"000000000000ffff"}`,
lcEndpoint)
LCEndpoint)
}
4 changes: 3 additions & 1 deletion data_layer/da_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ func NewDAManager(datype config.DAType, home string) *DAManager {

switch datype {
case config.Celestia:
dalayer = celestia.NewCelestia(home)
dalayer = &celestia.Celestia{
Root: home,
}
case config.Avail:
dalayer = avail.NewAvail(home)
case config.Mock:
Expand Down
14 changes: 1 addition & 13 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package sequencer
import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/utils"
"github.com/pelletier/go-toml"
"os"
"path/filepath"
Expand Down Expand Up @@ -46,18 +46,6 @@ func SetDefaultDymintConfig(rlpCfg config.RollappConfig) error {
return err
}

func UpdateDymintDAConfig(rlpCfg config.RollappConfig) error {
dymintTomlPath := GetDymintFilePath(rlpCfg.Home)
dymintCfg, err := toml.LoadFile(dymintTomlPath)
if err != nil {
return err
}
damanager := datalayer.NewDAManager(rlpCfg.DA, rlpCfg.Home)
daConfig := damanager.GetSequencerDAConfig()
dymintCfg.Set("da_config", daConfig)
return utils.WriteTomlTreeToFile(dymintCfg, dymintTomlPath)
}

func SetAppConfig(rlpCfg config.RollappConfig) error {
appConfigFilePath := filepath.Join(rlpCfg.Home, consts.ConfigDirName.Rollapp, "config", "app.toml")
appCfg, err := toml.LoadFile(appConfigFilePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ index-events = []
inter-block-cache = true
min-retain-blocks = 0
minimum-gas-prices = "0udym"
pruning = "custom"
pruning-interval = "18000"
pruning-keep-recent = "6048000"
pruning = "default"
pruning-interval = "0"
pruning-keep-recent = "0"

[api]
address = "tcp://0.0.0.0:1317"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ index-events = []
inter-block-cache = true
min-retain-blocks = 0
minimum-gas-prices = "0udym"
pruning = "custom"
pruning-interval = "18000"
pruning-keep-recent = "6048000"
pruning = "default"
pruning-interval = "0"
pruning-keep-recent = "0"

[api]
address = "tcp://0.0.0.0:1317"
Expand Down

This file was deleted.

13 changes: 8 additions & 5 deletions test/config/init/init_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package initconfig_test

import (
"github.com/dymensionxyz/roller/config"
"fmt"
"path/filepath"
"testing"

"github.com/dymensionxyz/roller/config"

"os"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
Expand Down Expand Up @@ -41,11 +43,12 @@ func TestInitCmd(t *testing.T) {
assert := assert.New(t)
tempDir, err := os.MkdirTemp(os.TempDir(), "test")
tempDir = filepath.Join(tempDir, ".roller")
fmt.Println(tc.name, tempDir)
assert.NoError(err)
defer func() {
err := os.RemoveAll(tempDir)
assert.NoError(err)
}()
//defer func() {
// err := os.RemoveAll(tempDir)
// assert.NoError(err)
//}()
initCmd := initconfig.InitCmd()
utils.AddGlobalFlags(initCmd)
denom := "dym"
Expand Down
Loading

0 comments on commit 353d449

Please sign in to comment.