@@ -582,6 +582,11 @@ class PeerManagerImpl final : public PeerManager
582
582
*/
583
583
bool MaybeDiscourageAndDisconnect (CNode& pnode, Peer& peer);
584
584
585
+ /* * Handle a transaction whose result was MempoolAcceptResult::ResultType::VALID.
586
+ * Updates m_txrequest, m_orphanage, and vExtraTxnForCompact. Also queues the tx for relay. */
587
+ void ProcessValidTx (NodeId nodeid, const CTransactionRef& tx, const std::list<CTransactionRef>& replaced_transactions)
588
+ EXCLUSIVE_LOCKS_REQUIRED(!m_peer_mutex, g_msgproc_mutex, cs_main);
589
+
585
590
/* *
586
591
* Reconsider orphan transactions after a parent has been accepted to the mempool.
587
592
*
@@ -3032,6 +3037,34 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
3032
3037
return ;
3033
3038
}
3034
3039
3040
+ void PeerManagerImpl::ProcessValidTx (NodeId nodeid, const CTransactionRef& tx, const std::list<CTransactionRef>& replaced_transactions)
3041
+ {
3042
+ AssertLockNotHeld (m_peer_mutex);
3043
+ AssertLockHeld (g_msgproc_mutex);
3044
+ AssertLockHeld (cs_main);
3045
+
3046
+ // As this version of the transaction was acceptable, we can forget about any requests for it.
3047
+ // No-op if the tx is not in txrequest.
3048
+ m_txrequest.ForgetTxHash (tx->GetHash ());
3049
+ m_txrequest.ForgetTxHash (tx->GetWitnessHash ());
3050
+
3051
+ m_orphanage.AddChildrenToWorkSet (*tx);
3052
+ // If it came from the orphanage, remove it. No-op if the tx is not in txorphanage.
3053
+ m_orphanage.EraseTx (tx->GetHash ());
3054
+
3055
+ LogDebug (BCLog::MEMPOOL, " AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n " ,
3056
+ nodeid,
3057
+ tx->GetHash ().ToString (),
3058
+ tx->GetWitnessHash ().ToString (),
3059
+ m_mempool.size (), m_mempool.DynamicMemoryUsage () / 1000 );
3060
+
3061
+ RelayTransaction (tx->GetHash (), tx->GetWitnessHash ());
3062
+
3063
+ for (const CTransactionRef& removedTx : replaced_transactions) {
3064
+ AddToCompactExtraTransactions (removedTx);
3065
+ }
3066
+ }
3067
+
3035
3068
bool PeerManagerImpl::ProcessOrphanTx (Peer& peer)
3036
3069
{
3037
3070
AssertLockHeld (g_msgproc_mutex);
@@ -3047,17 +3080,9 @@ bool PeerManagerImpl::ProcessOrphanTx(Peer& peer)
3047
3080
3048
3081
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
3049
3082
LogPrint (BCLog::TXPACKAGES, " accepted orphan tx %s (wtxid=%s)\n " , orphanHash.ToString (), orphan_wtxid.ToString ());
3050
- LogPrint (BCLog::MEMPOOL, " AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n " ,
3051
- peer.m_id ,
3052
- orphanHash.ToString (),
3053
- orphan_wtxid.ToString (),
3054
- m_mempool.size (), m_mempool.DynamicMemoryUsage () / 1000 );
3055
- RelayTransaction (orphanHash, porphanTx->GetWitnessHash ());
3056
- m_orphanage.AddChildrenToWorkSet (*porphanTx);
3057
- m_orphanage.EraseTx (orphanHash);
3058
- for (const CTransactionRef& removedTx : result.m_replaced_transactions .value ()) {
3059
- AddToCompactExtraTransactions (removedTx);
3060
- }
3083
+ Assume (result.m_replaced_transactions .has_value ());
3084
+ std::list<CTransactionRef> empty_replacement_list;
3085
+ ProcessValidTx (peer.m_id , porphanTx, result.m_replaced_transactions .value_or (empty_replacement_list));
3061
3086
return true ;
3062
3087
} else if (state.GetResult () != TxValidationResult::TX_MISSING_INPUTS) {
3063
3088
if (state.IsInvalid ()) {
@@ -4276,24 +4301,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
4276
4301
const TxValidationState& state = result.m_state ;
4277
4302
4278
4303
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
4279
- // As this version of the transaction was acceptable, we can forget about any
4280
- // requests for it.
4281
- m_txrequest.ForgetTxHash (tx.GetHash ());
4282
- m_txrequest.ForgetTxHash (tx.GetWitnessHash ());
4283
- RelayTransaction (tx.GetHash (), tx.GetWitnessHash ());
4284
- m_orphanage.AddChildrenToWorkSet (tx);
4285
-
4304
+ ProcessValidTx (pfrom.GetId (), ptx, result.m_replaced_transactions .value ());
4286
4305
pfrom.m_last_tx_time = GetTime<std::chrono::seconds>();
4287
-
4288
- LogPrint (BCLog::MEMPOOL, " AcceptToMemoryPool: peer=%d: accepted %s (wtxid=%s) (poolsz %u txn, %u kB)\n " ,
4289
- pfrom.GetId (),
4290
- tx.GetHash ().ToString (),
4291
- tx.GetWitnessHash ().ToString (),
4292
- m_mempool.size (), m_mempool.DynamicMemoryUsage () / 1000 );
4293
-
4294
- for (const CTransactionRef& removedTx : result.m_replaced_transactions .value ()) {
4295
- AddToCompactExtraTransactions (removedTx);
4296
- }
4297
4306
}
4298
4307
else if (state.GetResult () == TxValidationResult::TX_MISSING_INPUTS)
4299
4308
{
0 commit comments