mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-20 04:30:31 +01:00
Track headers presync progress and log it
This commit is contained in:
committed by
Suhas Daftuar
parent
03712dddfb
commit
355547334f
@@ -3711,6 +3711,29 @@ bool ChainstateManager::ProcessNewBlockHeaders(const std::vector<CBlockHeader>&
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChainstateManager::ReportHeadersPresync(const arith_uint256& work, int64_t height, int64_t timestamp)
|
||||
{
|
||||
AssertLockNotHeld(cs_main);
|
||||
const auto& chainstate = ActiveChainstate();
|
||||
{
|
||||
LOCK(cs_main);
|
||||
// Don't report headers presync progress if we already have a post-minchainwork header chain.
|
||||
// This means we lose reporting for potentially legimate, but unlikely, deep reorgs, but
|
||||
// prevent attackers that spam low-work headers from filling our logs.
|
||||
if (m_best_header->nChainWork >= UintToArith256(GetConsensus().nMinimumChainWork)) return;
|
||||
// Rate limit headers presync updates to 4 per second, as these are not subject to DoS
|
||||
// protection.
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (now < m_last_presync_update + std::chrono::milliseconds{250}) return;
|
||||
m_last_presync_update = now;
|
||||
}
|
||||
if (chainstate.IsInitialBlockDownload()) {
|
||||
const int64_t blocks_left{(GetTime() - timestamp) / GetConsensus().nPowTargetSpacing};
|
||||
const double progress{100.0 * height / (height + blocks_left)};
|
||||
LogPrintf("Pre-synchronizing blockheaders, height: %d (~%.2f%%)\n", height, progress);
|
||||
}
|
||||
}
|
||||
|
||||
/** Store block on disk. If dbp is non-nullptr, the file is known to already reside on disk */
|
||||
bool CChainState::AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock, bool min_pow_checked)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user