Compare commits

..

5 commits

Author SHA1 Message Date
Reproducibility Matters
ed4605711b
Merge 578654c686 into 433412fd84 2025-01-07 16:53:27 +01:00
TheCharlatan
578654c686
init: Use size_t consistently for cache sizes
This avoids having to rely on implicit casts when passing them to the
various functions allocating the caches.

This also fixes a bug where an incorrect amount of memory was allocated
on 32bit platforms. If the db cache size exceeded the maximum size of a
32 bit unsigned integer, it would overflow and allocate much less memory
than instructed to. Fix this by returning an error to the user if the
passed in dbcache size exceeeds the size of a size_t on that platform.

Add a release note for the change in behaviour on 32-bit systems.

Also take this opportunity to make the total amounts of cache in the
chainstate manager a size_t too.
2025-01-07 16:49:55 +01:00
TheCharlatan
1f81be60f5
kernel: Move kernel-related cache constants to kernel cache
They are not all related to the txdb, so a better place for them is the
new kernel cache file.
2025-01-07 16:49:54 +01:00
TheCharlatan
136e4080c2
kernel: Move non-kernel db cache size constants
These have nothing to do with the txdb, so move them out and into the
node caches.
2025-01-07 16:49:52 +01:00
TheCharlatan
41bc716488
kernel: Move kernel-specific cache size options to kernel
Carrying non-kernel related fields in the cache sizes for the indexes is
confusing for kernel library users. The cache sizes also are set
currently with magic numbers in bitcoin-chainstate. The comments for the
cache size calculations are also not completely clear.

Solve these things by moving the kernel-specific cache size fields to
their own struct.

This slightly changes the way the cache is allocated if the txindex
and/or blockfilterindex is used. Since they are now given precedence
over the block tree db cache, this results in a bit less cache being
allocated to the block tree db, coinsdb and coins caches. The effect is
negligible though, i.e. cache sizes with default dbcache reported
through the logs are:

master:
Cache configuration:
* Using 2.0 MiB for block index database
* Using 56.0 MiB for transaction index database
* Using 49.0 MiB for basic block filter index database
* Using 8.0 MiB for chain state database
* Using 335.0 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)

this branch:
Cache configuration:
* Using 2.0 MiB for block index database
* Using 56.2 MiB for transaction index database
* Using 49.2 MiB for basic block filter index database
* Using 8.0 MiB for chain state database
* Using 334.5 MiB for in-memory UTXO set (plus up to 286.1 MiB of unused mempool space)

Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
2025-01-07 16:49:47 +01:00

View file

@ -1611,16 +1611,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
}
auto [index_cache_sizes, kernel_cache_sizes] = *cache_sizes;
LogInfo("Cache configuration:\n");
LogInfo("* Using %.1f MiB for block index database\n", kernel_cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
LogInfo("Cache configuration:");
LogInfo("* Using %.1f MiB for block index database", kernel_cache_sizes.block_tree_db * (1.0 / 1024 / 1024));
if (args.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
LogInfo("* Using %.1f MiB for transaction index database\n", index_cache_sizes.tx_index * (1.0 / 1024 / 1024));
LogInfo("* Using %.1f MiB for transaction index database", index_cache_sizes.tx_index * (1.0 / 1024 / 1024));
}
for (BlockFilterType filter_type : g_enabled_filter_types) {
LogInfo("* Using %.1f MiB for %s block filter index database\n",
LogInfo("* Using %.1f MiB for %s block filter index database",
index_cache_sizes.filter_index * (1.0 / 1024 / 1024), BlockFilterTypeName(filter_type));
}
LogInfo("* Using %.1f MiB for chain state database\n", kernel_cache_sizes.coins_db * (1.0 / 1024 / 1024));
LogInfo("* Using %.1f MiB for chain state database", kernel_cache_sizes.coins_db * (1.0 / 1024 / 1024));
assert(!node.mempool);
assert(!node.chainman);