Skip to content

Commit 8196176

Browse files
committed
Rewrite parent txid loop of requested transactions
Previously, we would potentially add the same txid many times to the rolling bloom filter of recently announced transactions to a peer, if many outputs of the same txid appeared as inputs in a transaction. Eliminate this problem and avoid redundant lookups by asking the mempool for the unique parents of a requested transaction.
1 parent 0f16212 commit 8196176

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/net_processing.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,16 +1734,27 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
17341734
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
17351735
mempool.RemoveUnbroadcastTx(tx->GetHash());
17361736
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
1737-
for (const auto& txin : tx->vin) {
1738-
auto txinfo = mempool.info(txin.prevout.hash);
1739-
if (txinfo.tx && txinfo.m_time > now - UNCONDITIONAL_RELAY_DELAY) {
1740-
// Relaying a transaction with a recent but unconfirmed parent.
1741-
if (WITH_LOCK(pfrom.m_tx_relay->cs_tx_inventory, return !pfrom.m_tx_relay->filterInventoryKnown.contains(txin.prevout.hash))) {
1742-
LOCK(cs_main);
1743-
State(pfrom.GetId())->m_recently_announced_invs.insert(txin.prevout.hash);
1737+
std::vector<uint256> parent_ids_to_add;
1738+
{
1739+
LOCK(mempool.cs);
1740+
auto txiter = mempool.GetIter(tx->GetHash());
1741+
if (txiter) {
1742+
const CTxMemPool::setEntries& parents = mempool.GetMemPoolParents(*txiter);
1743+
parent_ids_to_add.reserve(parents.size());
1744+
for (CTxMemPool::txiter parent_iter : parents) {
1745+
if (parent_iter->GetTime() > now - UNCONDITIONAL_RELAY_DELAY) {
1746+
parent_ids_to_add.push_back(parent_iter->GetTx().GetHash());
1747+
}
17441748
}
17451749
}
17461750
}
1751+
for (const uint256& parent_txid : parent_ids_to_add) {
1752+
// Relaying a transaction with a recent but unconfirmed parent.
1753+
if (WITH_LOCK(pfrom.m_tx_relay->cs_tx_inventory, return !pfrom.m_tx_relay->filterInventoryKnown.contains(parent_txid))) {
1754+
LOCK(cs_main);
1755+
State(pfrom.GetId())->m_recently_announced_invs.insert(parent_txid);
1756+
}
1757+
}
17471758
} else {
17481759
vNotFound.push_back(inv);
17491760
}

0 commit comments

Comments
 (0)