Bugfix: getwork: NULL pindexPrev across CreateNewBlock, in case it fails

This commit is contained in:
Luke Dashjr 2012-05-09 17:02:07 +00:00
parent 776d0f3459
commit b354251f1a

10
rpc.cpp
View file

@ -967,8 +967,13 @@ Value getwork(const Array& params, bool fHelp)
delete pblock; delete pblock;
vNewBlock.clear(); vNewBlock.clear();
} }
// Clear pindexPrev so future getworks make a new block, despite any failures from here on
pindexPrev = NULL;
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated; nTransactionsUpdatedLast = nTransactionsUpdated;
pindexPrev = pindexBest; CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime(); nStart = GetTime();
// Create new block // Create new block
@ -976,6 +981,9 @@ Value getwork(const Array& params, bool fHelp)
if (!pblock) if (!pblock)
throw JSONRPCError(-7, "Out of memory"); throw JSONRPCError(-7, "Out of memory");
vNewBlock.push_back(pblock); vNewBlock.push_back(pblock);
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
} }
// Update nTime // Update nTime