aboutsummaryrefslogtreecommitdiff
path: root/src/bitcoinrpc.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-07-26 13:55:21 -0400
committerGavin Andresen <gavinandresen@gmail.com>2012-07-26 13:55:21 -0400
commit986a78979ef4e7d26ac10dcf5b2dfd0282d2e462 (patch)
tree909412f04fedde2bda0105198b85b27af314b9d2 /src/bitcoinrpc.cpp
parent701e1f5254b418f1f5317fe5eca25a4f47059abc (diff)
parent5d53f48acbbba0ac80e8a26545a3ecaf8d139356 (diff)
downloadbitcoin-986a78979ef4e7d26ac10dcf5b2dfd0282d2e462.tar.xz
Merge branch 'bugfix_CNBerr' of git://github.com/luke-jr/bitcoin
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 85ef9031c7..3af298a58b 100644
--- a/src/bitcoinrpc.cpp
+++ b/src/bitcoinrpc.cpp
@@ -1851,8 +1851,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
@@ -1860,6 +1865,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
@@ -1950,16 +1958,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