0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-10 10:52:31 -05:00

Push down use of cs_main into FindTxForGetData

This commit is contained in:
Pieter Wuille 2020-05-12 12:40:54 -07:00
parent c6131bf407
commit f2f32a3dee

View file

@ -1609,11 +1609,14 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
} }
//! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed). //! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
CTransactionRef static FindTxForGetData(const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main) CTransactionRef static FindTxForGetData(const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time) LOCKS_EXCLUDED(cs_main)
{ {
{
LOCK(cs_main);
// Look up transaction in relay pool // Look up transaction in relay pool
auto mi = mapRelay.find(txid); auto mi = mapRelay.find(txid);
if (mi != mapRelay.end()) return mi->second; if (mi != mapRelay.end()) return mi->second;
}
auto txinfo = mempool.info(txid); auto txinfo = mempool.info(txid);
if (txinfo.tx) { if (txinfo.tx) {
@ -1642,19 +1645,14 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
const std::chrono::seconds mempool_req = pfrom->m_tx_relay != nullptr ? pfrom->m_tx_relay->m_last_mempool_req.load() const std::chrono::seconds mempool_req = pfrom->m_tx_relay != nullptr ? pfrom->m_tx_relay->m_last_mempool_req.load()
: std::chrono::seconds::min(); : std::chrono::seconds::min();
{
LOCK(cs_main);
// Process as many TX items from the front of the getdata queue as // Process as many TX items from the front of the getdata queue as
// possible, since they're common and it's efficient to batch process // possible, since they're common and it's efficient to batch process
// them. // them.
while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) { while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
if (interruptMsgProc) if (interruptMsgProc) return;
return;
// The send buffer provides backpressure. If there's no space in // The send buffer provides backpressure. If there's no space in
// the buffer, pause processing until the next call. // the buffer, pause processing until the next call.
if (pfrom->fPauseSend) if (pfrom->fPauseSend) break;
break;
const CInv &inv = *it++; const CInv &inv = *it++;
@ -1672,7 +1670,6 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
vNotFound.push_back(inv); vNotFound.push_back(inv);
} }
} }
} // release cs_main
// Only process one BLOCK item per call, since they're uncommon and can be // Only process one BLOCK item per call, since they're uncommon and can be
// expensive to process. // expensive to process.