diff options
author | Andrew Chow <github@achow101.com> | 2023-02-28 09:54:06 -0500 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-02-28 09:54:10 -0500 |
commit | bb136aaf2c3bb862bf126751b0aeae62d695eaf7 (patch) | |
tree | ce93b06c9982ca43248617187879aa56150a7fc8 /src/validation.cpp | |
parent | 519ec2650e7a4dd2850ff74cba403cf446a44a5a (diff) | |
parent | 3141eab9c669488a2e7fef5f60d356ac92294922 (diff) |
Merge bitcoin/bitcoin#26533: prune: scan and unlink already pruned block files on startup
3141eab9c669488a2e7fef5f60d356ac92294922 test: add functional test for ScanAndUnlinkAlreadyPrunedFiles (Andrew Toth)
e252909e561e47d75cb3a892657662a139f6532c test: add unit test for ScanAndUnlinkAlreadyPrunedFiles (Andrew Toth)
77557dda4a123515d0fa2a545ee21d7c43a66988 prune: 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 since https://github.com/bitcoin/bitcoin/commit/ccd8ef65f93ed82a87cee634660bed3ac17d9eb5).
This PR mitigates this by scanning all pruned block files on startup after `LoadBlockIndexDB` and unlinking them again.
ACKs for top commit:
achow101:
ACK 3141eab9c669488a2e7fef5f60d356ac92294922
pablomartin4btc:
re-ACK with added functional test 3141eab9c669488a2e7fef5f60d356ac92294922.
furszy:
Code review ACK 3141eab9
theStack:
Code-review ACK 3141eab9c669488a2e7fef5f60d356ac92294922
Tree-SHA512: 6c73bc57838ad1b7e5d441af3c4d6bf4c61c4382e2b86485e57fbb74a61240710c0ceeceb8b4834e610ecfa3175c6955c81ea4b2285fee11ca6383f472979d8d
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 1357de3c01..64e4d148de 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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()); |