Browse Source

Merge branch 'bugfix_CNBerr' of git://github.com/luke-jr/bitcoin

miguelfreitas
Gavin Andresen 13 years ago
parent
commit
986a78979e
  1. 22
      src/bitcoinrpc.cpp

22
src/bitcoinrpc.cpp

@ -1851,8 +1851,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
@ -1860,6 +1865,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
@ -1950,16 +1958,26 @@ Value getmemorypool(const Array& params, bool fHelp)
if (pindexPrev != pindexBest || if (pindexPrev != pindexBest ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5)) (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
{ {
// Clear pindexPrev so future calls 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
if(pblock) if(pblock)
{
delete pblock; delete pblock;
pblock = NULL;
}
pblock = CreateNewBlock(reservekey); pblock = CreateNewBlock(reservekey);
if (!pblock) if (!pblock)
throw JSONRPCError(-7, "Out of memory"); throw JSONRPCError(-7, "Out of memory");
// Need to update only after we know CreateNewBlock succeeded
pindexPrev = pindexPrevNew;
} }
// Update nTime // Update nTime

Loading…
Cancel
Save