refactor: Extract default batch size into kernel
What changed, and why it matters
This is a simple code cleanup change: a single default value for a database batch size setting is moved from one header file to another and renamed to follow project conventions. The actual numeric value (16 MiB) and how it is used remain unchanged. There is no security relevance.
No security action needed. Treat as ordinary refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the default LevelDB write batch size constant. It removes nDefaultDbBatchSize from src/txdb.h and introduces DEFAULT_DB_CACHE_BATCH in src/kernel/caches.h. src/init.cpp and src/txdb.h are updated to reference the new constant. The value stays 16 MiB (16 << 20), and the CoinsViewOptions default initializer is modernized to brace-initialization. No functional behavior changes.
Changed components
src/init.cppsrc/kernel/caches.hsrc/txdb.hInspect captured patch +8 / −8
diff --git a/src/init.cpp b/src/init.cpp
index b6b52e2c..b29a2634 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -496,7 +496,7 @@ void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
argsman.AddArg("-coinstatsindex", strprintf("Maintain coinstats index used by the gettxoutsetinfo RPC (default: %u)", DEFAULT_COINSTATSINDEX), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-conf=<file>", strprintf("Specify path to read-only configuration file. Relative paths will be prefixed by datadir location (only useable from command line, not configuration file) (default: %s)", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
- argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
+ argsman.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", DEFAULT_DB_CACHE_BATCH), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::OPTIONS);
argsman.AddArg("-dbcache=<n>", strprintf("Maximum database cache size <n> MiB (minimum %d, default: %d). Make sure you have enough RAM. In addition, unused memory allocated to the mempool is shared with this cache (see -maxmempool).", MIN_DB_CACHE >> 20, DEFAULT_DB_CACHE >> 20), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-includeconf=<file>", "Specify additional configuration file, relative to the -datadir path (only useable from configuration file, not command line)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-allowignoredconf", strprintf("For backwards compatibility, treat an unused %s file in the datadir as a warning, not an error.", BITCOIN_CONF_FILENAME), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
diff --git a/src/kernel/caches.h b/src/kernel/caches.h
index 33ae6047..63bb44c5 100644
--- a/src/kernel/caches.h
+++ b/src/kernel/caches.h
@@ -11,6 +11,9 @@
//! Suggested default amount of cache reserved for the kernel (bytes)
static constexpr size_t DEFAULT_KERNEL_CACHE{450_MiB};
+//! Default LevelDB write batch size
+static constexpr size_t DEFAULT_DB_CACHE_BATCH{16_MiB};
+
//! Max memory allocated to block tree DB specific cache (bytes)
static constexpr size_t MAX_BLOCK_DB_CACHE{2_MiB};
//! Max memory allocated to coin DB specific cache (bytes)
diff --git a/src/txdb.h b/src/txdb.h
index 968b7c27..ea0cf9d7 100644
--- a/src/txdb.h
+++ b/src/txdb.h
@@ -8,6 +8,7 @@
#include <coins.h>
#include <dbwrapper.h>
+#include <kernel/caches.h>
#include <kernel/cs_main.h>
#include <sync.h>
#include <util/fs.h>
@@ -21,16 +22,12 @@
class COutPoint;
class uint256;
-//! -dbbatchsize default (bytes)
-static const int64_t nDefaultDbBatchSize = 16 << 20;
-
//! User-controlled performance and debug options.
struct CoinsViewOptions {
//! Maximum database write batch size in bytes.
- size_t batch_write_bytes = nDefaultDbBatchSize;
- //! If non-zero, randomly exit when the database is flushed with (1/ratio)
- //! probability.
- int simulate_crash_ratio = 0;
+ size_t batch_write_bytes{DEFAULT_DB_CACHE_BATCH};
+ //! If non-zero, randomly exit when the database is flushed with (1/ratio) probability.
+ int simulate_crash_ratio{0};
};
/** CCoinsView backed by the coin database (chainstate/) */
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.