6#include <chainparams.h>
14#include <validation.h>
16#include <boost/test/unit_test.hpp>
32 const BlockManager::Options blockman_opts{
33 .chainparams = *params,
34 .blocks_dir = m_args.GetBlocksDirPath(),
35 .notifications = notifications,
45 blockman.UpdateBlockInfo(params->GenesisBlock(), 0, pos);
52 FlatFilePos actual{blockman.SaveBlockToDisk(params->GenesisBlock(), 1)};
60 auto& blockman = chainman->m_blockman;
61 const CBlockIndex* old_tip{
WITH_LOCK(chainman->GetMutex(),
return chainman->ActiveChain().Tip())};
68 LOCK(chainman->GetMutex());
69 file_number = old_tip->GetBlockPos().nFile;
70 blockman.PruneOneBlockFile(file_number);
77 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
78 BOOST_CHECK(!blockman.OpenBlockFile(pos,
true).IsNull());
82 blockman.m_have_pruned =
true;
83 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
84 BOOST_CHECK(blockman.OpenBlockFile(pos,
true).IsNull());
87 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
90 const CBlockIndex* new_tip{
WITH_LOCK(chainman->GetMutex(),
return chainman->ActiveChain().Tip())};
91 BOOST_CHECK_NE(old_tip, new_tip);
92 const int new_file_number{
WITH_LOCK(chainman->GetMutex(),
return new_tip->GetBlockPos().nFile)};
94 BOOST_CHECK(!blockman.OpenBlockFile(new_pos,
true).IsNull());
102 auto& blockman = chainman->m_blockman;
106 const auto& func_prune_blocks = [&](
CBlockIndex* last_pruned_block)
111 it->nStatus &= ~BLOCK_HAVE_DATA;
118 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *chainman->ActiveChain()[0]));
122 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *lower_block));
125 int height_to_prune = tip.
nHeight / 2;
126 CBlockIndex* first_available_block = chainman->ActiveChain()[height_to_prune + 1];
128 func_prune_blocks(last_pruned_block);
132 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block));
133 BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block));
141 .blocks_dir = m_args.GetBlocksDirPath(),
142 .notifications = notifications,
155 constexpr int TEST_BLOCK_SIZE{81};
161 FlatFilePos pos1{blockman.SaveBlockToDisk(block1, 1)};
164 FlatFilePos pos2{blockman.SaveBlockToDisk(block2, 2)};
175 BOOST_CHECK(!blockman.ReadBlockFromDisk(read_block, pos1));
180 BOOST_CHECK(!blockman.ReadBlockFromDisk(read_block, pos2));
190 blockman.UpdateBlockInfo(block3, 3, pos2);
197 blockman.ReadBlockFromDisk(read_block, pos2);
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain100Setup)
@ BLOCK_HAVE_DATA
full block available in blk*.dat
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
unsigned int nBlocks
number of blocks stored in file
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int nHeight
height of the entry in the chain. The genesis block has height 0
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
static constexpr size_t BLOCK_SERIALIZATION_HEADER_SIZE
Size of header written by WriteBlockToDisk before a serialized CBlock.
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static constexpr TransactionSerParams TX_WITH_WITNESS
size_t GetSerializeSize(const T &t)
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
Testing fixture that pre-creates a 100-block REGTEST-mode block chain.
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
const CChainParams & chainparams
std::unique_ptr< ChainstateManager > chainman
std::unique_ptr< node::Warnings > warnings
Manages all the node warnings.
std::function< bool()> shutdown_request
Function to request a shutdown.
util::SignalInterrupt * shutdown_signal
Interrupt object used to track whether node shutdown was requested.
std::atomic< int > exit_status
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
#define ASSERT_DEBUG_LOG(message)