mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 07:09:15 +01:00
Add BlockManager::LoadingBlocks()
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user