mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge bitcoin/bitcoin#26533: prune: scan and unlink already pruned block files on startup
3141eab9c6test: add functional test for ScanAndUnlinkAlreadyPrunedFiles (Andrew Toth)e252909e56test: add unit test for ScanAndUnlinkAlreadyPrunedFiles (Andrew Toth)77557dda4aprune: scan and unlink already pruned block files on startup (Andrew Toth) Pull request description: There are a few cases where we can mark a block and undo file as pruned in our block index, but not actually remove the files from disk. 1. If we call `FindFilesToPrune` or `FindFilesToPruneManual` and crash before `UnlinkPrunedFiles`. 2. If on Windows there is an open file handle to the file somewhere else when calling `fs::remove` in `UnlinkPrunedFiles` (https://en.cppreference.com/w/cpp/filesystem/remove, https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-deletefilew#remarks). This could be from another process, or if we are calling `ReadBlockFromDisk`/`ReadRawBlockFromDisk` without having a lock on `cs_main` (which has been allowed sinceccd8ef65f9). This PR mitigates this by scanning all pruned block files on startup after `LoadBlockIndexDB` and unlinking them again. ACKs for top commit: achow101: ACK3141eab9c6pablomartin4btc: re-ACK with added functional test3141eab9c6. furszy: Code review ACK3141eab9theStack: Code-review ACK3141eab9c6Tree-SHA512: 6c73bc57838ad1b7e5d441af3c4d6bf4c61c4382e2b86485e57fbb74a61240710c0ceeceb8b4834e610ecfa3175c6955c81ea4b2285fee11ca6383f472979d8d
This commit is contained in:
@@ -4323,6 +4323,8 @@ bool ChainstateManager::LoadBlockIndex()
|
||||
bool ret = m_blockman.LoadBlockIndexDB(GetConsensus());
|
||||
if (!ret) return false;
|
||||
|
||||
m_blockman.ScanAndUnlinkAlreadyPrunedFiles();
|
||||
|
||||
std::vector<CBlockIndex*> vSortedByHeight{m_blockman.GetAllBlockIndices()};
|
||||
std::sort(vSortedByHeight.begin(), vSortedByHeight.end(),
|
||||
CBlockIndexHeightOnlyComparator());
|
||||
|
||||
Reference in New Issue
Block a user