diff --git a/cmd/da-light-client/da_light_client.go b/cmd/da-light-client/da_light_client.go index af00fe4e..17a1c01a 100644 --- a/cmd/da-light-client/da_light_client.go +++ b/cmd/da-light-client/da_light_client.go @@ -4,6 +4,7 @@ import ( "github.com/spf13/cobra" da_start "github.com/dymensionxyz/roller/cmd/da-light-client/start" + "github.com/dymensionxyz/roller/cmd/da-light-client/update" ) func DALightClientCmd() *cobra.Command { @@ -12,5 +13,7 @@ func DALightClientCmd() *cobra.Command { Short: "Commands for running and managing the data availability light client.", } cmd.AddCommand(da_start.Cmd()) + cmd.AddCommand(update.Cmd()) + return cmd } diff --git a/cmd/da-light-client/update/update.go b/cmd/da-light-client/update/update.go new file mode 100644 index 00000000..987b71b3 --- /dev/null +++ b/cmd/da-light-client/update/update.go @@ -0,0 +1,55 @@ +package update + +import ( + "github.com/pterm/pterm" + "github.com/spf13/cobra" + + "github.com/dymensionxyz/roller/utils/dependencies" + servicemanager "github.com/dymensionxyz/roller/utils/service_manager" +) + +const ( + rpcEndpointFlag = "rpc-endpoint" + metricsEndpointFlag = "metrics-endpoint" +) + +func Cmd() *cobra.Command { + runCmd := &cobra.Command{ + Use: "update", + Short: "Runs the DA light client.", + Run: func(cmd *cobra.Command, args []string) { + pterm.Info.Println("stopping existing system services, if any...") + err := servicemanager.StopSystemServices([]string{"da-light-client"}) + if err != nil { + pterm.Error.Println("failed to stop system services: ", err) + return + } + + dep := dependencies.DefaultCelestiaNodeDependency() + err = dependencies.InstallBinaryFromRepo( + dep, dep.DependencyName, + ) + if err != nil { + pterm.Error.Println("failed to install binary: ", err) + return + } + + pterm.Info.Println("stopping existing system services, if any...") + err = servicemanager.Start([]string{"da-light-client"}) + if err != nil { + pterm.Error.Println("failed to stop system services: ", err) + return + } + }, + } + + addFlags(runCmd) + return runCmd +} + +func addFlags(cmd *cobra.Command) { + cmd.Flags(). + StringP(rpcEndpointFlag, "", "mocha-4-consensus.mesa.newmetric.xyz", "The DA rpc endpoint to connect to.") + cmd.Flags(). + StringP(metricsEndpointFlag, "", "", "The OTEL collector metrics endpoint to connect to.") +} diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index d4d918a6..ba7ed347 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -95,7 +95,7 @@ func Cmd() *cobra.Command { } } - err = servicemanager.StopSystemServices() + err = servicemanager.StopSystemServices(consts.RollappSystemdServices) if err != nil { pterm.Error.Println("failed to stop system services: ", err) return diff --git a/cmd/services/start/start.go b/cmd/services/start/start.go index 81096de4..75d3ed9d 100644 --- a/cmd/services/start/start.go +++ b/cmd/services/start/start.go @@ -191,7 +191,6 @@ func EibcCmd() *cobra.Command { ) } }() - }, } return cmd diff --git a/utils/dependencies/celestia.go b/utils/dependencies/celestia.go new file mode 100644 index 00000000..c116f3bf --- /dev/null +++ b/utils/dependencies/celestia.go @@ -0,0 +1,41 @@ +package dependencies + +import ( + "os/exec" + + "github.com/dymensionxyz/roller/cmd/consts" + "github.com/dymensionxyz/roller/utils/dependencies/types" +) + +const ( + DefaultCelestiaNodeVersion = "v0.20.0-mocha" + DefaultCelestiaAppVersion = "v2.3.1" +) + +func DefaultCelestiaNodeDependency() types.Dependency { + return types.Dependency{ + DependencyName: "celestia", + RepositoryOwner: "celestiaorg", + RepositoryName: "celestia-node", + RepositoryUrl: "https://github.com/celestiaorg/celestia-node.git", + Release: DefaultCelestiaNodeVersion, + Binaries: []types.BinaryPathPair{ + { + Binary: "./build/celestia", + BinaryDestination: consts.Executables.Celestia, + BuildCommand: exec.Command( + "make", + "build", + ), + }, + { + Binary: "./cel-key", + BinaryDestination: consts.Executables.CelKey, + BuildCommand: exec.Command( + "make", + "cel-key", + ), + }, + }, + } +} diff --git a/utils/dependencies/dependencies.go b/utils/dependencies/dependencies.go index fd6c80e7..6e9fd03a 100644 --- a/utils/dependencies/dependencies.go +++ b/utils/dependencies/dependencies.go @@ -79,7 +79,7 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( if !withMockDA { rbi := NewRollappBinaryInfo( raResp.Rollapp.GenesisInfo.Bech32Prefix, - raResp.Rollapp.GenesisInfo.NativeDenom.Base, + raBinCommit, raVmType, ) @@ -273,6 +273,10 @@ func InstallBinaryFromRelease(dep types.Dependency) error { goArch = "x86_64" } + if goArch == "amd64" && dep.DependencyName == "celestia-node" { + goArch = "x86_64" + } + targetDir, err := os.MkdirTemp(os.TempDir(), dep.DependencyName) if err != nil { // nolint: errcheck,gosec diff --git a/utils/dependencies/rollapp.go b/utils/dependencies/rollapp.go index bfd6cdf0..8076d922 100644 --- a/utils/dependencies/rollapp.go +++ b/utils/dependencies/rollapp.go @@ -27,31 +27,7 @@ func NewRollappBinaryInfo(bech32Prefix, commit, vmType string) RollappBinaryInfo func DefaultRollappBuildableDependencies(raBinInfo RollappBinaryInfo) map[string]types.Dependency { deps := map[string]types.Dependency{} - deps["celestia"] = types.Dependency{ - DependencyName: "celestia", - RepositoryOwner: "celestiaorg", - RepositoryName: "celestia-node", - RepositoryUrl: "https://github.com/celestiaorg/celestia-node.git", - Release: "v0.18.2-mocha", - Binaries: []types.BinaryPathPair{ - { - Binary: "./build/celestia", - BinaryDestination: consts.Executables.Celestia, - BuildCommand: exec.Command( - "make", - "build", - ), - }, - { - Binary: "./cel-key", - BinaryDestination: consts.Executables.CelKey, - BuildCommand: exec.Command( - "make", - "cel-key", - ), - }, - }, - } + deps["celestia"] = DefaultCelestiaNodeDependency() switch raBinInfo.VMType { case "evm": diff --git a/utils/service_manager/service.go b/utils/service_manager/service.go index 0c6eb98a..c3ecbecf 100644 --- a/utils/service_manager/service.go +++ b/utils/service_manager/service.go @@ -8,6 +8,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "sync" "time" @@ -121,6 +122,33 @@ func (s *ServiceConfig) RunServiceWithRestart(name string, options ...bash.Comma }() } +func Start(services []string) error { + pterm.Info.Println("starting existing system services, if any...") + switch runtime.GOOS { + case "linux": + for _, svc := range services { + err := StartSystemdService(svc) + if err != nil { + return fmt.Errorf("failed to start %s systemd service: %v", svc, err) + } + } + case "darwin": + for _, svc := range services { + err := StartLaunchctlService(svc) + if err != nil { + return fmt.Errorf("failed to start %s systemd service: %v", svc, err) + } + } + default: + pterm.Error.Printf("unsupported platform: %s", runtime.GOOS) + } + pterm.Success.Printf( + "💈 Services %s started successfully.\n", + strings.Join(services, ", "), + ) + return nil +} + func StartSystemdService(serviceName string) error { cmd := exec.Command("sudo", "systemctl", "start", serviceName) @@ -221,11 +249,11 @@ func StopLaunchdService(serviceName string) error { return nil } -func StopSystemServices() error { +func StopSystemServices(services []string) error { pterm.Info.Println("stopping existing system services, if any...") switch runtime.GOOS { case "linux": - for _, svc := range consts.RollappSystemdServices { + for _, svc := range services { err := StopSystemdService(svc) if err != nil { pterm.Error.Println("failed to stop systemd service: ", err)