Skip to content

Commit

Permalink
net_processing: extra transactions data are accessed only via the msg…
Browse files Browse the repository at this point in the history
…proc thread

Previously vExtraTxnForCompact and vExtraTxnForCompactIt were protected
by g_cs_orphans; protect them instead by g_mutex_msgproc_thread instead,
as they are only used during message processing.
  • Loading branch information
ajtowns committed Mar 7, 2022
1 parent 09a5a75 commit c5dd02f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class PeerManagerImpl final : public PeerManager
*/
bool MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer);

void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans);
void ProcessOrphanTx(std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_mutex_msgproc_thread, cs_main, g_cs_orphans);
/** Process a single headers message from a peer. */
void ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
const std::vector<CBlockHeader>& headers,
Expand Down Expand Up @@ -594,14 +594,14 @@ class PeerManagerImpl final : public PeerManager
/** Storage for orphan information */
TxOrphanage m_orphanage;

void AddToCompactExtraTransactions(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
void AddToCompactExtraTransactions(const CTransactionRef& tx) EXCLUSIVE_LOCKS_REQUIRED(NetEventsInterface::g_mutex_msgproc_thread);

/** Orphan/conflicted/etc transactions that are kept for compact block reconstruction.
* The last -blockreconstructionextratxn/DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN of
* these are kept in a ring buffer */
std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(g_cs_orphans);
std::vector<std::pair<uint256, CTransactionRef>> vExtraTxnForCompact GUARDED_BY(NetEventsInterface::g_mutex_msgproc_thread);
/** Offset into vExtraTxnForCompact to insert the next tx */
size_t vExtraTxnForCompactIt GUARDED_BY(g_cs_orphans) = 0;
size_t vExtraTxnForCompactIt GUARDED_BY(NetEventsInterface::g_mutex_msgproc_thread) = 0;

/** Check whether the last unknown block a peer advertised is not yet known. */
void ProcessBlockAvailability(NodeId nodeid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
Expand Down Expand Up @@ -1341,6 +1341,8 @@ bool PeerManagerImpl::GetNodeStateStats(NodeId nodeid, CNodeStateStats& stats) c

void PeerManagerImpl::AddToCompactExtraTransactions(const CTransactionRef& tx)
{
AssertLockHeld(NetEventsInterface::g_mutex_msgproc_thread);

size_t max_extra_txn = gArgs.GetIntArg("-blockreconstructionextratxn", DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN);
if (max_extra_txn <= 0)
return;
Expand Down Expand Up @@ -2303,6 +2305,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
*/
void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
{
AssertLockHeld(NetEventsInterface::g_mutex_msgproc_thread);
AssertLockHeld(cs_main);
AssertLockHeld(g_cs_orphans);

Expand Down

0 comments on commit c5dd02f

Please sign in to comment.