Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show All 15 Lines | |||||
#include <checkqueue.h> | #include <checkqueue.h> | ||||
#include <config.h> | #include <config.h> | ||||
#include <consensus/activation.h> | #include <consensus/activation.h> | ||||
#include <consensus/merkle.h> | #include <consensus/merkle.h> | ||||
#include <consensus/tx_check.h> | #include <consensus/tx_check.h> | ||||
#include <consensus/tx_verify.h> | #include <consensus/tx_verify.h> | ||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <hash.h> | #include <hash.h> | ||||
#include <index/blockfilterindex.h> | |||||
#include <index/txindex.h> | #include <index/txindex.h> | ||||
#include <logging.h> | #include <logging.h> | ||||
#include <logging/timer.h> | #include <logging/timer.h> | ||||
#include <minerfund.h> | #include <minerfund.h> | ||||
#include <node/ui_interface.h> | #include <node/ui_interface.h> | ||||
#include <policy/fees.h> | #include <policy/fees.h> | ||||
#include <policy/mempool.h> | #include <policy/mempool.h> | ||||
#include <policy/policy.h> | #include <policy/policy.h> | ||||
▲ Show 20 Lines • Show All 2,119 Lines • ▼ Show 20 Lines | bool CChainState::FlushStateToDisk(const CChainParams &chainparams, | ||||
const size_t coins_count = CoinsTip().GetCacheSize(); | const size_t coins_count = CoinsTip().GetCacheSize(); | ||||
const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage(); | const size_t coins_mem_usage = CoinsTip().DynamicMemoryUsage(); | ||||
try { | try { | ||||
{ | { | ||||
bool fFlushForPrune = false; | bool fFlushForPrune = false; | ||||
bool fDoFullFlush = false; | bool fDoFullFlush = false; | ||||
CoinsCacheSizeState cache_state = | CoinsCacheSizeState cache_state = | ||||
GetCoinsCacheSizeState(&m_mempool); | GetCoinsCacheSizeState(&m_mempool); | ||||
LOCK(cs_LastBlockFile); | LOCK(cs_LastBlockFile); | ||||
if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && | if (fPruneMode && (fCheckForPruning || nManualPruneHeight > 0) && | ||||
!fReindex) { | !fReindex) { | ||||
// Make sure we don't prune above the blockfilterindexes | |||||
// bestblocks. Pruning is height-based. | |||||
int last_prune = m_chain.Height(); | |||||
ForEachBlockFilterIndex([&](BlockFilterIndex &index) { | |||||
last_prune = std::max( | |||||
1, std::min(last_prune, | |||||
index.GetSummary().best_block_height)); | |||||
}); | |||||
if (nManualPruneHeight > 0) { | if (nManualPruneHeight > 0) { | ||||
LOG_TIME_MILLIS_WITH_CATEGORY( | LOG_TIME_MILLIS_WITH_CATEGORY( | ||||
"find files to prune (manual)", BCLog::BENCH); | "find files to prune (manual)", BCLog::BENCH); | ||||
m_blockman.FindFilesToPruneManual( | m_blockman.FindFilesToPruneManual( | ||||
setFilesToPrune, nManualPruneHeight, m_chain.Height()); | setFilesToPrune, | ||||
std::min(last_prune, nManualPruneHeight), | |||||
m_chain.Height()); | |||||
} else { | } else { | ||||
LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", | LOG_TIME_MILLIS_WITH_CATEGORY("find files to prune", | ||||
BCLog::BENCH); | BCLog::BENCH); | ||||
m_blockman.FindFilesToPrune( | m_blockman.FindFilesToPrune( | ||||
setFilesToPrune, chainparams.PruneAfterHeight(), | setFilesToPrune, chainparams.PruneAfterHeight(), | ||||
m_chain.Height(), IsInitialBlockDownload()); | m_chain.Height(), last_prune, IsInitialBlockDownload()); | ||||
fCheckForPruning = false; | fCheckForPruning = false; | ||||
} | } | ||||
if (!setFilesToPrune.empty()) { | if (!setFilesToPrune.empty()) { | ||||
fFlushForPrune = true; | fFlushForPrune = true; | ||||
if (!fHavePruned) { | if (!fHavePruned) { | ||||
pblocktree->WriteFlag("prunedblockfiles", true); | pblocktree->WriteFlag("prunedblockfiles", true); | ||||
fHavePruned = true; | fHavePruned = true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,499 Lines • ▼ Show 20 Lines | static bool FindBlockPos(FlatFilePos &pos, unsigned int nAddSize, | ||||
unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; | unsigned int nFile = fKnown ? pos.nFile : nLastBlockFile; | ||||
if (vinfoBlockFile.size() <= nFile) { | if (vinfoBlockFile.size() <= nFile) { | ||||
vinfoBlockFile.resize(nFile + 1); | vinfoBlockFile.resize(nFile + 1); | ||||
} | } | ||||
bool finalize_undo = false; | bool finalize_undo = false; | ||||
if (!fKnown) { | if (!fKnown) { | ||||
while (vinfoBlockFile[nFile].nSize + nAddSize >= MAX_BLOCKFILE_SIZE) { | while (vinfoBlockFile[nFile].nSize + nAddSize >= | ||||
(gArgs.GetBoolArg("-fastprune", false) ? 0x10000 /* 64kb */ | |||||
: MAX_BLOCKFILE_SIZE)) { | |||||
// when the undo file is keeping up with the block file, we want to | // when the undo file is keeping up with the block file, we want to | ||||
// flush it explicitly when it is lagging behind (more blocks arrive | // flush it explicitly when it is lagging behind (more blocks arrive | ||||
// than are being connected), we let the undo block write case | // than are being connected), we let the undo block write case | ||||
// handle it | // handle it | ||||
assert(std::addressof(::ChainActive()) == | assert(std::addressof(::ChainActive()) == | ||||
std::addressof(active_chain)); | std::addressof(active_chain)); | ||||
finalize_undo = (vinfoBlockFile[nFile].nHeightLast == | finalize_undo = (vinfoBlockFile[nFile].nHeightLast == | ||||
(unsigned int)active_chain.Tip()->nHeight); | (unsigned int)active_chain.Tip()->nHeight); | ||||
▲ Show 20 Lines • Show All 947 Lines • ▼ Show 20 Lines | if (active_chainstate.FlushStateToDisk( | ||||
chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) { | chainparams, state, FlushStateMode::NONE, nManualPruneHeight)) { | ||||
LogPrintf("%s: failed to flush state (%s)\n", __func__, | LogPrintf("%s: failed to flush state (%s)\n", __func__, | ||||
state.ToString()); | state.ToString()); | ||||
} | } | ||||
} | } | ||||
void BlockManager::FindFilesToPrune(std::set<int> &setFilesToPrune, | void BlockManager::FindFilesToPrune(std::set<int> &setFilesToPrune, | ||||
uint64_t nPruneAfterHeight, | uint64_t nPruneAfterHeight, | ||||
int chain_tip_height, bool is_ibd) { | int chain_tip_height, int prune_height, | ||||
bool is_ibd) { | |||||
LOCK2(cs_main, cs_LastBlockFile); | LOCK2(cs_main, cs_LastBlockFile); | ||||
if (chain_tip_height < 0 || nPruneTarget == 0) { | if (chain_tip_height < 0 || nPruneTarget == 0) { | ||||
return; | return; | ||||
} | } | ||||
if (uint64_t(chain_tip_height) <= nPruneAfterHeight) { | if (uint64_t(chain_tip_height) <= nPruneAfterHeight) { | ||||
return; | return; | ||||
} | } | ||||
unsigned int nLastBlockWeCanPrune = chain_tip_height - MIN_BLOCKS_TO_KEEP; | unsigned int nLastBlockWeCanPrune = std::min( | ||||
prune_height, chain_tip_height - static_cast<int>(MIN_BLOCKS_TO_KEEP)); | |||||
uint64_t nCurrentUsage = CalculateCurrentUsage(); | uint64_t nCurrentUsage = CalculateCurrentUsage(); | ||||
// We don't check to prune until after we've allocated new space for files, | // We don't check to prune until after we've allocated new space for files, | ||||
// so we should leave a buffer under our target to account for another | // so we should leave a buffer under our target to account for another | ||||
// allocation before the next pruning. | // allocation before the next pruning. | ||||
uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE; | uint64_t nBuffer = BLOCKFILE_CHUNK_SIZE + UNDOFILE_CHUNK_SIZE; | ||||
uint64_t nBytesToPrune; | uint64_t nBytesToPrune; | ||||
int count = 0; | int count = 0; | ||||
▲ Show 20 Lines • Show All 1,511 Lines • Show Last 20 Lines |