Skip to content

Commit

Permalink
feat: Add command to modify DA light client rpc port (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Aug 14, 2023
1 parent 74aabfb commit c082e0d
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 72 deletions.
1 change: 0 additions & 1 deletion cmd/config/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ 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: 24 additions & 0 deletions cmd/config/set/lc_rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package set

import (
"errors"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/config"
"github.com/dymensionxyz/roller/sequencer"
"github.com/dymensionxyz/roller/utils"
"path/filepath"
)

func setLCRPC(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"),
"Gateway.Port", value); err != nil {
return err
}
return sequencer.UpdateDymintDAConfig(cfg)
}
16 changes: 3 additions & 13 deletions cmd/config/set/rollapp_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package set
import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/cmd/utils"
"github.com/dymensionxyz/roller/config"
"github.com/pelletier/go-toml"
"github.com/dymensionxyz/roller/utils"
"gopkg.in/yaml.v2"
"os"
"path/filepath"
Expand Down Expand Up @@ -72,19 +71,10 @@ 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 updateFieldInToml(configFilePath, "node", "tcp://localhost:"+newRpcPort)
return utils.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 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)
return utils.UpdateFieldInToml(configFilePath, "rpc.laddr", "tcp://0.0.0.0:"+newRpc)
}
3 changes: 3 additions & 0 deletions cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

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

func Cmd() *cobra.Command {
Expand All @@ -27,6 +28,8 @@ 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: 0 additions & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ 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: 1 addition & 0 deletions cmd/da-light-client/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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: 6 additions & 2 deletions cmd/run/services_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -26,8 +27,11 @@ func NewServicesInfoTable(rollappConfig config.RollappConfig, termWidth int) *wi
}

damanager := datalayer.NewDAManager(rollappConfig.DA, rollappConfig.Home)
if damanager.GetLightNodeEndpoint() != "" {
table.Rows = append(table.Rows, []string{"DA Light Client", utils.GetDALogFilePath(rollappConfig.Home), "26659"})
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})
}
return table
}
22 changes: 0 additions & 22 deletions cmd/utils/toml.go

This file was deleted.

45 changes: 31 additions & 14 deletions data_layer/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@ package celestia
import (
"encoding/json"
"fmt"
"math/big"
"os/exec"
"path/filepath"

"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"
)

// 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 @@ -45,9 +49,10 @@ func (c2 *Celestia) SetMetricsEndpoint(endpoint string) {
c2.metricsEndpoint = endpoint
}

func (c2 *Celestia) GetStatus(c config.RollappConfig) string {
logger := utils.GetRollerLogger(c.Home)
out, err := utils.RestQueryJson(fmt.Sprintf("%s/balance", consts.DefaultDALCRPC))
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))
const stoppedMsg = "Stopped, Restarting..."
if err != nil {
logger.Println("Error querying balance", err)
Expand All @@ -71,8 +76,21 @@ func (c2 *Celestia) GetStatus(c 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 LCEndpoint
return fmt.Sprintf("http://localhost:%s", c.getRPCPort())
}

// GetDAAccountAddress implements datalayer.DataLayer.
Expand Down Expand Up @@ -170,8 +188,6 @@ 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 @@ -191,6 +207,7 @@ 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: 1 addition & 3 deletions data_layer/da_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func NewDAManager(datype config.DAType, home string) *DAManager {

switch datype {
case config.Celestia:
dalayer = &celestia.Celestia{
Root: home,
}
dalayer = celestia.NewCelestia(home)
case config.Avail:
dalayer = avail.NewAvail(home)
case config.Mock:
Expand Down
14 changes: 13 additions & 1 deletion 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,6 +46,18 @@ 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 = "default"
pruning-interval = "0"
pruning-keep-recent = "0"
pruning = "custom"
pruning-interval = "18000"
pruning-keep-recent = "6048000"

[api]
address = "tcp://0.0.0.0:1317"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
aggregator = "true"
batch_submit_max_time = "100s"
block_batch_max_size_bytes = 1500000
block_batch_size = "500"
block_time = "0.2s"
da_config = "{\"base_url\": \"http://localhost:26659\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"gas_adjustment\": 1.3, \"namespace_id\":\"000000000000ffff\"}"
da_layer = "celestia"
dym_account_name = "hub_sequencer"
empty_blocks_max_time = "10s"
gas_fees = ""
gas_limit = 0
gas_prices = "0.25udym"
keyring_backend = "test"
keyring_home_dir = "PLACEHOLDER_KEYRING_HOME_DIR"
namespace_id = "000000000000ffff"
node_address = "https://dymension-devnet.rpc.silknodes.io:443"
rollapp_id = "mars_1-1"
settlement_layer = "dymension"

[instrumentation]
prometheus = true
prometheus_listen_addr = ":2112"
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 = "default"
pruning-interval = "0"
pruning-keep-recent = "0"
pruning = "custom"
pruning-interval = "18000"
pruning-keep-recent = "6048000"

[api]
address = "tcp://0.0.0.0:1317"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
aggregator = "true"
batch_submit_max_time = "100s"
block_batch_max_size_bytes = 1500000
block_batch_size = "500"
block_time = "0.2s"
da_config = "{\"base_url\": \"http://localhost:26659\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"gas_adjustment\": 1.3, \"namespace_id\":\"000000000000ffff\"}"
da_layer = "celestia"
dym_account_name = "hub_sequencer"
empty_blocks_max_time = "10s"
gas_fees = ""
gas_limit = 0
gas_prices = "0.25udym"
keyring_backend = "test"
keyring_home_dir = "PLACEHOLDER_KEYRING_HOME_DIR"
namespace_id = "000000000000ffff"
node_address = "https://dymension-devnet.rpc.silknodes.io:443"
rollapp_id = "mars_1-1"
settlement_layer = "dymension"

[instrumentation]
prometheus = true
prometheus_listen_addr = ":2112"
13 changes: 5 additions & 8 deletions test/config/init/init_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package initconfig_test

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

"github.com/dymensionxyz/roller/config"

"os"

initconfig "github.com/dymensionxyz/roller/cmd/config/init"
Expand Down Expand Up @@ -43,12 +41,11 @@ 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 c082e0d

Please sign in to comment.