Skip to content

Commit

Permalink
Check -dbcache maximum at startup
Browse files Browse the repository at this point in the history
Previously the number was silently rounded down.
  • Loading branch information
Sjors committed Aug 28, 2023
1 parent d65e467 commit 4e27771
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/release-notes-25358.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Node
------

- The maximum value for `-dbcache` has been increased to 32,000 MB due to recent UTXO set growth. Be sure to check that you have enough RAM before increasing this.
- Setting `-dbcache` above the maximum causes the node to abort startup. Previously it would round the number down.
4 changes: 4 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,10 @@ bool AppInitParameterInteraction(const ArgsManager& args)
return InitError(Untranslated("Cannot set -listen=0 together with -listenonion=1"));
}

if (args.GetIntArg("-dbcache", nDefaultDbCache) > nMaxDbCache) {
return InitError(Untranslated(strprintf("-dbcache must be at most %d MB", nMaxDbCache)));
}

// Make sure enough file descriptors are available
int nBind = std::max(nUserBind, size_t(1));
nUserMaxConnections = args.GetIntArg("-maxconnections", DEFAULT_MAX_PEER_CONNECTIONS);
Expand Down
2 changes: 1 addition & 1 deletion src/node/caches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CacheSizes CalculateCacheSizes(const ArgsManager& args, size_t n_indexes)
{
int64_t nTotalCache = (args.GetIntArg("-dbcache", nDefaultDbCache) << 20);
nTotalCache = std::max(nTotalCache, nMinDbCache << 20); // total cache cannot be less than nMinDbCache
nTotalCache = std::min(nTotalCache, nMaxDbCache << 20); // total cache cannot be greater than nMaxDbcache
assert(nTotalCache <= nMaxDbCache);
CacheSizes sizes;
sizes.block_tree_db = std::min(nTotalCache / 8, nMaxBlockDBCache << 20);
nTotalCache -= sizes.block_tree_db;
Expand Down

0 comments on commit 4e27771

Please sign in to comment.