Skip to content

Commit

Permalink
fix(init): retrieve da backend, initialize rollap before da
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and artemijspavlovs committed Sep 19, 2024
1 parent 4890bc7 commit 9840d5b
Show file tree
Hide file tree
Showing 18 changed files with 203 additions and 170 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## [1.7.1-alpha-rc01](https://github.com/dymensionxyz/roller/compare/v1.7.0-alpha-rc01...v1.7.1-alpha-rc01) (2024-09-18)


### Bug Fixes

* **da:** don't ask to override the existing da config ([#999](https://github.com/dymensionxyz/roller/issues/999)) ([eb7e31c](https://github.com/dymensionxyz/roller/commit/eb7e31cb8f1a019766f674e592c97f2aee71566d))
* display the relevant information based on node type ([8f82ffc](https://github.com/dymensionxyz/roller/commit/8f82ffc0db53bab38c186e29a9855e7828a40ed2))
* fix outputs that require node type ([4b218b8](https://github.com/dymensionxyz/roller/commit/4b218b858026c69558314c5d0395f5d762ea2ac0))
* **ui:** installation spinner shouldn't draw new lines ([62e25db](https://github.com/dymensionxyz/roller/commit/62e25dbe8b46981dec5ed50eaed7666663a4ad5c))
* **wasm:** add wasm vm type ([#1000](https://github.com/dymensionxyz/roller/issues/1000)) ([ce08f6d](https://github.com/dymensionxyz/roller/commit/ce08f6dc3f36e250fe01b8466c7261851d47bc8c))

## [1.7.0-alpha-rc01](https://github.com/dymensionxyz/roller/compare/v1.6.4-alpha-rc01...v1.7.0-alpha-rc01) (2024-09-18)


### Features

* **block-explorer:** add a command to tear down the block explorer setup ([#979](https://github.com/dymensionxyz/roller/issues/979)) ([4890bc7](https://github.com/dymensionxyz/roller/commit/4890bc7b1fb09070bb9abce362affb86fba3e7fd))


### Bug Fixes

* **block-explorer:** make the block-explorer creation more reliable ([#977](https://github.com/dymensionxyz/roller/issues/977)) ([fb69d9d](https://github.com/dymensionxyz/roller/commit/fb69d9d3fde392f13ae78ae58e39894f87b43e79))

## [1.6.4-alpha-rc01](https://github.com/dymensionxyz/roller/compare/v1.6.3-alpha-rc01...v1.6.4-alpha-rc01) (2024-09-18)


Expand Down
7 changes: 5 additions & 2 deletions cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ const RollerConfigFileName = "roller.toml"
type VMType string

const (
SDK_ROLLAPP VMType = "sdk"
EVM_ROLLAPP VMType = "evm"
SDK_ROLLAPP VMType = "sdk"
EVM_ROLLAPP VMType = "evm"
WASM_ROLLAPP VMType = "wasm"
)

func ToVMType(s string) (VMType, error) {
Expand All @@ -136,6 +137,8 @@ func ToVMType(s string) (VMType, error) {
return SDK_ROLLAPP, nil
case string(EVM_ROLLAPP):
return EVM_ROLLAPP, nil
case string(WASM_ROLLAPP):
return WASM_ROLLAPP, nil
default:
return "", fmt.Errorf("invalid VMType: %s", s)
}
Expand Down
14 changes: 11 additions & 3 deletions cmd/consts/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ const (
Avail DAType = "avail"
)

type DaNetwork string

const (
CelestiaTestnet DaNetwork = "mocha-4"
CelestiaMainnet DaNetwork = "celestia"
)

var DaNetworks = map[string]DaData{
"mock": {
Backend: "mock",
Backend: Local,
ApiUrl: "",
ID: "mock",
RpcUrl: "",
Expand All @@ -37,14 +44,15 @@ var DaNetworks = map[string]DaData{
"mocha-4": {
Backend: Celestia,
ApiUrl: DefaultCelestiaRestApiEndpoint,
ID: "mocha-4",
ID: CelestiaTestnet,
RpcUrl: DefaultCelestiaRPC,
StateNode: DefaultCelestiaStateNode,
GasPrice: "0.02",
},
"celestia": {
Backend: Celestia,
ApiUrl: "api-celestia.mzonder.com",
ID: "celestia",
ID: CelestiaMainnet,
RpcUrl: "rpc-celestia.mzonder.com",
StateNode: "",
GasPrice: "0.002",
Expand Down
12 changes: 6 additions & 6 deletions cmd/consts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type HubData = struct {
}

type DaData = struct {
Backend DAType `toml:"backend"`
ID string `toml:"id"`
ApiUrl string `toml:"api_url"`
RpcUrl string `toml:"rpc_url"`
StateNode string `toml:"state_node"`
GasPrice string `toml:"gas_price"`
Backend DAType `toml:"backend"`
ID DaNetwork `toml:"id"`
ApiUrl string `toml:"api_url"`
RpcUrl string `toml:"rpc_url"`
StateNode string `toml:"state_node"`
GasPrice string `toml:"gas_price"`
}
1 change: 1 addition & 0 deletions cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func Cmd() *cobra.Command {
home,
rollappConfig.RollappID,
&hd,
string(rollappConfig.VMType),
)
errorhandling.PrettifyErrorIfExists(err)

Expand Down
9 changes: 4 additions & 5 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func Cmd() *cobra.Command {
).Show()
}

pterm.Info.Println("validating RollApp ID: ", raID)
_, err = rollapp.ValidateChainID(raID)
if err != nil {
pterm.Error.Println("failed to validate chain id: ", err)
Expand All @@ -93,15 +92,15 @@ func Cmd() *cobra.Command {
if env == "mock" {
vmtypes := []string{"evm", "wasm"}
vmtype, _ := pterm.DefaultInteractiveSelect.
WithDefaultText("select the environment you want to initialize for").
WithDefaultText("select the rollapp VM type you want to initialize for").
WithOptions(vmtypes).
Show()
err = dependencies.InstallBinaries(env, true, vmtype)
if err != nil {
pterm.Error.Println("failed to install binaries: ", err)
return
}
err := runInit(cmd, env, raID)
err := runInit(cmd, env, raID, vmtype)
if err != nil {
fmt.Println("failed to run init: ", err)
return
Expand Down Expand Up @@ -141,7 +140,7 @@ func Cmd() *cobra.Command {
return
}
elapsed := time.Since(start)
fmt.Println("time elapsed: ", elapsed)
pterm.Info.Println("all dependencies installed in: ", elapsed)
// END: ex binaries install

isRollappRegistered, _ := rollapp.IsRollappRegistered(raID, hd)
Expand Down Expand Up @@ -172,7 +171,7 @@ func Cmd() *cobra.Command {
return
}

err = runInit(cmd, env, raID)
err = runInit(cmd, env, raID, strings.ToLower(raResponse.Rollapp.VmType))
if err != nil {
pterm.Error.Printf("failed to initialize the RollApp: %v\n", err)
return
Expand Down
135 changes: 81 additions & 54 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strconv"
"strings"

comettypes "github.com/cometbft/cometbft/types"
"github.com/pelletier/go-toml/v2"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
Expand All @@ -28,11 +29,12 @@ import (
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/errorhandling"
"github.com/dymensionxyz/roller/utils/filesystem"
"github.com/dymensionxyz/roller/utils/genesis"
genesisutils "github.com/dymensionxyz/roller/utils/genesis"
"github.com/dymensionxyz/roller/utils/sequencer"
)

func runInit(cmd *cobra.Command, env string, raID string) error {
// nolint: gocyclo
func runInit(cmd *cobra.Command, env, raID, vmType string) error {
home, err := filesystem.ExpandHomePath(cmd.Flag(cmdutils.FlagNames.Home).Value.String())
if err != nil {
pterm.Error.Println("failed to expand home directory")
Expand Down Expand Up @@ -134,14 +136,73 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
home,
raID,
&hd,
vmType,
)
if err != nil {
errorhandling.PrettifyErrorIfExists(err)
return err
}
initConfig := *initConfigPtr

mochaData := consts.DaNetworks[consts.DefaultCelestiaNetwork]
/* ------------------------------ Generate keys ----------------------------- */
addresses, err := initconfig.GenerateSequencersKeys(initConfig)
if err != nil {
errorhandling.PrettifyErrorIfExists(err)
return err
}

/* --------------------------- Initialize Rollapp -------------------------- */
raSpinner, err := pterm.DefaultSpinner.Start("initializing rollapp client")
if err != nil {
return err
}

err = initconfig.InitializeRollappConfig(&initConfig, hd)
if err != nil {
raSpinner.Fail("failed to initialize rollapp client")
return err
}

// adds the sequencer address to the whitelists
if env == "mock" {
err = genesisutils.InitializeRollappGenesis(initConfig)
if err != nil {
return err
}
}

// Initialize roller config
genesisPath := genesisutils.GetGenesisFilePath(home)
file, err := comettypes.GenesisDocFromFile(genesisPath)
if err != nil {
return err
}
var need genesisutils.AppState
j, _ := file.AppState.MarshalJSON()
err = json.Unmarshal(j, &need)
if err != nil {
return err
}
daBackend := need.RollappParams.Params.Da
pterm.Info.Println("DA backend: ", daBackend)

var daData consts.DaData
var daNetwork string
switch env {
case "playground":
if daBackend == string(consts.Celestia) {
daNetwork = consts.DefaultCelestiaNetwork
} else {
return fmt.Errorf("unsupported DA backend: %s", daBackend)
}
case "mock":
daNetwork = "mock"
default:
return fmt.Errorf("unsupported environment: %s", env)
}

daData = consts.DaNetworks[daNetwork]

rollerTomlData := map[string]string{
"rollapp_id": raID,
"rollapp_binary": strings.ToLower(consts.Executables.RollappEVM),
Expand All @@ -154,12 +215,12 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
"HubData.archive_rpc_url": hd.ARCHIVE_RPC_URL,
"HubData.gas_price": hd.GAS_PRICE,

"DA.backend": string(mochaData.Backend),
"DA.id": mochaData.ID,
"DA.api_url": mochaData.ApiUrl,
"DA.rpc_url": mochaData.RpcUrl,
"DA.state_node": mochaData.StateNode,
"DA.gas_price": "0.02",
"DA.backend": string(daData.Backend),
"DA.id": string(daData.ID),
"DA.api_url": daData.ApiUrl,
"DA.rpc_url": daData.RpcUrl,
"DA.state_node": daData.StateNode,
"DA.gas_price": daData.GasPrice,
}

for key, value := range rollerTomlData {
Expand All @@ -181,12 +242,15 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
return err
}

/* ------------------------------ Generate keys ----------------------------- */
addresses, err := initconfig.GenerateSequencersKeys(initConfig)
if err != nil {
errorhandling.PrettifyErrorIfExists(err)
return err
}
/* ------------------------------ Initialize Local Hub ---------------------------- */
// TODO: local hub is out of scope, implement as the last step
// hub := cmd.Flag(FlagNames.HubID).Value.String()
// if hub == consts.LocalHubName {
// err := initLocalHub(initConfig)
// utils.PrettifyErrorIfExists(err)
// }

raSpinner.Success("rollapp initialized successfully")

/* ------------------------ Initialize DA light node ------------------------ */
if env != "mock" {
Expand Down Expand Up @@ -313,43 +377,6 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
}
daSpinner.Success("successfully initialized da light client")
}
/* --------------------------- Initialize Rollapp -------------------------- */
raSpinner, err := pterm.DefaultSpinner.Start("initializing rollapp client")
if err != nil {
return err
}

err = initconfig.InitializeRollappConfig(&initConfig, hd)
if err != nil {
raSpinner.Fail("failed to initialize rollapp client")
return err
}

// adds the sequencer address to the whitelists
if env == "mock" {
err = genesis.InitializeRollappGenesis(initConfig)
if err != nil {
return err
}
}

/* ------------------------------ Create Init Files ---------------------------- */
// TODO: review, roller config is generated using genesis-creator
// some of the config values should be moved there
// err = config.Write(initConfig)
// if err != nil {
// return err
// }

/* ------------------------------ Initialize Local Hub ---------------------------- */
// TODO: local hub is out of scope, implement as the last step
// hub := cmd.Flag(FlagNames.HubID).Value.String()
// if hub == consts.LocalHubName {
// err := initLocalHub(initConfig)
// utils.PrettifyErrorIfExists(err)
// }

raSpinner.Success("rollapp initialized successfully")
/* ------------------------------ Print output ------------------------------ */

outputHandler.PrintInitOutput(initConfig, addresses, initConfig.RollappID)
Expand Down Expand Up @@ -406,7 +433,7 @@ func UpdateCelestiaConfig(file, hash string, height int) error {
func GetLatestDABlock(raCfg config.RollappConfig) (string, string, error) {
cmd := exec.Command(
consts.Executables.CelestiaApp,
"q", "block", "--node", raCfg.DA.RpcUrl, "--chain-id", raCfg.DA.ID,
"q", "block", "--node", raCfg.DA.RpcUrl, "--chain-id", string(raCfg.DA.ID),
)

out, err := bash.ExecCommandWithStdout(cmd)
Expand Down Expand Up @@ -453,7 +480,7 @@ func GetLatestDABlock(raCfg config.RollappConfig) (string, string, error) {
func GetDABlockByHeight(h string, raCfg config.RollappConfig) (string, string, error) {
cmd := exec.Command(
consts.Executables.CelestiaApp,
"q", "block", h, "--node", raCfg.DA.RpcUrl, "--chain-id", raCfg.DA.ID,
"q", "block", h, "--node", raCfg.DA.RpcUrl, "--chain-id", string(raCfg.DA.ID),
)

out, err := bash.ExecCommandWithStdout(cmd)
Expand Down
1 change: 1 addition & 0 deletions cmd/rollapp/sequencer/metadata/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func Cmd() *cobra.Command {
home,
rollerData.RollappID,
&hd,
string(rollerData.VMType),
)
errorhandling.PrettifyErrorIfExists(err)

Expand Down
Loading

0 comments on commit 9840d5b

Please sign in to comment.