diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -46,7 +46,12 @@ /** Minimum time between orphan transactions expire time checks in seconds */ static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60; /** How long to cache transactions in mapRelay for normal relay */ -static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME{15 * 60}; +static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME = + std::chrono::minutes{15}; +/** How long a transaction has to be in the mempool before it can + * unconditionally be relayed (even when not in mapRelay). */ +static constexpr std::chrono::seconds UNCONDITIONAL_RELAY_DELAY = + std::chrono::minutes{2}; /** * Headers download timeout expressed in microseconds. * Timeout = base + per_header * (expected number of headers) @@ -1976,9 +1981,10 @@ //! Determine whether or not a peer can request a transaction, and return it (or //! nullptr if not found or not allowed). -CTransactionRef static FindTxForGetData( - const CNode &peer, const TxId &txid, const std::chrono::seconds mempool_req, - const std::chrono::seconds longlived_mempool_time) LOCKS_EXCLUDED(cs_main) { +CTransactionRef static FindTxForGetData(const CNode &peer, const TxId &txid, + const std::chrono::seconds mempool_req, + const std::chrono::seconds now) + LOCKS_EXCLUDED(cs_main) { // Check if the requested transaction is so recent that we're just // about to announce it to the peer; if so, they certainly shouldn't // know we already have it. @@ -1993,9 +1999,9 @@ if (txinfo.tx) { // To protect privacy, do not answer getdata using the mempool when // that TX couldn't have been INVed in reply to a MEMPOOL request, - // or when it's too recent to have expired from mapRelay. + // and it's more recent than UNCONDITIONAL_RELAY_DELAY. if ((mempool_req.count() && txinfo.m_time <= mempool_req) || - txinfo.m_time <= longlived_mempool_time) { + txinfo.m_time <= now - UNCONDITIONAL_RELAY_DELAY) { return txinfo.tx; } } @@ -2022,9 +2028,7 @@ std::vector vNotFound; const CNetMsgMaker msgMaker(pfrom.GetCommonVersion()); - // mempool entries added before this time have likely expired from mapRelay - const std::chrono::seconds longlived_mempool_time = - GetTime() - RELAY_TX_CACHE_TIME; + const std::chrono::seconds now = GetTime(); // Get last mempool request time const std::chrono::seconds mempool_req = pfrom.m_tx_relay != nullptr @@ -2052,8 +2056,8 @@ continue; } - CTransactionRef tx = FindTxForGetData( - pfrom, TxId{inv.hash}, mempool_req, longlived_mempool_time); + CTransactionRef tx = + FindTxForGetData(pfrom, TxId{inv.hash}, mempool_req, now); if (tx) { int nSendFlags = 0; connman.PushMessage(&pfrom,