| 61 | } |
| 62 | |
| 63 | BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain100Setup) |
| 64 | { |
| 65 | // Cap last block file size, and mine new block in a new block file. |
| 66 | auto& chainman{*Assert(m_node.chainman)}; |
| 67 | auto& blockman{chainman.m_blockman}; |
| 68 | const CBlockIndex* old_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; |
| 69 | WITH_LOCK(chainman.GetMutex(), blockman.GetBlockFileInfo(old_tip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE); |
| 70 | CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); |
| 71 | |
| 72 | // Prune the older block file, but don't unlink it |
| 73 | int file_number; |
| 74 | { |
| 75 | LOCK(chainman.GetMutex()); |
| 76 | file_number = old_tip->GetBlockPos().nFile; |
| 77 | blockman.PruneOneBlockFile(file_number); |
| 78 | } |
| 79 | |
| 80 | const FlatFilePos pos(file_number, 0); |
| 81 | |
| 82 | // Check that the file is not unlinked after ScanAndUnlinkAlreadyPrunedFiles |
| 83 | // if m_have_pruned is not yet set |
| 84 | WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); |
| 85 | BOOST_CHECK(!blockman.OpenBlockFile(pos, true).IsNull()); |
| 86 | |
| 87 | // Check that the file is unlinked after ScanAndUnlinkAlreadyPrunedFiles |
| 88 | // once m_have_pruned is set |
| 89 | blockman.m_have_pruned = true; |
| 90 | WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); |
| 91 | BOOST_CHECK(blockman.OpenBlockFile(pos, true).IsNull()); |
| 92 | |
| 93 | // Check that calling with already pruned files doesn't cause an error |
| 94 | WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles()); |
| 95 | |
| 96 | // Check that the new tip file has not been removed |
| 97 | const CBlockIndex* new_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())}; |
| 98 | BOOST_CHECK_NE(old_tip, new_tip); |
| 99 | const int new_file_number{WITH_LOCK(chainman.GetMutex(), return new_tip->GetBlockPos().nFile)}; |
| 100 | const FlatFilePos new_pos(new_file_number, 0); |
| 101 | BOOST_CHECK(!blockman.OpenBlockFile(new_pos, true).IsNull()); |
| 102 | } |
| 103 | |
| 104 | BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup) |
| 105 | { |
nothing calls this directly
no test coverage detected