diff --git a/src/net_processing.h b/src/net_processing.h --- a/src/net_processing.h +++ b/src/net_processing.h @@ -91,15 +91,16 @@ std::vector m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex); - /** This peer's reported block height when we connected */ - std::atomic m_starting_height{-1}; /** * The final block hash that we sent in an `inv` message to this peer. * When the peer requests this block, we send an `inv` message to trigger * the peer to request the next sequence of block hashes. * Most peers use headers-first syncing, which doesn't use this mechanism */ - BlockHash m_continuation_block{}; + BlockHash m_continuation_block GUARDED_BY(m_block_inv_mutex){}; + + /** This peer's reported block height when we connected */ + std::atomic m_starting_height{-1}; /** * Set of txids to reconsider once their parent transactions have been diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2055,17 +2055,21 @@ } } - // Trigger the peer node to send a getblocks request for the next batch - // of inventory. - if (hash == peer.m_continuation_block) { - // Send immediately. This must send even if redundant, and - // we want it right after the last block so they don't wait for - // other stuff first. - std::vector vInv; - vInv.push_back( - CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); - connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv)); - peer.m_continuation_block = BlockHash(); + { + LOCK(peer.m_block_inv_mutex); + // Trigger the peer node to send a getblocks request for the next + // batch of inventory. + if (hash == peer.m_continuation_block) { + // Send immediately. This must send even if redundant, and + // we want it right after the last block so they don't wait for + // other stuff first. + std::vector vInv; + vInv.push_back( + CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); + connman.PushMessage(&pfrom, + msgMaker.Make(NetMsgType::INV, vInv)); + peer.m_continuation_block = BlockHash(); + } } } } @@ -3532,7 +3536,9 @@ // trigger the peer to getblocks the next batch of inventory. LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); - peer->m_continuation_block = pindex->GetBlockHash(); + WITH_LOCK(peer->m_block_inv_mutex, { + peer->m_continuation_block = pindex->GetBlockHash(); + }); break; } }