Skip to content

Commit 3a4a788

Browse files
committed
init: Correct coins db cache size setting
The chainstate caches are currently re-balanced on startup even in the non-assumeutxo case, leading to the database being needlessly re-opened and its cache re-allocated. Similar to `InitCoinsCache` and `m_coinstip_cache_size_bytes` the `m_coinsdb_cache_size_bytes` should be set in `InitCoinsDB`. Together with only conservatively setting the cache values when a assumeutxo chainstate is present, this allows for skipping the cache re-balance during initialization in the normal non-assumeutxo case.
1 parent e569eb8 commit 3a4a788

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/node/chainstate.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ static ChainstateLoadResult CompleteChainstateInitialization(
9595
assert(chainman.m_total_coinstip_cache > 0);
9696
assert(chainman.m_total_coinsdb_cache > 0);
9797

98-
// Conservative value which is arbitrarily chosen, as it will ultimately be changed
99-
// by a call to `chainman.MaybeRebalanceCaches()`. We just need to make sure
100-
// that the sum of the two caches (40%) does not exceed the allowable amount
101-
// during this temporary initialization state.
102-
double init_cache_fraction = 0.2;
98+
// If running with multiple chainstates, limit the cache sizes with a
99+
// discount factor. If discounted the actual cache size will be
100+
// recalculated by `chainman.MaybeRebalanceCaches()`. The discount factor
101+
// is conservatively chosen such that the sum of the caches does not exceed
102+
// the allowable amount during this temporary initialization state.
103+
double init_cache_fraction = chainman.GetAll().size() > 1 ? 0.2 : 1.0;
103104

104105
// At this point we're either in reindex or we've loaded a useful
105106
// block tree into BlockIndex()!

src/validation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,6 +1972,8 @@ void Chainstate::InitCoinsDB(
19721972
.obfuscate = true,
19731973
.options = m_chainman.m_options.coins_db},
19741974
m_chainman.m_options.coins_view);
1975+
1976+
m_coinsdb_cache_size_bytes = cache_size_bytes;
19751977
}
19761978

19771979
void Chainstate::InitCoinsCache(size_t cache_size_bytes)

0 commit comments

Comments
 (0)