39
39
static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60 ;
40
40
/* * Minimum time between orphan transactions expire time checks in seconds */
41
41
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 ;
42
+ /* * How long to cache transactions in mapRelay for normal relay */
43
+ static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME{15 * 60 };
42
44
/* * Headers download timeout expressed in microseconds
43
45
* Timeout = base + per_header * (expected number of headers) */
44
46
static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000 ; // 15 minutes
@@ -1522,6 +1524,10 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
1522
1524
// messages from this peer (likely resulting in our peer eventually
1523
1525
// disconnecting us).
1524
1526
if (pfrom->m_tx_relay != nullptr ) {
1527
+ // mempool entries added before this time have likely expired from mapRelay
1528
+ const std::chrono::seconds longlived_mempool_time = GetTime<std::chrono::seconds>() - RELAY_TX_CACHE_TIME;
1529
+ const std::chrono::seconds mempool_req = pfrom->m_tx_relay ->m_last_mempool_req .load ();
1530
+
1525
1531
LOCK (cs_main);
1526
1532
1527
1533
while (it != pfrom->vRecvGetData .end () && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
@@ -1541,11 +1547,15 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
1541
1547
if (mi != mapRelay.end ()) {
1542
1548
connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *mi->second ));
1543
1549
push = true ;
1544
- } else if (pfrom-> m_tx_relay -> m_last_mempool_req . load (). count ()) {
1550
+ } else {
1545
1551
auto txinfo = mempool.info (inv.hash );
1546
1552
// To protect privacy, do not answer getdata using the mempool when
1547
- // that TX couldn't have been INVed in reply to a MEMPOOL request.
1548
- if (txinfo.tx && txinfo.m_time <= pfrom->m_tx_relay ->m_last_mempool_req .load ()) {
1553
+ // that TX couldn't have been INVed in reply to a MEMPOOL request,
1554
+ // or when it's too recent to have expired from mapRelay.
1555
+ if (txinfo.tx && (
1556
+ (mempool_req.count () && txinfo.m_time <= mempool_req)
1557
+ || (txinfo.m_time <= longlived_mempool_time)))
1558
+ {
1549
1559
connman->PushMessage (pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *txinfo.tx ));
1550
1560
push = true ;
1551
1561
}
@@ -3931,7 +3941,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
3931
3941
3932
3942
auto ret = mapRelay.insert (std::make_pair (hash, std::move (txinfo.tx )));
3933
3943
if (ret.second ) {
3934
- vRelayExpiration.push_back (std::make_pair (nNow + 15 * 60 * 1000000 , ret.first ));
3944
+ vRelayExpiration.push_back (std::make_pair (nNow + std::chrono::microseconds{RELAY_TX_CACHE_TIME}. count () , ret.first ));
3935
3945
}
3936
3946
}
3937
3947
if (vInv.size () == MAX_INV_SZ) {
0 commit comments