Add internal interfaces for prune locks

Including desc member of PruneLockInfo for a human-readable description
This commit is contained in:
Luke Dashjr 2021-07-07 00:02:16 +00:00
parent 8b6cd814ca
commit b854b0411e
4 changed files with 36 additions and 0 deletions

View File

@ -32,6 +32,7 @@ struct CBlockLocator;
struct FeeCalculation;
namespace node {
struct NodeContext;
struct PruneLockInfo;
} // namespace node
namespace interfaces {
@ -132,6 +133,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;

View File

@ -262,11 +262,21 @@ void BlockManager::FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPr
nLastBlockWeCanPrune, 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);

View File

@ -65,6 +65,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
};
@ -218,8 +219,10 @@ public:
//! Check whether the block associated with this index entry is pruned or not.
bool IsBlockPruned(const CBlockIndex* pblockindex) 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);
};
void CleanupBlockRevFiles();

View File

@ -521,6 +521,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);