Skip to content

Commit b24a17f

Browse files
committed
Introduce constant for mempool-based relay separate from mapRelay caching
This constant is set to 2 minutes, rather than 15. This is still many times larger than the transaction broadcast interval (2s for outbound, 5s for inbound), so it should be acceptable for peers to know what our contents of the mempool was that long ago.
1 parent a9bc563 commit b24a17f

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/net_processing.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
3838
/** Minimum time between orphan transactions expire time checks in seconds */
3939
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
4040
/** 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};
4244
/** Headers download timeout expressed in microseconds
4345
* Timeout = base + per_header * (expected number of headers) */
4446
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
16171619
}
16181620

16191621
//! 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)
16211623
{
16221624
// Check if the requested transaction is so recent that we're just
16231625
// 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
16311633
if (txinfo.tx) {
16321634
// To protect privacy, do not answer getdata using the mempool when
16331635
// 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) {
16361638
return txinfo.tx;
16371639
}
16381640
}
@@ -1655,8 +1657,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
16551657
std::vector<CInv> vNotFound;
16561658
const CNetMsgMaker msgMaker(pfrom.GetSendVersion());
16571659

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>();
16601661
// Get last mempool request time
16611662
const std::chrono::seconds mempool_req = pfrom.m_tx_relay != nullptr ? pfrom.m_tx_relay->m_last_mempool_req.load()
16621663
: std::chrono::seconds::min();
@@ -1677,7 +1678,7 @@ void static ProcessGetData(CNode& pfrom, const CChainParams& chainparams, CConnm
16771678
continue;
16781679
}
16791680

1680-
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, mempool_req, longlived_mempool_time);
1681+
CTransactionRef tx = FindTxForGetData(pfrom, inv.hash, mempool_req, now);
16811682
if (tx) {
16821683
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
16831684
connman->PushMessage(&pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));

0 commit comments

Comments
 (0)