Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 2,210 Lines • ▼ Show 20 Lines | |||||
CoinsCacheSizeState | CoinsCacheSizeState | ||||
CChainState::GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, | CChainState::GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, | ||||
size_t max_mempool_size_bytes) { | size_t max_mempool_size_bytes) { | ||||
int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0; | int64_t nMempoolUsage = m_mempool ? m_mempool->DynamicMemoryUsage() : 0; | ||||
int64_t cacheSize = CoinsTip().DynamicMemoryUsage(); | int64_t cacheSize = CoinsTip().DynamicMemoryUsage(); | ||||
int64_t nTotalSpace = | int64_t nTotalSpace = | ||||
max_coins_cache_size_bytes + | max_coins_cache_size_bytes + | ||||
std::max<int64_t>(max_mempool_size_bytes - nMempoolUsage, 0); | std::max<int64_t>(int64_t(max_mempool_size_bytes) - nMempoolUsage, 0); | ||||
//! No need to periodic flush if at least this much space still available. | //! No need to periodic flush if at least this much space still available. | ||||
static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = | static constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES = | ||||
10 * 1024 * 1024; // 10MB | 10 * 1024 * 1024; // 10MB | ||||
int64_t large_threshold = std::max( | int64_t large_threshold = std::max( | ||||
(9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE_BYTES); | (9 * nTotalSpace) / 10, nTotalSpace - MAX_BLOCK_COINSDB_USAGE_BYTES); | ||||
if (cacheSize > nTotalSpace) { | if (cacheSize > nTotalSpace) { | ||||
▲ Show 20 Lines • Show All 2,114 Lines • ▼ Show 20 Lines | bool fHasMoreOrSameWork = | ||||
(m_chain.Tip() ? pindex->nChainWork >= m_chain.Tip()->nChainWork | (m_chain.Tip() ? pindex->nChainWork >= m_chain.Tip()->nChainWork | ||||
: true); | : true); | ||||
// Blocks that are too out-of-order needlessly limit the effectiveness of | // Blocks that are too out-of-order needlessly limit the effectiveness of | ||||
// pruning, because pruning will not delete block files that contain any | // pruning, because pruning will not delete block files that contain any | ||||
// blocks which are too close in height to the tip. Apply this test | // blocks which are too close in height to the tip. Apply this test | ||||
// regardless of whether pruning is enabled; it should generally be safe to | // regardless of whether pruning is enabled; it should generally be safe to | ||||
// not process unrequested blocks. | // not process unrequested blocks. | ||||
bool fTooFarAhead = | bool fTooFarAhead{pindex->nHeight > | ||||
(pindex->nHeight > int(m_chain.Height() + MIN_BLOCKS_TO_KEEP)); | m_chain.Height() + int(MIN_BLOCKS_TO_KEEP)}; | ||||
// TODO: Decouple this function from the block download logic by removing | // TODO: Decouple this function from the block download logic by removing | ||||
// fRequested | // fRequested | ||||
// This requires some new chain data structure to efficiently look up if a | // This requires some new chain data structure to efficiently look up if a | ||||
// block is in a chain leading to a candidate for best tip, despite not | // block is in a chain leading to a candidate for best tip, despite not | ||||
// being such a candidate itself. | // being such a candidate itself. | ||||
// Note that this would break the getblockfrompeer RPC | // Note that this would break the getblockfrompeer RPC | ||||
▲ Show 20 Lines • Show All 659 Lines • ▼ Show 20 Lines | try { | ||||
// Start one byte further next time, in case of failure. | // Start one byte further next time, in case of failure. | ||||
nRewind++; | nRewind++; | ||||
// Remove former limit. | // Remove former limit. | ||||
blkdat.SetLimit(); | blkdat.SetLimit(); | ||||
unsigned int nSize = 0; | unsigned int nSize = 0; | ||||
try { | try { | ||||
// Locate a header. | // Locate a header. | ||||
uint8_t buf[CMessageHeader::MESSAGE_START_SIZE]; | uint8_t buf[CMessageHeader::MESSAGE_START_SIZE]; | ||||
blkdat.FindByte(m_params.DiskMagic()[0]); | blkdat.FindByte(char(m_params.DiskMagic()[0])); | ||||
nRewind = blkdat.GetPos() + 1; | nRewind = blkdat.GetPos() + 1; | ||||
blkdat >> buf; | blkdat >> buf; | ||||
if (memcmp(buf, m_params.DiskMagic().data(), | if (memcmp(buf, m_params.DiskMagic().data(), | ||||
CMessageHeader::MESSAGE_START_SIZE)) { | CMessageHeader::MESSAGE_START_SIZE)) { | ||||
continue; | continue; | ||||
} | } | ||||
// Read size. | // Read size. | ||||
▲ Show 20 Lines • Show All 1,121 Lines • Show Last 20 Lines |