Skip to content

Commit

Permalink
Merge bitcoin#8080: Do not use mempool for GETDATA for tx accepted af…
Browse files Browse the repository at this point in the history
…ter the last mempool req.

7e908c7 Do not use mempool for GETDATA for tx accepted after the last mempool req. (Gregory Maxwell)
  • Loading branch information
laanwj authored and codablock committed Dec 22, 2017
1 parent b2a27c0 commit dfa0bd2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
fRelayTxes = false;
fSentAddr = false;
pfilter = new CBloomFilter();
timeLastMempoolReq = 0;
nLastBlockTime = 0;
nLastTXTime = 0;
nPingNonceSent = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ class CNode
std::atomic<int64_t> nLastBlockTime;
std::atomic<int64_t> nLastTXTime;

// 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;
Expand Down
5 changes: 4 additions & 1 deletion src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,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) {
connman.PushMessage(pfrom, NetMsgType::TX, tx);
pushed = true;
}
Expand Down
10 changes: 9 additions & 1 deletion src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,15 +925,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);
Expand Down
1 change: 1 addition & 0 deletions src/txmempool.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ class CTxMemPool
}

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
Expand Down

0 comments on commit dfa0bd2

Please sign in to comment.