@@ -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 }
@@ -1636,7 +1636,8 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16361636 mi != itByPrev->second .end ();
16371637 ++mi)
16381638 {
1639- const CTransaction& orphanTx = (*mi)->second .tx ;
1639+ const CTransactionRef& porphanTx = (*mi)->second .tx ;
1640+ const CTransaction& orphanTx = *porphanTx;
16401641 const uint256& orphanHash = orphanTx.GetHash ();
16411642 NodeId fromPeer = (*mi)->second .fromPeer ;
16421643 bool fMissingInputs2 = false ;
@@ -1648,7 +1649,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
16481649
16491650 if (setMisbehaving.count (fromPeer))
16501651 continue ;
1651- if (AcceptToMemoryPool (mempool, stateDummy, MakeTransactionRef (orphanTx) , true , &fMissingInputs2 )) {
1652+ if (AcceptToMemoryPool (mempool, stateDummy, porphanTx , true , &fMissingInputs2 )) {
16521653 LogPrint (" mempool" , " accepted orphan tx %s\n " , orphanHash.ToString ());
16531654 RelayTransaction (orphanTx, connman);
16541655 for (unsigned int i = 0 ; i < orphanTx.vout .size (); i++) {
@@ -1701,7 +1702,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
17011702 pfrom->AddInventoryKnown (_inv);
17021703 if (!AlreadyHave (_inv)) pfrom->AskFor (_inv);
17031704 }
1704- AddOrphanTx (tx , pfrom->GetId ());
1705+ AddOrphanTx (ptx , pfrom->GetId ());
17051706
17061707 // DoS prevention: do not allow mapOrphanTransactions to grow unbounded
17071708 unsigned int nMaxOrphanTx = (unsigned int )std::max ((int64_t )0 , GetArg (" -maxorphantx" , DEFAULT_MAX_ORPHAN_TRANSACTIONS));
0 commit comments