mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
Merge 9a288430df into merged_master (Bitcoin PR bitcoin/bitcoin#26900)
This commit is contained in:
commit
5b2b315520
9 changed files with 53 additions and 45 deletions
|
|
@ -53,9 +53,6 @@
|
|||
|
||||
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;
|
||||
|
|
@ -1743,8 +1740,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);
|
||||
|
|
@ -3749,7 +3745,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
|
||||
|
|
@ -3882,8 +3878,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// If pruning, don't inv blocks unless we have on disk and are likely to still have
|
||||
// for some reasonable time window (1 hour) that block relay might require.
|
||||
const int nPrunedBlocksLikelyToHave = MIN_BLOCKS_TO_KEEP - 3600 / m_chainparams.GetConsensus().nPowTargetSpacing;
|
||||
if (fPruneMode && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= m_chainman.ActiveChain().Tip()->nHeight - nPrunedBlocksLikelyToHave))
|
||||
{
|
||||
if (m_chainman.m_blockman.IsPruneMode() && (!(pindex->nStatus & BLOCK_HAVE_DATA) || pindex->nHeight <= m_chainman.ActiveChain().Tip()->nHeight - nPrunedBlocksLikelyToHave)) {
|
||||
LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
break;
|
||||
}
|
||||
|
|
@ -3959,7 +3954,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;
|
||||
}
|
||||
|
|
@ -4246,7 +4241,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;
|
||||
}
|
||||
|
|
@ -4468,7 +4463,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;
|
||||
}
|
||||
|
|
@ -4543,7 +4538,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;
|
||||
}
|
||||
|
|
@ -4588,7 +4583,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;
|
||||
}
|
||||
|
|
@ -5175,7 +5170,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);
|
||||
|
|
@ -5485,7 +5480,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
int64_t headers_ahead = m_chainman.m_best_header->nHeight - m_chainman.ActiveHeight();
|
||||
// ELEMENTS: Only download if our headers aren't "too far ahead" of our blocks.
|
||||
bool got_enough_headers = node::fTrimHeaders && (headers_ahead >= node::nHeaderDownloadBuffer);
|
||||
if (!state.fSyncStarted && CanServeBlocks(*peer) && !fImporting && !fReindex && !got_enough_headers) {
|
||||
if (!state.fSyncStarted && CanServeBlocks(*peer) && !m_chainman.m_blockman.LoadingBlocks() && !got_enough_headers) {
|
||||
// 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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue