Skip to content

Commit 168b781

Browse files
committed
Continue relaying transactions after they expire from mapRelay
1 parent a689c11 commit 168b781

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
4040
/** Minimum time between orphan transactions expire time checks in seconds */
4141
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};
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
@@ -1522,6 +1524,10 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
15221524
// messages from this peer (likely resulting in our peer eventually
15231525
// disconnecting us).
15241526
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+
15251531
LOCK(cs_main);
15261532

15271533
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
15411547
if (mi != mapRelay.end()) {
15421548
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
15431549
push = true;
1544-
} else if (pfrom->m_tx_relay->m_last_mempool_req.load().count()) {
1550+
} else {
15451551
auto txinfo = mempool.info(inv.hash);
15461552
// 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+
{
15491559
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
15501560
push = true;
15511561
}
@@ -3931,7 +3941,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
39313941

39323942
auto ret = mapRelay.insert(std::make_pair(hash, std::move(txinfo.tx)));
39333943
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));
39353945
}
39363946
}
39373947
if (vInv.size() == MAX_INV_SZ) {

0 commit comments

Comments
 (0)