Skip to content

Commit 862fd24

Browse files
committed
Merge #8080: Do not use mempool for GETDATA for tx accepted after the last mempool req.
7e908c7 Do not use mempool for GETDATA for tx accepted after the last mempool req. (Gregory Maxwell)
2 parents a2df115 + 7e908c7 commit 862fd24

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

src/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4513,7 +4513,10 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
45134513
}
45144514
if (!pushed && inv.type == MSG_TX) {
45154515
CTransaction tx;
4516-
if (mempool.lookup(inv.hash, tx)) {
4516+
int64_t txtime;
4517+
// To protect privacy, do not answer getdata using the mempool when
4518+
// that TX couldn't have been INVed in reply to a MEMPOOL request.
4519+
if (mempool.lookup(inv.hash, tx, txtime) && txtime <= pfrom->timeLastMempoolReq) {
45174520
pfrom->PushMessage(NetMsgType::TX, tx);
45184521
pushed = true;
45194522
}
@@ -5911,6 +5914,7 @@ bool SendMessages(CNode* pto)
59115914
vInv.clear();
59125915
}
59135916
}
5917+
pto->timeLastMempoolReq = GetTime();
59145918
}
59155919

59165920
// Determine transactions to relay

src/net.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,6 +2397,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23972397
fRelayTxes = false;
23982398
fSentAddr = false;
23992399
pfilter = new CBloomFilter();
2400+
timeLastMempoolReq = 0;
24002401
nPingNonceSent = 0;
24012402
nPingUsecStart = 0;
24022403
nPingUsecTime = 0;

src/net.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "sync.h"
1818
#include "uint256.h"
1919

20+
#include <atomic>
2021
#include <deque>
2122
#include <stdint.h>
2223

@@ -414,6 +415,8 @@ class CNode
414415
// Used for BIP35 mempool sending, also protected by cs_inventory
415416
bool fSendMempool;
416417

418+
// Last time a "MEMPOOL" request was serviced.
419+
std::atomic<int64_t> timeLastMempoolReq;
417420
// Ping time measurement:
418421
// The pong reply we're expecting, or 0 if no pong expected.
419422
uint64_t nPingNonceSent;

src/txmempool.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,15 +789,23 @@ void CTxMemPool::queryHashes(vector<uint256>& vtxid)
789789
std::sort(vtxid.begin(), vtxid.end(), DepthAndScoreComparator(this));
790790
}
791791

792-
bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const
792+
793+
bool CTxMemPool::lookup(uint256 hash, CTransaction& result, int64_t& time) const
793794
{
794795
LOCK(cs);
795796
indexed_transaction_set::const_iterator i = mapTx.find(hash);
796797
if (i == mapTx.end()) return false;
797798
result = i->GetTx();
799+
time = i->GetTime();
798800
return true;
799801
}
800802

803+
bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const
804+
{
805+
int64_t time;
806+
return CTxMemPool::lookup(hash, result, time);
807+
}
808+
801809
bool CTxMemPool::lookupFeeRate(const uint256& hash, CFeeRate& feeRate) const
802810
{
803811
LOCK(cs);

src/txmempool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ class CTxMemPool
602602
}
603603

604604
bool lookup(uint256 hash, CTransaction& result) const;
605+
bool lookup(uint256 hash, CTransaction& result, int64_t& time) const;
605606
bool lookupFeeRate(const uint256& hash, CFeeRate& feeRate) const;
606607

607608
/** Estimate fee rate needed to get into the next nBlocks

0 commit comments

Comments
 (0)