What changed, and why it matters
This commit adds a new housekeeping function, DeletePruneLock, that lets Bitcoin Core remove a previously created 'prune lock' by name. Prune locks are internal bookkeeping markers that prevent certain block data from being pruned too early. The change also adds unit tests for the new function. There is no indication this fixes a bug or addresses a security issue; it appears to be a normal feature/refactoring addition.
No security action required. Review as part of normal code review if this API is intended to be called from new code paths in related commits.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces BlockManager::DeletePruneLock(const std::string& name), guarded by cs_main, which erases an entry from m_prune_locks and returns whether an entry was removed. It exposes the method in the header with the same EXCLUSIVE_LOCKS_REQUIRED annotation and adds a BOOST unit test verifying create/update/delete semantics. No existing behavior is modified; only a new removal API is provided.
Changed components
src/node/blockstorage.cppsrc/node/blockstorage.hsrc/test/blockmanager_tests.cppInspect captured patch +31 / −0
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index ab6d23ec..27394e0d 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -404,6 +404,12 @@ void BlockManager::UpdatePruneLock(const std::string& name, const PruneLockInfo&
m_prune_locks[name] = lock_info;
}
+bool BlockManager::DeletePruneLock(const std::string& name)
+{
+ AssertLockHeld(::cs_main);
+ return m_prune_locks.erase(name) > 0;
+}
+
CBlockIndex* BlockManager::InsertBlockIndex(const uint256& hash)
{
AssertLockHeld(cs_main);
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index 4fefa86a..0eec629c 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -455,6 +455,9 @@ public:
//! 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);
+ //! Delete a prune lock identified by its name. Returns true if the lock existed.
+ bool DeletePruneLock(const std::string& name) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
+
/** Open a block file (blk?????.dat) */
AutoFile OpenBlockFile(const FlatFilePos& pos, bool fReadOnly) const;
diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp
index 68178dec..6ca4eb9b 100644
--- a/src/test/blockmanager_tests.cpp
+++ b/src/test/blockmanager_tests.cpp
@@ -300,4 +300,26 @@ BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
BOOST_CHECK_EQUAL(read_block.nVersion, 2);
}
+BOOST_FIXTURE_TEST_CASE(prune_lock_update_and_delete, TestingSetup)
+{
+ LOCK(::cs_main);
+ auto& chainman{*Assert(m_node.chainman)};
+ auto& blockman{chainman.m_blockman};
+
+ // Create a prune lock
+ blockman.UpdatePruneLock("test_lock", node::PruneLockInfo{.height_first = 100});
+
+ // Update it to a new height
+ blockman.UpdatePruneLock("test_lock", node::PruneLockInfo{.height_first = 200});
+
+ // Delete existing prune lock
+ BOOST_CHECK(blockman.DeletePruneLock("test_lock"));
+
+ // Verify deletion worked by trying to delete the same lock again
+ BOOST_CHECK(!blockman.DeletePruneLock("test_lock"));
+
+ // Deleting a non-existent lock returns false
+ BOOST_CHECK(!blockman.DeletePruneLock("nonexistent"));
+}
+
BOOST_AUTO_TEST_SUITE_END()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.