[net] split PushInventory()

PushInventory() is currently called with a CInv object, which can be a
MSG_TX or MSG_BLOCK. PushInventory() only uses the type to determine
whether to add the hash to setInventoryTxToSend or
vInventoryBlockToSend.

Since the caller always knows what type of inventory they're pushing,
the CInv is wastefully constructed and thrown away, and tx/block relay
is being split out, we split the function into PushTxInventory() and
PushBlockInventory().
This commit is contained in:
John Newbery
2020-06-18 15:19:12 -04:00
parent c2bcb99c1d
commit f52d403b81
2 changed files with 16 additions and 15 deletions

View File

@@ -973,19 +973,21 @@ public:
}
}
void PushInventory(const CInv& inv)
void PushTxInventory(const uint256& hash)
{
if (inv.type == MSG_TX && m_tx_relay != nullptr) {
LOCK(m_tx_relay->cs_tx_inventory);
if (!m_tx_relay->filterInventoryKnown.contains(inv.hash)) {
m_tx_relay->setInventoryTxToSend.insert(inv.hash);
}
} else if (inv.type == MSG_BLOCK) {
LOCK(cs_inventory);
vInventoryBlockToSend.push_back(inv.hash);
if (m_tx_relay == nullptr) return;
LOCK(m_tx_relay->cs_tx_inventory);
if (!m_tx_relay->filterInventoryKnown.contains(hash)) {
m_tx_relay->setInventoryTxToSend.insert(hash);
}
}
void PushBlockInventory(const uint256& hash)
{
LOCK(cs_inventory);
vInventoryBlockToSend.push_back(hash);
}
void PushBlockHash(const uint256 &hash)
{
LOCK(cs_inventory);