2525#include < reverse_iterator.h>
2626#include < scheduler.h>
2727#include < streams.h>
28+ #include < sync.h>
2829#include < tinyformat.h>
2930#include < txmempool.h>
3031#include < txorphanage.h>
@@ -256,6 +257,9 @@ class PeerManagerImpl final : public PeerManager
256257 const std::chrono::microseconds time_received, const std::atomic<bool >& interruptMsgProc) override ;
257258
258259private:
260+ void _RelayTransaction (const uint256& txid, const uint256& wtxid)
261+ EXCLUSIVE_LOCKS_REQUIRED(cs_main);
262+
259263 /* * Consider evicting an outbound peer based on the amount of time they've been behind our tip */
260264 void ConsiderEviction (CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
261265
@@ -1015,7 +1019,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
10151019
10161020 if (tx != nullptr ) {
10171021 LOCK (cs_main);
1018- RelayTransaction (txid, tx->GetWitnessHash ());
1022+ _RelayTransaction (txid, tx->GetWitnessHash ());
10191023 } else {
10201024 m_mempool.RemoveUnbroadcastTx (txid, true );
10211025 }
@@ -1511,6 +1515,11 @@ void PeerManagerImpl::SendPings()
15111515}
15121516
15131517void PeerManagerImpl::RelayTransaction (const uint256& txid, const uint256& wtxid)
1518+ {
1519+ WITH_LOCK (cs_main, _RelayTransaction (txid, wtxid););
1520+ }
1521+
1522+ void PeerManagerImpl::_RelayTransaction (const uint256& txid, const uint256& wtxid)
15141523{
15151524 m_connman.ForEachNode ([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED (::cs_main) {
15161525 AssertLockHeld (::cs_main);
@@ -2087,7 +2096,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
20872096
20882097 if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
20892098 LogPrint (BCLog::MEMPOOL, " accepted orphan tx %s\n " , orphanHash.ToString ());
2090- RelayTransaction (orphanHash, porphanTx->GetWitnessHash ());
2099+ _RelayTransaction (orphanHash, porphanTx->GetWitnessHash ());
20912100 m_orphanage.AddChildrenToWorkSet (*porphanTx, orphan_work_set);
20922101 m_orphanage.EraseTx (orphanHash);
20932102 for (const CTransactionRef& removedTx : result.m_replaced_transactions .value ()) {
@@ -3055,7 +3064,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
30553064 LogPrintf (" Not relaying non-mempool transaction %s from forcerelay peer=%d\n " , tx.GetHash ().ToString (), pfrom.GetId ());
30563065 } else {
30573066 LogPrintf (" Force relaying tx %s from peer=%d\n " , tx.GetHash ().ToString (), pfrom.GetId ());
3058- RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
3067+ _RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
30593068 }
30603069 }
30613070 return ;
@@ -3070,7 +3079,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
30703079 // requests for it.
30713080 m_txrequest.ForgetTxHash (tx.GetHash ());
30723081 m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
3073- RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
3082+ _RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
30743083 m_orphanage.AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
30753084
30763085 pfrom.nLastTXTime = GetTime ();
0 commit comments