Skip to content

Commit 180586f

Browse files
committed
Call AcceptBlock with the block's shared_ptr instead of CBlock&
1 parent 8baaba6 commit 180586f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/validation.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3047,8 +3047,10 @@ bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& headers, CValidatio
30473047
}
30483048

30493049
/** Store block on disk. If dbp is non-NULL, the file is known to already reside on disk */
3050-
static bool AcceptBlock(const CBlock& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock)
3050+
static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock)
30513051
{
3052+
const CBlock& block = *pblock;
3053+
30523054
if (fNewBlock) *fNewBlock = false;
30533055
AssertLockHeld(cs_main);
30543056

@@ -3128,7 +3130,7 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
31283130
CBlockIndex *pindex = NULL;
31293131
if (fNewBlock) *fNewBlock = false;
31303132
CValidationState state;
3131-
bool ret = AcceptBlock(*pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock);
3133+
bool ret = AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, NULL, fNewBlock);
31323134
CheckBlockIndex(chainparams.GetConsensus());
31333135
if (!ret) {
31343136
GetMainSignals().BlockChecked(*pblock, state);
@@ -3755,7 +3757,8 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
37553757
dbp->nPos = nBlockPos;
37563758
blkdat.SetLimit(nBlockPos + nSize);
37573759
blkdat.SetPos(nBlockPos);
3758-
CBlock block;
3760+
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
3761+
CBlock& block = *pblock;
37593762
blkdat >> block;
37603763
nRewind = blkdat.GetPos();
37613764

@@ -3773,7 +3776,7 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
37733776
if (mapBlockIndex.count(hash) == 0 || (mapBlockIndex[hash]->nStatus & BLOCK_HAVE_DATA) == 0) {
37743777
LOCK(cs_main);
37753778
CValidationState state;
3776-
if (AcceptBlock(block, state, chainparams, NULL, true, dbp, NULL))
3779+
if (AcceptBlock(pblock, state, chainparams, NULL, true, dbp, NULL))
37773780
nLoaded++;
37783781
if (state.IsError())
37793782
break;
@@ -3800,16 +3803,17 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB
38003803
std::pair<std::multimap<uint256, CDiskBlockPos>::iterator, std::multimap<uint256, CDiskBlockPos>::iterator> range = mapBlocksUnknownParent.equal_range(head);
38013804
while (range.first != range.second) {
38023805
std::multimap<uint256, CDiskBlockPos>::iterator it = range.first;
3803-
if (ReadBlockFromDisk(block, it->second, chainparams.GetConsensus()))
3806+
std::shared_ptr<CBlock> pblockrecursive = std::make_shared<CBlock>();
3807+
if (ReadBlockFromDisk(*pblockrecursive, it->second, chainparams.GetConsensus()))
38043808
{
3805-
LogPrint("reindex", "%s: Processing out of order child %s of %s\n", __func__, block.GetHash().ToString(),
3809+
LogPrint("reindex", "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(),
38063810
head.ToString());
38073811
LOCK(cs_main);
38083812
CValidationState dummy;
3809-
if (AcceptBlock(block, dummy, chainparams, NULL, true, &it->second, NULL))
3813+
if (AcceptBlock(pblockrecursive, dummy, chainparams, NULL, true, &it->second, NULL))
38103814
{
38113815
nLoaded++;
3812-
queue.push_back(block.GetHash());
3816+
queue.push_back(pblockrecursive->GetHash());
38133817
}
38143818
}
38153819
range.first++;

0 commit comments

Comments
 (0)