@@ -2152,11 +2152,20 @@ static int64_t nTimeFlush = 0;
2152
2152
static int64_t nTimeChainState = 0 ;
2153
2153
static int64_t nTimePostConnect = 0 ;
2154
2154
2155
+ /* *
2156
+ * Used to track conflicted transactions removed from mempool and transactions
2157
+ * applied to the UTXO state as a part of a single ActivateBestChainStep call.
2158
+ */
2159
+ struct ConnectTrace {
2160
+ std::vector<CTransactionRef> txConflicted;
2161
+ std::vector<std::tuple<CTransactionRef,CBlockIndex*,int >> txChanged;
2162
+ };
2163
+
2155
2164
/* *
2156
2165
* Connect a new block to chainActive. pblock is either NULL or a pointer to a CBlock
2157
2166
* corresponding to pindexNew, to bypass loading it again from disk.
2158
2167
*/
2159
- bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, std::vector<CTransactionRef> &txConflicted, std::vector<std::tuple<CTransactionRef,CBlockIndex*, int >> &txChanged )
2168
+ bool static ConnectTip (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const CBlock* pblock, ConnectTrace& connectTrace )
2160
2169
{
2161
2170
assert (pindexNew->pprev == chainActive.Tip ());
2162
2171
// Read block from disk.
@@ -2192,12 +2201,12 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2192
2201
int64_t nTime5 = GetTimeMicros (); nTimeChainState += nTime5 - nTime4;
2193
2202
LogPrint (" bench" , " - Writing chainstate: %.2fms [%.2fs]\n " , (nTime5 - nTime4) * 0.001 , nTimeChainState * 0.000001 );
2194
2203
// Remove conflicting transactions from the mempool.;
2195
- mempool.removeForBlock (pblock->vtx , pindexNew->nHeight , &txConflicted, !IsInitialBlockDownload ());
2204
+ mempool.removeForBlock (pblock->vtx , pindexNew->nHeight , &connectTrace. txConflicted , !IsInitialBlockDownload ());
2196
2205
// Update chainActive & related variables.
2197
2206
UpdateTip (pindexNew, chainparams);
2198
2207
2199
2208
for (unsigned int i=0 ; i < pblock->vtx .size (); i++)
2200
- txChanged.emplace_back (pblock->vtx [i], pindexNew, i);
2209
+ connectTrace. txChanged .emplace_back (pblock->vtx [i], pindexNew, i);
2201
2210
2202
2211
int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2203
2212
LogPrint (" bench" , " - Connect postprocess: %.2fms [%.2fs]\n " , (nTime6 - nTime5) * 0.001 , nTimePostConnect * 0.000001 );
@@ -2279,7 +2288,7 @@ static void PruneBlockIndexCandidates() {
2279
2288
* Try to make some progress towards making pindexMostWork the active block.
2280
2289
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2281
2290
*/
2282
- static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound , std::vector<CTransactionRef>& txConflicted, std::vector<std::tuple<CTransactionRef,CBlockIndex*, int >>& txChanged )
2291
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound , ConnectTrace& connectTrace )
2283
2292
{
2284
2293
AssertLockHeld (cs_main);
2285
2294
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2312,7 +2321,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
2312
2321
2313
2322
// Connect new blocks.
2314
2323
BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2315
- if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL , txConflicted, txChanged )) {
2324
+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : NULL , connectTrace )) {
2316
2325
if (state.IsInvalid ()) {
2317
2326
// The block violates a consensus rule.
2318
2327
if (!state.CorruptionPossible ())
@@ -2380,17 +2389,13 @@ static void NotifyHeaderTip() {
2380
2389
bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock *pblock) {
2381
2390
CBlockIndex *pindexMostWork = NULL ;
2382
2391
CBlockIndex *pindexNewTip = NULL ;
2383
- std::vector<std::tuple<CTransactionRef,CBlockIndex*,int >> txChanged;
2384
- if (pblock)
2385
- txChanged.reserve (pblock->vtx .size ());
2386
2392
do {
2387
- txChanged.clear ();
2388
2393
boost::this_thread::interruption_point ();
2389
2394
if (ShutdownRequested ())
2390
2395
break ;
2391
2396
2392
2397
const CBlockIndex *pindexFork;
2393
- std::vector<CTransactionRef> txConflicted ;
2398
+ ConnectTrace connectTrace ;
2394
2399
bool fInitialDownload ;
2395
2400
{
2396
2401
LOCK (cs_main);
@@ -2404,7 +2409,7 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2404
2409
return true ;
2405
2410
2406
2411
bool fInvalidFound = false ;
2407
- if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound , txConflicted, txChanged ))
2412
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound , connectTrace ))
2408
2413
return false ;
2409
2414
2410
2415
if (fInvalidFound ) {
@@ -2421,13 +2426,13 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2421
2426
2422
2427
// throw all transactions though the signal-interface
2423
2428
// while _not_ holding the cs_main lock
2424
- for (const auto & tx : txConflicted)
2429
+ for (const auto & tx : connectTrace. txConflicted )
2425
2430
{
2426
2431
GetMainSignals ().SyncTransaction (*tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
2427
2432
}
2428
2433
// ... and about transactions that got confirmed:
2429
- for (unsigned int i = 0 ; i < txChanged.size (); i++)
2430
- GetMainSignals ().SyncTransaction (*std::get<0 >(txChanged[i]), std::get<1 >(txChanged[i]), std::get<2 >(txChanged[i]));
2434
+ for (unsigned int i = 0 ; i < connectTrace. txChanged .size (); i++)
2435
+ GetMainSignals ().SyncTransaction (*std::get<0 >(connectTrace. txChanged [i]), std::get<1 >(connectTrace. txChanged [i]), std::get<2 >(connectTrace. txChanged [i]));
2431
2436
2432
2437
// Notify external listeners about the new tip.
2433
2438
GetMainSignals ().UpdatedBlockTip (pindexNewTip, pindexFork, fInitialDownload );
0 commit comments