@@ -1315,13 +1315,17 @@ void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInde
1315
1315
}
1316
1316
}
1317
1317
1318
- // Relay to all peers
1319
- m_connman.ForEachNode ([&vHashes](CNode* pnode) {
1320
- LOCK (pnode->cs_inventory );
1321
- for (const uint256& hash : reverse_iterate (vHashes)) {
1322
- pnode->vBlockHashesToAnnounce .push_back (hash);
1318
+ {
1319
+ LOCK (m_peer_mutex);
1320
+ for (auto & it : m_peer_map) {
1321
+ Peer& peer = *it.second ;
1322
+ LOCK (peer.m_block_inv_mutex );
1323
+ for (const uint256& hash : reverse_iterate (vHashes)) {
1324
+ peer.vBlockHashesToAnnounce .push_back (hash);
1325
+ }
1323
1326
}
1324
- });
1327
+ }
1328
+
1325
1329
m_connman.WakeMessageHandler ();
1326
1330
}
1327
1331
@@ -2795,7 +2799,7 @@ void PeerManager::ProcessMessage(CNode& pfrom, const std::string& msg_type, CDat
2795
2799
LogPrint (BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n " , pindex->nHeight , pindex->GetBlockHash ().ToString ());
2796
2800
break ;
2797
2801
}
2798
- WITH_LOCK (pfrom. cs_inventory , pfrom. vInventoryBlockToSend .push_back (pindex->GetBlockHash ()));
2802
+ WITH_LOCK (peer-> m_block_inv_mutex , peer-> vInventoryBlockToSend .push_back (pindex->GetBlockHash ()));
2799
2803
if (--nLimit <= 0 )
2800
2804
{
2801
2805
// When this block is requested, we'll send an inv that'll
@@ -4218,11 +4222,11 @@ bool PeerManager::SendMessages(CNode* pto)
4218
4222
// If no header would connect, or if we have too many
4219
4223
// blocks, or if the peer doesn't want headers, just
4220
4224
// add all to the inv queue.
4221
- LOCK (pto-> cs_inventory );
4225
+ LOCK (peer-> m_block_inv_mutex );
4222
4226
std::vector<CBlock> vHeaders;
4223
4227
bool fRevertToInv = ((!state.fPreferHeaders &&
4224
- (!state.fPreferHeaderAndIDs || pto ->vBlockHashesToAnnounce .size () > 1 )) ||
4225
- pto ->vBlockHashesToAnnounce .size () > MAX_BLOCKS_TO_ANNOUNCE);
4228
+ (!state.fPreferHeaderAndIDs || peer ->vBlockHashesToAnnounce .size () > 1 )) ||
4229
+ peer ->vBlockHashesToAnnounce .size () > MAX_BLOCKS_TO_ANNOUNCE);
4226
4230
const CBlockIndex *pBestIndex = nullptr ; // last header queued for delivery
4227
4231
ProcessBlockAvailability (pto->GetId ()); // ensure pindexBestKnownBlock is up-to-date
4228
4232
@@ -4231,7 +4235,7 @@ bool PeerManager::SendMessages(CNode* pto)
4231
4235
// Try to find first header that our peer doesn't have, and
4232
4236
// then send all headers past that one. If we come across any
4233
4237
// headers that aren't on ::ChainActive(), give up.
4234
- for (const uint256 & hash : pto ->vBlockHashesToAnnounce ) {
4238
+ for (const uint256& hash : peer ->vBlockHashesToAnnounce ) {
4235
4239
const CBlockIndex* pindex = LookupBlockIndex (hash);
4236
4240
assert (pindex);
4237
4241
if (::ChainActive ()[pindex->nHeight ] != pindex) {
@@ -4322,8 +4326,8 @@ bool PeerManager::SendMessages(CNode* pto)
4322
4326
// If falling back to using an inv, just try to inv the tip.
4323
4327
// The last entry in vBlockHashesToAnnounce was our tip at some point
4324
4328
// in the past.
4325
- if (!pto ->vBlockHashesToAnnounce .empty ()) {
4326
- const uint256 & hashToAnnounce = pto ->vBlockHashesToAnnounce .back ();
4329
+ if (!peer ->vBlockHashesToAnnounce .empty ()) {
4330
+ const uint256& hashToAnnounce = peer ->vBlockHashesToAnnounce .back ();
4327
4331
const CBlockIndex* pindex = LookupBlockIndex (hashToAnnounce);
4328
4332
assert (pindex);
4329
4333
@@ -4337,32 +4341,32 @@ bool PeerManager::SendMessages(CNode* pto)
4337
4341
4338
4342
// If the peer's chain has this block, don't inv it back.
4339
4343
if (!PeerHasHeader (&state, pindex)) {
4340
- pto ->vInventoryBlockToSend .push_back (hashToAnnounce);
4344
+ peer ->vInventoryBlockToSend .push_back (hashToAnnounce);
4341
4345
LogPrint (BCLog::NET, " %s: sending inv peer=%d hash=%s\n " , __func__,
4342
4346
pto->GetId (), hashToAnnounce.ToString ());
4343
4347
}
4344
4348
}
4345
4349
}
4346
- pto ->vBlockHashesToAnnounce .clear ();
4350
+ peer ->vBlockHashesToAnnounce .clear ();
4347
4351
}
4348
4352
4349
4353
//
4350
4354
// Message: inventory
4351
4355
//
4352
4356
std::vector<CInv> vInv;
4353
4357
{
4354
- LOCK (pto-> cs_inventory );
4355
- vInv.reserve (std::max<size_t >(pto ->vInventoryBlockToSend .size (), INVENTORY_BROADCAST_MAX));
4358
+ LOCK (peer-> m_block_inv_mutex );
4359
+ vInv.reserve (std::max<size_t >(peer ->vInventoryBlockToSend .size (), INVENTORY_BROADCAST_MAX));
4356
4360
4357
4361
// Add blocks
4358
- for (const uint256& hash : pto ->vInventoryBlockToSend ) {
4362
+ for (const uint256& hash : peer ->vInventoryBlockToSend ) {
4359
4363
vInv.push_back (CInv (MSG_BLOCK, hash));
4360
4364
if (vInv.size () == MAX_INV_SZ) {
4361
4365
m_connman.PushMessage (pto, msgMaker.Make (NetMsgType::INV, vInv));
4362
4366
vInv.clear ();
4363
4367
}
4364
4368
}
4365
- pto ->vInventoryBlockToSend .clear ();
4369
+ peer ->vInventoryBlockToSend .clear ();
4366
4370
4367
4371
if (pto->m_tx_relay != nullptr ) {
4368
4372
LOCK (pto->m_tx_relay ->cs_tx_inventory );
0 commit comments