What changed, and why it matters
This commit simply renames a function from GetTotalRAM to TryGetTotalRam across the codebase. The behavior of the code does not change at all. The rename is meant to make it clearer to programmers that the function may fail to detect the system's RAM. There is no security fix or vulnerability here.
No security action needed. Treat as a normal non-security refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
A scripted refactor that renames std::optional
Changed components
src/common/system.cppsrc/common/system.hsrc/node/caches.cppsrc/test/system_ram_tests.cppInspect captured patch +5 / −5
diff --git a/src/common/system.cpp b/src/common/system.cpp
index ca7b857d..1b1bff17 100644
--- a/src/common/system.cpp
+++ b/src/common/system.cpp
@@ -111,7 +111,7 @@ int GetNumCores()
return std::thread::hardware_concurrency();
}
-std::optional<size_t> GetTotalRAM()
+std::optional<size_t> TryGetTotalRam()
{
[[maybe_unused]] auto clamp{[](uint64_t v) { return size_t(std::min(v, uint64_t{std::numeric_limits<size_t>::max()})); }};
#ifdef WIN32
diff --git a/src/common/system.h b/src/common/system.h
index a3100fec..e0d1b917 100644
--- a/src/common/system.h
+++ b/src/common/system.h
@@ -35,6 +35,6 @@ int GetNumCores();
/**
* Return the total RAM available on the current system, if detectable.
*/
-std::optional<size_t> GetTotalRAM();
+std::optional<size_t> TryGetTotalRam();
#endif // BITCOIN_COMMON_SYSTEM_H
diff --git a/src/node/caches.cpp b/src/node/caches.cpp
index fc13b8a2..ea69c717 100644
--- a/src/node/caches.cpp
+++ b/src/node/caches.cpp
@@ -40,7 +40,7 @@ namespace node {
uint64_t GetDefaultDBCache()
{
if constexpr (sizeof(void*) >= 8) {
- if (GetTotalRAM().value_or(0) >= HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM) {
+ if (TryGetTotalRam().value_or(0) >= HIGH_DEFAULT_DBCACHE_MIN_TOTAL_RAM) {
return HIGH_DEFAULT_DBCACHE;
}
}
@@ -88,7 +88,7 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
void LogOversizedDbCache(const ArgsManager& args) noexcept
{
- if (const auto total_ram{GetTotalRAM()}) {
+ if (const auto total_ram{TryGetTotalRam()}) {
const uint64_t db_cache{CalculateDbCacheBytes(args)};
if (ShouldWarnOversizedDbCache(db_cache, *total_ram)) {
InitWarning(bilingual_str{tfm::format(_("A %zu MiB dbcache may be too large for a system memory of only %zu MiB."),
diff --git a/src/test/system_ram_tests.cpp b/src/test/system_ram_tests.cpp
index 4eb4e1e3..79e4ebfb 100644
--- a/src/test/system_ram_tests.cpp
+++ b/src/test/system_ram_tests.cpp
@@ -14,7 +14,7 @@ BOOST_AUTO_TEST_SUITE(system_ram_tests)
BOOST_AUTO_TEST_CASE(total_ram)
{
- const auto total{GetTotalRAM()};
+ const auto total{TryGetTotalRam()};
if (!total) {
BOOST_WARN_MESSAGE(false, "skipping total_ram: total RAM unknown");
return;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.