mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-30 07:43:48 +02:00
Merge #18637: coins: allow cache resize after init
f19fdd47a6test: add test for CChainState::ResizeCoinsCaches() (James O'Beirne)8ac3ef4699add ChainstateManager::MaybeRebalanceCaches() (James O'Beirne)f36aaa6392Add CChainState::ResizeCoinsCaches (James O'Beirne)b223111da2txdb: add CCoinsViewDB::ChangeCacheSize (James O'Beirne) Pull request description: This is part of the [assumeutxo project](https://github.com/bitcoin/bitcoin/projects/11): Parent PR: #15606 Issue: #15605 Specification: https://github.com/jamesob/assumeutxo-docs/tree/master/proposal --- In the assumeutxo implementation draft (#15056), once a UTXO snapshot is loaded, a new chainstate object is created after initialization. This means that we have to reclaim some of the cache that we've allocated to the original chainstate (per `dbcache=`) to repurpose for the snapshot chainstate. Furthermore, it makes sense to have different cache allocations depending on which chainstate is more active. While the snapshot chainstate is working to get to the network tip (and the background validation chainstate is idle), it makes sense that the snapshot chainstate should have the majority of cache allocation. And contrariwise once the snapshot has reached network tip, most of the cache should be given to the background validation chainstate. This set of changes (detailed in the commit messages) allows us to dynamically resize the various coins caches. None of the functionality introduced here is used at the moment, but will be in the next AU PR (which introduces `ActivateSnapshot`). `ChainstateManager::MaybeRebalanceCaches()` defines the (somewhat normative) cache allocations between the snapshot and background validation chainstates. I'd be interested in feedback if anyone has thoughts on the proportions I've set there. ACKs for top commit: ajtowns: weak utACKf19fdd47a6-- didn't find any major problems, but not super confident that I didn't miss anything fjahr: Code review ACKf19fdd4ryanofsky: Code review ACKf19fdd47a6. Only change since last review is constructor cleanup (no change in behavior). I think the suggestions here from ajtowns and others are good, but shouldn't delay merging the PR (and hold up assumeutxo) Tree-SHA512: fffb7847fb6993dd4a1a41cf11179b211b0b20b7eb5f7cf6266442136bfe9d43b830bbefcafd475bfd4af273f5573500594aa41fff03e0ed5c2a1e8562ff9269
This commit is contained in:
@@ -127,7 +127,6 @@ extern bool g_parallel_script_checks;
|
||||
extern bool fRequireStandard;
|
||||
extern bool fCheckBlockIndex;
|
||||
extern bool fCheckpointsEnabled;
|
||||
extern size_t nCoinCacheUsage;
|
||||
/** A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) */
|
||||
extern CFeeRate minRelayTxFee;
|
||||
/** If the tip is older than this (in seconds), the node is considered to be in initial block download. */
|
||||
@@ -532,7 +531,7 @@ public:
|
||||
|
||||
//! Initialize the in-memory coins cache (to be done after the health of the on-disk database
|
||||
//! is verified).
|
||||
void InitCoinsCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
//! @returns whether or not the CoinsViews object has been fully initialized and we can
|
||||
//! safely flush this object to disk.
|
||||
@@ -581,6 +580,17 @@ public:
|
||||
//! Destructs all objects related to accessing the UTXO set.
|
||||
void ResetCoinsViews() { m_coins_views.reset(); }
|
||||
|
||||
//! The cache size of the on-disk coins view.
|
||||
size_t m_coinsdb_cache_size_bytes{0};
|
||||
|
||||
//! The cache size of the in-memory coins view.
|
||||
size_t m_coinstip_cache_size_bytes{0};
|
||||
|
||||
//! Resize the CoinsViews caches dynamically and flush state to disk.
|
||||
//! @returns true unless an error occurred during the flush.
|
||||
bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
|
||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
/**
|
||||
* Update the on-disk chain state.
|
||||
* The caches and indexes are flushed depending on the mode we're called with
|
||||
@@ -797,6 +807,14 @@ public:
|
||||
//! chainstate to avoid duplicating block metadata.
|
||||
BlockManager m_blockman GUARDED_BY(::cs_main);
|
||||
|
||||
//! The total number of bytes available for us to use across all in-memory
|
||||
//! coins caches. This will be split somehow across chainstates.
|
||||
int64_t m_total_coinstip_cache{0};
|
||||
//
|
||||
//! The total number of bytes available for us to use across all leveldb
|
||||
//! coins databases. This will be split somehow across chainstates.
|
||||
int64_t m_total_coinsdb_cache{0};
|
||||
|
||||
//! Instantiate a new chainstate and assign it based upon whether it is
|
||||
//! from a snapshot.
|
||||
//!
|
||||
@@ -885,6 +903,10 @@ public:
|
||||
|
||||
//! Clear (deconstruct) chainstate data.
|
||||
void Reset();
|
||||
|
||||
//! Check to see if caches are out of balance and if so, call
|
||||
//! ResizeCoinsCaches() as needed.
|
||||
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
};
|
||||
|
||||
/** DEPRECATED! Please use node.chainman instead. May only be used in validation.cpp internally */
|
||||
|
||||
Reference in New Issue
Block a user