From 911dcc372e72583cf5c8457ca3e9d62dd7de7959 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Thu, 12 Aug 2021 19:50:13 +0100 Subject: [PATCH] ProcessGetData(): Rework IsExpiringSoon check This brings the code more closely in line with upstream, and prepares for subsequent performance improvements. --- src/main.cpp | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d0bae9de7..31794b904 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6132,32 +6132,21 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } else if (inv.IsKnownType()) { - // Check the mempool to see if a transaction is expiring soon. If so, do not send to peer. - // Note that a transaction enters the mempool first, before the serialized form is cached - // in mapRelay after a successful relay. - bool isExpiringSoon = false; + // Send stream from relay memory bool pushed = false; - CTransaction tx; - bool isInMempool = mempool.lookup(inv.hash, tx); - if (isInMempool) { - isExpiringSoon = IsExpiringSoonTx(tx, currentHeight + 1); - } - - if (!isExpiringSoon) { - // Send stream from relay memory - { - LOCK(cs_mapRelay); - map::iterator mi = mapRelay.find(inv.hash); - if (mi != mapRelay.end()) { - pfrom->PushMessage(inv.GetCommand(), (*mi).second); - pushed = true; - } + { + LOCK(cs_mapRelay); + map::iterator mi = mapRelay.find(inv.hash); + if (mi != mapRelay.end() && !IsExpiringSoonTx((*mi).second, currentHeight + 1)) { + pfrom->PushMessage(inv.GetCommand(), (*mi).second); + pushed = true; } - if (!pushed && inv.type == MSG_TX) { - if (isInMempool) { - pfrom->PushMessage("tx", tx); - pushed = true; - } + } + if (!pushed && inv.type == MSG_TX) { + CTransaction tx; + if (mempool.lookup(inv.hash, tx) && !IsExpiringSoonTx(tx, currentHeight + 1)) { + pfrom->PushMessage("tx", tx); + pushed = true; } }