changeset 2444:0af264877a33 draft

Bugfix: getwork: NULL pindexPrev across CreateNewBlock, in case it fails
author Luke Dashjr <luke-jr+git@utopios.org>
date Wed, 09 May 2012 17:02:07 +0000
parents 94c9b179df77
children 28d9422ecd90
files rpc.cpp
diffstat 1 files changed, 9 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -967,8 +967,13 @@
                     delete pblock;
                 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;
-            pindexPrev = pindexBest;
+            CBlockIndex* pindexPrevNew = pindexBest;
             nStart = GetTime();
 
             // Create new block
@@ -976,6 +981,9 @@
             if (!pblock)
                 throw JSONRPCError(-7, "Out of memory");
             vNewBlock.push_back(pblock);
+
+            // Need to update only after we know CreateNewBlock succeeded
+            pindexPrev = pindexPrevNew;
         }
 
         // Update nTime