mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-22 14:35:07 +02:00
validation: Make PruneOneBlockFile() a member of ChainstateManager
This commit is contained in:
parent
fa84b1cd84
commit
fa24d49098
@ -196,8 +196,8 @@ CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& loc
|
||||
std::unique_ptr<CBlockTreeDB> pblocktree;
|
||||
|
||||
// See definition for documentation
|
||||
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight);
|
||||
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
|
||||
static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& setFilesToPrune, int nManualPruneHeight);
|
||||
static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
|
||||
bool CheckInputScripts(const CTransaction& tx, TxValidationState &state, const CCoinsViewCache &inputs, unsigned int flags, bool cacheSigStore, bool cacheFullScriptStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = nullptr);
|
||||
static FILE* OpenUndoFile(const FlatFilePos &pos, bool fReadOnly = false);
|
||||
static FlatFileSeq BlockFileSeq();
|
||||
@ -2282,11 +2282,11 @@ bool CChainState::FlushStateToDisk(
|
||||
if (nManualPruneHeight > 0) {
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune (manual)", BCLog::BENCH);
|
||||
|
||||
FindFilesToPruneManual(setFilesToPrune, nManualPruneHeight);
|
||||
FindFilesToPruneManual(g_chainman, setFilesToPrune, nManualPruneHeight);
|
||||
} else {
|
||||
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", BCLog::BENCH);
|
||||
|
||||
FindFilesToPrune(setFilesToPrune, chainparams.PruneAfterHeight());
|
||||
FindFilesToPrune(g_chainman, setFilesToPrune, chainparams.PruneAfterHeight());
|
||||
fCheckForPruning = false;
|
||||
}
|
||||
if (!setFilesToPrune.empty()) {
|
||||
@ -3895,12 +3895,12 @@ uint64_t CalculateCurrentUsage()
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Prune a block file (modify associated database entries)*/
|
||||
void PruneOneBlockFile(const int fileNumber)
|
||||
void ChainstateManager::PruneOneBlockFile(const int fileNumber)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
for (const auto& entry : g_chainman.BlockIndex()) {
|
||||
for (const auto& entry : m_blockman.m_block_index) {
|
||||
CBlockIndex* pindex = entry.second;
|
||||
if (pindex->nFile == fileNumber) {
|
||||
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
||||
@ -3914,12 +3914,12 @@ void PruneOneBlockFile(const int fileNumber)
|
||||
// to be downloaded again in order to consider its chain, at which
|
||||
// point it would be considered as a candidate for
|
||||
// m_blocks_unlinked or setBlockIndexCandidates.
|
||||
auto range = g_chainman.m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
|
||||
auto range = m_blockman.m_blocks_unlinked.equal_range(pindex->pprev);
|
||||
while (range.first != range.second) {
|
||||
std::multimap<CBlockIndex *, CBlockIndex *>::iterator _it = range.first;
|
||||
range.first++;
|
||||
if (_it->second == pindex) {
|
||||
g_chainman.m_blockman.m_blocks_unlinked.erase(_it);
|
||||
m_blockman.m_blocks_unlinked.erase(_it);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3941,7 +3941,7 @@ void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune)
|
||||
}
|
||||
|
||||
/* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */
|
||||
static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight)
|
||||
static void FindFilesToPruneManual(ChainstateManager& chainman, std::set<int>& setFilesToPrune, int nManualPruneHeight)
|
||||
{
|
||||
assert(fPruneMode && nManualPruneHeight > 0);
|
||||
|
||||
@ -3955,7 +3955,7 @@ static void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPr
|
||||
for (int fileNumber = 0; fileNumber < nLastBlockFile; fileNumber++) {
|
||||
if (vinfoBlockFile[fileNumber].nSize == 0 || vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
|
||||
continue;
|
||||
PruneOneBlockFile(fileNumber);
|
||||
chainman.PruneOneBlockFile(fileNumber);
|
||||
setFilesToPrune.insert(fileNumber);
|
||||
count++;
|
||||
}
|
||||
@ -3988,7 +3988,7 @@ void PruneBlockFilesManual(int nManualPruneHeight)
|
||||
*
|
||||
* @param[out] setFilesToPrune The set of file indices that can be unlinked will be returned
|
||||
*/
|
||||
static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
|
||||
static void FindFilesToPrune(ChainstateManager& chainman, std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight)
|
||||
{
|
||||
LOCK2(cs_main, cs_LastBlockFile);
|
||||
if (::ChainActive().Tip() == nullptr || nPruneTarget == 0) {
|
||||
@ -4030,7 +4030,7 @@ static void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfte
|
||||
if (vinfoBlockFile[fileNumber].nHeightLast > nLastBlockWeCanPrune)
|
||||
continue;
|
||||
|
||||
PruneOneBlockFile(fileNumber);
|
||||
chainman.PruneOneBlockFile(fileNumber);
|
||||
// Queue up the files for removal
|
||||
setFilesToPrune.insert(fileNumber);
|
||||
nCurrentUsage -= nBytesToPrune;
|
||||
|
@ -214,11 +214,6 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pin
|
||||
/** Calculate the amount of disk space the block & undo files currently use */
|
||||
uint64_t CalculateCurrentUsage();
|
||||
|
||||
/**
|
||||
* Mark one block file as pruned.
|
||||
*/
|
||||
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
/**
|
||||
* Actually unlink the specified files
|
||||
*/
|
||||
@ -865,6 +860,9 @@ public:
|
||||
CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
|
||||
CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
|
||||
|
||||
//! Mark one block file as pruned (modify associated database entries)
|
||||
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
//! Load the block tree and coins database from disk, initializing state if we're running with -reindex
|
||||
bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
|
@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||
// Prune the older block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
|
||||
|
||||
@ -144,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||
// Prune the remaining block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
PruneOneBlockFile(newTip->GetBlockPos().nFile);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(newTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
|
||||
|
||||
@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
||||
// Prune the older block file.
|
||||
{
|
||||
LOCK(cs_main);
|
||||
PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
|
||||
}
|
||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user