From dc57755a8574ec817cf40eba35d7647720974c79 Mon Sep 17 00:00:00 2001 From: artpav <19916123+artemijspavlovs@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:57:23 +0300 Subject: [PATCH] feat: add wasm rollapp support (#968) --- cmd/binaries/install/install.go | 6 ++- cmd/consts/consts.go | 2 +- cmd/relayer/setup/setup.go | 12 +++++ cmd/rollapp/init/init.go | 21 ++++++-- cmd/rollapp/init/utils.go | 32 ++++++------ cmd/rollapp/setup/setup.go | 4 +- cmd/rollapp/start/start.go | 7 ++- utils/config/tomlconfig/toml.go | 3 +- utils/dependencies/dependencies.go | 84 +++++++++++++++++++++--------- utils/dymint/dymint.go | 11 ++-- utils/rollapp/bechprefix.go | 11 +++- 11 files changed, 135 insertions(+), 58 deletions(-) diff --git a/cmd/binaries/install/install.go b/cmd/binaries/install/install.go index 2a99034d..1aa2d997 100644 --- a/cmd/binaries/install/install.go +++ b/cmd/binaries/install/install.go @@ -84,7 +84,11 @@ func Cmd() *cobra.Command { pterm.Error.Println("no bech") return } - err = dependencies.InstallBinaries(raResponse.Rollapp.GenesisInfo.Bech32Prefix, false) + err = dependencies.InstallBinaries( + raResponse.Rollapp.GenesisInfo.Bech32Prefix, + false, + strings.ToLower(raResponse.Rollapp.VmType), + ) if err != nil { pterm.Error.Println("failed to install binaries: ", err) return diff --git a/cmd/consts/consts.go b/cmd/consts/consts.go index 99780bdc..28c01703 100644 --- a/cmd/consts/consts.go +++ b/cmd/consts/consts.go @@ -31,7 +31,7 @@ var Executables = struct { CelestiaApp string }{ Roller: fmt.Sprintf("%s/roller", binsDir), - RollappEVM: fmt.Sprintf("%s/rollapp-evm", binsDir), + RollappEVM: fmt.Sprintf("%s/rollappd", binsDir), Dymension: fmt.Sprintf("%s/dymd", binsDir), Celestia: fmt.Sprintf("%s/celestia", InternalBinsDir), CelKey: fmt.Sprintf("%s/cel-key", InternalBinsDir), diff --git a/cmd/relayer/setup/setup.go b/cmd/relayer/setup/setup.go index d3ad6e3e..d61bf42c 100644 --- a/cmd/relayer/setup/setup.go +++ b/cmd/relayer/setup/setup.go @@ -134,6 +134,18 @@ func Cmd() *cobra.Command { svcFileName := fmt.Sprintf("%s.service", svc) svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName) + err := filesystem.RemoveFileIfExists(svcFilePath) + if err != nil { + pterm.Error.Println("failed to remove systemd service: ", err) + return + } + } + } else if runtime.GOOS == "darwin" { + pterm.Info.Println("removing old systemd services") + for _, svc := range consts.RelayerSystemdServices { + svcFileName := fmt.Sprintf("xyz.dymension.roller.%s.plist", svc) + svcFilePath := filepath.Join("/Library/LaunchDaemons/", svcFileName) + err := filesystem.RemoveFileIfExists(svcFilePath) if err != nil { pterm.Error.Println("failed to remove systemd service: ", err) diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index 26b646df..4cd9a948 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -7,14 +7,15 @@ import ( "strings" "time" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/utils/bash" "github.com/dymensionxyz/roller/utils/dependencies" "github.com/dymensionxyz/roller/utils/dependencies/types" "github.com/dymensionxyz/roller/utils/rollapp" - "github.com/pterm/pterm" - "github.com/spf13/cobra" ) func Cmd() *cobra.Command { @@ -90,7 +91,12 @@ func Cmd() *cobra.Command { } if env == "mock" { - err = dependencies.InstallBinaries(env, true) + vmtypes := []string{"evm", "wasm"} + vmtype, _ := pterm.DefaultInteractiveSelect. + WithDefaultText("select the environment 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 @@ -126,7 +132,10 @@ func Cmd() *cobra.Command { pterm.Error.Println("no bech") return } - err = dependencies.InstallBinaries(raResponse.Rollapp.GenesisInfo.Bech32Prefix, false) + err = dependencies.InstallBinaries( + raResponse.Rollapp.GenesisInfo.Bech32Prefix, false, + strings.ToLower(raResponse.Rollapp.VmType), + ) if err != nil { pterm.Error.Println("failed to install binaries: ", err) return @@ -147,7 +156,9 @@ func Cmd() *cobra.Command { return } - bp, err := rollapp.ExtractBech32Prefix() + bp, err := rollapp.ExtractBech32Prefix( + strings.ToLower(raResponse.Rollapp.VmType), + ) if err != nil { pterm.Error.Println("failed to extract bech32 prefix from binary", err) } diff --git a/cmd/rollapp/init/utils.go b/cmd/rollapp/init/utils.go index cb23e16f..c67c184f 100644 --- a/cmd/rollapp/init/utils.go +++ b/cmd/rollapp/init/utils.go @@ -12,6 +12,11 @@ import ( "strconv" "strings" + "github.com/pelletier/go-toml/v2" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + "gopkg.in/yaml.v2" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" @@ -25,10 +30,6 @@ import ( "github.com/dymensionxyz/roller/utils/filesystem" "github.com/dymensionxyz/roller/utils/genesis" "github.com/dymensionxyz/roller/utils/sequencer" - "github.com/pelletier/go-toml/v2" - "github.com/pterm/pterm" - "github.com/spf13/cobra" - "gopkg.in/yaml.v2" ) func runInit(cmd *cobra.Command, env string, raID string) error { @@ -129,10 +130,22 @@ func runInit(cmd *cobra.Command, env string, raID string) error { } hd := consts.Hubs[env] + initConfigPtr, err := tomlconfig.LoadRollappMetadataFromChain( + home, + raID, + &hd, + ) + if err != nil { + errorhandling.PrettifyErrorIfExists(err) + return err + } + initConfig := *initConfigPtr + mochaData := consts.DaNetworks[consts.DefaultCelestiaNetwork] rollerTomlData := map[string]string{ "rollapp_id": raID, "rollapp_binary": strings.ToLower(consts.Executables.RollappEVM), + "execution": string(initConfigPtr.VMType), "home": home, "HubData.id": hd.ID, @@ -161,17 +174,6 @@ func runInit(cmd *cobra.Command, env string, raID string) error { } } - initConfigPtr, err := tomlconfig.LoadRollappMetadataFromChain( - home, - raID, - &hd, - ) - if err != nil { - errorhandling.PrettifyErrorIfExists(err) - return err - } - initConfig := *initConfigPtr - errorhandling.RunOnInterrupt(outputHandler.StopSpinner) err = initConfig.Validate() if err != nil { diff --git a/cmd/rollapp/setup/setup.go b/cmd/rollapp/setup/setup.go index 662215eb..a0d9b306 100644 --- a/cmd/rollapp/setup/setup.go +++ b/cmd/rollapp/setup/setup.go @@ -107,7 +107,9 @@ func Cmd() *cobra.Command { return } - bp, err := rollapp.ExtractBech32Prefix() + bp, err := rollapp.ExtractBech32Prefix( + strings.ToLower(raResponse.Rollapp.VmType), + ) if err != nil { pterm.Error.Println("failed to extract bech32 prefix from binary", err) } diff --git a/cmd/rollapp/start/start.go b/cmd/rollapp/start/start.go index 9dfa9111..d1dc0313 100644 --- a/cmd/rollapp/start/start.go +++ b/cmd/rollapp/start/start.go @@ -10,6 +10,9 @@ import ( "strings" "time" + "github.com/pterm/pterm" + "github.com/spf13/cobra" + initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" "github.com/dymensionxyz/roller/cmd/utils" @@ -20,8 +23,6 @@ import ( "github.com/dymensionxyz/roller/utils/errorhandling" "github.com/dymensionxyz/roller/utils/filesystem" sequencerutils "github.com/dymensionxyz/roller/utils/sequencer" - "github.com/pterm/pterm" - "github.com/spf13/cobra" ) // var OneDaySequencePrice = big.NewInt(1) @@ -61,6 +62,8 @@ Consider using 'services' if you want to run a 'systemd' service instead. seq := sequencer.GetInstance(rollappConfig) startRollappCmd := seq.GetStartCmd() + fmt.Println(startRollappCmd.String()) + LogPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp, "rollapp.log") RollappDirPath = filepath.Join(rollappConfig.Home, consts.ConfigDirName.Rollapp) diff --git a/utils/config/tomlconfig/toml.go b/utils/config/tomlconfig/toml.go index 5570db57..848c4374 100644 --- a/utils/config/tomlconfig/toml.go +++ b/utils/config/tomlconfig/toml.go @@ -4,6 +4,7 @@ import ( "encoding/json" "os" "path/filepath" + "strings" naoinatoml "github.com/naoina/toml" @@ -102,7 +103,7 @@ func LoadRollappMetadataFromChain( return nil, err } - vmt, _ := consts.ToVMType(raResponse.Rollapp.VmType) + vmt, _ := consts.ToVMType(strings.ToLower(raResponse.Rollapp.VmType)) cfg = config.RollappConfig{ Home: home, diff --git a/utils/dependencies/dependencies.go b/utils/dependencies/dependencies.go index d3951fd7..47eac385 100644 --- a/utils/dependencies/dependencies.go +++ b/utils/dependencies/dependencies.go @@ -20,7 +20,7 @@ import ( "github.com/dymensionxyz/roller/utils/dependencies/types" ) -func InstallBinaries(bech32 string, withMockDA bool) error { +func InstallBinaries(bech32 string, withMockDA bool, vmType string) error { c := exec.Command("sudo", "mkdir", "-p", consts.InternalBinsDir) _, err := bash.ExecCommandWithStdout(c) if err != nil { @@ -62,21 +62,40 @@ func InstallBinaries(bech32 string, withMockDA bool) error { }, }, } - buildableDeps["rollapp"] = types.Dependency{ - Name: "rollapp", - Repository: "https://github.com/dymensionxyz/rollapp-evm.git", - Release: "fe4246e7ca7f4a636881eb099ebd6e10cd386133", // 20240917 denom-metadata fix - Binaries: []types.BinaryPathPair{ - { - Binary: "./build/rollapp-evm", - BinaryDestination: consts.Executables.RollappEVM, - BuildCommand: exec.Command( - "make", - "build", - fmt.Sprintf("BECH32_PREFIX=%s", bech32), - ), + if vmType == "evm" { + buildableDeps["rollapp"] = types.Dependency{ + Name: "rollapp", + Repository: "https://github.com/dymensionxyz/rollapp-evm.git", + Release: "fe4246e7ca7f4a636881eb099ebd6e10cd386133", // 20240917 denom-metadata fix + Binaries: []types.BinaryPathPair{ + { + Binary: "./build/rollapp-evm", + BinaryDestination: consts.Executables.RollappEVM, + BuildCommand: exec.Command( + "make", + "build", + fmt.Sprintf("BECH32_PREFIX=%s", bech32), + ), + }, }, - }, + } + } else if vmType == "wasm" { + buildableDeps["rollapp"] = types.Dependency{ + Name: "rollapp", + Repository: "https://github.com/dymensionxyz/rollapp-wasm.git", + Release: "a34bc942d86d658a11038c69e860c973e96a1053", // 20240917 denom-metadata fix + Binaries: []types.BinaryPathPair{ + { + Binary: "./build/rollapp-wasm", + BinaryDestination: consts.Executables.RollappEVM, + BuildCommand: exec.Command( + "make", + "build", + fmt.Sprintf("BECH32_PREFIX=%s", bech32), + ), + }, + }, + } } } @@ -158,17 +177,32 @@ func InstallBinaries(bech32 string, withMockDA bool) error { return err } - goreleaserDeps["rollapp"] = types.Dependency{ - Name: "rollapp-evm", - Repository: "https://github.com/artemijspavlovs/rollapp-evm", - Release: "v2.3.4-pg-roller", - Binaries: []types.BinaryPathPair{ - { - Binary: "rollappd", - BinaryDestination: consts.Executables.RollappEVM, + if vmType == "evm" { + goreleaserDeps["rollapp"] = types.Dependency{ + Name: "rollapp-evm", + Repository: "https://github.com/artemijspavlovs/rollapp-evm", + Release: "v2.3.4-pg-roller", + Binaries: []types.BinaryPathPair{ + { + Binary: "rollappd", + BinaryDestination: consts.Executables.RollappEVM, + }, }, - }, + } + } else if vmType == "wasm" { + goreleaserDeps["rollapp"] = types.Dependency{ + Name: "rollapp-evm", + Repository: "https://github.com/artemijspavlovs/rollapp-wasm", + Release: "v1.0.0-rc04-roller-02", + Binaries: []types.BinaryPathPair{ + { + Binary: "rollappd", + BinaryDestination: consts.Executables.RollappEVM, + }, + }, + } } + } // @@ -250,7 +284,7 @@ func InstallBinaryFromRepo(dep types.Dependency, td string) error { return err } spinner.UpdateText( - fmt.Sprintf("Successfully installed %s\n", filepath.Base(binary.BinaryDestination)), + fmt.Sprintf("Finishing installation %s\n", filepath.Base(binary.BinaryDestination)), ) } diff --git a/utils/dymint/dymint.go b/utils/dymint/dymint.go index 715e78c1..ee0d0478 100644 --- a/utils/dymint/dymint.go +++ b/utils/dymint/dymint.go @@ -222,16 +222,17 @@ func WaitForHealthyRollApp(url string) { } func IsRollappHealthy(url string) (bool, any) { - fmt.Println(url) // nolint:gosec resp, err := http.Get(url) if err != nil { - fmt.Printf("Error making request: %v\n", err) + msg := fmt.Sprintf("Error making request: %v\n", err) + return false, msg } body, err := io.ReadAll(resp.Body) if err != nil { - fmt.Printf("Error reading response body: %v\n", err) + msg := fmt.Sprintf("Error reading response body: %v\n", err) + return false, msg } // nolint:errcheck,gosec resp.Body.Close() @@ -248,8 +249,8 @@ func IsRollappHealthy(url string) (bool, any) { } if response.Result.IsHealthy { - return true, "" + return true, response.Result.Error } - return false, "" + return true, response.Result.Error } diff --git a/utils/rollapp/bechprefix.go b/utils/rollapp/bechprefix.go index 463d1875..7c8429ff 100644 --- a/utils/rollapp/bechprefix.go +++ b/utils/rollapp/bechprefix.go @@ -2,6 +2,7 @@ package rollapp import ( "errors" + "fmt" "os/exec" "regexp" "strings" @@ -10,15 +11,21 @@ import ( "github.com/dymensionxyz/roller/utils/bash" ) -func ExtractBech32Prefix() (string, error) { +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 } lines := strings.Split(out.String(), "\n") - pattern := `github\.com/dymensionxyz/rollapp-evm/app\.AccountAddressPrefix=(\w+)` + var pattern string + if vmType == "evm" { + pattern = `github\.com/dymensionxyz/rollapp-evm/app\.AccountAddressPrefix=(\w+)` + } else if vmType == "wasm" { + pattern = `github\.com/dymensionxyz/rollapp-wasm/app\.AccountAddressPrefix=(\w+)` + } re := regexp.MustCompile(pattern) var ldflags string var bech32Prefix string