mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-12 19:20:42 +02:00
Add internal interfaces for prune locks
Including desc member of PruneLockInfo for a human-readable description
This commit is contained in:
parent
1ebacb60f8
commit
55fc577c9a
@ -34,6 +34,7 @@ struct CBlockLocator;
|
||||
struct FeeCalculation;
|
||||
namespace node {
|
||||
struct NodeContext;
|
||||
struct PruneLockInfo;
|
||||
} // namespace node
|
||||
|
||||
namespace interfaces {
|
||||
@ -148,6 +149,10 @@ public:
|
||||
//! pruned), and contains transactions.
|
||||
virtual bool haveBlockOnDisk(int height) = 0;
|
||||
|
||||
virtual bool pruneLockExists(const std::string& name) const = 0;
|
||||
virtual void updatePruneLock(const std::string& name, const node::PruneLockInfo& lock_info) = 0;
|
||||
virtual void deletePruneLock(const std::string& name) = 0;
|
||||
|
||||
//! Get locator for the current chain tip.
|
||||
virtual CBlockLocator getTipLocator() = 0;
|
||||
|
||||
|
@ -403,11 +403,21 @@ void BlockManager::FindFilesToPrune(
|
||||
min_block_to_prune, last_block_can_prune, count);
|
||||
}
|
||||
|
||||
bool BlockManager::PruneLockExists(const std::string& name) const {
|
||||
return m_prune_locks.count(name);
|
||||
}
|
||||
|
||||
void BlockManager::UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) {
|
||||
AssertLockHeld(::cs_main);
|
||||
m_prune_locks[name] = lock_info;
|
||||
}
|
||||
|
||||
void BlockManager::DeletePruneLock(const std::string& name)
|
||||
{
|
||||
AssertLockHeld(::cs_main);
|
||||
m_prune_locks.erase(name);
|
||||
}
|
||||
|
||||
CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
@ -92,6 +92,7 @@ struct CBlockIndexHeightOnlyComparator {
|
||||
};
|
||||
|
||||
struct PruneLockInfo {
|
||||
std::string desc; //! Arbitrary human-readable description of the lock purpose
|
||||
int height_first{std::numeric_limits<int>::max()}; //! Height of earliest block that should be kept and not pruned
|
||||
int height_last{std::numeric_limits<int>::max()}; //! Height of latest block that should be kept and not pruned
|
||||
};
|
||||
@ -409,8 +410,10 @@ public:
|
||||
//! Check whether the block associated with this index entry is pruned or not.
|
||||
bool IsBlockPruned(const CBlockIndex& block) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
bool PruneLockExists(const std::string& name) const SHARED_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);
|
||||
void DeletePruneLock(const std::string& name) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||
|
||||
/** Open a block file (blk?????.dat) */
|
||||
AutoFile OpenBlockFile(const FlatFilePos& pos, bool fReadOnly = false) const;
|
||||
|
@ -554,6 +554,24 @@ public:
|
||||
const CBlockIndex* block{chainman().ActiveChain()[height]};
|
||||
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
|
||||
}
|
||||
bool pruneLockExists(const std::string& name) const override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
auto& blockman = m_node.chainman->m_blockman;
|
||||
return blockman.PruneLockExists(name);
|
||||
}
|
||||
void updatePruneLock(const std::string& name, const node::PruneLockInfo& lock_info) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
auto& blockman = m_node.chainman->m_blockman;
|
||||
blockman.UpdatePruneLock(name, lock_info);
|
||||
}
|
||||
void deletePruneLock(const std::string& name) override
|
||||
{
|
||||
LOCK(cs_main);
|
||||
auto& blockman = m_node.chainman->m_blockman;
|
||||
blockman.DeletePruneLock(name);
|
||||
}
|
||||
CBlockLocator getTipLocator() override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
|
Loading…
Reference in New Issue
Block a user