|
53 | 53 |
|
54 | 54 | using node::ReadBlockFromDisk; |
55 | 55 | using node::ReadRawBlockFromDisk; |
56 | | -using node::fImporting; |
57 | | -using node::fPruneMode; |
58 | | -using node::fReindex; |
59 | 56 |
|
60 | 57 | /** How long to cache transactions in mapRelay for normal relay */ |
61 | 58 | static constexpr auto RELAY_TX_CACHE_TIME = 15min; |
@@ -1739,8 +1736,7 @@ bool PeerManagerImpl::BlockRequestAllowed(const CBlockIndex* pindex) |
1739 | 1736 |
|
1740 | 1737 | std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBlockIndex& block_index) |
1741 | 1738 | { |
1742 | | - if (fImporting) return "Importing..."; |
1743 | | - if (fReindex) return "Reindexing..."; |
| 1739 | + if (m_chainman.m_blockman.LoadingBlocks()) return "Loading blocks ..."; |
1744 | 1740 |
|
1745 | 1741 | // Ensure this peer exists and hasn't been disconnected |
1746 | 1742 | PeerRef peer = GetPeerRef(peer_id); |
@@ -3697,7 +3693,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
3697 | 3693 | LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId()); |
3698 | 3694 |
|
3699 | 3695 | UpdateBlockAvailability(pfrom.GetId(), inv.hash); |
3700 | | - if (!fAlreadyHave && !fImporting && !fReindex && !IsBlockRequested(inv.hash)) { |
| 3696 | + if (!fAlreadyHave && !m_chainman.m_blockman.LoadingBlocks() && !IsBlockRequested(inv.hash)) { |
3701 | 3697 | // Headers-first is the primary method of announcement on |
3702 | 3698 | // the network. If a node fell back to sending blocks by |
3703 | 3699 | // inv, it may be for a re-org, or because we haven't |
@@ -3830,8 +3826,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
3830 | 3826 | // If pruning, don't inv blocks unless we have on disk and are likely to still have |
3831 | 3827 | // for some reasonable time window (1 hour) that block relay might require. |
3832 | 3828 | const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / m_chainparams.GetConsensus().nPowTargetSpacing; |
3833 | | - if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= m_chainman.ActiveChain().Tip()->nHeight - nPrunedBlocksLikelyToHave)) |
3834 | | - { |
| 3829 | + if (m_chainman.m_blockman.IsPruneMode() && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= m_chainman.ActiveChain().Tip()->nHeight - nPrunedBlocksLikelyToHave)) { |
3835 | 3830 | LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); |
3836 | 3831 | break; |
3837 | 3832 | } |
@@ -3907,7 +3902,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
3907 | 3902 | return; |
3908 | 3903 | } |
3909 | 3904 |
|
3910 | | - if (fImporting || fReindex) { |
| 3905 | + if (m_chainman.m_blockman.LoadingBlocks()) { |
3911 | 3906 | LogPrint(BCLog::NET, "Ignoring getheaders from peer=%d while importing/reindexing\n", pfrom.GetId()); |
3912 | 3907 | return; |
3913 | 3908 | } |
@@ -4186,7 +4181,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
4186 | 4181 | if (msg_type == NetMsgType::CMPCTBLOCK) |
4187 | 4182 | { |
4188 | 4183 | // Ignore cmpctblock received while importing |
4189 | | - if (fImporting || fReindex) { |
| 4184 | + if (m_chainman.m_blockman.LoadingBlocks()) { |
4190 | 4185 | LogPrint(BCLog::NET, "Unexpected cmpctblock message received from peer %d\n", pfrom.GetId()); |
4191 | 4186 | return; |
4192 | 4187 | } |
@@ -4402,7 +4397,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
4402 | 4397 | if (msg_type == NetMsgType::BLOCKTXN) |
4403 | 4398 | { |
4404 | 4399 | // Ignore blocktxn received while importing |
4405 | | - if (fImporting || fReindex) { |
| 4400 | + if (m_chainman.m_blockman.LoadingBlocks()) { |
4406 | 4401 | LogPrint(BCLog::NET, "Unexpected blocktxn message received from peer %d\n", pfrom.GetId()); |
4407 | 4402 | return; |
4408 | 4403 | } |
@@ -4477,7 +4472,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
4477 | 4472 | if (msg_type == NetMsgType::HEADERS) |
4478 | 4473 | { |
4479 | 4474 | // Ignore headers received while importing |
4480 | | - if (fImporting || fReindex) { |
| 4475 | + if (m_chainman.m_blockman.LoadingBlocks()) { |
4481 | 4476 | LogPrint(BCLog::NET, "Unexpected headers message received from peer %d\n", pfrom.GetId()); |
4482 | 4477 | return; |
4483 | 4478 | } |
@@ -4522,7 +4517,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, |
4522 | 4517 | if (msg_type == NetMsgType::BLOCK) |
4523 | 4518 | { |
4524 | 4519 | // Ignore block received while importing |
4525 | | - if (fImporting || fReindex) { |
| 4520 | + if (m_chainman.m_blockman.LoadingBlocks()) { |
4526 | 4521 | LogPrint(BCLog::NET, "Unexpected block message received from peer %d\n", pfrom.GetId()); |
4527 | 4522 | return; |
4528 | 4523 | } |
@@ -5109,7 +5104,7 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers() |
5109 | 5104 | if (now > m_stale_tip_check_time) { |
5110 | 5105 | // Check whether our tip is stale, and if so, allow using an extra |
5111 | 5106 | // outbound peer |
5112 | | - if (!fImporting && !fReindex && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) { |
| 5107 | + if (!m_chainman.m_blockman.LoadingBlocks() && m_connman.GetNetworkActive() && m_connman.GetUseAddrmanOutgoing() && TipMayBeStale()) { |
5113 | 5108 | LogPrintf("Potential stale tip detected, will try using extra outbound peer (last tip update: %d seconds ago)\n", |
5114 | 5109 | count_seconds(now - m_last_tip_update.load())); |
5115 | 5110 | m_connman.SetTryNewOutboundPeer(true); |
@@ -5416,7 +5411,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto) |
5416 | 5411 | } |
5417 | 5412 | } |
5418 | 5413 |
|
5419 | | - if (!state.fSyncStarted && CanServeBlocks(*peer) && !fImporting && !fReindex) { |
| 5414 | + if (!state.fSyncStarted && CanServeBlocks(*peer) && !m_chainman.m_blockman.LoadingBlocks()) { |
5420 | 5415 | // Only actively request headers from a single peer, unless we're close to today. |
5421 | 5416 | if ((nSyncStarted == 0 && sync_blocks_and_headers_from_peer) || m_chainman.m_best_header->Time() > GetAdjustedTime() - 24h) { |
5422 | 5417 | const CBlockIndex* pindexStart = m_chainman.m_best_header; |
|
0 commit comments