diff --git a/cmd/binaries/binaries.go b/cmd/binaries/binaries.go index 3d7cb1c2..2d00924d 100644 --- a/cmd/binaries/binaries.go +++ b/cmd/binaries/binaries.go @@ -3,7 +3,7 @@ package binaries import ( "github.com/spf13/cobra" - "github.com/dymensionxyz/roller/cmd/binaries/install" + "github.com/dymensionxyz/roller/cmd/binaries/versions" ) func Cmd() *cobra.Command { @@ -12,7 +12,8 @@ func Cmd() *cobra.Command { Short: "Commands to manage roller dependencies", } - cmd.AddCommand(install.Cmd()) + // cmd.AddCommand(install.Cmd()) + cmd.AddCommand(versions.Cmd()) return cmd } diff --git a/cmd/binaries/versions/versions.go b/cmd/binaries/versions/versions.go new file mode 100644 index 00000000..2eee0aff --- /dev/null +++ b/cmd/binaries/versions/versions.go @@ -0,0 +1,46 @@ +package versions + +import ( + "fmt" + + "github.com/spf13/cobra" + + "github.com/dymensionxyz/roller/cmd/consts" + "github.com/dymensionxyz/roller/utils/dependencies" +) + +func Cmd() *cobra.Command { + versionCmd := &cobra.Command{ + Use: "versions", + Short: "Print all binary versions", + Run: func(cmd *cobra.Command, args []string) { + dymdVersion, err := dependencies.GetCurrentCommit(consts.Executables.Dymension) + if err != nil { + fmt.Println("failed to get dymd version:", err) + return + } + fmt.Println("dymd version:", dymdVersion) + celestiaVersion, err := dependencies.GetCurrentCommit(consts.Executables.Celestia) + if err != nil { + fmt.Println("failed to get celestia version:", err) + return + } + fmt.Println("celestia version:", celestiaVersion) + + relayerVersion, err := dependencies.GetCurrentCommit(consts.Executables.Relayer) + if err != nil { + fmt.Println("failed to get relayer version:", err) + return + } + fmt.Println("relayer version:", relayerVersion) + + eibcVersion, err := dependencies.GetCurrentCommit(consts.Executables.Eibc) + if err != nil { + fmt.Println("failed to get eibc version:", err) + return + } + fmt.Println("eibc version:", eibcVersion) + }, + } + return versionCmd +} diff --git a/cmd/da-light-client/update/update.go b/cmd/da-light-client/update/update.go index f8c07795..cb1080c8 100644 --- a/cmd/da-light-client/update/update.go +++ b/cmd/da-light-client/update/update.go @@ -28,6 +28,7 @@ func Cmd() *cobra.Command { dep := dependencies.DefaultCelestiaNodeDependency() err = dependencies.InstallBinaryFromRepo( dep, dep.DependencyName, + true, ) if err != nil { pterm.Error.Println("failed to install binary: ", err) diff --git a/cmd/eibc/init/init.go b/cmd/eibc/init/init.go index db8012f2..da0f9024 100644 --- a/cmd/eibc/init/init.go +++ b/cmd/eibc/init/init.go @@ -234,7 +234,7 @@ func Cmd() *cobra.Command { } else { deps := dependencies.DefaultEibcClientPrebuiltDependencies() for _, v := range deps { - err := dependencies.InstallBinaryFromRelease(v) + err := dependencies.InstallBinaryFromRelease(v, true) if err != nil { pterm.Error.Printfln("failed to install binary: %s", err) return diff --git a/cmd/relayer/setup/setup.go b/cmd/relayer/setup/setup.go index f1b3d61f..b7f950d4 100644 --- a/cmd/relayer/setup/setup.go +++ b/cmd/relayer/setup/setup.go @@ -1,7 +1,6 @@ package setup import ( - "context" "fmt" "os" "slices" @@ -9,10 +8,8 @@ import ( "strings" "time" - firebase "firebase.google.com/go" "github.com/pterm/pterm" "github.com/spf13/cobra" - "google.golang.org/api/option" initconfig "github.com/dymensionxyz/roller/cmd/config/init" "github.com/dymensionxyz/roller/cmd/consts" @@ -107,55 +104,49 @@ func Cmd() *cobra.Command { pterm.Error.Println("failed to fetch rollapp information from hub: ", err) return } + err = genesis.DownloadGenesis(home, raResp.Rollapp.Metadata.GenesisUrl) if err != nil { pterm.Error.Println("failed to download genesis file: ", err) return } + as, err := genesis.GetGenesisAppState(home) if err != nil { pterm.Error.Println("failed to get genesis app state: ", err) return } - ctx := context.Background() - conf := &firebase.Config{ProjectID: "drs-metadata"} - app, err := firebase.NewApp(ctx, conf, option.WithoutAuthentication()) - if err != nil { - pterm.Error.Printfln("failed to initialize firebase app: %v", err) - return - } - drsVersion := strconv.Itoa(as.RollappParams.Params.DrsVersion) - client, err := app.Firestore(ctx) + drsVersion := strconv.Itoa(as.RollappParams.Params.DrsVersion) + drsInfo, err := firebaseutils.GetLatestDrsVersionCommit(drsVersion) if err != nil { - pterm.Error.Printfln("failed to create firestore client: %v", err) + pterm.Error.Println("failed to retrieve latest commit: ", err) return } - defer client.Close() - // Fetch DRS version information using the nested collection path - // Path format: versions/{version}/revisions/{revision} - drsInfo, err := firebaseutils.GetLatestDrsVersionCommit(drsVersion) - if err != nil { - pterm.Error.Println("failed to retrieve latest DRS version: ", err) - return + var raCommit string + switch strings.ToLower(raResp.Rollapp.VmType) { + case "evm": + raCommit = drsInfo.EvmCommit + case "wasm": + raCommit = drsInfo.WasmCommit } rbi := dependencies.NewRollappBinaryInfo( raResp.Rollapp.GenesisInfo.Bech32Prefix, - drsInfo.Commit, + raCommit, strings.ToLower(raResp.Rollapp.VmType), ) raDep := dependencies.DefaultRollappDependency(rbi) - err = dependencies.InstallBinaryFromRepo(raDep, raDep.DependencyName) + err = dependencies.InstallBinaryFromRepo(raDep, raDep.DependencyName, false) if err != nil { pterm.Error.Printfln("failed to install binary: %s", err) return } rlyDep := dependencies.DefaultRelayerPrebuiltDependencies() - err = dependencies.InstallBinaryFromRelease(rlyDep["rly"]) + err = dependencies.InstallBinaryFromRelease(rlyDep["rly"], true) if err != nil { pterm.Error.Printfln("failed to install binary: %s", err) return diff --git a/cmd/rollapp/drs/update/update.go b/cmd/rollapp/drs/update/update.go index 75cc4586..363cebc1 100644 --- a/cmd/rollapp/drs/update/update.go +++ b/cmd/rollapp/drs/update/update.go @@ -58,13 +58,6 @@ func Cmd() *cobra.Command { return } - if drsInfo.Commit[:6] == cv { - pterm.Info.Println("You are already using the latest version of DRS") - return - } - - // if doesn't match, take latest as the reference - // download the latest, build into ~/.roller/tmp raResp, err := rollapputils.GetMetadataFromChain( rollerData.RollappID, rollerData.HubData, @@ -74,6 +67,21 @@ func Cmd() *cobra.Command { return } + var commit string + switch strings.ToLower(raResp.Rollapp.VmType) { + case "evm": + commit = drsInfo.EvmCommit + case "wasm": + commit = drsInfo.WasmCommit + } + + if commit == cv { + pterm.Info.Println("You are already using the latest version of DRS") + return + } + + // if doesn't match, take latest as the reference + // download the latest, build into ~/.roller/tmp raNewBinDir, err := os.MkdirTemp(os.TempDir(), "rollapp-drs-update") if err != nil { pterm.Error.Println( @@ -86,7 +94,7 @@ func Cmd() *cobra.Command { rbi := dependencies.NewRollappBinaryInfo( raResp.Rollapp.GenesisInfo.Bech32Prefix, - drsInfo.Commit, + commit, strings.ToLower(raResp.Rollapp.VmType), ) @@ -101,7 +109,7 @@ func Cmd() *cobra.Command { pterm.Info.Println("starting update") raDep.Binaries[0].BinaryDestination = tmpBinLocation - err = dependencies.InstallBinaryFromRepo(raDep, raDep.DependencyName) + err = dependencies.InstallBinaryFromRepo(raDep, raDep.DependencyName, true) if err != nil { pterm.Error.Println("failed to install rollapp binary: ", err) return diff --git a/cmd/rollapp/init/init.go b/cmd/rollapp/init/init.go index c77ddfad..1a1422a1 100644 --- a/cmd/rollapp/init/init.go +++ b/cmd/rollapp/init/init.go @@ -2,7 +2,6 @@ package initrollapp import ( "fmt" - "os/exec" "strings" "time" @@ -16,7 +15,6 @@ import ( "github.com/dymensionxyz/roller/utils/config/scripts" "github.com/dymensionxyz/roller/utils/config/tomlconfig" "github.com/dymensionxyz/roller/utils/dependencies" - "github.com/dymensionxyz/roller/utils/dependencies/types" "github.com/dymensionxyz/roller/utils/filesystem" "github.com/dymensionxyz/roller/utils/keys" "github.com/dymensionxyz/roller/utils/rollapp" @@ -66,6 +64,13 @@ func Cmd() *cobra.Command { } if isRootExist { + dymdDep := dependencies.DefaultDymdDependency() + err = dependencies.InstallBinaryFromRelease(dymdDep, true) + if err != nil { + pterm.Error.Println("failed to install dymd: ", err) + return + } + shouldContinue, err := sequencer.CheckExistingSequencer(home) if err != nil { pterm.Error.Printf( @@ -130,23 +135,9 @@ func Cmd() *cobra.Command { // TODO: move to consts // TODO(v2): move to roller config if !shouldUseMockBackend && env != "custom" { - dymdBinaryOptions := types.Dependency{ - DependencyName: "dymension", - RepositoryOwner: "dymensionxyz", - RepositoryName: "dymension", - RepositoryUrl: "https://github.com/artemijspavlovs/dymension", - Release: "v3.1.0-pg10", - Binaries: []types.BinaryPathPair{ - { - Binary: "dymd", - BinaryDestination: consts.Executables.Dymension, - BuildCommand: exec.Command("make", "build"), - }, - }, - PersistFiles: []types.PersistFile{}, - } + dymdBinaryOptions := dependencies.DefaultDymdDependency() pterm.Info.Println("installing dependencies") - err = dependencies.InstallBinaryFromRelease(dymdBinaryOptions) + err = dependencies.InstallBinaryFromRelease(dymdBinaryOptions, true) if err != nil { pterm.Error.Println("failed to install dymd: ", err) return @@ -202,12 +193,10 @@ func Cmd() *cobra.Command { }, } - if !shouldSkipBinaryInstallation { - _, _, err = dependencies.InstallBinaries(true, raRespMock) - if err != nil { - pterm.Error.Println("failed to install binaries: ", err) - return - } + _, _, err = dependencies.InstallBinaries(true, raRespMock) + if err != nil { + pterm.Error.Println("failed to install binaries: ", err) + return } err := runInit( @@ -227,7 +216,7 @@ func Cmd() *cobra.Command { if shouldSkipBinaryInstallation { dymdDep := dependencies.DefaultDymdDependency() - err = dependencies.InstallBinaryFromRelease(dymdDep) + err = dependencies.InstallBinaryFromRelease(dymdDep, true) if err != nil { pterm.Error.Println("failed to install dymd: ", err) return diff --git a/cmd/root.go b/cmd/root.go index c080bf53..74408fe2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" + "github.com/dymensionxyz/roller/cmd/binaries" blockexplorer "github.com/dymensionxyz/roller/cmd/block-explorer" initconfig "github.com/dymensionxyz/roller/cmd/config/init" da_light_client "github.com/dymensionxyz/roller/cmd/da-light-client" @@ -40,6 +41,7 @@ func init() { rootCmd.AddCommand(eibc.Cmd()) rootCmd.AddCommand(blockexplorer.Cmd()) rootCmd.AddCommand(version.Cmd()) + rootCmd.AddCommand(binaries.Cmd()) initconfig.AddGlobalFlags(rootCmd) } diff --git a/utils/dependencies/celestia.go b/utils/dependencies/celestia.go index 08780d24..3588ca42 100644 --- a/utils/dependencies/celestia.go +++ b/utils/dependencies/celestia.go @@ -8,8 +8,11 @@ import ( ) const ( - DefaultCelestiaNodeVersion = "v0.20.2-mocha" - DefaultCelestiaAppVersion = "v2.3.1" + // 2dc9cce7b5dffc14fd4fe156d2aa9869318e0f68= "v0.20.2-mocha" + DefaultCelestiaNodeVersion = "2dc9cce7b5dffc14fd4fe156d2aa9869318e0f68" + + // 5d6c695= "v3.0.0-mocha" + DefaultCelestiaAppVersion = "v3.0.0-mocha" ) func DefaultCelestiaNodeDependency() types.Dependency { @@ -39,3 +42,21 @@ func DefaultCelestiaNodeDependency() types.Dependency { }, } } + +func DefaultCelestiaAppPrebuiltDependency() types.Dependency { + return types.Dependency{ + DependencyName: "celestia-app", + RepositoryUrl: "https://github.com/celestiaorg/celestia-app", + Release: DefaultCelestiaAppVersion, + Binaries: []types.BinaryPathPair{ + { + Binary: "celestia-appd", + BinaryDestination: consts.Executables.CelestiaApp, + BuildCommand: exec.Command( + "make", + "build", + ), + }, + }, + } +} diff --git a/utils/dependencies/dependencies.go b/utils/dependencies/dependencies.go index b88ba375..e769c2c7 100644 --- a/utils/dependencies/dependencies.go +++ b/utils/dependencies/dependencies.go @@ -46,6 +46,7 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( defer os.RemoveAll(genesisTmpDir) var drsVersion string + var raCommit string raVmType := strings.ToLower(raResp.Rollapp.VmType) if !withMockDA { // TODO refactor, this genesis file fetch is redundand and will slow the process down @@ -71,7 +72,13 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( if err != nil { return nil, nil, err } - drsVersion = drsInfo.Commit + + switch strings.ToLower(raResp.Rollapp.VmType) { + case "evm": + raCommit = drsInfo.EvmCommit + case "wasm": + raCommit = drsInfo.WasmCommit + } } defer func() { @@ -87,7 +94,7 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( if !withMockDA { rbi := NewRollappBinaryInfo( raResp.Rollapp.GenesisInfo.Bech32Prefix, - drsVersion, + raCommit, raVmType, ) @@ -167,22 +174,20 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( }, } } - } for k, dep := range goreleaserDeps { - err := InstallBinaryFromRelease(dep) + err := InstallBinaryFromRelease(dep, true) if err != nil { - errMsg := fmt.Sprintf("failed to build binary %s: %v", k, err) + errMsg := fmt.Sprintf("[release] failed to install binary %s from release: %v", k, err) return nil, nil, errors.New(errMsg) } - } for k, dep := range buildableDeps { - err := InstallBinaryFromRepo(dep, k) + err := InstallBinaryFromRepo(dep, k, true) if err != nil { - errMsg := fmt.Sprintf("failed to build binary %s: %v", k, err) + errMsg := fmt.Sprintf("[build] failed to build binary %s: %v", k, err) return nil, nil, errors.New(errMsg) } } @@ -190,7 +195,19 @@ func InstallBinaries(withMockDA bool, raResp rollapp.ShowRollappResponse) ( return buildableDeps, goreleaserDeps, nil } -func InstallBinaryFromRepo(dep types.Dependency, td string) error { +func InstallBinaryFromRepo(dep types.Dependency, td string, withCheck bool) error { + if withCheck { + remainingBinaries, err := checkBinaryVersions(dep) + if err != nil { + return err + } + + dep.Binaries = remainingBinaries + if len(dep.Binaries) == 0 { + return nil + } + } + spinner, _ := pterm.DefaultSpinner.Start( fmt.Sprintf("[%s] installing", dep.DependencyName), ) @@ -269,7 +286,71 @@ func InstallBinaryFromRepo(dep types.Dependency, td string) error { return nil } -func InstallBinaryFromRelease(dep types.Dependency) error { +func checkBinaryVersions(dep types.Dependency) ([]types.BinaryPathPair, error) { + var remainingBinaries []types.BinaryPathPair + for _, binary := range dep.Binaries { + _, err := os.Stat(binary.BinaryDestination) + if err != nil { + if os.IsNotExist(err) { + remainingBinaries = append(remainingBinaries, binary) + } else { + return nil, err + } + } else { + commit, err := GetCurrentCommit(binary.BinaryDestination) + if err != nil { + return nil, err + } + + var want string + var have string + + switch binary.BinaryDestination { + case consts.Executables.CelestiaApp: + want = strings.TrimPrefix(dep.Release, "v") + have = commit + case consts.Executables.Eibc: + want = dep.Release + have = fmt.Sprintf("v%s", commit) + case consts.Executables.Relayer: + want = dep.Release + have = commit + case consts.Executables.Dymension: + want = dep.Release + have = fmt.Sprintf("v%s", commit) + default: + want = dep.Release[:6] + have = commit[:6] + } + + pterm.Info.Printfln( + "comparing installed versions for %s (want: %s / have: %s)", + binary.BinaryDestination, + want, + have, + ) + + if have != want { + remainingBinaries = append(remainingBinaries, binary) + } + } + } + return remainingBinaries, nil +} + +func InstallBinaryFromRelease(dep types.Dependency, withCheck bool) error { + if withCheck { + remainingBinaries, err := checkBinaryVersions(dep) + if err != nil { + return err + } + + dep.Binaries = remainingBinaries + if len(dep.Binaries) == 0 { + return nil + } + } + spinner, _ := pterm.DefaultSpinner.Start( fmt.Sprintf("[%s] installing", dep.DependencyName), ) @@ -307,6 +388,8 @@ func InstallBinaryFromRelease(dep types.Dependency) error { ) spinner.UpdateText(fmt.Sprintf("[%s] downloading %s", dep.DependencyName, dep.Release)) + // nolint: errcheck + spinner.Stop() err = DownloadRelease(url, targetDir, dep, spinner) if err != nil { // nolint: errcheck,gosec @@ -324,13 +407,11 @@ func DownloadRelease( dep types.Dependency, spinner *pterm.SpinnerPrinter, ) error { - // Create a new HTTP request req, err := http.NewRequest("GET", url, nil) if err != nil { return err } - // Send the request resp, err := http.DefaultClient.Do(req) if err != nil { return err @@ -338,19 +419,14 @@ func DownloadRelease( // nolint: errcheck defer resp.Body.Close() - // Create a progress bar bar := progressbar.DefaultBytes( resp.ContentLength, "Downloading", ) - // Create a reader that will update the progress bar reader := progressbar.NewReader(resp.Body, bar) - - // Create a pointer to the reader readerPtr := &reader - // Create a wrapper that implements io.ReadCloser readCloserWrapper := struct { io.Reader io.Closer @@ -361,7 +437,6 @@ func DownloadRelease( // nolint: errcheck,gosec spinner.Stop() - // Extract the tar.gz file with progress err = archives.ExtractTarGz(destination, readCloserWrapper, dep) if err != nil { return err diff --git a/utils/dependencies/dymd.go b/utils/dependencies/dymd.go index e4f15465..a9ee018e 100644 --- a/utils/dependencies/dymd.go +++ b/utils/dependencies/dymd.go @@ -1,19 +1,19 @@ package dependencies import ( - "errors" - "os" "os/exec" - "regexp" "strings" "github.com/pterm/pterm" "github.com/dymensionxyz/roller/cmd/consts" - "github.com/dymensionxyz/roller/utils/bash" "github.com/dymensionxyz/roller/utils/dependencies/types" ) +const ( + DefaultDymdCommit = "v3.1.0-mig01" +) + func customDymdDependency(dymdCommit string) types.Dependency { dymdCommit = strings.TrimSpace(dymdCommit) @@ -37,40 +37,6 @@ func customDymdDependency(dymdCommit string) types.Dependency { } } -func ExtractCommitFromBinaryVersion(binary string) (string, error) { - _, err := os.Stat(binary) - if err != nil { - if os.IsNotExist(err) { - return "", nil - } - return "", err - } - - cmd := exec.Command(binary, "version", "--long") - - out, err := bash.ExecCommandWithStdout(cmd) - if err != nil { - return "", err - } - - lns := strings.Split(out.String(), "\n") - var cl string - for _, l := range lns { - if strings.Contains(l, "commit") { - cl = l - break - } - } - - re := regexp.MustCompile(`commit: ([a-f0-9]+)`) - match := re.FindStringSubmatch(cl) - if len(match) > 1 { - return match[1], nil - } else { - return "", errors.New("commit not found in the version output") - } -} - func InstallCustomDymdVersion(dymdCommit string) error { dep := customDymdDependency(dymdCommit) @@ -80,7 +46,7 @@ func InstallCustomDymdVersion(dymdCommit string) error { } if commit == "" || commit[:6] != dep.Release[:6] { - err := InstallBinaryFromRepo(dep, dep.DependencyName) + err := InstallBinaryFromRepo(dep, dep.DependencyName, true) if err != nil { return err } @@ -97,7 +63,7 @@ func DefaultDymdDependency() types.Dependency { RepositoryOwner: "dymensionxyz", RepositoryName: "dymension", RepositoryUrl: "https://github.com/artemijspavlovs/dymension", - Release: "v3.1.0-mig01", + Release: DefaultDymdCommit, Binaries: []types.BinaryPathPair{ { Binary: "dymd", diff --git a/utils/dependencies/extract.go b/utils/dependencies/extract.go new file mode 100644 index 00000000..79cee9b6 --- /dev/null +++ b/utils/dependencies/extract.go @@ -0,0 +1,138 @@ +package dependencies + +import ( + "errors" + "os" + "os/exec" + "regexp" + "strings" + + "github.com/dymensionxyz/roller/cmd/consts" + "github.com/dymensionxyz/roller/utils/bash" +) + +const ( + celestiaCommitFlagPattern = `github\.com/celestiaorg/celestia-node/nodebuilder/node\.lastCommit=(\w+)` + celestiaAppCommitFlagPattern = `github\.com/cosmos/cosmos-sdk/version\.Commit=(\w+)` + celKeyCommitFlagPattern = `vcs\.revision=(\w+)` + eibcCommitFlagPattern = `main\.version=([\w\.-]+)` + relayerCommitFlagPattern = `github\.com/cosmos/relayer/v2/cmd\.Version=([\w\.-]+)` + dymdCommitFlagPattern = `github\.com/cosmos/cosmos-sdk/version\.Version=([\w\\.-]+)` +) + +func GetCurrentCommit(binary string) (string, error) { + switch binary { + case consts.Executables.Dymension: + return GetVersion(consts.Executables.Dymension) + case consts.Executables.Celestia: + return ExtractCommitFromBuildFlags(consts.Executables.Celestia, celestiaCommitFlagPattern) + case consts.Executables.CelestiaApp: + return GetVersion(consts.Executables.CelestiaApp) + case consts.Executables.CelKey: + return ExtractCommitFromBuildFlags(consts.Executables.CelKey, celKeyCommitFlagPattern) + case consts.Executables.RollappEVM: + return ExtractCommitFromBinaryVersion(consts.Executables.RollappEVM) + case consts.Executables.Eibc: + return ExtractCommitFromBuildFlags(consts.Executables.Eibc, eibcCommitFlagPattern) + case consts.Executables.Relayer: + return ExtractCommitFromBuildFlags(consts.Executables.Relayer, relayerCommitFlagPattern) + default: + return "", errors.New("unsupported binary") + } +} + +func ExtractCommitFromBuildFlags(binary, pattern string) (string, error) { + c := exec.Command( + "go", + "version", + "-m", + binary, + ) + + out, err := bash.ExecCommandWithStdout(c) + if err != nil { + return "", err + } + + lines := strings.Split(out.String(), "\n") + + re := regexp.MustCompile(pattern) + var ldflags string + var commit string + + for _, line := range lines { + if binary == consts.Executables.CelKey { + if strings.Contains(line, "vcs.revision") { + ldflags = line + break + } + } else { + if strings.Contains(line, "-ldflags") { + ldflags = line + break + } + } + } + + match := re.FindStringSubmatch(ldflags) + if len(match) > 1 { + commit = match[1] + } else { + commit = "" + } + + return commit, err +} + +func ExtractCommitFromBinaryVersion(binary string) (string, error) { + _, err := os.Stat(binary) + if err != nil { + if os.IsNotExist(err) { + return "", nil + } + return "", err + } + + cmd := exec.Command(binary, "version", "--long") + + out, err := bash.ExecCommandWithStdout(cmd) + if err != nil { + return "", err + } + + lns := strings.Split(out.String(), "\n") + var cl string + for _, l := range lns { + if strings.Contains(l, "commit") { + cl = l + break + } + } + + re := regexp.MustCompile(`commit: ([a-f0-9]+)`) + match := re.FindStringSubmatch(cl) + if len(match) > 1 { + return match[1], nil + } else { + return "", errors.New("commit not found in the version output") + } +} + +func GetVersion(binary string) (string, error) { + _, err := os.Stat(binary) + if err != nil { + if os.IsNotExist(err) { + return "", nil + } + return "", err + } + + cmd := exec.Command(binary, "version") + + out, err := bash.ExecCommandWithStdout(cmd) + if err != nil { + return "", err + } + + return strings.TrimSpace(out.String()), nil +} diff --git a/utils/dependencies/rollapp.go b/utils/dependencies/rollapp.go index 09b86bb2..6ad379e0 100644 --- a/utils/dependencies/rollapp.go +++ b/utils/dependencies/rollapp.go @@ -83,21 +83,7 @@ func DefaultRollappDependency(raBinInfo RollappBinaryInfo) types.Dependency { func DefaultRollappPrebuiltDependencies() map[string]types.Dependency { deps := map[string]types.Dependency{ - "celestia-app": { - DependencyName: "celestia-app", - RepositoryUrl: "https://github.com/celestiaorg/celestia-app", - Release: "v2.1.2", - Binaries: []types.BinaryPathPair{ - { - Binary: "celestia-appd", - BinaryDestination: consts.Executables.CelestiaApp, - BuildCommand: exec.Command( - "make", - "build", - ), - }, - }, - }, + "celestia-app": DefaultCelestiaAppPrebuiltDependency(), } return deps diff --git a/utils/firebase/firebase.go b/utils/firebase/firebase.go index 162e8f13..bea8c32d 100644 --- a/utils/firebase/firebase.go +++ b/utils/firebase/firebase.go @@ -13,7 +13,9 @@ import ( // DrsVersionInfo represents the structure of DRS version information in Firestore type DrsVersionInfo struct { - Commit string `firestore:"commit"` + Commit string `firestore:"commit"` // @20241125 legacy, was used when drs support was added only to evm + EvmCommit string `firestore:"evm-commit"` + WasmCommit string `firestore:"wasm-commit"` } func GetLatestDrsVersionCommit(drsVersion string) (*DrsVersionInfo, error) { diff --git a/utils/healthagent/healthagent.go b/utils/healthagent/healthagent.go index 5a7279ce..05ac8fbd 100644 --- a/utils/healthagent/healthagent.go +++ b/utils/healthagent/healthagent.go @@ -24,6 +24,7 @@ import ( func Start(home string, l *log.Logger) { for { + time.Sleep(15 * time.Second) var healthy bool localEndpoint := "localhost" defaultRaMetricPort := "2112" @@ -91,7 +92,6 @@ func Start(home string, l *log.Logger) { } healthy = true - time.Sleep(15 * time.Second) } }