aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2019-09-10 18:00:17 +1000
committerAnthony Towns <aj@erisian.com.au>2019-10-23 11:36:24 +1000
commit168b781fe7f3f13b24c52a151f36de4cdd0a340a (patch)
tree67cb17dcacd0211ca372a5355f983290e516b65a /src/net_processing.cpp
parenta689c119076c7b8dc5b4dea4539e4cbf5adfb72f (diff)
downloadbitcoin-168b781fe7f3f13b24c52a151f36de4cdd0a340a.tar.xz
Continue relaying transactions after they expire from mapRelay
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index e345af604c..e5f101758c 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -39,6 +39,8 @@
static constexpr int64_t ORPHAN_TX_EXPIRE_TIME = 20 * 60;
/** 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};
/** Headers download timeout expressed in microseconds
* Timeout = base + per_header * (expected number of headers) */
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
// messages from this peer (likely resulting in our peer eventually
// disconnecting us).
if (pfrom->m_tx_relay != nullptr) {
+ // mempool entries added before this time have likely expired from mapRelay
+ const std::chrono::seconds longlived_mempool_time = GetTime<std::chrono::seconds>() - RELAY_TX_CACHE_TIME;
+ const std::chrono::seconds mempool_req = pfrom->m_tx_relay->m_last_mempool_req.load();
+
LOCK(cs_main);
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
if (mi != mapRelay.end()) {
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *mi->second));
push = true;
- } else if (pfrom->m_tx_relay->m_last_mempool_req.load().count()) {
+ } else {
auto txinfo = mempool.info(inv.hash);
// To protect privacy, do not answer getdata using the mempool when
- // that TX couldn't have been INVed in reply to a MEMPOOL request.
- if (txinfo.tx && txinfo.m_time <= pfrom->m_tx_relay->m_last_mempool_req.load()) {
+ // that TX couldn't have been INVed in reply to a MEMPOOL request,
+ // or when it's too recent to have expired from mapRelay.
+ if (txinfo.tx && (
+ (mempool_req.count() && txinfo.m_time <= mempool_req)
+ || (txinfo.m_time <= longlived_mempool_time)))
+ {
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *txinfo.tx));
push = true;
}
@@ -3931,7 +3941,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
auto ret = mapRelay.insert(std::make_pair(hash, std::move(txinfo.tx)));
if (ret.second) {
- vRelayExpiration.push_back(std::make_pair(nNow + 15 * 60 * 1000000, ret.first));
+ vRelayExpiration.push_back(std::make_pair(nNow + std::chrono::microseconds{RELAY_TX_CACHE_TIME}.count(), ret.first));
}
}
if (vInv.size() == MAX_INV_SZ) {