aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorLuke Dashjr <[email protected]>2012-08-12 17:14:15 +0000
committerLuke Dashjr <[email protected]>2012-08-12 17:14:29 +0000
commit89c5c381b7e8e29da361e1bf647010ad94e5fea0 (patch)
treef13719abe0887bba94b23de542a20f78c50495ab /src/bitcoinrpc.cpp
parentMerge branch '0.5.x' into 0.6.0.x (diff)
parentMerge branch 'bugfix_CNBerr' into 0.5.x (diff)
downloaddiscoin-89c5c381b7e8e29da361e1bf647010ad94e5fea0.tar.xz
discoin-89c5c381b7e8e29da361e1bf647010ad94e5fea0.zip
Merge branch '0.5.x' into 0.6.0.x
Diffstat (limited to 'src/bitcoinrpc.cpp')
-rw-r--r--src/bitcoinrpc.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp
index 78812ba63..e5bb5a0e5 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1814,8 +1814,13 @@ Value getwork(const Array& params, bool fHelp)
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
@@ -1823,6 +1828,9 @@ Value getwork(const Array& params, bool fHelp)
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
@@ -1913,16 +1921,26 @@ Value getmemorypool(const Array& params, bool fHelp)
if (pindexPrev != pindexBest ||
(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;
- pindexPrev = pindexBest;
+ CBlockIndex* pindexPrevNew = pindexBest;
nStart = GetTime();
// Create new block
if(pblock)
+ {
delete pblock;
+ pblock = NULL;
+ }
pblock = CreateNewBlock(reservekey);
if (!pblock)
throw JSONRPCError(-7, "Out of memory");
+
+ // Need to update only after we know CreateNewBlock succeeded
+ pindexPrev = pindexPrevNew;
}
// Update nTime