@@ -51,7 +51,7 @@ struct IteratorComparator
5151
5252struct COrphanTx {
5353 // When modifying, adapt the copy of this definition in tests/DoS_tests.
54- CTransaction tx;
54+ CTransactionRef tx;
5555 NodeId fromPeer;
5656 int64_t nTimeExpire;
5757};
@@ -586,9 +586,9 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals)
586586// mapOrphanTransactions
587587//
588588
589- bool AddOrphanTx (const CTransaction & tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
589+ bool AddOrphanTx (const CTransactionRef & tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
590590{
591- uint256 hash = tx. GetHash ();
591+ const uint256& hash = tx-> GetHash ();
592592 if (mapOrphanTransactions.count (hash))
593593 return false ;
594594
@@ -599,7 +599,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(c
599599 // have been mined or received.
600600 // 100 orphans, each of which is at most 99,999 bytes big is
601601 // at most 10 megabytes of orphans and somewhat more byprev index (in the worst case):
602- unsigned int sz = GetTransactionWeight (tx);
602+ unsigned int sz = GetTransactionWeight (* tx);
603603 if (sz >= MAX_STANDARD_TX_WEIGHT)
604604 {
605605 LogPrint (" mempool" , " ignoring large orphan tx (size: %u, hash: %s)\n " , sz, hash.ToString ());
@@ -608,7 +608,7 @@ bool AddOrphanTx(const CTransaction& tx, NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(c
608608
609609 auto ret = mapOrphanTransactions.emplace (hash, COrphanTx{tx, peer, GetTime () + ORPHAN_TX_EXPIRE_TIME});
610610 assert (ret.second );
611- BOOST_FOREACH (const CTxIn& txin, tx. vin ) {
611+ BOOST_FOREACH (const CTxIn& txin, tx-> vin ) {
612612 mapOrphanTransactionsByPrev[txin.prevout ].insert (ret.first );
613613 }
614614
@@ -622,7 +622,7 @@ int static EraseOrphanTx(uint256 hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
622622 map<uint256, COrphanTx>::iterator it = mapOrphanTransactions.find (hash);
623623 if (it == mapOrphanTransactions.end ())
624624 return 0 ;
625- BOOST_FOREACH (const CTxIn& txin, it->second .tx . vin )
625+ BOOST_FOREACH (const CTxIn& txin, it->second .tx -> vin )
626626 {
627627 auto itPrev = mapOrphanTransactionsByPrev.find (txin.prevout );
628628 if (itPrev == mapOrphanTransactionsByPrev.end ())
@@ -644,7 +644,7 @@ void EraseOrphansFor(NodeId peer)
644644 map<uint256, COrphanTx>::iterator maybeErase = iter++; // increment to avoid iterator becoming invalid
645645 if (maybeErase->second .fromPeer == peer)
646646 {
647- nErased += EraseOrphanTx (maybeErase->second .tx . GetHash ());
647+ nErased += EraseOrphanTx (maybeErase->second .tx -> GetHash ());
648648 }
649649 }
650650 if (nErased > 0 ) LogPrint (" mempool" , " Erased %d orphan tx from peer %d\n " , nErased, peer);
@@ -665,7 +665,7 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRE
665665 {
666666 map<uint256, COrphanTx>::iterator maybeErase = iter++;
667667 if (maybeErase->second .nTimeExpire <= nNow) {
668- nErased += EraseOrphanTx (maybeErase->second .tx . GetHash ());
668+ nErased += EraseOrphanTx (maybeErase->second .tx -> GetHash ());
669669 } else {
670670 nMinExpTime = std::min (maybeErase->second .nTimeExpire , nMinExpTime);
671671 }
@@ -736,7 +736,7 @@ void PeerLogicValidation::SyncTransaction(const CTransaction& tx, const CBlockIn
736736 auto itByPrev = mapOrphanTransactionsByPrev.find (tx.vin [j].prevout );
737737 if (itByPrev == mapOrphanTransactionsByPrev.end ()) continue ;
738738 for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
739- const CTransaction& orphanTx = (*mi)->second .tx ;
739+ const CTransaction& orphanTx = * (*mi)->second .tx ;
740740 const uint256& orphanHash = orphanTx.GetHash ();
741741 vOrphanErase.push_back (orphanHash);
742742 }
@@ -1600,7 +1600,9 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16001600
16011601 deque<COutPoint> vWorkQueue;
16021602 vector<uint256> vEraseQueue;
1603- CTransaction tx (deserialize, vRecv);
1603+ CTransactionRef ptx;
1604+ vRecv >> ptx;
1605+ const CTransaction& tx = *ptx;
16041606
16051607 CInv inv (MSG_TX, tx.GetHash ());
16061608 pfrom->AddInventoryKnown (inv);
@@ -1613,7 +1615,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16131615 pfrom->setAskFor .erase (inv.hash );
16141616 mapAlreadyAskedFor.erase (inv.hash );
16151617
1616- if (!AlreadyHave (inv) && AcceptToMemoryPool (mempool, state, tx , true , &fMissingInputs )) {
1618+ if (!AlreadyHave (inv) && AcceptToMemoryPool (mempool, state, ptx , true , &fMissingInputs )) {
16171619 mempool.check (pcoinsTip);
16181620 RelayTransaction (tx, connman);
16191621 for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
@@ -1638,7 +1640,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16381640 mi != itByPrev->second .end ();
16391641 ++mi)
16401642 {
1641- const CTransaction& orphanTx = (*mi)->second .tx ;
1643+ const CTransactionRef& porphanTx = (*mi)->second .tx ;
1644+ const CTransaction& orphanTx = *porphanTx;
16421645 const uint256& orphanHash = orphanTx.GetHash ();
16431646 NodeId fromPeer = (*mi)->second .fromPeer ;
16441647 bool fMissingInputs2 = false ;
@@ -1650,7 +1653,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16501653
16511654 if (setMisbehaving.count (fromPeer))
16521655 continue ;
1653- if (AcceptToMemoryPool (mempool, stateDummy, orphanTx , true , &fMissingInputs2 )) {
1656+ if (AcceptToMemoryPool (mempool, stateDummy, porphanTx , true , &fMissingInputs2 )) {
16541657 LogPrint (" mempool" , " accepted orphan tx %s\n " , orphanHash.ToString ());
16551658 RelayTransaction (orphanTx, connman);
16561659 for (unsigned int i = 0 ; i < orphanTx.vout .size (); i++) {
@@ -1703,7 +1706,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
17031706 pfrom->AddInventoryKnown (_inv);
17041707 if (!AlreadyHave (_inv)) pfrom->AskFor (_inv);
17051708 }
1706- AddOrphanTx (tx , pfrom->GetId ());
1709+ AddOrphanTx (ptx , pfrom->GetId ());
17071710
17081711 // DoS prevention: do not allow mapOrphanTransactions to grow unbounded
17091712 unsigned int nMaxOrphanTx = (unsigned int )std::max ((int64_t )0 , GetArg (" -maxorphantx" , DEFAULT_MAX_ORPHAN_TRANSACTIONS));
0 commit comments