Skip to content

Commit fce7c75

Browse files
author
MarcoFalke
committed
Merge #16851: Continue relaying transactions after they expire from mapRelay
168b781 Continue relaying transactions after they expire from mapRelay (Anthony Towns) Pull request description: This change allows peers to request transactions even after they've expired from mapRelay and even if they're not doing mempool requests. This is intended to allow for CPFP of old transactions -- if parent tx P wasn't relayed due to low fees, then a higher fee rate child C is relayed, peers will currently request the parent P, but we prior to this patch, we will not relay it due to it not being in mapRelay. ACKs for top commit: MarcoFalke: re-ACK 168b781 (only change is comment fixup) sdaftuar: re-ACK 168b781 sipa: ACK 168b781 Tree-SHA512: b206666dd1450cd0a161ae55fd1a7eda2c3d226842ba27d91fe463b551fd924b65b92551b14d6786692e15cf9a9a989666550dfc980b48ab0f8d4ca305bc7762
2 parents 7730260 + 168b781 commit fce7c75

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
@@ -38,6 +38,8 @@
3838
static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
3939
/** Minimum time between orphan transactions expire time checks in seconds */
4040
static constexpr int64_t ORPHAN_TX_EXPIRE_INTERVAL = 5 * 60;
41+
/** How long to cache transactions in mapRelay for normal relay */
42+
static constexpr std::chrono::seconds RELAY_TX_CACHE_TIME{15 * 60};
4143
/** Headers download timeout expressed in microseconds
4244
* Timeout = base + per_header * (expected number of headers) */
4345
static constexpr int64_t HEADERS_DOWNLOAD_TIMEOUT_BASE = 15 * 60 * 1000000; // 15 minutes
@@ -1513,6 +1515,10 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
15131515
// messages from this peer (likely resulting in our peer eventually
15141516
// disconnecting us).
15151517
if (pfrom->m_tx_relay != nullptr) {
1518+
// mempool entries added before this time have likely expired from mapRelay
1519+
const std::chrono::seconds longlived_mempool_time = GetTime<std::chrono::seconds>() - RELAY_TX_CACHE_TIME;
1520+
const std::chrono::seconds mempool_req = pfrom->m_tx_relay->m_last_mempool_req.load();
1521+
15161522
LOCK(cs_main);
15171523

15181524
while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
@@ -1532,11 +1538,15 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
15321538
if (mi != mapRelay.end()) {
15331539
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
15341540
push = true;
1535-
} else if (pfrom->m_tx_relay->m_last_mempool_req.load().count()) {
1541+
} else {
15361542
auto txinfo = mempool.info(inv.hash);
15371543
// To protect privacy, do not answer getdata using the mempool when
1538-
// that TX couldn't have been INVed in reply to a MEMPOOL request.
1539-
if (txinfo.tx && txinfo.m_time <= pfrom->m_tx_relay->m_last_mempool_req.load()) {
1544+
// that TX couldn't have been INVed in reply to a MEMPOOL request,
1545+
// or when it's too recent to have expired from mapRelay.
1546+
if (txinfo.tx && (
1547+
(mempool_req.count() && txinfo.m_time <= mempool_req)
1548+
|| (txinfo.m_time <= longlived_mempool_time)))
1549+
{
15401550
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
15411551
push = true;
15421552
}
@@ -3876,7 +3886,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
38763886

38773887
auto ret = mapRelay.insert(std::make_pair(hash, std::move(txinfo.tx)));
38783888
if (ret.second) {
3879-
vRelayExpiration.push_back(std::make_pair(nNow + 15 * 60 * 1000000, ret.first));
3889+
vRelayExpiration.push_back(std::make_pair(nNow + std::chrono::microseconds{RELAY_TX_CACHE_TIME}.count(), ret.first));
38803890
}
38813891
}
38823892
if (vInv.size() == MAX_INV_SZ) {

0 commit comments

Comments
 (0)