diff --git a/Cargo.lock b/Cargo.lock index 0c4842ec..1b809994 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1147,7 +1147,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "preflight" -version = "21.0.1" +version = "21.1.0" dependencies = [ "anyhow", "base64 0.22.0", @@ -1620,7 +1620,7 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stellar-rpc-client" -version = "21.0.1" +version = "21.1.0" dependencies = [ "clap", "hex", diff --git a/Cargo.toml b/Cargo.toml index a0e8b42f..9f58ae3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ members = [ default-members = ["cmd/crates/stellar-rpc-client"] [workspace.package] -version = "21.0.1" +version = "21.1.0" rust-version = "1.74.0" [workspace.dependencies.soroban-env-host] diff --git a/cmd/deptool/analyze.go b/cmd/deptool/analyze.go deleted file mode 100644 index ec638905..00000000 --- a/cmd/deptool/analyze.go +++ /dev/null @@ -1,350 +0,0 @@ -package main - -import ( - "errors" - "fmt" - "strings" - "time" - - git "github.com/go-git/go-git/v5" - - "github.com/go-git/go-git/v5/plumbing" - "github.com/go-git/go-git/v5/plumbing/object" - "github.com/go-git/go-git/v5/plumbing/storer" - "github.com/go-git/go-git/v5/storage/memory" -) - -type analyzedProjectDependency struct { - projectDependency - branchName string - fullCommitHash string - latestBranchCommit string - latestBranchCommitTime time.Time - latestBranchVersion string - workspaceVersion bool // is the version is defined per workspace or package ? -} - -type analyzedDependencyFunc func(string, analyzedProjectDependency) - -func analyze(dependencies *projectDependencies, analyzedDependencyFunc analyzedDependencyFunc) map[string]analyzedProjectDependency { - out := make(map[string]analyzedProjectDependency) - -outerDependenciesLoop: - for pkg, depInfo := range dependencies.dependencyNames { - // check if we've already analyzed this project before - // ( since multiple dependencies might refer to the same repo) - for _, prevAnalyzedDep := range out { - if prevAnalyzedDep.githubPath == depInfo.githubPath && - prevAnalyzedDep.githubCommit == depInfo.githubCommit && - prevAnalyzedDep.workspaceVersion { - // yes, we did. - out[pkg] = analyzedProjectDependency{ - projectDependency: *depInfo, - branchName: prevAnalyzedDep.branchName, - fullCommitHash: prevAnalyzedDep.fullCommitHash, - latestBranchCommit: prevAnalyzedDep.latestBranchCommit, - latestBranchCommitTime: prevAnalyzedDep.latestBranchCommitTime, - workspaceVersion: prevAnalyzedDep.workspaceVersion, - latestBranchVersion: prevAnalyzedDep.latestBranchVersion, - } - if analyzedDependencyFunc != nil { - analyzedDependencyFunc(pkg, out[pkg]) - } - continue outerDependenciesLoop - } - } - out[pkg] = analyzedDependency(*depInfo) - - if analyzedDependencyFunc != nil { - analyzedDependencyFunc(pkg, out[pkg]) - } - } - - return out -} - -func analyzedDependency(depInfo projectDependency) analyzedProjectDependency { - path := depInfo.githubPath - if !strings.HasPrefix(path, "https://") { - path = "https://" + path - } - repo, err := git.Clone(memory.NewStorage(), nil, &git.CloneOptions{ - URL: path, - Tags: git.AllTags, - }) - if err != nil { - fmt.Printf("unable to clone repository at %s\n", path) - exitErr() - } - - revCommit, err := lookupShortCommit(repo, depInfo.githubCommit) - if err != nil { - exitErr() - } - - branches, err := getBranches(repo) - if err != nil { - exitErr() - } - - latestCommitRef, err := findBranchFromCommit(repo, branches, revCommit) - if err != nil { - exitErr() - } - if latestCommitRef == nil { - if err != nil { - fmt.Printf("unable to find parent branch for logged commit ?! : %v\n", err) - } else { - fmt.Printf("unable to find parent branch for logged commit %s on %s\n", revCommit.Hash.String(), path) - } - exitErr() - } - parentBranchName := strings.ReplaceAll(latestCommitRef.Name().String(), "refs/heads/", "") - - latestCommit, err := repo.CommitObject(latestCommitRef.Hash()) - if err != nil { - fmt.Printf("unable to get latest commit : %v\n", err) - exitErr() - } - - var updatedVersion string - var workspaceVersion bool - if depInfo.class == depClassCargo { - // for cargo versions, we need to look into the actual repository in order to determine - // the earliest version of the most up-to-date version. - latestCommit, updatedVersion, workspaceVersion, err = findLatestVersion(repo, latestCommitRef, revCommit, depInfo.name) - if err != nil { - exitErr() - } - } - - return analyzedProjectDependency{ - projectDependency: depInfo, - branchName: parentBranchName, - fullCommitHash: revCommit.Hash.String(), - latestBranchCommit: latestCommit.Hash.String(), - latestBranchCommitTime: latestCommit.Committer.When.UTC(), - latestBranchVersion: updatedVersion, - workspaceVersion: workspaceVersion, - } -} - -func findBranchFromCommit(repo *git.Repository, branches map[plumbing.Hash]*plumbing.Reference, revCommit *object.Commit) (branch *plumbing.Reference, err error) { - visited := make(map[plumbing.Hash]bool, 0) - for len(branches) > 0 { - for commit, branch := range branches { - if commit.String() == revCommit.Hash.String() { - // we found the branch. - return branch, nil - } - visited[commit] = true - delete(branches, commit) - - parentCommit, err := repo.CommitObject(commit) - if err != nil { - fmt.Printf("unable to get parent commit : %v\n", err) - return nil, err - } - for _, parent := range parentCommit.ParentHashes { - if !visited[parent] { - branches[parent] = branch - } - } - } - } - return nil, nil -} - -func lookupShortCommit(repo *git.Repository, shortCommit string) (revCommit *object.Commit, err error) { - cIter, err := repo.Log(&git.LogOptions{ - All: true, - }) - if err != nil { - fmt.Printf("unable to get log entries for %s: %v\n", shortCommit, err) - return nil, err - } - - // ... just iterates over the commits, looking for a commit with a specific hash. - lookoutCommit := strings.ToLower(shortCommit) - - err = cIter.ForEach(func(c *object.Commit) error { - revString := strings.ToLower(c.Hash.String()) - if strings.HasPrefix(revString, lookoutCommit) { - // found ! - revCommit = c - return storer.ErrStop - } - return nil - }) - if err != nil && err != storer.ErrStop { - fmt.Printf("unable to iterate on log entries : %v\n", err) - exitErr() - } - if revCommit == nil { - fmt.Printf("the commit object for short commit %s was missing ?!\n", lookoutCommit) - exitErr() - } - cIter.Close() - return revCommit, nil -} - -func getBranches(repo *git.Repository) (branches map[plumbing.Hash]*plumbing.Reference, err error) { - remoteOrigin, err := repo.Remote("origin") - if err != nil { - fmt.Printf("unable to retrieve origin remote : %v\n", err) - return nil, err - } - - remoteRefs, err := remoteOrigin.List(&git.ListOptions{}) - if err != nil { - fmt.Printf("unable to list remote refs : %v\n", err) - return nil, err - } - branchPrefix := "refs/heads/" - branches = make(map[plumbing.Hash]*plumbing.Reference, 0) - for _, remoteRef := range remoteRefs { - refName := remoteRef.Name().String() - if !strings.HasPrefix(refName, branchPrefix) { - continue - } - branches[remoteRef.Hash()] = remoteRef - } - return branches, nil -} - -func findLatestVersion(repo *git.Repository, latestCommitRef *plumbing.Reference, revCommit *object.Commit, pkgName string) (updatedLatestCommit *object.Commit, version string, workspaceVersion bool, err error) { - // create a list of all the commits between the head and the current. - commits := []*object.Commit{} - headCommit, err := repo.CommitObject(latestCommitRef.Hash()) - if err != nil { - return nil, "", false, err - } - for { - commits = append(commits, headCommit) - if headCommit.Hash == revCommit.Hash { - // we're done. - break - } - if parent, err := headCommit.Parent(0); err != nil || parent == nil { - break - } else { - headCommit = parent - } - } - - var versions []string - var workspaceVer []bool - for _, commit := range commits { - version, workspaceVersion, err := findCargoVersionForCommit(pkgName, commit) - if err != nil { - return nil, "", false, err - } - versions = append(versions, version) - workspaceVer = append(workspaceVer, workspaceVersion) - } - for i := 1; i < len(versions); i++ { - if versions[i] != versions[i-1] { - // the version at i-1 is "newer", so we should pick that one. - return commits[i-1], versions[i-1], workspaceVer[i-1], nil - } - } - - return commits[len(commits)-1], versions[len(commits)-1], workspaceVer[len(commits)-1], nil -} - -//lint:ignore funlen gocyclo -func findCargoVersionForCommit(pkgName string, commit *object.Commit) (string, bool, error) { - treeRoot, err := commit.Tree() - if err != nil { - return "", false, err - } - rootCargoFile, err := treeRoot.File("Cargo.toml") - if err != nil { - fmt.Printf("The package %s has unsupported repository structure\n", pkgName) - return "", false, errors.New("unsupported repository structure") - } - internalWorkspacePackage := false - - rootCargoFileLines, err := rootCargoFile.Lines() - if err != nil { - return "", false, err - } - var section string - var curPkgName string - for _, line := range rootCargoFileLines { - if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") { - section = line[1 : len(line)-1] - continue - } - if strings.HasPrefix(line, "members") { - section = "members" - continue - } - switch section { - case "members": - if strings.Contains(line, pkgName) { - // this is a workspace that points to an internal member; - // the member is the package we're after. - internalWorkspacePackage = true - } - case "workspace.package": - lineParts := strings.Split(line, "=") - if len(lineParts) != 2 { - continue - } - if !strings.HasPrefix(lineParts[0], "version") { - continue - } - version := strings.ReplaceAll(strings.TrimSpace(lineParts[1]), "\"", "") - return version, true, nil - case "package": - lineParts := strings.Split(line, "=") - if len(lineParts) != 2 { - continue - } - if strings.HasPrefix(lineParts[0], "name") { - curPkgName = strings.ReplaceAll(strings.TrimSpace(lineParts[1]), "\"", "") - continue - } else if strings.HasPrefix(lineParts[0], "version") && curPkgName == pkgName { - version := strings.ReplaceAll(strings.TrimSpace(lineParts[1]), "\"", "") - return version, false, nil - } - } - } - // fall-back to package specific versioning. - - if internalWorkspacePackage { - pkgCargoFile, err := treeRoot.File(pkgName + "/Cargo.toml") - if err != nil { - return "", false, err - } - pkgCargoFileLines, err := pkgCargoFile.Lines() - if err != nil { - return "", false, err - } - var section string - var curPkgName string - for _, line := range pkgCargoFileLines { - if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") { - section = line[1 : len(line)-1] - continue - } - switch section { - case "package": - lineParts := strings.Split(line, "=") - if len(lineParts) != 2 { - continue - } - if strings.HasPrefix(lineParts[0], "name") { - curPkgName = strings.ReplaceAll(strings.TrimSpace(lineParts[1]), "\"", "") - continue - } else if strings.HasPrefix(lineParts[0], "version") && curPkgName == pkgName { - version := strings.ReplaceAll(strings.TrimSpace(lineParts[1]), "\"", "") - return version, false, nil - } - } - } - } - fmt.Printf("The package %s has unsupported repository structure\n", pkgName) - return "", false, errors.New("unsupported repository structure") -} diff --git a/cmd/deptool/deptool.go b/cmd/deptool/deptool.go deleted file mode 100644 index cc6599f2..00000000 --- a/cmd/deptool/deptool.go +++ /dev/null @@ -1,85 +0,0 @@ -package main - -import ( - "fmt" - "os" - - "github.com/spf13/cobra" -) - -var versionCheck bool -var projectDir string -var writeChanges bool -var writeChangesInPlace bool - -var rootCmd = &cobra.Command{ - Use: "deptool", - Short: "Repository dependency tool", - Long: `Repository dependency tool`, - Run: func(cmd *cobra.Command, args []string) { - if versionCheck { - fmt.Println("Build version: 1.0") - return - } - - //If no arguments passed, we should fallback to help - cmd.HelpFunc()(cmd, args) - }, -} - -var scanCmd = &cobra.Command{ - Use: "scan", - Short: "scan project dependencies", - Run: func(cmd *cobra.Command, args []string) { - deps := scanProject(projectDir) - printDependencies(deps) - }, -} - -var analyzeCmd = &cobra.Command{ - Use: "analyze", - Short: "analyze project dependencies", - Run: func(cmd *cobra.Command, args []string) { - deps := scanProject(projectDir) - analyzed := analyze(deps, analyzedDepPrinter) - hasChanges := false - // see if any of the dependencies could be upgraded. - for _, dep := range analyzed { - if dep.latestBranchCommit != dep.fullCommitHash { - // yes, it could be upgraded. - hasChanges = true - break - } - } - - if hasChanges { - if writeChanges || writeChangesInPlace { - writeUpdates(projectDir, analyzed, writeChangesInPlace) - } - os.Exit(1) - } - }, -} - -func initCommandHandlers() { - rootCmd.Flags().BoolVarP(&versionCheck, "version", "v", false, "Display and write current build version and exit") - scanCmd.Flags().StringVarP(&projectDir, "directory", "d", ".", "The directory where the project resides") - analyzeCmd.Flags().StringVarP(&projectDir, "directory", "d", ".", "The directory where the project resides") - analyzeCmd.Flags().BoolVarP(&writeChanges, "write", "w", false, "Once analysis is complete, write out the proposed change to Cargo.toml.proposed and go.mod.proposed") - analyzeCmd.Flags().BoolVarP(&writeChangesInPlace, "writeInPlace", "p", false, "Once analysis is complete, write out the changes to the existing Cargo.toml and go.mod") - - rootCmd.AddCommand(scanCmd) - rootCmd.AddCommand(analyzeCmd) -} - -func main() { - initCommandHandlers() - if err := rootCmd.Execute(); err != nil { - fmt.Println(err) - exitErr() - } -} - -func exitErr() { - os.Exit(-1) -} diff --git a/cmd/deptool/printer.go b/cmd/deptool/printer.go deleted file mode 100644 index 19c59095..00000000 --- a/cmd/deptool/printer.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import "fmt" - -const ( - colorReset = "\033[0m" - //colorRed = "\033[31m" - colorGreen = "\033[32m" - colorYellow = "\033[33m" - //colorBlue = "\033[34m" - colorPurple = "\033[35m" - colorCyan = "\033[36m" - colorWhite = "\033[37m" -) - -func printDependencies(dependencies *projectDependencies) { - for _, dep := range dependencies.dependencies { - var version string - if dep.version != "" { - version = fmt.Sprintf(" %s%s", colorGreen, dep.version) - } - fmt.Printf("%s %s %s[%s%s%s@%s%s%s%s]%s\n", - colorGreen, - dep.name, - colorYellow, - colorCyan, - dep.githubPath, - colorWhite, - colorPurple, - dep.githubCommit, - version, - colorYellow, - colorReset) - } -} - -func analyzedDepPrinter(pkg string, dep analyzedProjectDependency) { - var version, latestBranchVersion string - if dep.version != "" { - version = fmt.Sprintf(" %s%s", colorGreen, dep.version) - } - // do we have an upgrade ? - if dep.fullCommitHash == dep.latestBranchCommit { - fmt.Printf("%s %s %s[%s%s%s@%s%s%s%s]%s\n", - colorGreen, - pkg, - colorYellow, - colorCyan, - dep.githubPath, - colorWhite, - colorPurple, - dep.githubCommit, - version, - colorYellow, - colorReset) - return - } - - if dep.latestBranchVersion != "" { - latestBranchVersion = fmt.Sprintf(" %s%s", colorGreen, dep.latestBranchVersion) - } - fmt.Printf("%s %s %s[%s%s%s@%s%s%s%s]%s Upgrade %s[%s%s%s%s]%s\n", - colorGreen, - pkg, - colorYellow, - colorCyan, - dep.githubPath, - colorWhite, - colorPurple, - dep.githubCommit, - version, - colorYellow, - colorReset, - colorYellow, - colorPurple, - dep.latestBranchCommit[:len(dep.githubCommit)], - latestBranchVersion, - colorYellow, - colorReset, - ) -} diff --git a/cmd/deptool/scanner.go b/cmd/deptool/scanner.go deleted file mode 100644 index 5045ff60..00000000 --- a/cmd/deptool/scanner.go +++ /dev/null @@ -1,159 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path" - "sort" - "strings" - - toml "github.com/pelletier/go-toml" - modfile "golang.org/x/mod/modfile" -) - -const cargoTomlFile = "Cargo.toml" -const goModFile = "go.mod" - -type depClass int - -const ( - depClassCargo depClass = iota - depClassMod -) - -type projectDependencies struct { - dependencies []*projectDependency - dependencyNames map[string]*projectDependency -} - -type projectDependency struct { - class depClass - githubPath string - githubCommit string - direct bool - version string - name string -} - -type cargoDependencyToml struct { - Git string `toml:"git"` - Rev string `toml:"rev"` - Version string `toml:"version"` -} - -type workspaceDepenenciesToml struct { - Dependencies map[string]cargoDependencyToml `toml:"dependencies"` -} - -type patchCratesIOToml struct { - CratesIO map[string]cargoDependencyToml `toml:"crates-io"` -} - -type cargoToml struct { - Workspace workspaceDepenenciesToml // this is the workspace.dependencies entry; the toml decoder breaks it into workspace and dependencies - Patch patchCratesIOToml // this is the patch.crates-io entry -} - -func scanProject(dir string) *projectDependencies { - dependencies := &projectDependencies{ - dependencyNames: make(map[string]*projectDependency), - } - - loadParseCargoToml(dir, dependencies) - loadParseGoMod(dir, dependencies) - - return dependencies -} - -func loadParseCargoToml(dir string, dependencies *projectDependencies) { - cargoFileBytes, err := os.ReadFile(path.Join(dir, cargoTomlFile)) - if err != nil { - fmt.Printf("Unable to read Cargo.toml file : %v\n", err) - exitErr() - } - - var parsedCargo cargoToml - err = toml.Unmarshal(cargoFileBytes, &parsedCargo) - if err != nil { - fmt.Printf("Unable to parse Cargo.toml file : %v\n", err) - exitErr() - } - addTomlDependencies(dependencies, parsedCargo.Patch.CratesIO, false) - addTomlDependencies(dependencies, parsedCargo.Workspace.Dependencies, true) -} - -func addTomlDependencies(dependencies *projectDependencies, tomlDeps map[string]cargoDependencyToml, direct bool) { - names := make([]string, 0, len(tomlDeps)) - for name := range tomlDeps { - names = append(names, name) - } - sort.Strings(names) - for _, pkgName := range names { - crateGit := tomlDeps[pkgName] - if crateGit.Git == "" { - continue - } - - current := &projectDependency{ - class: depClassCargo, - githubPath: crateGit.Git, - githubCommit: crateGit.Rev, - version: crateGit.Version, - direct: direct, - name: pkgName, - } - if existing, has := dependencies.dependencyNames[pkgName]; has && (existing.githubCommit != current.githubCommit || existing.githubPath != current.githubPath) { - fmt.Printf("Conflicting entries in Cargo.toml file :\n%v\nvs.\n%v\n", existing, current) - exitErr() - } - if current.githubPath == "" { - continue - } - dependencies.dependencyNames[pkgName] = current - dependencies.dependencies = append(dependencies.dependencies, current) - } -} - -func loadParseGoMod(dir string, dependencies *projectDependencies) { - fileName := path.Join(dir, goModFile) - - cargoFileBytes, err := os.ReadFile(fileName) - if err != nil { - fmt.Printf("Unable to read go.mod file : %v\n", err) - exitErr() - } - - modFile, err := modfile.Parse("", cargoFileBytes, nil) - if err != nil { - fmt.Printf("Unable to read go.mod file : %v\n", err) - exitErr() - } - // scan all the stellar related required modules. - for _, require := range modFile.Require { - if !strings.Contains(require.Mod.Path, "github.com/stellar") || require.Indirect { - continue - } - splittedVersion := strings.Split(require.Mod.Version, "-") - if len(splittedVersion) != 3 { - continue - } - - pathComp := strings.Split(require.Mod.Path, "/") - pkgName := pathComp[len(pathComp)-1] - - current := &projectDependency{ - class: depClassMod, - githubPath: require.Mod.Path, - githubCommit: splittedVersion[2], - direct: true, - name: pkgName, - } - - if existing, has := dependencies.dependencyNames[pkgName]; has && (existing.githubCommit != current.githubCommit || existing.githubPath != current.githubPath) { - fmt.Printf("Conflicting entries in go.mod file :\n%v\nvs.\n%v\n", existing, current) - exitErr() - } - dependencies.dependencyNames[pkgName] = current - dependencies.dependencies = append(dependencies.dependencies, current) - } -} diff --git a/cmd/deptool/writeout.go b/cmd/deptool/writeout.go deleted file mode 100644 index 38e2e002..00000000 --- a/cmd/deptool/writeout.go +++ /dev/null @@ -1,137 +0,0 @@ -package main - -import ( - "bytes" - "fmt" - "os" - "path" - "strings" - - modfile "golang.org/x/mod/modfile" -) - -func writeUpdates(dir string, deps map[string]analyzedProjectDependency, inplace bool) { - writeUpdatesGoMod(dir, deps, inplace) - writeUpdatesCargoToml(dir, deps, inplace) -} - -func writeUpdatesGoMod(dir string, deps map[string]analyzedProjectDependency, inplace bool) { - fileName := path.Join(dir, goModFile) - - modFileBytes, err := os.ReadFile(fileName) - if err != nil { - fmt.Printf("Unable to read go.mod file : %v\n", err) - exitErr() - } - - modFile, err := modfile.Parse("", modFileBytes, nil) - if err != nil { - fmt.Printf("Unable to read go.mod file : %v\n", err) - exitErr() - } - - changed := false - for _, analyzed := range deps { - if analyzed.class != depClassMod { - continue - } - if analyzed.latestBranchCommit == analyzed.githubCommit { - continue - } - // find if we have entry in the mod file. - for _, req := range modFile.Require { - if req.Mod.Path != analyzed.githubPath { - continue - } - // this entry needs to be updated. - splittedVersion := strings.Split(req.Mod.Version, "-") - splittedVersion[2] = analyzed.latestBranchCommit[:len(splittedVersion[2])] - splittedVersion[1] = fmt.Sprintf("%04d%02d%02d%02d%02d%02d", - analyzed.latestBranchCommitTime.Year(), - analyzed.latestBranchCommitTime.Month(), - analyzed.latestBranchCommitTime.Day(), - analyzed.latestBranchCommitTime.Hour(), - analyzed.latestBranchCommitTime.Minute(), - analyzed.latestBranchCommitTime.Second()) - newVer := fmt.Sprintf("%s-%s-%s", splittedVersion[0], splittedVersion[1], splittedVersion[2]) - curPath := req.Mod.Path - err = modFile.DropRequire(req.Mod.Path) - if err != nil { - fmt.Printf("Unable to drop requirement : %v\n", err) - exitErr() - } - err = modFile.AddRequire(curPath, newVer) - if err != nil { - fmt.Printf("Unable to add requirement : %v\n", err) - exitErr() - } - changed = true - } - } - - if !changed { - return - } - - outputBytes, err := modFile.Format() - if err != nil { - fmt.Printf("Unable to format mod file : %v\n", err) - exitErr() - } - if !inplace { - fileName += ".proposed" - } - err = os.WriteFile(fileName, outputBytes, 0200) - if err != nil { - fmt.Printf("Unable to write %s file : %v\n", fileName, err) - exitErr() - } - err = os.Chmod(fileName, 0644) - if err != nil { - fmt.Printf("Unable to chmod %s file : %v\n", fileName, err) - exitErr() - } -} - -func writeUpdatesCargoToml(dir string, deps map[string]analyzedProjectDependency, inplace bool) { - fileName := path.Join(dir, cargoTomlFile) - - modFileBytes, err := os.ReadFile(fileName) - if err != nil { - fmt.Printf("Unable to read go.mod file : %v\n", err) - exitErr() - } - - changed := false - for _, analyzed := range deps { - if analyzed.class != depClassCargo { - continue - } - if analyzed.latestBranchCommit == analyzed.githubCommit { - continue - } - newCommit := analyzed.latestBranchCommit[:len(analyzed.githubCommit)] - // we want to replace every instance of analyzed.githubCommit with newCommit - modFileBytes = bytes.ReplaceAll(modFileBytes, []byte(analyzed.githubCommit), []byte(newCommit)) - - // set the changed flag - changed = true - } - - if !changed { - return - } - if !inplace { - fileName = fileName + ".proposed" - } - err = os.WriteFile(fileName, modFileBytes, 0200) - if err != nil { - fmt.Printf("Unable to write %s file : %v\n", fileName, err) - exitErr() - } - err = os.Chmod(fileName, 0644) - if err != nil { - fmt.Printf("Unable to chmod %s file : %v\n", fileName, err) - exitErr() - } -} diff --git a/cmd/soroban-rpc/internal/config/options.go b/cmd/soroban-rpc/internal/config/options.go index 9161fdef..1ec2b6b3 100644 --- a/cmd/soroban-rpc/internal/config/options.go +++ b/cmd/soroban-rpc/internal/config/options.go @@ -201,7 +201,7 @@ func (cfg *Config) options() ConfigOptions { Name: "ingestion-timeout", Usage: "Ingestion Timeout when bootstrapping data (checkpoint and in-memory initialization) and preparing ledger reads", ConfigKey: &cfg.IngestionTimeout, - DefaultValue: 30 * time.Minute, + DefaultValue: 50 * time.Minute, }, { Name: "checkpoint-frequency", diff --git a/cmd/soroban-rpc/internal/daemon/daemon.go b/cmd/soroban-rpc/internal/daemon/daemon.go index eea41854..feb7792d 100644 --- a/cmd/soroban-rpc/internal/daemon/daemon.go +++ b/cmd/soroban-rpc/internal/daemon/daemon.go @@ -228,14 +228,14 @@ func MustNew(cfg *config.Config) *Daemon { } return nil }) + if err != nil { + logger.WithError(err).Fatal("could not obtain txmeta cache from the database") + } if currentSeq != 0 { logger.WithFields(supportlog.F{ "seq": currentSeq, }).Info("finished initializing in-memory store") } - if err != nil { - logger.WithError(err).Fatal("could not obtain txmeta cache from the database") - } onIngestionRetry := func(err error, dur time.Duration) { logger.WithError(err).Error("could not run ingestion. Retrying") diff --git a/cmd/soroban-rpc/internal/db/ledger.go b/cmd/soroban-rpc/internal/db/ledger.go index 1b4b0aa2..e0bf7fd1 100644 --- a/cmd/soroban-rpc/internal/db/ledger.go +++ b/cmd/soroban-rpc/internal/db/ledger.go @@ -49,7 +49,7 @@ func (r ledgerReader) StreamAllLedgers(ctx context.Context, f StreamLedgerFn) er return err } } - return nil + return q.Err() } // GetLedger fetches a single ledger from the db. diff --git a/cmd/soroban-rpc/internal/db/ledgerentry.go b/cmd/soroban-rpc/internal/db/ledgerentry.go index 1553ecf5..8286e955 100644 --- a/cmd/soroban-rpc/internal/db/ledgerentry.go +++ b/cmd/soroban-rpc/internal/db/ledgerentry.go @@ -215,7 +215,7 @@ func (l *ledgerEntryReadTx) getRawLedgerEntries(keys ...string) (map[string]stri } } } - return result, nil + return result, q.Err() } func GetLedgerEntry(tx LedgerEntryReadTx, key xdr.LedgerKey) (bool, xdr.LedgerEntry, *uint32, error) { diff --git a/cmd/soroban-rpc/internal/events/events.go b/cmd/soroban-rpc/internal/events/events.go index 12e8e765..fcea2a2b 100644 --- a/cmd/soroban-rpc/internal/events/events.go +++ b/cmd/soroban-rpc/internal/events/events.go @@ -207,6 +207,7 @@ func (m *MemoryStore) IngestEvents(ledgerCloseMeta xdr.LedgerCloseMeta) error { } m.lock.Lock() if _, err = m.eventsByLedger.Append(bucket); err != nil { + m.lock.Unlock() return err } m.lock.Unlock() diff --git a/cmd/soroban-rpc/lib/preflight/Cargo.toml b/cmd/soroban-rpc/lib/preflight/Cargo.toml index 996c41c3..249eba63 100644 --- a/cmd/soroban-rpc/lib/preflight/Cargo.toml +++ b/cmd/soroban-rpc/lib/preflight/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "preflight" -version = "21.0.1" +version = "21.1.0" publish = false [lib]