@@ -2461,7 +2461,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2461
2461
2462
2462
CCheckQueueControl<CScriptCheck> control (fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL );
2463
2463
2464
- std::vector<uint256> vOrphanErase;
2465
2464
std::vector<int > prevheights;
2466
2465
CAmount nFees = 0 ;
2467
2466
int nInputs = 0 ;
@@ -2492,17 +2491,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2492
2491
prevheights[j] = view.AccessCoins (tx.vin [j].prevout .hash )->nHeight ;
2493
2492
}
2494
2493
2495
- // Which orphan pool entries must we evict?
2496
- for (size_t j = 0 ; j < tx.vin .size (); j++) {
2497
- auto itByPrev = mapOrphanTransactionsByPrev.find (tx.vin [j].prevout );
2498
- if (itByPrev == mapOrphanTransactionsByPrev.end ()) continue ;
2499
- for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
2500
- const CTransaction& orphanTx = (*mi)->second .tx ;
2501
- const uint256& orphanHash = orphanTx.GetHash ();
2502
- vOrphanErase.push_back (orphanHash);
2503
- }
2504
- }
2505
-
2506
2494
if (!SequenceLocks (tx, nLockTimeFlags, &prevheights, *pindex)) {
2507
2495
return state.DoS (100 , error (" %s: contains a non-BIP68-final transaction" , __func__),
2508
2496
REJECT_INVALID, " bad-txns-nonfinal" );
@@ -2592,14 +2580,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
2592
2580
GetMainSignals ().UpdatedTransaction (hashPrevBestCoinBase);
2593
2581
hashPrevBestCoinBase = block.vtx [0 ].GetHash ();
2594
2582
2595
- // Erase orphan transactions include or precluded by this block
2596
- if (vOrphanErase.size ()) {
2597
- int nErased = 0 ;
2598
- BOOST_FOREACH (uint256 &orphanHash, vOrphanErase) {
2599
- nErased += EraseOrphanTx (orphanHash);
2600
- }
2601
- LogPrint (" mempool" , " Erased %d orphan tx included or conflicted by block\n " , nErased);
2602
- }
2603
2583
2604
2584
int64_t nTime6 = GetTimeMicros (); nTimeCallbacks += nTime6 - nTime5;
2605
2585
LogPrint (" bench" , " - Callbacks: %.2fms [%.2fs]\n " , 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001 );
@@ -3105,6 +3085,33 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
3105
3085
}
3106
3086
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
3107
3087
3088
+ // Remove orphan transactions with cs_main
3089
+ {
3090
+ LOCK (cs_main);
3091
+ std::vector<uint256> vOrphanErase;
3092
+ for (unsigned int i = 0 ; i < txChanged.size (); i++) {
3093
+ const CTransaction& tx = std::get<0 >(txChanged[i]);
3094
+ // Which orphan pool entries must we evict?
3095
+ for (size_t j = 0 ; j < tx.vin .size (); j++) {
3096
+ auto itByPrev = mapOrphanTransactionsByPrev.find (tx.vin [j].prevout );
3097
+ if (itByPrev == mapOrphanTransactionsByPrev.end ()) continue ;
3098
+ for (auto mi = itByPrev->second .begin (); mi != itByPrev->second .end (); ++mi) {
3099
+ const CTransaction& orphanTx = (*mi)->second .tx ;
3100
+ const uint256& orphanHash = orphanTx.GetHash ();
3101
+ vOrphanErase.push_back (orphanHash);
3102
+ }
3103
+ }
3104
+ }
3105
+ // Erase orphan transactions include or precluded by this block
3106
+ if (vOrphanErase.size ()) {
3107
+ int nErased = 0 ;
3108
+ BOOST_FOREACH (uint256 &orphanHash, vOrphanErase) {
3109
+ nErased += EraseOrphanTx (orphanHash);
3110
+ }
3111
+ LogPrint (" mempool" , " Erased %d orphan tx included or conflicted by block\n " , nErased);
3112
+ }
3113
+ }
3114
+
3108
3115
// Notifications/callbacks that can run without cs_main
3109
3116
3110
3117
// throw all transactions though the signal-interface
0 commit comments