Merge 317ddca8e68637f0ad774e46f69b3a5d29218cf6 into db2c57ae9eebdb75c58cd165ac929919969c19a9

This commit is contained in:
Pol Espinasa 2025-03-17 10:38:31 +01:00 committed by GitHub
commit 1d0842f666
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 15 deletions

View File

@ -326,7 +326,8 @@ public:
}
double getVerificationProgress() override
{
return chainman().GuessVerificationProgress(WITH_LOCK(chainman().GetMutex(), return chainman().ActiveChain().Tip()));
LOCK(chainman().GetMutex());
return chainman().GuessVerificationProgress(chainman().ActiveChain().Tip());
}
bool isInitialBlockDownload() override
{
@ -410,7 +411,7 @@ public:
{
return MakeSignalHandler(::uiInterface.NotifyBlockTip_connect([fn, this](SynchronizationState sync_state, const CBlockIndex* block) {
fn(sync_state, BlockTip{block->nHeight, block->GetBlockTime(), block->GetBlockHash()},
chainman().GuessVerificationProgress(block));
WITH_LOCK(chainman().GetMutex(), return chainman().GuessVerificationProgress(block)));
}));
}
std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override

View File

@ -4720,7 +4720,6 @@ bool Chainstate::LoadChainTip()
// Ignoring return value for now.
(void)m_chainman.GetNotifications().blockTip(GetSynchronizationState(/*init=*/true, m_chainman.m_blockman.m_blockfiles_indexed), *pindex);
}
return true;
}
@ -5601,11 +5600,8 @@ bool Chainstate::ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
return ret;
}
//! Guess how far we are in the verification process at the given block index
//! require cs_main if pindex has not been validated yet (because m_chain_tx_count might be unset)
double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) const
{
const ChainTxData& data{GetParams().TxData()};
if (pindex == nullptr) {
return 0.0;
}
@ -5615,16 +5611,21 @@ double ChainstateManager::GuessVerificationProgress(const CBlockIndex* pindex) c
return 0.0;
}
int64_t nNow = time(nullptr);
double fTxTotal;
if (pindex->m_chain_tx_count <= data.tx_count) {
fTxTotal = data.tx_count + (nNow - data.nTime) * data.dTxRate;
} else {
fTxTotal = pindex->m_chain_tx_count + (nNow - pindex->GetBlockTime()) * data.dTxRate;
int64_t end_of_chain_timestamp = TicksSinceEpoch<std::chrono::seconds>(NodeClock::time_point{std::chrono::seconds{pindex->GetBlockTime()}});
if (m_best_header && m_best_header->nChainWork > pindex->nChainWork) {
int64_t header_age = TicksSinceEpoch<std::chrono::seconds>(Now<NodeSeconds>()) - m_best_header->GetBlockTime();
if (header_age < 24 * 60 * 60) {
end_of_chain_timestamp = std::max(end_of_chain_timestamp, m_best_header->GetBlockTime());
}
}
double fTxTotal;
const ChainTxData& data{GetParams().TxData()};
if (pindex->m_chain_tx_count <= data.tx_count) {
fTxTotal = data.tx_count + (end_of_chain_timestamp - data.nTime) * data.dTxRate;
} else {
fTxTotal = pindex->m_chain_tx_count + (end_of_chain_timestamp - pindex->GetBlockTime()) * data.dTxRate;
}
return std::min<double>(pindex->m_chain_tx_count / fTxTotal, 1.0);
}

View File

@ -1149,7 +1149,7 @@ public:
bool IsInitialBlockDownload() const;
/** Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). */
double GuessVerificationProgress(const CBlockIndex* pindex) const;
double GuessVerificationProgress(const CBlockIndex* pindex) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/**
* Import blocks from an external file