@@ -600,15 +600,6 @@ class PeerManagerImpl final : public PeerManager
600
600
void ProcessValidTx (NodeId nodeid, const CTransactionRef& tx, const std::list<CTransactionRef>& replaced_transactions)
601
601
EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main);
602
602
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 */
612
603
struct PackageToValidate {
613
604
const Package m_txns;
614
605
const std::vector<NodeId> m_senders;
@@ -633,6 +624,12 @@ class PeerManagerImpl final : public PeerManager
633
624
}
634
625
};
635
626
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
+
636
633
/* * Look for a child of this transaction in the orphanage to form a 1-parent-1-child package,
637
634
* skipping any combinations that have already been tried. Return the resulting package along with
638
635
* 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
3252
3249
}
3253
3250
}
3254
3251
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)
3256
3253
{
3257
3254
AssertLockNotHeld (m_peer_mutex);
3258
3255
AssertLockHeld (g_msgproc_mutex);
3259
3256
AssertLockHeld (cs_main);
3260
3257
3258
+ const auto & package = package_to_validate.m_txns ;
3259
+ const auto & senders = package_to_validate.m_senders ;
3260
+
3261
3261
if (package_result.m_state .IsInvalid ()) {
3262
3262
m_recent_rejects_reconsiderable.insert (GetPackageHash (package));
3263
3263
}
3264
3264
// We currently only expect to process 1-parent-1-child packages. Remove if this changes.
3265
3265
if (!Assume (package.size () == 2 )) return ;
3266
3266
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
-
3271
3267
// Iterate backwards to erase in-package descendants from the orphanage before they become
3272
3268
// relevant in AddChildrenToWorkSet.
3273
3269
auto package_iter = package.rbegin ();
@@ -3276,14 +3272,14 @@ void PeerManagerImpl::ProcessPackageResult(const Package& package, const Package
3276
3272
const auto & tx = *package_iter;
3277
3273
const NodeId nodeid = *senders_iter;
3278
3274
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 ()) {
3280
3278
const auto & tx_result = it_result->second ;
3281
3279
switch (tx_result.m_result_type ) {
3282
3280
case MempoolAcceptResult::ResultType::VALID:
3283
3281
{
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 );
3287
3283
break ;
3288
3284
}
3289
3285
case MempoolAcceptResult::ResultType::INVALID:
@@ -3378,9 +3374,7 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
3378
3374
3379
3375
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
3380
3376
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 );
3384
3378
return true ;
3385
3379
} else if (state.GetResult () != TxValidationResult::TX_MISSING_INPUTS) {
3386
3380
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,
4553
4547
const auto package_result{ProcessNewPackage (m_chainman.ActiveChainstate (), m_mempool, package_to_validate->m_txns , /* test_accept=*/ false , /* client_maxfeerate=*/ std::nullopt)};
4554
4548
LogDebug (BCLog::TXPACKAGES, " package evaluation for %s: %s\n " , package_to_validate->ToString (),
4555
4549
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);
4557
4551
}
4558
4552
}
4559
4553
// 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,
4578
4572
const TxValidationState& state = result.m_state ;
4579
4573
4580
4574
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 );
4584
4576
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
4585
4577
}
4586
4578
else if (state.GetResult () == TxValidationResult::TX_MISSING_INPUTS)
@@ -4670,7 +4662,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4670
4662
const auto package_result{ProcessNewPackage (m_chainman.ActiveChainstate (), m_mempool, package_to_validate->m_txns , /* test_accept=*/ false , /* client_maxfeerate=*/ std::nullopt)};
4671
4663
LogDebug (BCLog::TXPACKAGES, " package evaluation for %s: %s\n " , package_to_validate->ToString (),
4672
4664
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);
4674
4666
}
4675
4667
}
4676
4668
0 commit comments