@@ -38,7 +38,9 @@ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
38
38
/* * Minimum time between orphan transactions expire time checks in seconds */
39
39
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60 ;
40
40
/* * How long to cache transactions in mapRelay for normal relay */
41
- static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME{15 * 60 };
41
+ static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME = std::chrono::minutes{15 };
42
+ /* * How long a transaction has to be in the mempool before it can unconditionally be relayed (even when not in mapRelay). */
43
+ static constexpr std::chrono::seconds UNCONDITIONAL_RELAY_DELAY = std::chrono::minutes{2 };
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
@@ -1617,7 +1619,7 @@ void static ProcessGetBlockData(CNode& pfrom, const CChainParams& chainparams, c
1617
1619
}
1618
1620
1619
1621
// ! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
1620
- CTransactionRef static FindTxForGetData (CNode& peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time ) LOCKS_EXCLUDED(cs_main)
1622
+ CTransactionRef static FindTxForGetData (const CNode& peer, const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds now ) LOCKS_EXCLUDED(cs_main)
1621
1623
{
1622
1624
// Check if the requested transaction is so recent that we're just
1623
1625
// about to announce it to the peer; if so, they certainly shouldn't
@@ -1631,8 +1633,8 @@ CTransactionRef static FindTxForGetData(CNode& peer, const uint256& txid, const
1631
1633
if (txinfo.tx ) {
1632
1634
// To protect privacy, do not answer getdata using the mempool when
1633
1635
// that TX couldn't have been INVed in reply to a MEMPOOL request,
1634
- // or when it's too recent to have expired from mapRelay .
1635
- if ((mempool_req.count () && txinfo.m_time <= mempool_req) || txinfo.m_time <= longlived_mempool_time ) {
1636
+ // and it's more recent than UNCONDITIONAL_RELAY_DELAY .
1637
+ if ((mempool_req.count () && txinfo.m_time <= mempool_req) || txinfo.m_time <= now - UNCONDITIONAL_RELAY_DELAY ) {
1636
1638
return txinfo.tx ;
1637
1639
}
1638
1640
}
@@ -1655,8 +1657,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1655
1657
std::vector<CInv> vNotFound;
1656
1658
const CNetMsgMaker msgMaker (pfrom.GetSendVersion ());
1657
1659
1658
- // mempool entries added before this time have likely expired from mapRelay
1659
- const std::chrono::seconds longlived_mempool_time = GetTime<std::chrono::seconds>() - RELAY_TX_CACHE_TIME;
1660
+ const std::chrono::seconds now = GetTime<std::chrono::seconds>();
1660
1661
// Get last mempool request time
1661
1662
const std::chrono::seconds mempool_req = pfrom.m_tx_relay != nullptr ? pfrom.m_tx_relay ->m_last_mempool_req .load ()
1662
1663
: std::chrono::seconds::min ();
@@ -1677,7 +1678,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
1677
1678
continue ;
1678
1679
}
1679
1680
1680
- CTransactionRef tx = FindTxForGetData (pfrom, inv.hash , mempool_req, longlived_mempool_time );
1681
+ CTransactionRef tx = FindTxForGetData (pfrom, inv.hash , mempool_req, now );
1681
1682
if (tx) {
1682
1683
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0 );
1683
1684
connman->PushMessage (&pfrom, msgMaker.Make (nSendFlags, NetMsgType::TX, *tx));
0 commit comments