diff --git a/cmd/config/init/init.go b/cmd/config/init/init.go index bd4049d8..f5969cbf 100644 --- a/cmd/config/init/init.go +++ b/cmd/config/init/init.go @@ -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 diff --git a/cmd/config/set/lc_rpc.go b/cmd/config/set/lc_rpc.go deleted file mode 100644 index e4fe73b0..00000000 --- a/cmd/config/set/lc_rpc.go +++ /dev/null @@ -1,24 +0,0 @@ -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) -} diff --git a/cmd/config/set/rollapp_rpc.go b/cmd/config/set/rollapp_rpc.go index bda34b0e..ef8f26e1 100644 --- a/cmd/config/set/rollapp_rpc.go +++ b/cmd/config/set/rollapp_rpc.go @@ -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" @@ -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) } diff --git a/cmd/config/set/set.go b/cmd/config/set/set.go index 11f35580..3ac2afd1 100644 --- a/cmd/config/set/set.go +++ b/cmd/config/set/set.go @@ -9,7 +9,6 @@ import ( var supportedKeys = []string{ "rollapp-rpc-port", - "lc-rpc-port", } func Cmd() *cobra.Command { @@ -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) } diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index af00b46e..28a6fb92 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -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. diff --git a/cmd/da-light-client/start/start.go b/cmd/da-light-client/start/start.go index eb207358..99479b72 100644 --- a/cmd/da-light-client/start/start.go +++ b/cmd/da-light-client/start/start.go @@ -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) diff --git a/cmd/run/services_info.go b/cmd/run/services_info.go index efbca6e4..92de33d4 100644 --- a/cmd/run/services_info.go +++ b/cmd/run/services_info.go @@ -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" ) @@ -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 } diff --git a/cmd/utils/toml.go b/cmd/utils/toml.go new file mode 100644 index 00000000..22eaf1f3 --- /dev/null +++ b/cmd/utils/toml.go @@ -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 +} diff --git a/data_layer/celestia/celestia.go b/data_layer/celestia/celestia.go index 677c07b8..b262186c 100644 --- a/data_layer/celestia/celestia.go +++ b/data_layer/celestia/celestia.go @@ -3,17 +3,19 @@ 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" @@ -21,19 +23,13 @@ const ( 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) { @@ -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) @@ -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. @@ -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 != "" { @@ -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) } diff --git a/data_layer/da_layer.go b/data_layer/da_layer.go index 9cd97969..0a1f1b1c 100644 --- a/data_layer/da_layer.go +++ b/data_layer/da_layer.go @@ -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: diff --git a/sequencer/config.go b/sequencer/config.go index ffb4e6ac..124347d3 100644 --- a/sequencer/config.go +++ b/sequencer/config.go @@ -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" @@ -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) diff --git a/test/config/init/goldens/init_with_flags/rollapp/config/app.toml b/test/config/init/goldens/init_with_flags/rollapp/config/app.toml index a1301add..49696427 100644 --- a/test/config/init/goldens/init_with_flags/rollapp/config/app.toml +++ b/test/config/init/goldens/init_with_flags/rollapp/config/app.toml @@ -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" diff --git a/test/config/init/goldens/init_with_flags/rollapp/config/dymint.toml b/test/config/init/goldens/init_with_flags/rollapp/config/dymint.toml deleted file mode 100644 index 783fc94f..00000000 --- a/test/config/init/goldens/init_with_flags/rollapp/config/dymint.toml +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/test/config/init/goldens/init_without_flags/rollapp/config/app.toml b/test/config/init/goldens/init_without_flags/rollapp/config/app.toml index a1301add..49696427 100644 --- a/test/config/init/goldens/init_without_flags/rollapp/config/app.toml +++ b/test/config/init/goldens/init_without_flags/rollapp/config/app.toml @@ -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" diff --git a/test/config/init/goldens/init_without_flags/rollapp/config/dymint.toml b/test/config/init/goldens/init_without_flags/rollapp/config/dymint.toml deleted file mode 100644 index 783fc94f..00000000 --- a/test/config/init/goldens/init_without_flags/rollapp/config/dymint.toml +++ /dev/null @@ -1,22 +0,0 @@ -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" diff --git a/test/config/init/init_test.go b/test/config/init/init_test.go index bd9cabca..f5927e99 100644 --- a/test/config/init/init_test.go +++ b/test/config/init/init_test.go @@ -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" @@ -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" diff --git a/test/config/init/testutils/keys.go b/test/config/init/testutils/keys.go index 78bb3c37..21403c80 100644 --- a/test/config/init/testutils/keys.go +++ b/test/config/init/testutils/keys.go @@ -3,7 +3,6 @@ package testutils import ( "errors" "github.com/dymensionxyz/roller/sequencer" - "github.com/dymensionxyz/roller/utils" "os" "github.com/dymensionxyz/roller/cmd/consts" @@ -43,7 +42,7 @@ func SanitizeConfigDir(root string) error { func SanitizeDymintToml(root string) error { dymintTomlPath := sequencer.GetDymintFilePath(root) - return utils.UpdateFieldInToml(dymintTomlPath, "keyring_home_dir", "PLACEHOLDER_KEYRING_HOME_DIR") + return os.Remove(dymintTomlPath) } func verifyFileExists(path string) error { _, err := os.Stat(path) diff --git a/utils/toml.go b/utils/toml.go deleted file mode 100644 index 7c1592f5..00000000 --- a/utils/toml.go +++ /dev/null @@ -1,40 +0,0 @@ -package utils - -import ( - "fmt" - "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 -} - -func GetKeyFromTomlFile(tmlFilePath, key string) (string, error) { - tomlTree, err := toml.LoadFile(tmlFilePath) - if err != nil { - return "", err - } - return tomlTree.Get(key).(string), nil -} - -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 WriteTomlTreeToFile(tomlCfg, tmlFilePath) -}