Skip to content

Commit

Permalink
feat: Add a command to change DA with an existing rollapp (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
ItayLevyOfficial authored Aug 27, 2023
1 parent 09a18aa commit 487f0c8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
41 changes: 41 additions & 0 deletions cmd/config/set/da.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package set

import (
"fmt"
"github.com/dymensionxyz/roller/cmd/consts"
"github.com/dymensionxyz/roller/config"
datalayer "github.com/dymensionxyz/roller/data_layer"
"github.com/dymensionxyz/roller/sequencer"
"os"
"path/filepath"
)

func setDA(rlpCfg config.RollappConfig, value config.DAType) error {
if value == rlpCfg.DA {
return nil
}
supportedDas := []config.DAType{config.Celestia, config.Avail, config.Local}
if !config.IsValidDAType(string(value)) {
return fmt.Errorf("invalid DA type. Supported types are: %v", supportedDas)
}
return updateDaConfig(rlpCfg, value)
}

func updateDaConfig(rlpCfg config.RollappConfig, newDa config.DAType) error {
if err := cleanDADir(rlpCfg); err != nil {
return err
}
daManager := datalayer.NewDAManager(newDa, rlpCfg.Home)
if err := daManager.InitializeLightNodeConfig(); err != nil {
return err
}
rlpCfg.DA = newDa
if err := sequencer.UpdateDymintDAConfig(rlpCfg); err != nil {
return err
}
return config.WriteConfigToTOML(rlpCfg)
}

func cleanDADir(cfg config.RollappConfig) error {
return os.RemoveAll(filepath.Join(cfg.Home, consts.ConfigDirName.DALightNode))
}
3 changes: 3 additions & 0 deletions cmd/config/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var supportedKeys = []string{
"rollapp-rpc-port",
"lc-rpc-port",
"da",
}

func Cmd() *cobra.Command {
Expand All @@ -30,6 +31,8 @@ func Cmd() *cobra.Command {
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)
}
Expand Down
31 changes: 18 additions & 13 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ func SetDefaultDymintConfig(rlpCfg config.RollappConfig) error {
if err != nil {
return err
}
damanager := datalayer.NewDAManager(rlpCfg.DA, rlpCfg.Home)
daConfig := damanager.GetSequencerDAConfig()
dymintCfg.Set("da_layer", string(rlpCfg.DA))
if daConfig != "" {
dymintCfg.Set("da_config", daConfig)
if err := updateDaConfigInToml(rlpCfg, dymintCfg); err != nil {
return err
}
hubKeysDir := filepath.Join(rlpCfg.Home, consts.ConfigDirName.HubKeys)
dymintCfg.Set("settlement_layer", "dymension")
dymintCfg.Set("block_batch_size", "500")
if rlpCfg.DA == config.Celestia {
celDAManager, ok := damanager.DataLayer.(*celestia.Celestia)
if !ok {
return fmt.Errorf("invalid damanager type, expected *celestia.Celestia, got %T", damanager.DataLayer)
}
dymintCfg.Set("namespace_id", celDAManager.NamespaceID)
}
dymintCfg.Set("block_time", "0.2s")
dymintCfg.Set("batch_submit_max_time", "100s")
dymintCfg.Set("empty_blocks_max_time", "3600s")
Expand All @@ -60,10 +50,25 @@ func UpdateDymintDAConfig(rlpCfg config.RollappConfig) error {
if err != nil {
return err
}
if err := updateDaConfigInToml(rlpCfg, dymintCfg); err != nil {
return err
}
return utils.WriteTomlTreeToFile(dymintCfg, dymintTomlPath)
}

func updateDaConfigInToml(rlpCfg config.RollappConfig, dymintCfg *toml.Tree) error {
damanager := datalayer.NewDAManager(rlpCfg.DA, rlpCfg.Home)
dymintCfg.Set("da_layer", string(rlpCfg.DA))
daConfig := damanager.GetSequencerDAConfig()
dymintCfg.Set("da_config", daConfig)
return utils.WriteTomlTreeToFile(dymintCfg, dymintTomlPath)
if rlpCfg.DA == config.Celestia {
celDAManager, ok := damanager.DataLayer.(*celestia.Celestia)
if !ok {
return fmt.Errorf("invalid damanager type, expected *celestia.Celestia, got %T", damanager.DataLayer)
}
dymintCfg.Set("namespace_id", celDAManager.NamespaceID)
}
return nil
}

func SetAppConfig(rlpCfg config.RollappConfig) error {
Expand Down

0 comments on commit 487f0c8

Please sign in to comment.