aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorJohn Newbery <john@johnnewbery.com>2020-12-19 10:27:24 +0000
committerJohn Newbery <john@johnnewbery.com>2020-12-20 10:06:14 +0000
commit3002b4af2b4fde63026f8f7c575452a5c989c662 (patch)
treec4e3cae21eacc9b19254ba361379c594efcb0000 /src/net_processing.cpp
parent184557e8e03f76ff18dacdb32c12692d8578691f (diff)
downloadbitcoin-3002b4af2b4fde63026f8f7c575452a5c989c662.tar.xz
[net processing] Guard m_continuation_block with m_block_inv_mutex
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 4b0bc2bcd2..4b9688d517 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1615,15 +1615,18 @@ void static ProcessGetBlockData(CNode& pfrom, Peer& peer, const CChainParams& ch
}
}
- // Trigger the peer node to send a getblocks request for the next batch of inventory
- if (inv.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<CInv> vInv;
- vInv.push_back(CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
- connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
- peer.m_continuation_block.SetNull();
+ {
+ LOCK(peer.m_block_inv_mutex);
+ // Trigger the peer node to send a getblocks request for the next batch of inventory
+ if (inv.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<CInv> vInv;
+ vInv.push_back(CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash()));
+ connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::INV, vInv));
+ peer.m_continuation_block.SetNull();
+ }
}
}
}
@@ -2799,12 +2802,11 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
break;
}
WITH_LOCK(peer->m_block_inv_mutex, peer->m_blocks_for_inv_relay.push_back(pindex->GetBlockHash()));
- if (--nLimit <= 0)
- {
+ if (--nLimit <= 0) {
// When this block is requested, we'll send an inv that'll
// 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;
}
}