@@ -2158,7 +2158,7 @@ static int64_t nTimePostConnect = 0;
2158
2158
*/
2159
2159
struct ConnectTrace {
2160
2160
std::vector<CTransactionRef> txConflicted;
2161
- std::vector<std::tuple<CTransactionRef, CBlockIndex*,int >> txChanged ;
2161
+ std::vector<std::pair< CBlockIndex*, std::shared_ptr< const CBlock> > > blocksConnected ;
2162
2162
};
2163
2163
2164
2164
/* *
@@ -2170,11 +2170,15 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2170
2170
assert (pindexNew->pprev == chainActive.Tip ());
2171
2171
// Read block from disk.
2172
2172
int64_t nTime1 = GetTimeMicros ();
2173
- CBlock block;
2174
2173
if (!pblock) {
2175
- if (!ReadBlockFromDisk (block, pindexNew, chainparams.GetConsensus ()))
2174
+ std::shared_ptr<CBlock> pblockNew = std::make_shared<CBlock>();
2175
+ connectTrace.blocksConnected .emplace_back (pindexNew, pblockNew);
2176
+ if (!ReadBlockFromDisk (*pblockNew, pindexNew, chainparams.GetConsensus ()))
2176
2177
return AbortNode (state, " Failed to read block" );
2177
- pblock = █
2178
+ pblock = pblockNew.get ();
2179
+ } else {
2180
+ // TODO: This copy is a major performance regression, but ProcessNewBlock callers need updated to fix this
2181
+ connectTrace.blocksConnected .emplace_back (pindexNew, std::make_shared<const CBlock>(*pblock));
2178
2182
}
2179
2183
// Apply the block atomically to the chain state.
2180
2184
int64_t nTime2 = GetTimeMicros (); nTimeReadFromDisk += nTime2 - nTime1;
@@ -2205,9 +2209,6 @@ bool static ConnectTip(CValidationState& state, const CChainParams& chainparams,
2205
2209
// Update chainActive & related variables.
2206
2210
UpdateTip (pindexNew, chainparams);
2207
2211
2208
- for (unsigned int i=0 ; i < pblock->vtx .size (); i++)
2209
- connectTrace.txChanged .emplace_back (pblock->vtx [i], pindexNew, i);
2210
-
2211
2212
int64_t nTime6 = GetTimeMicros (); nTimePostConnect += nTime6 - nTime5; nTimeTotal += nTime6 - nTime1;
2212
2213
LogPrint (" bench" , " - Connect postprocess: %.2fms [%.2fs]\n " , (nTime6 - nTime5) * 0.001 , nTimePostConnect * 0.000001 );
2213
2214
LogPrint (" bench" , " - Connect block: %.2fms [%.2fs]\n " , (nTime6 - nTime1) * 0.001 , nTimeTotal * 0.000001 );
@@ -2329,6 +2330,8 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
2329
2330
state = CValidationState ();
2330
2331
fInvalidFound = true ;
2331
2332
fContinue = false ;
2333
+ // If we didn't actually connect the block, don't notify listeners about it
2334
+ connectTrace.blocksConnected .pop_back ();
2332
2335
break ;
2333
2336
} else {
2334
2337
// A system error occurred (disk space, database error, ...).
@@ -2431,8 +2434,12 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2431
2434
GetMainSignals ().SyncTransaction (*tx, pindexNewTip, CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK);
2432
2435
}
2433
2436
// ... and about transactions that got confirmed:
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]));
2437
+ for (const auto & pair : connectTrace.blocksConnected ) {
2438
+ assert (pair.second );
2439
+ const CBlock& block = *(pair.second );
2440
+ for (unsigned int i = 0 ; i < block.vtx .size (); i++)
2441
+ GetMainSignals ().SyncTransaction (*block.vtx [i], pair.first , i);
2442
+ }
2436
2443
2437
2444
// Notify external listeners about the new tip.
2438
2445
GetMainSignals ().UpdatedBlockTip (pindexNewTip, pindexFork, fInitialDownload );
0 commit comments