25
25
#include < reverse_iterator.h>
26
26
#include < scheduler.h>
27
27
#include < streams.h>
28
+ #include < sync.h>
28
29
#include < tinyformat.h>
29
30
#include < txmempool.h>
30
31
#include < txorphanage.h>
@@ -256,6 +257,9 @@ class PeerManagerImpl final : public PeerManager
256
257
const std::chrono::microseconds time_received, const std::atomic<bool >& interruptMsgProc) override ;
257
258
258
259
private:
260
+ void _RelayTransaction (const uint256& txid, const uint256& wtxid)
261
+ EXCLUSIVE_LOCKS_REQUIRED(cs_main);
262
+
259
263
/* * Consider evicting an outbound peer based on the amount of time they've been behind our tip */
260
264
void ConsiderEviction (CNode& pto, int64_t time_in_seconds) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
261
265
@@ -1015,7 +1019,7 @@ void PeerManagerImpl::ReattemptInitialBroadcast(CScheduler& scheduler)
1015
1019
1016
1020
if (tx != nullptr ) {
1017
1021
LOCK (cs_main);
1018
- RelayTransaction (txid, tx->GetWitnessHash ());
1022
+ _RelayTransaction (txid, tx->GetWitnessHash ());
1019
1023
} else {
1020
1024
m_mempool.RemoveUnbroadcastTx (txid, true );
1021
1025
}
@@ -1511,6 +1515,11 @@ void PeerManagerImpl::SendPings()
1511
1515
}
1512
1516
1513
1517
void 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)
1514
1523
{
1515
1524
m_connman.ForEachNode ([&txid, &wtxid](CNode* pnode) EXCLUSIVE_LOCKS_REQUIRED (::cs_main) {
1516
1525
AssertLockHeld (::cs_main);
@@ -2087,7 +2096,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
2087
2096
2088
2097
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
2089
2098
LogPrint (BCLog::MEMPOOL, " accepted orphan tx %s\n " , orphanHash.ToString ());
2090
- RelayTransaction (orphanHash, porphanTx->GetWitnessHash ());
2099
+ _RelayTransaction (orphanHash, porphanTx->GetWitnessHash ());
2091
2100
m_orphanage.AddChildrenToWorkSet (*porphanTx, orphan_work_set);
2092
2101
m_orphanage.EraseTx (orphanHash);
2093
2102
for (const CTransactionRef& removedTx : result.m_replaced_transactions .value ()) {
@@ -3055,7 +3064,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3055
3064
LogPrintf (" Not relaying non-mempool transaction %s from forcerelay peer=%d\n " , tx.GetHash ().ToString (), pfrom.GetId ());
3056
3065
} else {
3057
3066
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 ());
3059
3068
}
3060
3069
}
3061
3070
return ;
@@ -3070,7 +3079,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
3070
3079
// requests for it.
3071
3080
m_txrequest.ForgetTxHash (tx.GetHash ());
3072
3081
m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
3073
- RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
3082
+ _RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
3074
3083
m_orphanage.AddChildrenToWorkSet (tx, peer->m_orphan_work_set );
3075
3084
3076
3085
pfrom.nLastTXTime = GetTime ();
0 commit comments