Skip to content

Commit f2f32a3

Browse files
committed
Push down use of cs_main into FindTxForGetData
1 parent c6131bf commit f2f32a3

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

src/net_processing.cpp

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,11 +1609,14 @@ void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, c
16091609
}
16101610

16111611
//! Determine whether or not a peer can request a transaction, and return it (or nullptr if not found or not allowed).
1612-
CTransactionRef static FindTxForGetData(const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1612+
CTransactionRef static FindTxForGetData(const uint256& txid, const std::chrono::seconds mempool_req, const std::chrono::seconds longlived_mempool_time) LOCKS_EXCLUDED(cs_main)
16131613
{
1614-
// Look up transaction in relay pool
1615-
auto mi = mapRelay.find(txid);
1616-
if (mi != mapRelay.end()) return mi->second;
1614+
{
1615+
LOCK(cs_main);
1616+
// Look up transaction in relay pool
1617+
auto mi = mapRelay.find(txid);
1618+
if (mi != mapRelay.end()) return mi->second;
1619+
}
16171620

16181621
auto txinfo = mempool.info(txid);
16191622
if (txinfo.tx) {
@@ -1642,37 +1645,31 @@ void static ProcessGetData(CNode* pfrom, const CChainParams& chainparams, CConnm
16421645
const std::chrono::seconds mempool_req = pfrom->m_tx_relay != nullptr ? pfrom->m_tx_relay->m_last_mempool_req.load()
16431646
: std::chrono::seconds::min();
16441647

1645-
{
1646-
LOCK(cs_main);
1647-
1648-
// Process as many TX items from the front of the getdata queue as
1649-
// possible, since they're common and it's efficient to batch process
1650-
// them.
1651-
while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
1652-
if (interruptMsgProc)
1653-
return;
1654-
// The send buffer provides backpressure. If there's no space in
1655-
// the buffer, pause processing until the next call.
1656-
if (pfrom->fPauseSend)
1657-
break;
1648+
// Process as many TX items from the front of the getdata queue as
1649+
// possible, since they're common and it's efficient to batch process
1650+
// them.
1651+
while (it != pfrom->vRecvGetData.end() && (it->type == MSG_TX || it->type == MSG_WITNESS_TX)) {
1652+
if (interruptMsgProc) return;
1653+
// The send buffer provides backpressure. If there's no space in
1654+
// the buffer, pause processing until the next call.
1655+
if (pfrom->fPauseSend) break;
16581656

1659-
const CInv &inv = *it++;
1657+
const CInv &inv = *it++;
16601658

1661-
if (pfrom->m_tx_relay == nullptr) {
1662-
// Ignore GETDATA requests for transactions from blocks-only peers.
1663-
continue;
1664-
}
1659+
if (pfrom->m_tx_relay == nullptr) {
1660+
// Ignore GETDATA requests for transactions from blocks-only peers.
1661+
continue;
1662+
}
16651663

1666-
CTransactionRef tx = FindTxForGetData(inv.hash, mempool_req, longlived_mempool_time);
1667-
if (tx) {
1668-
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
1669-
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
1670-
mempool.RemoveUnbroadcastTx(inv.hash);
1671-
} else {
1672-
vNotFound.push_back(inv);
1673-
}
1664+
CTransactionRef tx = FindTxForGetData(inv.hash, mempool_req, longlived_mempool_time);
1665+
if (tx) {
1666+
int nSendFlags = (inv.type == MSG_TX ? SERIALIZE_TRANSACTION_NO_WITNESS : 0);
1667+
connman->PushMessage(pfrom, msgMaker.Make(nSendFlags, NetMsgType::TX, *tx));
1668+
mempool.RemoveUnbroadcastTx(inv.hash);
1669+
} else {
1670+
vNotFound.push_back(inv);
16741671
}
1675-
} // release cs_main
1672+
}
16761673

16771674
// Only process one BLOCK item per call, since they're uncommon and can be
16781675
// expensive to process.

0 commit comments

Comments
 (0)