@@ -600,15 +600,6 @@ class PeerManagerImpl final : public PeerManager
600600 void ProcessValidTx (NodeId nodeid, const CTransactionRef& tx, const std::list<CTransactionRef>& replaced_transactions)
601601 EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main);
602602
603- /* * Handle the results of package validation: calls ProcessValidTx and ProcessInvalidTx for
604- * individual transactions, and caches rejection for the package as a group.
605- * @param[in] senders Must contain the nodeids of the peers that provided each transaction
606- * in package, in the same order.
607- * */
608- void ProcessPackageResult (const Package& package, const PackageMempoolAcceptResult& package_result, const std::vector<NodeId>& senders)
609- EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main);
610-
611- /* * A package to validate */
612603 struct PackageToValidate {
613604 const Package m_txns;
614605 const std::vector<NodeId> m_senders;
@@ -633,6 +624,12 @@ class PeerManagerImpl final : public PeerManager
633624 }
634625 };
635626
627+ /* * Handle the results of package validation: calls ProcessValidTx and ProcessInvalidTx for
628+ * individual transactions, and caches rejection for the package as a group.
629+ */
630+ void ProcessPackageResult (const PackageToValidate& package_to_validate, const PackageMempoolAcceptResult& package_result)
631+ EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main);
632+
636633 /* * Look for a child of this transaction in the orphanage to form a 1-parent-1-child package,
637634 * skipping any combinations that have already been tried. Return the resulting package along with
638635 * the senders of its respective transactions, or std::nullopt if no package is found. */
@@ -3252,22 +3249,21 @@ void PeerManagerImpl::ProcessValidTx(NodeId nodeid, const CTransactionRef& tx, c
32523249 }
32533250}
32543251
3255- void PeerManagerImpl::ProcessPackageResult (const Package& package , const PackageMempoolAcceptResult& package_result, const std::vector<NodeId>& senders )
3252+ void PeerManagerImpl::ProcessPackageResult (const PackageToValidate& package_to_validate , const PackageMempoolAcceptResult& package_result)
32563253{
32573254 AssertLockNotHeld (m_peer_mutex);
32583255 AssertLockHeld (g_msgproc_mutex);
32593256 AssertLockHeld (cs_main);
32603257
3258+ const auto & package = package_to_validate.m_txns ;
3259+ const auto & senders = package_to_validate.m_senders ;
3260+
32613261 if (package_result.m_state .IsInvalid ()) {
32623262 m_recent_rejects_reconsiderable.insert (GetPackageHash (package));
32633263 }
32643264 // We currently only expect to process 1-parent-1-child packages. Remove if this changes.
32653265 if (!Assume (package.size () == 2 )) return ;
32663266
3267- // No package results to look through for PCKG_POLICY or PCKG_MEMPOOL_ERROR
3268- if (package_result.m_state .GetResult () == PackageValidationResult::PCKG_POLICY ||
3269- package_result.m_state .GetResult () == PackageValidationResult::PCKG_MEMPOOL_ERROR) return ;
3270-
32713267 // Iterate backwards to erase in-package descendants from the orphanage before they become
32723268 // relevant in AddChildrenToWorkSet.
32733269 auto package_iter = package.rbegin ();
@@ -3276,14 +3272,14 @@ void PeerManagerImpl::ProcessPackageResult(const Package& package, const Package
32763272 const auto & tx = *package_iter;
32773273 const NodeId nodeid = *senders_iter;
32783274 const auto it_result{package_result.m_tx_results .find (tx->GetWitnessHash ())};
3279- if (Assume (it_result != package_result.m_tx_results .end ())) {
3275+
3276+ // It is not guaranteed that a result exists for every transaction.
3277+ if (it_result != package_result.m_tx_results .end ()) {
32803278 const auto & tx_result = it_result->second ;
32813279 switch (tx_result.m_result_type ) {
32823280 case MempoolAcceptResult::ResultType::VALID:
32833281 {
3284- Assume (tx_result.m_replaced_transactions .has_value ());
3285- std::list<CTransactionRef> empty_replacement_list;
3286- ProcessValidTx (nodeid, tx, tx_result.m_replaced_transactions .value_or (empty_replacement_list));
3282+ ProcessValidTx (nodeid, tx, tx_result.m_replaced_transactions );
32873283 break ;
32883284 }
32893285 case MempoolAcceptResult::ResultType::INVALID:
@@ -3378,9 +3374,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
33783374
33793375 if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
33803376 LogPrint (BCLog::TXPACKAGES, " accepted orphan tx %s (wtxid=%s)\n " , orphanHash.ToString (), orphan_wtxid.ToString ());
3381- Assume (result.m_replaced_transactions .has_value ());
3382- std::list<CTransactionRef> empty_replacement_list;
3383- ProcessValidTx (peer.m_id , porphanTx, result.m_replaced_transactions .value_or (empty_replacement_list));
3377+ ProcessValidTx (peer.m_id , porphanTx, result.m_replaced_transactions );
33843378 return true ;
33853379 } else if (state.GetResult () != TxValidationResult::TX_MISSING_INPUTS) {
33863380 LogPrint (BCLog::TXPACKAGES, " invalid orphan tx %s (wtxid=%s) from peer=%d. %s\n " ,
@@ -4553,7 +4547,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
45534547 const auto package_result{ProcessNewPackage (m_chainman.ActiveChainstate (), m_mempool, package_to_validate->m_txns , /* test_accept=*/ false , /* client_maxfeerate=*/ std::nullopt )};
45544548 LogDebug (BCLog::TXPACKAGES, " package evaluation for %s: %s\n " , package_to_validate->ToString (),
45554549 package_result.m_state .IsValid () ? " package accepted" : " package rejected" );
4556- ProcessPackageResult (package_to_validate-> m_txns , package_result, package_to_validate-> m_senders );
4550+ ProcessPackageResult (package_to_validate. value () , package_result);
45574551 }
45584552 }
45594553 // If a tx is detected by m_recent_rejects it is ignored. Because we haven't
@@ -4578,9 +4572,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
45784572 const TxValidationState& state = result.m_state ;
45794573
45804574 if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
4581- Assume (result.m_replaced_transactions .has_value ());
4582- std::list<CTransactionRef> empty_replacement_list;
4583- ProcessValidTx (pfrom.GetId (), ptx, result.m_replaced_transactions .value_or (empty_replacement_list));
4575+ ProcessValidTx (pfrom.GetId (), ptx, result.m_replaced_transactions );
45844576 pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
45854577 }
45864578 else if (state.GetResult () == TxValidationResult::TX_MISSING_INPUTS)
@@ -4670,7 +4662,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
46704662 const auto package_result{ProcessNewPackage (m_chainman.ActiveChainstate (), m_mempool, package_to_validate->m_txns , /* test_accept=*/ false , /* client_maxfeerate=*/ std::nullopt )};
46714663 LogDebug (BCLog::TXPACKAGES, " package evaluation for %s: %s\n " , package_to_validate->ToString (),
46724664 package_result.m_state .IsValid () ? " package accepted" : " package rejected" );
4673- ProcessPackageResult (package_to_validate-> m_txns , package_result, package_to_validate-> m_senders );
4665+ ProcessPackageResult (package_to_validate. value () , package_result);
46744666 }
46754667 }
46764668
0 commit comments