[net processing] Move fPreferHeaders from CNodeState to Peer

This commit is contained in:
dergoegge committed 2023-03-30 14:56:19 +02:00
1 parent 3605011e79
commit 8a2cb1f749
1 file changed
+6 -6
+6 -6
View File
@@ -391,6 +391,9 @@ struct Peer {
/** When to potentially disconnect peer for stalling headers download */ /** When to potentially disconnect peer for stalling headers download */
std::chrono::microseconds m_headers_sync_timeout GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0us}; std::chrono::microseconds m_headers_sync_timeout GUARDED_BY(NetEventsInterface::g_msgproc_mutex){0us};
/** Whether this peer wants invs or headers (when possible) for block announcements */
bool fPreferHeaders GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
explicit Peer(NodeId id, ServiceFlags our_services) explicit Peer(NodeId id, ServiceFlags our_services)
: m_id{id} : m_id{id}
, m_our_services{our_services} , m_our_services{our_services}
@@ -430,8 +433,6 @@ struct CNodeState {
int nBlocksInFlight{0}; int nBlocksInFlight{0};
//! Whether we consider this a preferred download peer. //! Whether we consider this a preferred download peer.
bool fPreferredDownload{false}; bool fPreferredDownload{false};
//! Whether this peer wants invs or headers (when possible) for block announcements.
bool fPreferHeaders GUARDED_BY(NetEventsInterface::g_msgproc_mutex){false};
/** Whether this peer wants invs or cmpctblocks (when possible) for block announcements. */ /** Whether this peer wants invs or cmpctblocks (when possible) for block announcements. */
bool m_requested_hb_cmpctblocks{false}; bool m_requested_hb_cmpctblocks{false};
/** Whether this peer will send us cmpctblocks if we request them. */ /** Whether this peer will send us cmpctblocks if we request them. */
@@ -3447,8 +3448,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
} }
if (msg_type == NetMsgType::SENDHEADERS) { if (msg_type == NetMsgType::SENDHEADERS) {
LOCK(cs_main); peer->fPreferHeaders = true;
State(pfrom.GetId())->fPreferHeaders = true;
return; return;
} }
@@ -5454,7 +5454,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
// add all to the inv queue. // add all to the inv queue.
LOCK(peer->m_block_inv_mutex); LOCK(peer->m_block_inv_mutex);
std::vector<CBlock> vHeaders; std::vector<CBlock> vHeaders;
bool fRevertToInv = ((!state.fPreferHeaders && bool fRevertToInv = ((!peer->fPreferHeaders &&
(!state.m_requested_hb_cmpctblocks || peer->m_blocks_for_headers_relay.size() > 1)) || (!state.m_requested_hb_cmpctblocks || peer->m_blocks_for_headers_relay.size() > 1)) ||
peer->m_blocks_for_headers_relay.size() > MAX_BLOCKS_TO_ANNOUNCE); peer->m_blocks_for_headers_relay.size() > MAX_BLOCKS_TO_ANNOUNCE);
const CBlockIndex *pBestIndex = nullptr; // last header queued for delivery const CBlockIndex *pBestIndex = nullptr; // last header queued for delivery
@@ -5531,7 +5531,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock)); m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::CMPCTBLOCK, cmpctblock));
} }
state.pindexBestHeaderSent = pBestIndex; state.pindexBestHeaderSent = pBestIndex;
} else if (state.fPreferHeaders) { } else if (peer->fPreferHeaders) {
if (vHeaders.size() > 1) { if (vHeaders.size() > 1) {
LogPrint(BCLog::NET, "%s: %u headers, range (%s, %s), to peer=%d\n", __func__, LogPrint(BCLog::NET, "%s: %u headers, range (%s, %s), to peer=%d\n", __func__,
vHeaders.size(), vHeaders.size(),