2929#include < reverse_iterator.h>
3030#include < scheduler.h>
3131#include < streams.h>
32+ #include < sync.h>
3233#include < timedata.h>
3334#include < tinyformat.h>
3435#include < index/txindex.h>
@@ -644,6 +645,8 @@ class PeerManagerImpl final : public PeerManager
644645 bool IsInvInFilter (NodeId nodeid, const uint256& hash) const override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
645646 void AskPeersForTransaction (const uint256& txid, bool is_masternode) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
646647private:
648+ void _RelayTransaction (const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
649+
647650 /* * Helpers to process result of external handlers of message */
648651 void ProcessPeerMsgRet (const PeerMsgRet& ret, CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
649652 void PostProcessMessage (MessageProcessingResult&& ret, NodeId node) override EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex);
@@ -1628,7 +1631,8 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
16281631 CTransactionRef tx = m_mempool.get (txid);
16291632
16301633 if (tx != nullptr ) {
1631- RelayTransaction (txid);
1634+ LOCK (cs_main);
1635+ _RelayTransaction (txid);
16321636 } else {
16331637 m_mempool.RemoveUnbroadcastTx (txid, true );
16341638 }
@@ -2427,6 +2431,11 @@ void PeerManagerImpl::RelayInvFiltered(CInv &inv, const uint256& relatedTxHash,
24272431}
24282432
24292433void PeerManagerImpl::RelayTransaction (const uint256& txid)
2434+ {
2435+ WITH_LOCK (cs_main, _RelayTransaction (txid));
2436+ }
2437+
2438+ void PeerManagerImpl::_RelayTransaction (const uint256& txid)
24302439{
24312440 const CInv inv{m_cj_ctx->dstxman ->GetDSTX (txid) ? MSG_DSTX : MSG_TX, txid};
24322441 LOCK (m_peer_mutex);
@@ -3205,7 +3214,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
32053214
32063215 if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
32073216 LogPrint (BCLog::MEMPOOL, " accepted orphan tx %s\n " , orphanHash.ToString ());
3208- RelayTransaction (porphanTx->GetHash ());
3217+ _RelayTransaction (porphanTx->GetHash ());
32093218 m_orphanage.AddChildrenToWorkSet (*porphanTx, orphan_work_set);
32103219 m_orphanage.EraseTx (orphanHash);
32113220 break ;
@@ -3488,7 +3497,7 @@ void PeerManagerImpl::PostProcessMessage(MessageProcessingResult&& result, NodeI
34883497 WITH_LOCK (cs_main, EraseObjectRequest (node, result.m_to_erase .value ()));
34893498 }
34903499 for (const auto & tx : result.m_transactions ) {
3491- WITH_LOCK (cs_main, RelayTransaction (tx));
3500+ WITH_LOCK (cs_main, _RelayTransaction (tx));
34923501 }
34933502 if (result.m_inventory ) {
34943503 RelayInv (result.m_inventory .value ());
@@ -4476,7 +4485,7 @@ void PeerManagerImpl::ProcessMessage(
44764485 LogPrintf (" Not relaying non-mempool transaction %s from forcerelay peer=%d\n " , tx.GetHash ().ToString (), pfrom.GetId ());
44774486 } else {
44784487 LogPrintf (" Force relaying tx %s from peer=%d\n " , tx.GetHash ().ToString (), pfrom.GetId ());
4479- RelayTransaction (tx.GetHash ());
4488+ _RelayTransaction (tx.GetHash ());
44804489 }
44814490 }
44824491 return ;
@@ -4493,7 +4502,7 @@ void PeerManagerImpl::ProcessMessage(
44934502 m_cj_ctx->dstxman ->AddDSTX (dstx);
44944503 }
44954504
4496- RelayTransaction (tx.GetHash ());
4505+ _RelayTransaction (tx.GetHash ());
44974506 m_orphanage.AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
44984507
44994508 pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
0 commit comments