@@ -80,9 +80,6 @@ uint64_t nPruneTarget = 0;
80
80
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE;
81
81
bool fEnableReplacement = DEFAULT_ENABLE_REPLACEMENT;
82
82
83
- std::map<uint256, CTransaction> mapRelay;
84
- std::deque<std::pair<int64_t , uint256> > vRelayExpiration;
85
- CCriticalSection cs_mapRelay;
86
83
87
84
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
88
85
CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;
@@ -215,6 +212,12 @@ namespace {
215
212
216
213
/* * Number of peers from which we're downloading blocks. */
217
214
int nPeersWithValidatedDownloads = 0 ;
215
+
216
+ /* * Relay map, protected by cs_main. */
217
+ typedef std::map<uint256, std::shared_ptr<const CTransaction>> MapRelay;
218
+ MapRelay mapRelay;
219
+ /* * Expiration-time ordered list of (expire time, relay map entry) pairs, protected by cs_main). */
220
+ std::deque<std::pair<int64_t , MapRelay::iterator>> vRelayExpiration;
218
221
} // anon namespace
219
222
220
223
// ////////////////////////////////////////////////////////////////////////////
@@ -4505,31 +4508,24 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
4505
4508
}
4506
4509
}
4507
4510
}
4508
- else if (inv.IsKnownType () )
4511
+ else if (inv.type == MSG_TX )
4509
4512
{
4510
- CTransaction tx;
4511
4513
// Send stream from relay memory
4512
4514
bool push = false ;
4513
- {
4514
- LOCK (cs_mapRelay);
4515
- map<uint256, CTransaction>::iterator mi = mapRelay.find (inv.hash );
4516
- if (mi != mapRelay.end ()) {
4517
- tx = (*mi).second ;
4518
- push = true ;
4519
- }
4520
- }
4521
- if (!push && inv.type == MSG_TX) {
4515
+ auto mi = mapRelay.find (inv.hash );
4516
+ if (mi != mapRelay.end ()) {
4517
+ pfrom->PushMessage (NetMsgType::TX, *mi->second );
4518
+ push = true ;
4519
+ } else {
4522
4520
auto txinfo = mempool.info (inv.hash );
4523
4521
// To protect privacy, do not answer getdata using the mempool when
4524
4522
// that TX couldn't have been INVed in reply to a MEMPOOL request.
4525
4523
if (txinfo.tx && txinfo.nTime <= pfrom->timeLastMempoolReq ) {
4526
- tx = *txinfo.tx ;
4524
+ pfrom-> PushMessage (NetMsgType::TX, *txinfo.tx ) ;
4527
4525
push = true ;
4528
4526
}
4529
4527
}
4530
- if (push) {
4531
- pfrom->PushMessage (inv.GetCommand (), tx);
4532
- } else {
4528
+ if (!push) {
4533
4529
vNotFound.push_back (inv);
4534
4530
}
4535
4531
}
@@ -5978,17 +5974,16 @@ bool SendMessages(CNode* pto)
5978
5974
vInv.push_back (CInv (MSG_TX, hash));
5979
5975
nRelayedTransactions++;
5980
5976
{
5981
- LOCK (cs_mapRelay);
5982
5977
// Expire old relay messages
5983
5978
while (!vRelayExpiration.empty () && vRelayExpiration.front ().first < GetTime ())
5984
5979
{
5985
5980
mapRelay.erase (vRelayExpiration.front ().second );
5986
5981
vRelayExpiration.pop_front ();
5987
5982
}
5988
5983
5989
- auto ret = mapRelay.insert (std::make_pair (hash, * txinfo.tx ));
5984
+ auto ret = mapRelay.insert (std::make_pair (hash, std::move ( txinfo.tx ) ));
5990
5985
if (ret.second ) {
5991
- vRelayExpiration.push_back (std::make_pair (GetTime () + 15 * 60 , hash ));
5986
+ vRelayExpiration.push_back (std::make_pair (GetTime () + 15 * 60 , ret. first ));
5992
5987
}
5993
5988
}
5994
5989
if (vInv.size () == MAX_INV_SZ) {
0 commit comments