From b710ddf2eeb191ea9b75de68ea779f48e65f501a Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Tue, 20 Apr 2021 15:15:23 +1000 Subject: [PATCH] net_processing: extra transactions data are accessed only via the msgproc 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. --- src/net_processing.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 661c50c4709ccb..c2413353fdb3b4 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -514,8 +514,9 @@ class PeerManagerImpl final : public PeerManager */ bool MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer); - void ProcessOrphanTx(std::set& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(cs_main, g_cs_orphans) - EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex); + void ProcessOrphanTx(std::set& 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& headers, @@ -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> vExtraTxnForCompact GUARDED_BY(g_cs_orphans); + std::vector> 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); @@ -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; @@ -2347,6 +2350,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer, */ void PeerManagerImpl::ProcessOrphanTx(std::set& orphan_work_set) { + AssertLockHeld(NetEventsInterface::g_mutex_msgproc_thread); AssertLockHeld(cs_main); AssertLockHeld(g_cs_orphans);