Skip to content

Commit 61745c7

Browse files
committed
lock m_recent_confirmed_transactions using m_tx_download_mutex
1 parent 723ea0f commit 61745c7

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

src/net_processing.cpp

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ class PeerManagerImpl final : public PeerManager
490490

491491
/** Overridden from CValidationInterface. */
492492
void ActiveTipChange(const CBlockIndex* new_tip, bool) override
493-
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
493+
EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
494494
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
495-
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
495+
EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
496496
void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex* pindex) override
497-
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, !m_tx_download_mutex);
497+
EXCLUSIVE_LOCKS_REQUIRED(!m_tx_download_mutex);
498498
void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) override
499499
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
500500
void BlockChecked(const CBlock& block, const BlockValidationState& state) override
@@ -507,9 +507,9 @@ class PeerManagerImpl final : public PeerManager
507507
void FinalizeNode(const CNode& node) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_headers_presync_mutex, !m_tx_download_mutex);
508508
bool HasAllDesirableServiceFlags(ServiceFlags services) const override;
509509
bool ProcessMessages(CNode* pfrom, std::atomic<bool>& interrupt) override
510-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex, !m_headers_presync_mutex, g_msgproc_mutex, !m_tx_download_mutex);
510+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_most_recent_block_mutex, !m_headers_presync_mutex, g_msgproc_mutex, !m_tx_download_mutex);
511511
bool SendMessages(CNode* pto) override
512-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex, g_msgproc_mutex, !m_tx_download_mutex);
512+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_most_recent_block_mutex, g_msgproc_mutex, !m_tx_download_mutex);
513513

514514
/** Implement PeerManager */
515515
void StartScheduledTasks(CScheduler& scheduler) override;
@@ -528,7 +528,7 @@ class PeerManagerImpl final : public PeerManager
528528
void UnitTestMisbehaving(NodeId peer_id) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex) { Misbehaving(*Assert(GetPeerRef(peer_id)), ""); };
529529
void ProcessMessage(CNode& pfrom, const std::string& msg_type, DataStream& vRecv,
530530
const std::chrono::microseconds time_received, const std::atomic<bool>& interruptMsgProc) override
531-
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_recent_confirmed_transactions_mutex, !m_most_recent_block_mutex, !m_headers_presync_mutex, g_msgproc_mutex, !m_tx_download_mutex);
531+
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, !m_most_recent_block_mutex, !m_headers_presync_mutex, g_msgproc_mutex, !m_tx_download_mutex);
532532
void UpdateLastBlockAnnounceTime(NodeId node, int64_t time_in_seconds) override;
533533
ServiceFlags GetDesirableServiceFlags(ServiceFlags services) const override;
534534

@@ -863,7 +863,7 @@ class PeerManagerImpl final : public PeerManager
863863
* - m_recent_confirmed_transactions
864864
* */
865865
bool AlreadyHaveTx(const GenTxid& gtxid, bool include_reconsiderable)
866-
EXCLUSIVE_LOCKS_REQUIRED(!m_recent_confirmed_transactions_mutex, m_tx_download_mutex);
866+
EXCLUSIVE_LOCKS_REQUIRED(m_tx_download_mutex);
867867

868868
/**
869869
* Filter for transactions that were recently rejected by the mempool.
@@ -938,8 +938,7 @@ class PeerManagerImpl final : public PeerManager
938938
* transaction per day that would be inadvertently ignored (which is the
939939
* same probability that we have in the reject filter).
940940
*/
941-
Mutex m_recent_confirmed_transactions_mutex;
942-
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_recent_confirmed_transactions_mutex){48'000, 0.000'001};
941+
CRollingBloomFilter m_recent_confirmed_transactions GUARDED_BY(m_tx_download_mutex){48'000, 0.000'001};
943942

944943
/**
945944
* For sending `inv`s to inbound peers, we use a single (exponentially
@@ -2119,20 +2118,15 @@ void PeerManagerImpl::BlockConnected(
21192118
LOCK(m_tx_download_mutex);
21202119
m_orphanage.EraseForBlock(*pblock);
21212120

2122-
{
2123-
LOCK(m_recent_confirmed_transactions_mutex);
2124-
for (const auto& ptx : pblock->vtx) {
2125-
m_recent_confirmed_transactions.insert(ptx->GetHash().ToUint256());
2126-
if (ptx->HasWitness()) {
2127-
m_recent_confirmed_transactions.insert(ptx->GetWitnessHash().ToUint256());
2128-
}
2121+
for (const auto& ptx : pblock->vtx) {
2122+
m_recent_confirmed_transactions.insert(ptx->GetHash().ToUint256());
2123+
if (ptx->HasWitness()) {
2124+
m_recent_confirmed_transactions.insert(ptx->GetWitnessHash().ToUint256());
21292125
}
21302126
}
2131-
{
2132-
for (const auto& ptx : pblock->vtx) {
2133-
m_txrequest.ForgetTxHash(ptx->GetHash());
2134-
m_txrequest.ForgetTxHash(ptx->GetWitnessHash());
2135-
}
2127+
for (const auto& ptx : pblock->vtx) {
2128+
m_txrequest.ForgetTxHash(ptx->GetHash());
2129+
m_txrequest.ForgetTxHash(ptx->GetWitnessHash());
21362130
}
21372131
}
21382132

@@ -2146,7 +2140,7 @@ void PeerManagerImpl::BlockDisconnected(const std::shared_ptr<const CBlock> &blo
21462140
// block's worth of transactions in it, but that should be fine, since
21472141
// presumably the most common case of relaying a confirmed transaction
21482142
// should be just after a new block containing it is found.
2149-
LOCK(m_recent_confirmed_transactions_mutex);
2143+
LOCK(m_tx_download_mutex);
21502144
m_recent_confirmed_transactions.reset();
21512145
}
21522146

@@ -2310,10 +2304,7 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
23102304

23112305
if (include_reconsiderable && m_recent_rejects_reconsiderable.contains(hash)) return true;
23122306

2313-
{
2314-
LOCK(m_recent_confirmed_transactions_mutex);
2315-
if (m_recent_confirmed_transactions.contains(hash)) return true;
2316-
}
2307+
if (m_recent_confirmed_transactions.contains(hash)) return true;
23172308

23182309
return m_recent_rejects.contains(hash) || m_mempool.exists(gtxid);
23192310
}

0 commit comments

Comments
 (0)