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 by g_mutex_msgproc_thread instead, as they
are only used during message processing.
  • Loading branch information
ajtowns committed May 16, 2022
1 parent 45e1aa3 commit b710ddf
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,9 @@ 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)
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
void ProcessOrphanTx(std::set<uint256>& orphan_work_set)
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, 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 @@ -755,14 +756,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 @@ -1397,6 +1398,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 @@ -2347,6 +2350,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 b710ddf

Please sign in to comment.