@@ -2288,7 +2288,7 @@ static void PruneBlockIndexCandidates() {
2288
2288
* Try to make some progress towards making pindexMostWork the active block.
2289
2289
* pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
2290
2290
*/
2291
- static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const CBlock* pblock, bool & fInvalidFound , ConnectTrace& connectTrace)
2291
+ static bool ActivateBestChainStep (CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr< const CBlock>& pblock, bool & fInvalidFound , ConnectTrace& connectTrace)
2292
2292
{
2293
2293
AssertLockHeld (cs_main);
2294
2294
const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2321,8 +2321,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
2321
2321
2322
2322
// Connect new blocks.
2323
2323
BOOST_REVERSE_FOREACH (CBlockIndex *pindexConnect, vpindexToConnect) {
2324
- // TODO: The pblock copy is a major performance regression, but callers need updated to fix this
2325
- if (!ConnectTip (state, chainparams, pindexConnect, (pblock && pindexConnect == pindexMostWork) ? std::make_shared<const CBlock>(*pblock) : std::shared_ptr<const CBlock>(), connectTrace)) {
2324
+ if (!ConnectTip (state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace)) {
2326
2325
if (state.IsInvalid ()) {
2327
2326
// The block violates a consensus rule.
2328
2327
if (!state.CorruptionPossible ())
@@ -2389,7 +2388,7 @@ static void NotifyHeaderTip() {
2389
2388
* or an activated best chain. pblock is either NULL or a pointer to a block
2390
2389
* that is already loaded (to avoid loading it again from disk).
2391
2390
*/
2392
- bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, const CBlock * pblock) {
2391
+ bool ActivateBestChain (CValidationState &state, const CChainParams& chainparams, std::shared_ptr< const CBlock> pblock) {
2393
2392
CBlockIndex *pindexMostWork = NULL ;
2394
2393
CBlockIndex *pindexNewTip = NULL ;
2395
2394
do {
@@ -2412,7 +2411,8 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
2412
2411
return true ;
2413
2412
2414
2413
bool fInvalidFound = false ;
2415
- if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : NULL , fInvalidFound , connectTrace))
2414
+ std::shared_ptr<const CBlock> nullBlockPtr;
2415
+ if (!ActivateBestChainStep (state, chainparams, pindexMostWork, pblock && pblock->GetHash () == pindexMostWork->GetBlockHash () ? pblock : nullBlockPtr, fInvalidFound , connectTrace))
2416
2416
return false ;
2417
2417
2418
2418
if (fInvalidFound ) {
@@ -3142,8 +3142,13 @@ bool ProcessNewBlock(const CChainParams& chainparams, const CBlock* pblock, bool
3142
3142
3143
3143
NotifyHeaderTip ();
3144
3144
3145
+ // TODO: This copy is a major performance regression, but callers need updated to fix this
3146
+ std::shared_ptr<const CBlock> block_ptr;
3147
+ if (pblock)
3148
+ block_ptr.reset (new CBlock (*pblock));
3149
+
3145
3150
CValidationState state; // Only used to report errors, not invalidity - ignore it
3146
- if (!ActivateBestChain (state, chainparams, pblock ))
3151
+ if (!ActivateBestChain (state, chainparams, block_ptr ))
3147
3152
return error (" %s: ActivateBestChain failed" , __func__);
3148
3153
3149
3154
return true ;
0 commit comments