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:
parent
fd462fd8c4
commit
911dcc372e
19
src/main.cpp
19
src/main.cpp
|
@ -6132,34 +6132,23 @@ 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.
|
|
||||||
// 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;
|
|
||||||
CTransaction tx;
|
|
||||||
bool isInMempool = mempool.lookup(inv.hash, tx);
|
|
||||||
if (isInMempool) {
|
|
||||||
isExpiringSoon = IsExpiringSoonTx(tx, currentHeight + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isExpiringSoon) {
|
|
||||||
// Send stream from relay memory
|
// Send stream from relay memory
|
||||||
|
bool pushed = false;
|
||||||
{
|
{
|
||||||
LOCK(cs_mapRelay);
|
LOCK(cs_mapRelay);
|
||||||
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
|
map<uint256, CTransaction>::iterator mi = mapRelay.find(inv.hash);
|
||||||
if (mi != mapRelay.end()) {
|
if (mi != mapRelay.end() && !IsExpiringSoonTx((*mi).second, currentHeight + 1)) {
|
||||||
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
|
pfrom->PushMessage(inv.GetCommand(), (*mi).second);
|
||||||
pushed = true;
|
pushed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!pushed && inv.type == MSG_TX) {
|
if (!pushed && inv.type == MSG_TX) {
|
||||||
if (isInMempool) {
|
CTransaction tx;
|
||||||
|
if (mempool.lookup(inv.hash, tx) && !IsExpiringSoonTx(tx, currentHeight + 1)) {
|
||||||
pfrom->PushMessage("tx", tx);
|
pfrom->PushMessage("tx", tx);
|
||||||
pushed = true;
|
pushed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!pushed) {
|
if (!pushed) {
|
||||||
vNotFound.push_back(inv);
|
vNotFound.push_back(inv);
|
||||||
|
|
Loading…
Reference in New Issue