diff options
| author | Wladimir J. van der Laan <[email protected]> | 2016-05-31 15:47:15 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2016-05-31 15:47:32 +0200 |
| commit | 862fd24b40b478f815dcb5df4f705cae2c0a1cf9 (patch) | |
| tree | e76f4407498a0df5a8b017b9a3102f92de074c0a /src | |
| parent | Merge #8090: Adding P2SH(p2pkh) script test case (diff) | |
| parent | Do not use mempool for GETDATA for tx accepted after the last mempool req. (diff) | |
| download | discoin-862fd24b40b478f815dcb5df4f705cae2c0a1cf9.tar.xz discoin-862fd24b40b478f815dcb5df4f705cae2c0a1cf9.zip | |
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)
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 6 | ||||
| -rw-r--r-- | src/net.cpp | 1 | ||||
| -rw-r--r-- | src/net.h | 3 | ||||
| -rw-r--r-- | src/txmempool.cpp | 10 | ||||
| -rw-r--r-- | src/txmempool.h | 1 |
5 files changed, 19 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index ffc57d48b..c2905784f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4513,7 +4513,10 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam } if (!pushed && inv.type == MSG_TX) { CTransaction tx; - if (mempool.lookup(inv.hash, tx)) { + int64_t txtime; + // 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 (mempool.lookup(inv.hash, tx, txtime) && txtime <= pfrom->timeLastMempoolReq) { pfrom->PushMessage(NetMsgType::TX, tx); pushed = true; } @@ -5911,6 +5914,7 @@ bool SendMessages(CNode* pto) vInv.clear(); } } + pto->timeLastMempoolReq = GetTime(); } // Determine transactions to relay diff --git a/src/net.cpp b/src/net.cpp index a0c670e59..78a914ebd 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2397,6 +2397,7 @@ CNode::CNode(SOCKET hSocketIn, const CAddress& addrIn, const std::string& addrNa fRelayTxes = false; fSentAddr = false; pfilter = new CBloomFilter(); + timeLastMempoolReq = 0; nPingNonceSent = 0; nPingUsecStart = 0; nPingUsecTime = 0; @@ -17,6 +17,7 @@ #include "sync.h" #include "uint256.h" +#include <atomic> #include <deque> #include <stdint.h> @@ -414,6 +415,8 @@ public: // Used for BIP35 mempool sending, also protected by cs_inventory bool fSendMempool; + // Last time a "MEMPOOL" request was serviced. + std::atomic<int64_t> timeLastMempoolReq; // Ping time measurement: // The pong reply we're expecting, or 0 if no pong expected. uint64_t nPingNonceSent; diff --git a/src/txmempool.cpp b/src/txmempool.cpp index aa5df6ca4..4f17e7f8c 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -789,15 +789,23 @@ void CTxMemPool::queryHashes(vector<uint256>& vtxid) std::sort(vtxid.begin(), vtxid.end(), DepthAndScoreComparator(this)); } -bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const + +bool CTxMemPool::lookup(uint256 hash, CTransaction& result, int64_t& time) const { LOCK(cs); indexed_transaction_set::const_iterator i = mapTx.find(hash); if (i == mapTx.end()) return false; result = i->GetTx(); + time = i->GetTime(); return true; } +bool CTxMemPool::lookup(uint256 hash, CTransaction& result) const +{ + int64_t time; + return CTxMemPool::lookup(hash, result, time); +} + bool CTxMemPool::lookupFeeRate(const uint256& hash, CFeeRate& feeRate) const { LOCK(cs); diff --git a/src/txmempool.h b/src/txmempool.h index 3e1d38797..75cf0f4c1 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -602,6 +602,7 @@ public: } bool lookup(uint256 hash, CTransaction& result) const; + bool lookup(uint256 hash, CTransaction& result, int64_t& time) const; bool lookupFeeRate(const uint256& hash, CFeeRate& feeRate) const; /** Estimate fee rate needed to get into the next nBlocks |