diff --git a/src/net.h b/src/net.h --- a/src/net.h +++ b/src/net.h @@ -1125,20 +1125,21 @@ } } - void PushInventory(const CInv &inv) { - if (inv.type == MSG_TX && m_tx_relay != nullptr) { - const TxId txid(inv.hash); - LOCK(m_tx_relay->cs_tx_inventory); - if (!m_tx_relay->filterInventoryKnown.contains(txid)) { - m_tx_relay->setInventoryTxToSend.insert(txid); - } - } else if (inv.type == MSG_BLOCK) { - const BlockHash hash(inv.hash); - LOCK(cs_inventory); - vInventoryBlockToSend.push_back(hash); + void PushTxInventory(const TxId &txid) { + if (m_tx_relay == nullptr) { + return; + } + LOCK(m_tx_relay->cs_tx_inventory); + if (!m_tx_relay->filterInventoryKnown.contains(txid)) { + m_tx_relay->setInventoryTxToSend.insert(txid); } } + void PushBlockInventory(const BlockHash &blockhash) { + LOCK(cs_inventory); + vInventoryBlockToSend.push_back(blockhash); + } + void PushBlockHash(const BlockHash &hash) { LOCK(cs_inventory); vBlockHashesToAnnounce.push_back(hash); diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1748,8 +1748,8 @@ } void RelayTransaction(const TxId &txid, const CConnman &connman) { - CInv inv(MSG_TX, txid); - connman.ForEachNode([&inv](CNode *pnode) { pnode->PushInventory(inv); }); + connman.ForEachNode( + [&txid](CNode *pnode) { pnode->PushTxInventory(txid); }); } static void RelayAddress(const CAddress &addr, bool fReachable, @@ -1959,9 +1959,9 @@ // Trigger the peer node to send a getblocks request for the next batch // of inventory. if (hash == pfrom.hashContinue) { - // Bypass PushInventory, this must send even if redundant, and we - // want it right after the last block so they don't wait for other - // stuff first. + // Bypass PushBlockInventory, 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 vInv; vInv.push_back( CInv(MSG_BLOCK, ::ChainActive().Tip()->GetBlockHash())); @@ -3181,7 +3181,7 @@ pindex->nHeight, pindex->GetBlockHash().ToString()); break; } - pfrom.PushInventory(CInv(MSG_BLOCK, pindex->GetBlockHash())); + pfrom.PushBlockInventory(pindex->GetBlockHash()); 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. @@ -5079,7 +5079,7 @@ // If the peer's chain has this block, don't inv it back. if (!PeerHasHeader(&state, pindex)) { - pto->PushInventory(CInv(MSG_BLOCK, hashToAnnounce)); + pto->PushBlockInventory(hashToAnnounce); LogPrint(BCLog::NET, "%s: sending inv peer=%d hash=%s\n", __func__, pto->GetId(), hashToAnnounce.ToString());