ProcessGetData(): Rework IsExpiringSoon check

This brings the code more closely in line with upstream, and prepares
for subsequent performance improvements.
This commit is contained in:
Jack Grigg 2021-08-12 19:50:13 +01:00
parent fd462fd8c4
commit 911dcc372e
1 changed files with 13 additions and 24 deletions

View File

@ -6132,32 +6132,21 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
} }
else if (inv.IsKnownType()) else if (inv.IsKnownType())
{ {
// Check the mempool to see if a transaction is expiring soon. If so, do not send to peer. // Send stream from relay memory
// Note that a transaction enters the mempool first, before the serialized form is cached
// in mapRelay after a successful relay.
bool isExpiringSoon = false;
bool pushed = false; bool pushed = false;
CTransaction tx; {
bool isInMempool = mempool.lookup(inv.hash, tx); LOCK(cs_mapRelay);
if (isInMempool) { map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
isExpiringSoon = IsExpiringSoonTx(tx, currentHeight + 1); if (mi != mapRelay.end() && !IsExpiringSoonTx((*mi).second, currentHeight + 1)) {
} pfrom->PushMessage(inv.GetCommand(), (*mi).second);
pushed = true;
if (!isExpiringSoon) {
// Send stream from relay memory
{
LOCK(cs_mapRelay);
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
if (mi != mapRelay.end()) {
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
pushed = true;
}
} }
if (!pushed && inv.type == MSG_TX) { }
if (isInMempool) { if (!pushed && inv.type == MSG_TX) {
pfrom->PushMessage("tx", tx); CTransaction tx;
pushed = true; if (mempool.lookup(inv.hash, tx) && !IsExpiringSoonTx(tx, currentHeight + 1)) {
} pfrom->PushMessage("tx", tx);
pushed = true;
} }
} }