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,
37 .
path = m_args.GetDataDirNet() /
"blocks" /
"index",
49 blockman.UpdateBlockInfo(params->GenesisBlock(), 0, pos);
56 FlatFilePos actual{blockman.WriteBlock(params->GenesisBlock(), 1)};
64 auto& blockman = chainman->m_blockman;
65 const CBlockIndex* old_tip{
WITH_LOCK(chainman->GetMutex(),
return chainman->ActiveChain().Tip())};
72 LOCK(chainman->GetMutex());
73 file_number = old_tip->GetBlockPos().nFile;
74 blockman.PruneOneBlockFile(file_number);
81 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
82 BOOST_CHECK(!blockman.OpenBlockFile(pos,
true).IsNull());
86 blockman.m_have_pruned =
true;
87 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
88 BOOST_CHECK(blockman.OpenBlockFile(pos,
true).IsNull());
91 WITH_LOCK(chainman->GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
94 const CBlockIndex* new_tip{
WITH_LOCK(chainman->GetMutex(),
return chainman->ActiveChain().Tip())};
95 BOOST_CHECK_NE(old_tip, new_tip);
96 const int new_file_number{
WITH_LOCK(chainman->GetMutex(),
return new_tip->GetBlockPos().nFile)};
98 BOOST_CHECK(!blockman.OpenBlockFile(new_pos,
true).IsNull());
106 auto& blockman = chainman->m_blockman;
110 const auto& func_prune_blocks = [&](
CBlockIndex* last_pruned_block)
115 it->nStatus &= ~BLOCK_HAVE_DATA;
122 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *chainman->ActiveChain()[0]));
126 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *lower_block));
129 int height_to_prune = tip.
nHeight / 2;
130 CBlockIndex* first_available_block = chainman->ActiveChain()[height_to_prune + 1];
132 func_prune_blocks(last_pruned_block);
136 BOOST_CHECK(blockman.CheckBlockDataAvailability(tip, *first_available_block));
137 BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block));
145 .blocks_dir = m_args.GetBlocksDirPath(),
146 .notifications = notifications,
148 .
path = m_args.GetDataDirNet() /
"blocks" /
"index",
163 constexpr int TEST_BLOCK_SIZE{81};
183 BOOST_CHECK(!blockman.ReadBlock(read_block, pos1));
188 BOOST_CHECK(!blockman.ReadBlock(read_block, pos2));
198 blockman.UpdateBlockInfo(block3, 3, pos2);
205 blockman.ReadBlock(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 WriteBlock before a serialized CBlock (8 bytes)
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.
Application-specific storage settings.
fs::path path
Location in the filesystem where leveldb data will be stored.
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)