aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2020-07-26 23:25:27 -0400
committerSuhas Daftuar <sdaftuar@gmail.com>2020-08-04 13:59:11 -0400
commit81961762439fb72fc2ef168164689ddc29d7ef94 (patch)
treef9c8f801ce4e1652a88dab1e9aed982051303206 /src
parent0f16212c5931b30f430014caa485de53f9a14920 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/net_processing.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index c503a97be5..b52427d84b 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1734,16 +1734,27 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
connman.PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
mempool.RemoveUnbroadcastTx(tx->GetHash());
// As we're going to send tx, make sure its unconfirmed parents are made requestable.
- for (const auto& txin : tx->vin) {
- auto txinfo = mempool.info(txin.prevout.hash);
- if (txinfo.tx && txinfo.m_time > now - UNCONDITIONAL_RELAY_DELAY) {
- // Relaying a transaction with a recent but unconfirmed parent.
- if (WITH_LOCK(pfrom.m_tx_relay->cs_tx_inventory, return !pfrom.m_tx_relay->filterInventoryKnown.contains(txin.prevout.hash))) {
- LOCK(cs_main);
- State(pfrom.GetId())->m_recently_announced_invs.insert(txin.prevout.hash);
+ std::vector<uint256> parent_ids_to_add;
+ {
+ LOCK(mempool.cs);
+ auto txiter = mempool.GetIter(tx->GetHash());
+ if (txiter) {
+ const CTxMemPool::setEntries& parents = mempool.GetMemPoolParents(*txiter);
+ parent_ids_to_add.reserve(parents.size());
+ for (CTxMemPool::txiter parent_iter : parents) {
+ if (parent_iter->GetTime() > now - UNCONDITIONAL_RELAY_DELAY) {
+ parent_ids_to_add.push_back(parent_iter->GetTx().GetHash());
+ }
}
}
}
+ for (const uint256& parent_txid : parent_ids_to_add) {
+ // Relaying a transaction with a recent but unconfirmed parent.
+ if (WITH_LOCK(pfrom.m_tx_relay->cs_tx_inventory, return !pfrom.m_tx_relay->filterInventoryKnown.contains(parent_txid))) {
+ LOCK(cs_main);
+ State(pfrom.GetId())->m_recently_announced_invs.insert(parent_txid);
+ }
+ }
} else {
vNotFound.push_back(inv);
}