@@ -2288,7 +2288,7 @@ static void PruneBlockIndexCandidates() {
22882288 * Try to make some progress towards making pindexMostWork the active block.
22892289 * pblock is either NULL or a pointer to a CBlock corresponding to pindexMostWork.
22902290 */
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)
22922292{
22932293 AssertLockHeld (cs_main);
22942294 const CBlockIndex *pindexOldTip = chainActive.Tip ();
@@ -2321,8 +2321,7 @@ static bool ActivateBestChainStep(CValidationState& state, const CChainParams& c
23212321
23222322 // Connect new blocks.
23232323 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)) {
23262325 if (state.IsInvalid ()) {
23272326 // The block violates a consensus rule.
23282327 if (!state.CorruptionPossible ())
@@ -2389,7 +2388,7 @@ static void NotifyHeaderTip() {
23892388 * or an activated best chain. pblock is either NULL or a pointer to a block
23902389 * that is already loaded (to avoid loading it again from disk).
23912390 */
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) {
23932392 CBlockIndex *pindexMostWork = NULL ;
23942393 CBlockIndex *pindexNewTip = NULL ;
23952394 do {
@@ -2412,7 +2411,8 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
24122411 return true ;
24132412
24142413 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))
24162416 return false ;
24172417
24182418 if (fInvalidFound ) {
@@ -3142,8 +3142,13 @@ bool ProcessNewBlock(const CChainParams& chainparams, const CBlock* pblock, bool
31423142
31433143 NotifyHeaderTip ();
31443144
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+
31453150 CValidationState state; // Only used to report errors, not invalidity - ignore it
3146- if (!ActivateBestChain (state, chainparams, pblock ))
3151+ if (!ActivateBestChain (state, chainparams, block_ptr ))
31473152 return error (" %s: ActivateBestChain failed" , __func__);
31483153
31493154 return true ;
0 commit comments