@@ -1722,13 +1722,17 @@ void PeerManager::UpdatedBlockTip(const CBlockIndex *pindexNew,
1722
1722
}
1723
1723
}
1724
1724
1725
- // Relay to all peers
1726
- m_connman.ForEachNode ([&vHashes](CNode *pnode) {
1727
- LOCK (pnode->cs_inventory );
1728
- for (const BlockHash &hash : reverse_iterate (vHashes)) {
1729
- pnode->vBlockHashesToAnnounce .push_back (hash);
1725
+ {
1726
+ LOCK (m_peer_mutex);
1727
+ for (auto &it : m_peer_map) {
1728
+ Peer &peer = *it.second ;
1729
+ LOCK (peer.m_block_inv_mutex );
1730
+ for (const BlockHash &hash : reverse_iterate (vHashes)) {
1731
+ peer.vBlockHashesToAnnounce .push_back (hash);
1732
+ }
1730
1733
}
1731
- });
1734
+ }
1735
+
1732
1736
m_connman.WakeMessageHandler ();
1733
1737
}
1734
1738
@@ -3519,8 +3523,9 @@ void PeerManager::ProcessMessage(const Config &config, CNode &pfrom,
3519
3523
pindex->nHeight , pindex->GetBlockHash ().ToString ());
3520
3524
break ;
3521
3525
}
3522
- WITH_LOCK (pfrom.cs_inventory , pfrom.vInventoryBlockToSend .push_back (
3523
- pindex->GetBlockHash ()));
3526
+ WITH_LOCK (
3527
+ peer->m_block_inv_mutex ,
3528
+ peer->vInventoryBlockToSend .push_back (pindex->GetBlockHash ()));
3524
3529
if (--nLimit <= 0 ) {
3525
3530
// When this block is requested, we'll send an inv that'll
3526
3531
// trigger the peer to getblocks the next batch of inventory.
@@ -5382,13 +5387,13 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
5382
5387
// connect, and send. If no header would connect, or if we have too
5383
5388
// many blocks, or if the peer doesn't want headers, just add all to
5384
5389
// the inv queue.
5385
- LOCK (pto-> cs_inventory );
5390
+ LOCK (peer-> m_block_inv_mutex );
5386
5391
std::vector<CBlock> vHeaders;
5387
5392
bool fRevertToInv =
5388
5393
((!state.fPreferHeaders &&
5389
5394
(!state.fPreferHeaderAndIDs ||
5390
- pto ->vBlockHashesToAnnounce .size () > 1 )) ||
5391
- pto ->vBlockHashesToAnnounce .size () > MAX_BLOCKS_TO_ANNOUNCE);
5395
+ peer ->vBlockHashesToAnnounce .size () > 1 )) ||
5396
+ peer ->vBlockHashesToAnnounce .size () > MAX_BLOCKS_TO_ANNOUNCE);
5392
5397
// last header queued for delivery
5393
5398
const CBlockIndex *pBestIndex = nullptr ;
5394
5399
// ensure pindexBestKnownBlock is up-to-date
@@ -5399,7 +5404,7 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
5399
5404
// Try to find first header that our peer doesn't have, and then
5400
5405
// send all headers past that one. If we come across an headers
5401
5406
// that aren't on ::ChainActive(), give up.
5402
- for (const BlockHash &hash : pto ->vBlockHashesToAnnounce ) {
5407
+ for (const BlockHash &hash : peer ->vBlockHashesToAnnounce ) {
5403
5408
const CBlockIndex *pindex = LookupBlockIndex (hash);
5404
5409
assert (pindex);
5405
5410
if (::ChainActive ()[pindex->nHeight ] != pindex) {
@@ -5505,9 +5510,9 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
5505
5510
// If falling back to using an inv, just try to inv the tip. The
5506
5511
// last entry in vBlockHashesToAnnounce was our tip at some
5507
5512
// point in the past.
5508
- if (!pto ->vBlockHashesToAnnounce .empty ()) {
5513
+ if (!peer ->vBlockHashesToAnnounce .empty ()) {
5509
5514
const BlockHash &hashToAnnounce =
5510
- pto ->vBlockHashesToAnnounce .back ();
5515
+ peer ->vBlockHashesToAnnounce .back ();
5511
5516
const CBlockIndex *pindex =
5512
5517
LookupBlockIndex (hashToAnnounce);
5513
5518
assert (pindex);
@@ -5525,14 +5530,14 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
5525
5530
5526
5531
// If the peer's chain has this block, don't inv it back.
5527
5532
if (!PeerHasHeader (&state, pindex)) {
5528
- pto ->vInventoryBlockToSend .push_back (hashToAnnounce);
5533
+ peer ->vInventoryBlockToSend .push_back (hashToAnnounce);
5529
5534
LogPrint (BCLog::NET,
5530
5535
" %s: sending inv peer=%d hash=%s\n " , __func__,
5531
5536
pto->GetId (), hashToAnnounce.ToString ());
5532
5537
}
5533
5538
}
5534
5539
}
5535
- pto ->vBlockHashesToAnnounce .clear ();
5540
+ peer ->vBlockHashesToAnnounce .clear ();
5536
5541
}
5537
5542
} // release cs_main
5538
5543
@@ -5550,17 +5555,17 @@ bool PeerManager::SendMessages(const Config &config, CNode *pto,
5550
5555
};
5551
5556
5552
5557
{
5553
- LOCK2 (cs_main, pto-> cs_inventory );
5558
+ LOCK2 (cs_main, peer-> m_block_inv_mutex );
5554
5559
5555
- vInv.reserve (std::max<size_t >(pto ->vInventoryBlockToSend .size (),
5560
+ vInv.reserve (std::max<size_t >(peer ->vInventoryBlockToSend .size (),
5556
5561
INVENTORY_BROADCAST_MAX_PER_MB *
5557
5562
config.GetMaxBlockSize () / 1000000 ));
5558
5563
5559
5564
// Add blocks
5560
- for (const BlockHash &hash : pto ->vInventoryBlockToSend ) {
5565
+ for (const BlockHash &hash : peer ->vInventoryBlockToSend ) {
5561
5566
addInvAndMaybeFlush (MSG_BLOCK, hash);
5562
5567
}
5563
- pto ->vInventoryBlockToSend .clear ();
5568
+ peer ->vInventoryBlockToSend .clear ();
5564
5569
5565
5570
auto computeNextInvSendTime =
5566
5571
[&](std::chrono::microseconds &next) -> bool {
0 commit comments