Skip to content

Commit 344e831

Browse files
committed
[net processing] Remove PushBlockInventory and PushBlockHash
PushBlockInventory() and PushBlockHash() are functions that can be replaced with single-line statements. This also eliminates the single place that cs_inventory is taken recursively.
1 parent 879acc6 commit 344e831

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

src/net.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -982,18 +982,6 @@ class CNode
982982
}
983983
}
984984

985-
void PushBlockInventory(const uint256& hash)
986-
{
987-
LOCK(cs_inventory);
988-
vInventoryBlockToSend.push_back(hash);
989-
}
990-
991-
void PushBlockHash(const uint256 &hash)
992-
{
993-
LOCK(cs_inventory);
994-
vBlockHashesToAnnounce.push_back(hash);
995-
}
996-
997985
void CloseSocketDisconnect();
998986

999987
void copyStats(CNodeStats &stats, const std::vector<bool> &m_asmap);

src/net_processing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,9 +1328,10 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
13281328
}
13291329
// Relay inventory, but don't relay old inventory during initial block download.
13301330
connman->ForEachNode([nNewHeight, &vHashes](CNode* pnode) {
1331+
LOCK(pnode->cs_inventory);
13311332
if (nNewHeight > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : 0)) {
13321333
for (const uint256& hash : reverse_iterate(vHashes)) {
1333-
pnode->PushBlockHash(hash);
1334+
pnode->vBlockHashesToAnnounce.push_back(hash);
13341335
}
13351336
}
13361337
});
@@ -1607,7 +1608,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
16071608
// Trigger the peer node to send a getblocks request for the next batch of inventory
16081609
if (inv.hash == pfrom.hashContinue)
16091610
{
1610-
// Bypass PushBlockInventory, this must send even if redundant,
1611+
// Send immediately. This must send even if redundant,
16111612
// and we want it right after the last block so they don't
16121613
// wait for other stuff first.
16131614
std::vector<CInv> vInv;
@@ -2666,7 +2667,7 @@ void ProcessMessage(
26662667
LogPrint(BCLog::NET, " getblocks stopping, pruned or too old block at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
26672668
break;
26682669
}
2669-
pfrom.PushBlockInventory(pindex->GetBlockHash());
2670+
WITH_LOCK(pfrom.cs_inventory, pfrom.vInventoryBlockToSend.push_back(pindex->GetBlockHash()));
26702671
if (--nLimit <= 0)
26712672
{
26722673
// When this block is requested, we'll send an inv that'll
@@ -4083,7 +4084,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
40834084

40844085
// If the peer's chain has this block, don't inv it back.
40854086
if (!PeerHasHeader(&state, pindex)) {
4086-
pto->PushBlockInventory(hashToAnnounce);
4087+
pto->vInventoryBlockToSend.push_back(hashToAnnounce);
40874088
LogPrint(BCLog::NET, "%s: sending inv peer=%d hash=%s\n", __func__,
40884089
pto->GetId(), hashToAnnounce.ToString());
40894090
}

0 commit comments

Comments
 (0)