diff options
author | Fabian Jahr <fjahr@protonmail.com> | 2021-05-13 19:13:08 +0200 |
---|---|---|
committer | Fabian Jahr <fjahr@protonmail.com> | 2022-04-25 23:21:58 +0200 |
commit | 2561823531c25e1510c107eb41de944b00444ce0 (patch) | |
tree | 715633d4adf89c6c78b9733ed1f2d6cd776843bf /src/node/blockstorage.h | |
parent | 231fc7b035481f748159968353c1cab81354e843 (diff) | |
download | bitcoin-2561823531c25e1510c107eb41de944b00444ce0.tar.xz |
blockstorage: Add prune locks to BlockManager
This change also introduces an aditional buffer of 10 blocks (PRUNE_LOCK_BUFFER) that will not be pruned before the best block.
Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
Diffstat (limited to 'src/node/blockstorage.h')
-rw-r--r-- | src/node/blockstorage.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h index 229c099f1f..b33941dfa6 100644 --- a/src/node/blockstorage.h +++ b/src/node/blockstorage.h @@ -13,6 +13,7 @@ #include <atomic> #include <cstdint> +#include <unordered_map> #include <vector> extern RecursiveMutex cs_main; @@ -65,6 +66,10 @@ struct CBlockIndexHeightOnlyComparator { bool operator()(const CBlockIndex* pa, const CBlockIndex* pb) const; }; +struct PruneLockInfo { + int height_first{std::numeric_limits<int>::max()}; //! Height of earliest block that should be kept and not pruned +}; + /** * Maintains a tree of blocks (stored in `m_block_index`) which is consulted * to determine where the most-work tip is. @@ -118,6 +123,14 @@ private: /** Dirty block file entries. */ std::set<int> m_dirty_fileinfo; + /** + * Map from external index name to oldest block that must not be pruned. + * + * @note Internally, only blocks at height (height_first - PRUNE_LOCK_BUFFER - 1) and + * below will be pruned, but callers should avoid assuming any particular buffer size. + */ + std::unordered_map<std::string, PruneLockInfo> m_prune_locks GUARDED_BY(::cs_main); + public: BlockMap m_block_index GUARDED_BY(cs_main); @@ -175,6 +188,9 @@ public: //! Check whether the block associated with this index entry is pruned or not. bool IsBlockPruned(const CBlockIndex* pblockindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + //! Create or update a prune lock identified by its name + void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); + ~BlockManager() { Unload(); |