Skip to content

Commit 3002b4a

Browse files
committed
[net processing] Guard m_continuation_block with m_block_inv_mutex
1 parent 184557e commit 3002b4a

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,15 +1615,18 @@ void static ProcessGetBlockData(CNode& pfrom, Peer& peer, const CChainParams& ch
16151615
}
16161616
}
16171617

1618-
// Trigger the peer node to send a getblocks request for the next batch of inventory
1619-
if (inv.hash == peer.m_continuation_block) {
1620-
// Send immediately. This must send even if redundant,
1621-
// and we want it right after the last block so they don't
1622-
// wait for other stuff first.
1623-
std::vector<CInv> vInv;
1624-
vInv.push_back(CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
1625-
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
1626-
peer.m_continuation_block.SetNull();
1618+
{
1619+
LOCK(peer.m_block_inv_mutex);
1620+
// Trigger the peer node to send a getblocks request for the next batch of inventory
1621+
if (inv.hash == peer.m_continuation_block) {
1622+
// Send immediately. This must send even if redundant,
1623+
// and we want it right after the last block so they don't
1624+
// wait for other stuff first.
1625+
std::vector<CInv> vInv;
1626+
vInv.push_back(CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
1627+
connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
1628+
peer.m_continuation_block.SetNull();
1629+
}
16271630
}
16281631
}
16291632
}
@@ -2799,12 +2802,11 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
27992802
break;
28002803
}
28012804
WITH_LOCK(peer->m_block_inv_mutex, peer->m_blocks_for_inv_relay.push_back(pindex->GetBlockHash()));
2802-
if (--nLimit <= 0)
2803-
{
2805+
if (--nLimit <= 0) {
28042806
// When this block is requested, we'll send an inv that'll
28052807
// trigger the peer to getblocks the next batch of inventory.
28062808
LogPrint(BCLog::NET, " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
2807-
peer->m_continuation_block = pindex->GetBlockHash();
2809+
WITH_LOCK(peer->m_block_inv_mutex, {peer->m_continuation_block = pindex->GetBlockHash();});
28082810
break;
28092811
}
28102812
}

src/net_processing.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ struct Peer {
7373
* message. If we can't announce via a `headers` message, we'll fall back to
7474
* announcing via `inv`. */
7575
std::vector<uint256> m_blocks_for_headers_relay GUARDED_BY(m_block_inv_mutex);
76-
77-
/** This peer's reported block height when we connected */
78-
std::atomic<int> m_starting_height{-1};
7976
/** The final block hash that we sent in an `inv` message to this peer.
8077
* When the peer requests this block, we send an `inv` message to trigger
8178
* the peer to request the next sequence of block hashes.
8279
* Most peers use headers-first syncing, which doesn't use this mechanism */
83-
uint256 m_continuation_block{};
80+
uint256 m_continuation_block GUARDED_BY(m_block_inv_mutex) {};
81+
82+
/** This peer's reported block height when we connected */
83+
std::atomic<int> m_starting_height{-1};
8484

8585
/** Set of txids to reconsider once their parent transactions have been accepted **/
8686
std::set<uint256> m_orphan_work_set GUARDED_BY(g_cs_orphans);

0 commit comments

Comments
 (0)