From 9840d5b913064a088f92db33f66407d045bb661a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:16:16 +0300 Subject: [PATCH] fix(init): retrieve da backend, initialize rollap before da --- CHANGELOG.md | 23 +++ cmd/consts/consts.go | 7 +- cmd/consts/da.go | 14 +- cmd/consts/types.go | 12 +- cmd/relayer/setup/setup.go | 1 + cmd/rollapp/init/init.go | 9 +- cmd/rollapp/init/utils.go | 135 +++++++++++------- .../sequencer/metadata/export/export.go | 1 + cmd/rollapp/setup/setup.go | 79 ++-------- cmd/rollapp/start/start.go | 14 +- data_layer/celestia/celestia.go | 10 +- utils/config/config.go | 6 +- utils/config/tomlconfig/toml.go | 8 +- utils/dependencies/dependencies.go | 8 +- utils/filesystem/filesystem.go | 2 +- utils/genesis/genesis.go | 38 ++++- utils/rollapp/bechprefix.go | 2 - utils/rollapp/rollappId.go | 4 +- 18 files changed, 203 insertions(+), 170 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3500c83b..d95f36a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 429f1aa2..c8513295 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -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) { @@ -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) } diff --git a/cmd/consts/da.go b/cmd/consts/da.go index ba8a081f..5ae2aebb 100644 --- a/cmd/consts/da.go +++ b/cmd/consts/da.go @@ -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: "", @@ -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", diff --git a/cmd/consts/types.go b/cmd/consts/types.go index d82893c0..585e5890 100644 --- a/cmd/consts/types.go +++ b/cmd/consts/types.go @@ -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"` } diff --git a/cmd/relayer/setup/setup.go b/cmd/relayer/setup/setup.go index d61bf42c..2c4c140a 100644 --- a/cmd/relayer/setup/setup.go +++ b/cmd/relayer/setup/setup.go @@ -81,6 +81,7 @@ func Cmd() *cobra.Command { home, rollappConfig.RollappID, &hd, + string(rollappConfig.VMType), ) errorhandling.PrettifyErrorIfExists(err) diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index 4cd9a948..750ff39d 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -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) @@ -93,7 +92,7 @@ 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) @@ -101,7 +100,7 @@ func Cmd() *cobra.Command { 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 @@ -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) @@ -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 diff --git a/cmd/rollapp/init/utils.go b/cmd/rollapp/init/utils.go index c67c184f..5ccf3762 100644 --- a/cmd/rollapp/init/utils.go +++ b/cmd/rollapp/init/utils.go @@ -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" @@ -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") @@ -134,6 +136,7 @@ func runInit(cmd *cobra.Command, env string, raID string) error { home, raID, &hd, + vmType, ) if err != nil { errorhandling.PrettifyErrorIfExists(err) @@ -141,7 +144,65 @@ func runInit(cmd *cobra.Command, env string, raID string) error { } 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), @@ -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 { @@ -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" { @@ -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) @@ -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) @@ -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) diff --git a/cmd/rollapp/sequencer/metadata/export/export.go b/cmd/rollapp/sequencer/metadata/export/export.go index 8cc96dd3..c8467fdc 100644 --- a/cmd/rollapp/sequencer/metadata/export/export.go +++ b/cmd/rollapp/sequencer/metadata/export/export.go @@ -51,6 +51,7 @@ func Cmd() *cobra.Command { home, rollerData.RollappID, &hd, + string(rollerData.VMType), ) errorhandling.PrettifyErrorIfExists(err) diff --git a/cmd/rollapp/setup/setup.go b/cmd/rollapp/setup/setup.go index 262db5eb..a5ab5964 100644 --- a/cmd/rollapp/setup/setup.go +++ b/cmd/rollapp/setup/setup.go @@ -80,6 +80,7 @@ func Cmd() *cobra.Command { home, rollerData.RollappID, &hd, + string(rollerData.VMType), ) errorhandling.PrettifyErrorIfExists(err) @@ -129,6 +130,13 @@ func Cmd() *cobra.Command { WithOptions(options). Show() + rollerConfigFilePath := filepath.Join(home, consts.RollerConfigFileName) + err = globalutils.UpdateFieldInToml(rollerConfigFilePath, "node_type", nodeType) + if err != nil { + pterm.Error.Println("failed to update node type in roller config file: ", err) + return + } + switch nodeType { case "sequencer": pterm.Info.Println("getting the existing sequencer address ") @@ -502,7 +510,6 @@ func Cmd() *cobra.Command { } // DA - oh := initconfig.NewOutputHandler(false) damanager := datalayer.NewDAManager(rollappConfig.DA.Backend, rollappConfig.Home) daHome := filepath.Join( damanager.GetRootDirectory(), @@ -516,27 +523,7 @@ func Cmd() *cobra.Command { var shouldOverwrite bool if isDaInitialized { - pterm.Info.Println("DA client is already initialized") - oh.StopSpinner() - shouldOverwrite, err = oh.PromptOverwriteConfig(daHome) - if err != nil { - return - } - } - - if shouldOverwrite { - pterm.Info.Println("overriding the existing da configuration") - err := os.RemoveAll(daHome) - if err != nil { - pterm.Error.Printf("failed to remove %s: %v\n", daHome, err) - return - } - - err = os.MkdirAll(daHome, 0o755) - if err != nil { - pterm.Error.Printf("failed to create %s: %v\n", daHome, err) - return - } + pterm.Warning.Println("DA client is already initialized") } if !isDaInitialized || shouldOverwrite { @@ -758,54 +745,6 @@ func Cmd() *cobra.Command { return cmd } -func printOutput(rlpCfg config.RollappConfig, cmd *exec.Cmd) { - seq := sequencer.GetInstance(rlpCfg) - pterm.DefaultSection.WithIndentCharacter("💈 "). - Println("The Rollapp sequencer is running on your local machine!") - fmt.Println("💈 Endpoints:") - - fmt.Printf("EVM RPC: http://127.0.0.1:%v\n", seq.JsonRPCPort) - fmt.Printf("Node RPC: http://127.0.0.1:%v\n", seq.RPCPort) - fmt.Printf("Rest API: http://127.0.0.1:%v\n", seq.APIPort) - - fmt.Println("💈 Log file path: ", LogPath) - fmt.Println("💈 Rollapp root dir: ", RollappDirPath) - fmt.Printf( - "💈 PID: %d (saved in %s)\n", - cmd.Process.Pid, - filepath.Join(rlpCfg.Home, "rollapputils.pid"), - ) -} - -func createPidFile(path string, cmd *exec.Cmd) error { - pidPath := filepath.Join(path, "rollapputils.pid") - file, err := os.Create(pidPath) - if err != nil { - fmt.Println("Error creating file:", err) - return err - } - // nolint errcheck - defer file.Close() - - pid := cmd.Process.Pid - _, err = file.WriteString(fmt.Sprintf("%d", pid)) - if err != nil { - fmt.Println("Error writing to file:", err) - return err - } - - return nil -} - -func parseError(errMsg string) string { - lines := strings.Split(errMsg, "\n") - if len(lines) > 0 && - lines[0] == "Error: failed to initialize database: resource temporarily unavailable" { - return "The Rollapp sequencer is already running on your local machine. Only one sequencer can run at any given time." - } - return errMsg -} - func populateSequencerMetadata(raCfg config.RollappConfig) error { cd := dymensionseqtypes.ContactDetails{ Website: "", diff --git a/cmd/rollapp/start/start.go b/cmd/rollapp/start/start.go index d1dc0313..73a058f7 100644 --- a/cmd/rollapp/start/start.go +++ b/cmd/rollapp/start/start.go @@ -67,7 +67,6 @@ Consider using 'services' if you want to run a 'systemd' service instead. LogPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log") RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) - fmt.Println(startRollappCmd.String()) ctx, cancel := context.WithCancel(context.Background()) defer cancel() go bash.RunCmdAsync( @@ -117,12 +116,15 @@ func PrintOutput( msg = pterm.DefaultBasicText.WithStyle( pterm. FgGreen.ToStyle(), - ).Sprintf("💈 The Rollapp sequencer is running on your local machine!") + ).Sprintf("💈 The Rollapp %s is running on your local machine!", rlpCfg.NodeType) } else { msg = pterm.DefaultBasicText.WithStyle( pterm. FgRed.ToStyle(), - ).Sprintf("❗ The Rollapp sequencer is in unhealthy state. Please check the logs for more information.") + ).Sprintf( + "❗ The Rollapp %s is in unhealthy state. Please check the logs for more information.", + rlpCfg.NodeType, + ) } fmt.Println(msg) @@ -135,7 +137,9 @@ func PrintOutput( if withEndpoints { pterm.DefaultSection.WithIndentCharacter("💈"). Println("Endpoints:") - fmt.Printf("EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort) + if rlpCfg.VMType == "evm" { + fmt.Printf("EVM RPC: http://0.0.0.0:%v\n", seq.JsonRPCPort) + } fmt.Printf("Node RPC: http://0.0.0.0:%v\n", seq.RPCPort) fmt.Printf("Rest API: http://0.0.0.0:%v\n", seq.APIPort) } @@ -159,7 +163,7 @@ func PrintOutput( pterm.DefaultSection.WithIndentCharacter("💈"). Println("Wallet Info:") fmt.Println("Sequencer Address:", seqAddrData[0].Address) - if withBalance { + if withBalance && rlpCfg.NodeType == "sequencer" { fmt.Println("Sequencer Balance:", seqAddrData[0].Balance.String()) go func() { for { diff --git a/data_layer/celestia/celestia.go b/data_layer/celestia/celestia.go index e0003529..20fc0d73 100644 --- a/data_layer/celestia/celestia.go +++ b/data_layer/celestia/celestia.go @@ -131,7 +131,7 @@ func (c *Celestia) InitializeLightNodeConfig() (string, error) { initLightNodeCmd := exec.Command( consts.Executables.Celestia, "light", "init", "--p2p.network", - raCfg.DA.ID, + string(raCfg.DA.ID), "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode), ) // err := initLightNodeCmd.Run() @@ -190,7 +190,7 @@ func (c *Celestia) getDAAccData(home string) (*utils.AccountData, error) { "--node", raCfg.DA.RpcUrl, "--chain-id", - raCfg.DA.ID, + string(raCfg.DA.ID), "-o", "json", ) @@ -256,7 +256,7 @@ func (c *Celestia) CheckDABalance() ([]utils.NotFundedAddressData, error) { RequiredBalance: lcMinBalance, KeyName: c.GetKeyName(), Denom: consts.Denoms.Celestia, - Network: raCfg.DA.ID, + Network: string(raCfg.DA.ID), }, ) } @@ -276,7 +276,7 @@ func (c *Celestia) GetStartDACmd() *exec.Cmd { "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode), "--gateway", // "--gateway.deprecated-endpoints", - "--p2p.network", raCfg.DA.ID, + "--p2p.network", string(raCfg.DA.ID), } if c.metricsEndpoint != "" { args = append(args, "--metrics", "--metrics.endpoint", c.metricsEndpoint) @@ -307,7 +307,7 @@ func (c *Celestia) getAuthToken(t string, raCfg config.RollappConfig) (string, e "auth", t, "--p2p.network", - raCfg.DA.ID, + string(raCfg.DA.ID), "--node.store", filepath.Join(c.Root, consts.ConfigDirName.DALightNode), ) diff --git a/utils/config/config.go b/utils/config/config.go index 670ba9a0..5aec0c61 100644 --- a/utils/config/config.go +++ b/utils/config/config.go @@ -6,12 +6,13 @@ import ( "strings" "unicode" + "github.com/pterm/pterm" + "github.com/dymensionxyz/roller/cmd/consts" globalutils "github.com/dymensionxyz/roller/utils" - "github.com/pterm/pterm" ) -var SupportedDas = []consts.DAType{consts.Celestia, consts.Avail, consts.Local} +var SupportedDas = []consts.DAType{consts.Celestia, consts.Local} type RollappConfig struct { Home string `toml:"home"` @@ -20,6 +21,7 @@ type RollappConfig struct { RollappID string `toml:"rollapp_id"` RollappBinary string `toml:"rollapp_binary"` VMType consts.VMType `toml:"execution"` + NodeType string `toml:"node_type"` Denom string `toml:"denom"` // TokenSupply string Decimals uint diff --git a/utils/config/tomlconfig/toml.go b/utils/config/tomlconfig/toml.go index 848c4374..3ab5f1bd 100644 --- a/utils/config/tomlconfig/toml.go +++ b/utils/config/tomlconfig/toml.go @@ -64,9 +64,13 @@ func Load(path string) ([]byte, error) { func LoadRollappMetadataFromChain( home, raID string, - hd *consts.HubData, + hd *consts.HubData, vmType string, ) (*config.RollappConfig, error) { var cfg config.RollappConfig + vmt, err := consts.ToVMType(vmType) + if err != nil { + return nil, err + } if hd.ID == "mock" { cfg = config.RollappConfig{ Home: home, @@ -74,7 +78,7 @@ func LoadRollappMetadataFromChain( GenesisHash: "", GenesisUrl: "", RollappBinary: consts.Executables.RollappEVM, - VMType: consts.EVM_ROLLAPP, + VMType: vmt, Denom: "mock", Decimals: 18, HubData: *hd, diff --git a/utils/dependencies/dependencies.go b/utils/dependencies/dependencies.go index 755807b2..1be753b5 100644 --- a/utils/dependencies/dependencies.go +++ b/utils/dependencies/dependencies.go @@ -191,9 +191,9 @@ func InstallBinaries(bech32 string, withMockDA bool, vmType string) error { } } else if vmType == "wasm" { goreleaserDeps["rollapp"] = types.Dependency{ - Name: "rollapp-evm", + Name: "rollapp-wasm", Repository: "https://github.com/artemijspavlovs/rollapp-wasm", - Release: "v1.0.0-rc04-roller-02", + Release: "v1.0.0-rc04-roller-03", Binaries: []types.BinaryPathPair{ { Binary: "rollappd", @@ -228,7 +228,7 @@ func InstallBinaries(bech32 string, withMockDA bool, vmType string) error { func InstallBinaryFromRepo(dep types.Dependency, td string) error { spinner, _ := pterm.DefaultSpinner.Start( - fmt.Sprintf("Installing %s\n", dep.Name), + fmt.Sprintf("Installing %s", dep.Name), ) targetDir, err := os.MkdirTemp(os.TempDir(), td) if err != nil { @@ -294,7 +294,7 @@ func InstallBinaryFromRepo(dep types.Dependency, td string) error { func InstallBinaryFromRelease(dep types.Dependency) error { spinner, _ := pterm.DefaultSpinner.Start( - fmt.Sprintf("Installing %s\n", dep.Name), + fmt.Sprintf("Installing %s", dep.Name), ) goOs := strings.Title(runtime.GOOS) goArch := strings.ToLower(runtime.GOARCH) diff --git a/utils/filesystem/filesystem.go b/utils/filesystem/filesystem.go index 620ad554..21851c0e 100644 --- a/utils/filesystem/filesystem.go +++ b/utils/filesystem/filesystem.go @@ -76,7 +76,7 @@ func ExpandHomePath(path string) (string, error) { // TODO: download the file in chunks if possible func DownloadFile(url, fp string) error { spinner, _ := pterm.DefaultSpinner. - Start("Downloading file file from ", url) + Start(fmt.Sprintf("Downloading file from %s", url)) // nolint:gosec resp, err := http.Get(url) diff --git a/utils/genesis/genesis.go b/utils/genesis/genesis.go index 1f5df36e..9b593cd4 100644 --- a/utils/genesis/genesis.go +++ b/utils/genesis/genesis.go @@ -12,6 +12,8 @@ import ( "strings" "github.com/cometbft/cometbft/types" + "github.com/pterm/pterm" + "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/utils/bash" "github.com/dymensionxyz/roller/utils/config" @@ -19,17 +21,24 @@ import ( "github.com/dymensionxyz/roller/utils/filesystem" "github.com/dymensionxyz/roller/utils/rollapp" "github.com/dymensionxyz/roller/utils/sequencer" - "github.com/pterm/pterm" ) type AppState struct { - Bank Bank `json:"bank"` + Bank Bank `json:"bank"` + RollappParams RollappParams `json:"rollappparams"` } type Bank struct { Supply []Denom `json:"supply"` } +type RollappParams struct { + Params struct { + Da string `json:"da"` + Version string `json:"version"` + } `json:"params"` +} + type Denom struct { Denom string `json:"denom"` } @@ -244,14 +253,13 @@ func UpdateGenesisParams(home string, raCfg *config.RollappConfig) error { func getDefaultGenesisParams( raCfg *config.RollappConfig, ) []config.PathValue { - return []config.PathValue{ + var params []config.PathValue + + commonParams := []config.PathValue{ {Path: "app_state.mint.params.mint_denom", Value: raCfg.BaseDenom}, {Path: "app_state.staking.params.bond_denom", Value: raCfg.BaseDenom}, - {Path: "app_state.evm.params.evm_denom", Value: raCfg.BaseDenom}, {Path: "app_state.gov.deposit_params.min_deposit.0.denom", Value: raCfg.BaseDenom}, {Path: "consensus_params.block.max_gas", Value: "40000000"}, - {Path: "app_state.feemarket.params.no_base_fee", Value: true}, - {Path: "app_state.feemarket.params.min_gas_price", Value: "0.0"}, {Path: "app_state.distribution.params.base_proposer_reward", Value: "0.8"}, {Path: "app_state.distribution.params.community_tax", Value: "0.00002"}, {Path: "app_state.gov.voting_params.voting_period", Value: "300s"}, @@ -260,9 +268,25 @@ func getDefaultGenesisParams( Path: "app_state.bank.denom_metadata", Value: getBankDenomMetadata(raCfg.BaseDenom, raCfg.Decimals), }, - {Path: "app_state.evm.params.extra_eips", Value: []string{"3855"}}, {Path: "app_state.claims.params.claims_denom", Value: raCfg.BaseDenom}, } + + if raCfg.VMType == consts.WASM_ROLLAPP { + wasmParams := []config.PathValue{} + params = append(commonParams, wasmParams...) + } + + if raCfg.VMType == consts.EVM_ROLLAPP { + evmParams := []config.PathValue{ + {Path: "app_state.evm.params.evm_denom", Value: raCfg.BaseDenom}, + {Path: "app_state.feemarket.params.no_base_fee", Value: true}, + {Path: "app_state.evm.params.extra_eips", Value: []string{"3855"}}, + {Path: "app_state.feemarket.params.min_gas_price", Value: "0.0"}, + } + params = append(commonParams, evmParams...) + } + + return params } func getBankDenomMetadata(denom string, decimals uint) []BankDenomMetadata { diff --git a/utils/rollapp/bechprefix.go b/utils/rollapp/bechprefix.go index 7c8429ff..4d5c81ca 100644 --- a/utils/rollapp/bechprefix.go +++ b/utils/rollapp/bechprefix.go @@ -2,7 +2,6 @@ package rollapp import ( "errors" - "fmt" "os/exec" "regexp" "strings" @@ -13,7 +12,6 @@ import ( func ExtractBech32Prefix(vmType string) (string, error) { c := exec.Command("go", "version", "-m", consts.Executables.RollappEVM) - fmt.Println(c.String()) out, err := bash.ExecCommandWithStdout(c) if err != nil { return "", err diff --git a/utils/rollapp/rollappId.go b/utils/rollapp/rollappId.go index de3973c2..1157f73a 100644 --- a/utils/rollapp/rollappId.go +++ b/utils/rollapp/rollappId.go @@ -45,7 +45,7 @@ type ChainID struct { // from Dymension source code `x/rollapp/types/chain_id.go` @20240911 func ValidateChainID(id string) (ChainID, error) { spinner, _ := pterm.DefaultSpinner.WithRemoveWhenDone(). - Start(fmt.Sprintf("validating rollapp id '%s'\n", id)) + Start(fmt.Sprintf("validating rollapp id '%s'", id)) chainID := strings.TrimSpace(id) if chainID == "" { @@ -92,7 +92,7 @@ func ValidateChainID(id string) (ChainID, error) { ) } - spinner.Success(fmt.Sprintf("'%s' is a valid RollApp ID", id)) + spinner.Success(fmt.Sprintf("'%s' is a valid RollApp ID\n", id)) return ChainID{ chainID: chainID, eip155ID: chainIDInt,