Skip to content

Commit

Permalink
feat: add wasm rollapp support (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 17, 2024
1 parent 75e21cc commit dc57755
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 58 deletions.
6 changes: 5 additions & 1 deletion cmd/binaries/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
12 changes: 12 additions & 0 deletions cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 16 additions & 5 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
32 changes: 17 additions & 15 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion cmd/rollapp/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/rollapp/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion utils/config/tomlconfig/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"strings"

naoinatoml "github.com/naoina/toml"

Expand Down Expand Up @@ -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,
Expand Down
84 changes: 59 additions & 25 deletions utils/dependencies/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
),
},
},
}
}
}

Expand Down Expand Up @@ -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,
},
},
}
}

}

//
Expand Down Expand Up @@ -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)),
)
}

Expand Down
11 changes: 6 additions & 5 deletions utils/dymint/dymint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
11 changes: 9 additions & 2 deletions utils/rollapp/bechprefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rollapp

import (
"errors"
"fmt"
"os/exec"
"regexp"
"strings"
Expand All @@ -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
Expand Down

0 comments on commit dc57755

Please sign in to comment.