Skip to content

Commit 7e908c7

Browse files
committed
Do not use mempool for GETDATA for tx accepted after the last mempool req.
The ability to GETDATA a transaction which has not (yet) been relayed is a privacy loss vector. The use of the mempool for this was added as part of the mempool p2p message and is only needed to fetch transactions returned by it.
1 parent 8844ef1 commit 7e908c7

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
@@ -4503,7 +4503,10 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
45034503
}
45044504
if (!pushed && inv.type == MSG_TX) {
45054505
CTransaction tx;
4506-
if (mempool.lookup(inv.hash, tx)) {
4506+
int64_t txtime;
4507+
// To protect privacy, do not answer getdata using the mempool when
4508+
// that TX couldn't have been INVed in reply to a MEMPOOL request.
4509+
if (mempool.lookup(inv.hash, tx, txtime) && txtime <= pfrom->timeLastMempoolReq) {
45074510
pfrom->PushMessage(NetMsgType::TX, tx);
45084511
pushed = true;
45094512
}
@@ -5902,6 +5905,7 @@ bool SendMessages(CNode* pto)
59025905
vInv.clear();
59035906
}
59045907
}
5908+
pto->timeLastMempoolReq = GetTime();
59055909
}
59065910

59075911
// Determine transactions to relay

src/net.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,6 +2396,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa
23962396
fRelayTxes = false;
23972397
fSentAddr = false;
23982398
pfilter = new CBloomFilter();
2399+
timeLastMempoolReq = 0;
23992400
nPingNonceSent = 0;
24002401
nPingUsecStart = 0;
24012402
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

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

417+
// Last time a "MEMPOOL" request was serviced.
418+
std::atomic<int64_t> timeLastMempoolReq;
416419
// Ping time measurement:
417420
// The pong reply we're expecting, or 0 if no pong expected.
418421
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)