From 374bf0de992ec9e458cfa8412867c03cddfb3219 Mon Sep 17 00:00:00 2001 From: Garand Tyson Date: Tue, 17 Mar 2026 14:57:53 -0700 Subject: [PATCH] Clean up version warning --- src/main/ApplicationUtils.cpp | 16 +++++++++++----- src/main/main.cpp | 21 +++++++++++---------- src/main/test/ApplicationUtilsTests.cpp | 6 ++++++ 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/ApplicationUtils.cpp b/src/main/ApplicationUtils.cpp index 6c05c7b074..fb7b4cf592 100644 --- a/src/main/ApplicationUtils.cpp +++ b/src/main/ApplicationUtils.cpp @@ -1180,16 +1180,22 @@ publish(Application::pointer app) return 0; } -// Returns the major release version extracted from the git tag _if_ this is a -// release-tagged version of stellar core (one that looks like vNN.X.Y or -// vNN.X.YrcZ or vNN.X.YHOTZ). If its version has some other name structure +// Returns the major release version extracted from a release-version string if +// it matches one of the supported release formats, such as vNN.X.Y, +// vNN.X.YrcZ, vNN.X.YHOTZ, or the packaged form +// `stellar-core NN.X.Y ()`. If its version has some other name // structure, return std::nullopt. std::optional getStellarCoreMajorReleaseVersion(std::string const& vstr) { - std::regex re("^v([0-9]+)\\.[0-9]+\\.[0-9]+(rc[0-9]+|HOT[0-9]+)?$"); + std::regex releaseTagRe( + "^v([0-9]+)\\.[0-9]+\\.[0-9]+(rc[0-9]+|HOT[0-9]+)?$"); + std::regex packagedReleaseRe( + "^stellar-core ([0-9]+)\\.[0-9]+\\.[0-9]+(rc[0-9]+|HOT[0-9]+)? " + "\\([0-9a-fA-F]+\\)$"); std::smatch match; - if (std::regex_match(vstr, match, re)) + if (std::regex_match(vstr, match, releaseTagRe) || + std::regex_match(vstr, match, packagedReleaseRe)) { uint32_t vers = stoi(match.str(1)); return std::make_optional(vers); diff --git a/src/main/main.cpp b/src/main/main.cpp index 016a8454aa..f5dae0d5bb 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -232,11 +232,12 @@ checkXDRFileIdentity() void checkStellarCoreMajorVersionProtocolIdentity() { - // This extracts a major version number from the git version string embedded - // in the binary if, and only if, that version string has the form of a - // release tag: specifically vX.Y.Z, or vX.Y.ZrcN, or vX.Y.ZHOTN. Other - // version strings return nullopt, for example non-release-tagged versions - // that typically look more like `v21.0.0rc1-84-g08d89bb4a` + // This extracts a major version number from the version string embedded in + // the binary if, and only if, it identifies a release build. Supported + // formats include source builds like vX.Y.Z, vX.Y.ZrcN, vX.Y.ZHOTN, and + // packaged builds like `stellar-core X.Y.Z ()`. Other version + // strings return nullopt, for example git-describe versions that typically + // look more like `v21.0.0rc1-84-g08d89bb4a`. auto major_release_version = stellar::getStellarCoreMajorReleaseVersion(STELLAR_CORE_VERSION); if (major_release_version) @@ -274,11 +275,11 @@ checkStellarCoreMajorVersionProtocolIdentity() } else { - // If we are running a version that does not look exactly like vX.Y.Z or - // vX.Y.ZrcN or vX.Y.ZHOTN, then we are running a non-release version of - // stellar-core and we relax the check above and just warn. - std::cerr << "Warning: running non-release version " - << STELLAR_CORE_VERSION << " of stellar-core" << std::endl; + // If we are running a version that does not match a recognized release + // version string format, then we relax the check above and just warn. + LOG_WARNING(DEFAULT_LOG, "Running non-release version {} of " + "stellar-core", + STELLAR_CORE_VERSION); } } } // namespace diff --git a/src/main/test/ApplicationUtilsTests.cpp b/src/main/test/ApplicationUtilsTests.cpp index b57171dc23..359f4a2402 100644 --- a/src/main/test/ApplicationUtilsTests.cpp +++ b/src/main/test/ApplicationUtilsTests.cpp @@ -165,7 +165,13 @@ TEST_CASE("application major version numbers", "[applicationutils]") std::make_optional(20)); CHECK(getStellarCoreMajorReleaseVersion("v20.0.0HOT4") == std::make_optional(20)); + CHECK(getStellarCoreMajorReleaseVersion( + "stellar-core 23.0.0 " + "(d5cbc0793d6eab25eac886969c5bc0f7da69d6ea)") == + std::make_optional(23)); CHECK(getStellarCoreMajorReleaseVersion("v19.1.2-10") == std::nullopt); + CHECK(getStellarCoreMajorReleaseVersion("v23.0.0-1-gd5cbc0793d6e") == + std::nullopt); CHECK(getStellarCoreMajorReleaseVersion("v19.9.0-30-g726eabdea-dirty") == std::nullopt); }