mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-28 12:50:17 +02:00
Add BlockManager::LoadingBlocks()
This commit is contained in:
parent
599e941c19
commit
fa0f0436d8
@ -53,9 +53,7 @@
|
||||
|
||||
using node::ReadBlockFromDisk;
|
||||
using node::ReadRawBlockFromDisk;
|
||||
using node::fImporting;
|
||||
using node::fPruneMode;
|
||||
using node::fReindex;
|
||||
|
||||
/** How long to cache transactions in mapRelay for normal relay */
|
||||
static constexpr auto RELAY_TX_CACHE_TIME = 15min;
|
||||
@ -1730,8 +1728,7 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex)
|
||||
|
||||
std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index)
|
||||
{
|
||||
if (fImporting) return "Importing...";
|
||||
if (fReindex) return "Reindexing...";
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) return "Loading blocks ...";
|
||||
|
||||
// Ensure this peer exists and hasn't been disconnected
|
||||
PeerRef peer = GetPeerRef(peer_id);
|
||||
@ -3679,7 +3676,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
|
||||
UpdateBlockAvailability(pfrom.GetId(), inv.hash);
|
||||
if (!fAlreadyHave && !fImporting && !fReindex && !IsBlockRequested(inv.hash)) {
|
||||
if (!fAlreadyHave && !m_chainman.m_blockman.LoadingBlocks() && !IsBlockRequested(inv.hash)) {
|
||||
// Headers-first is the primary method of announcement on
|
||||
// the network. If a node fell back to sending blocks by
|
||||
// inv, it may be for a re-org, or because we haven't
|
||||
@ -3889,7 +3886,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
return;
|
||||
}
|
||||
|
||||
if (fImporting || fReindex) {
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d while importing/reindexing\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -4171,7 +4168,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
if (msg_type == NetMsgType::CMPCTBLOCK)
|
||||
{
|
||||
// Ignore cmpctblock received while importing
|
||||
if (fImporting || fReindex) {
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
LogPrint(BCLog::NET, "Unexpected cmpctblock message received from peer %d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -4387,7 +4384,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
if (msg_type == NetMsgType::BLOCKTXN)
|
||||
{
|
||||
// Ignore blocktxn received while importing
|
||||
if (fImporting || fReindex) {
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
LogPrint(BCLog::NET, "Unexpected blocktxn message received from peer %d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -4462,7 +4459,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
if (msg_type == NetMsgType::HEADERS)
|
||||
{
|
||||
// Ignore headers received while importing
|
||||
if (fImporting || fReindex) {
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
LogPrint(BCLog::NET, "Unexpected headers message received from peer %d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -4507,7 +4504,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
||||
if (msg_type == NetMsgType::BLOCK)
|
||||
{
|
||||
// Ignore block received while importing
|
||||
if (fImporting || fReindex) {
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
LogPrint(BCLog::NET, "Unexpected block message received from peer %d\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
@ -5092,7 +5089,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()
|
||||
if (now > m_stale_tip_check_time) {
|
||||
// Check whether our tip is stale, and if so, allow using an extra
|
||||
// outbound peer
|
||||
if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
|
||||
if (!m_chainman.m_blockman.LoadingBlocks() && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) {
|
||||
LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n",
|
||||
count_seconds(now - m_last_tip_update.load()));
|
||||
m_connman.SetTryNewOutboundPeer(true);
|
||||
@ -5399,7 +5396,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
||||
}
|
||||
}
|
||||
|
||||
if (!state.fSyncStarted && CanServeBlocks(*peer) && !fImporting && !fReindex) {
|
||||
if (!state.fSyncStarted && CanServeBlocks(*peer) && !m_chainman.m_blockman.LoadingBlocks()) {
|
||||
// Only actively request headers from a single peer, unless we're close to today.
|
||||
if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->Time() > GetAdjustedTime() - 24h) {
|
||||
const CBlockIndex* pindexStart = m_chainman.m_best_header;
|
||||
|
@ -176,6 +176,11 @@ public:
|
||||
/** Store block on disk. If dbp is not nullptr, then it provides the known position of the block within a block file on disk. */
|
||||
FlatFilePos SaveBlockToDisk(const CBlock& block, int nHeight, CChain& active_chain, const CChainParams& chainparams, const FlatFilePos* dbp);
|
||||
|
||||
[[nodiscard]] bool LoadingBlocks() const
|
||||
{
|
||||
return fImporting || fReindex;
|
||||
}
|
||||
|
||||
/** Calculate the amount of disk space the block & undo files currently use */
|
||||
uint64_t CalculateCurrentUsage();
|
||||
|
||||
|
@ -711,8 +711,9 @@ public:
|
||||
LOCK(::cs_main);
|
||||
return chainman().m_blockman.m_have_pruned;
|
||||
}
|
||||
bool isReadyToBroadcast() override { return !node::fImporting && !node::fReindex && !isInitialBlockDownload(); }
|
||||
bool isInitialBlockDownload() override {
|
||||
bool isReadyToBroadcast() override { return !chainman().m_blockman.LoadingBlocks() && !isInitialBlockDownload(); }
|
||||
bool isInitialBlockDownload() override
|
||||
{
|
||||
return chainman().ActiveChainstate().IsInitialBlockDownload();
|
||||
}
|
||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||
|
@ -76,7 +76,6 @@ using node::BlockManager;
|
||||
using node::BlockMap;
|
||||
using node::CBlockIndexHeightOnlyComparator;
|
||||
using node::CBlockIndexWorkComparator;
|
||||
using node::fImporting;
|
||||
using node::fPruneMode;
|
||||
using node::fReindex;
|
||||
using node::ReadBlockFromDisk;
|
||||
@ -1573,8 +1572,9 @@ bool Chainstate::IsInitialBlockDownload() const
|
||||
LOCK(cs_main);
|
||||
if (m_cached_finished_ibd.load(std::memory_order_relaxed))
|
||||
return false;
|
||||
if (fImporting || fReindex)
|
||||
if (m_chainman.m_blockman.LoadingBlocks()) {
|
||||
return true;
|
||||
}
|
||||
if (m_chain.Tip() == nullptr)
|
||||
return true;
|
||||
if (m_chain.Tip()->nChainWork < m_chainman.MinimumChainWork()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user