aboutsummaryrefslogtreecommitdiff
path: root/src/rpcmining.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-10-14 20:39:00 -0700
committerGavin Andresen <gavinandresen@gmail.com>2013-10-14 20:39:00 -0700
commitb9beea6e9d0f789f11d249b040e549d535bdc295 (patch)
treee87c3422b52b1f6d78b88b9cea756c1f3cb8d37b /src/rpcmining.cpp
parentae6601872be4065f90713b9b6ef07e9883afec79 (diff)
parent4c6d41b8b653ef90639b1a32f6aab0bb1cef90c5 (diff)
Merge pull request #3077 from sipa/chain
Refactor/encapsulate chain globals into a CChain class
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r--src/rpcmining.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp
index b013b4b200..f123c3a9e0 100644
--- a/src/rpcmining.cpp
+++ b/src/rpcmining.cpp
@@ -37,10 +37,7 @@ void ShutdownRPCMining()
// or from the last difficulty change if 'lookup' is nonpositive.
// If 'height' is nonnegative, compute the estimate at the time when a given block was found.
Value GetNetworkHashPS(int lookup, int height) {
- CBlockIndex *pb = pindexBest;
-
- if (height >= 0 && height < nBestHeight)
- pb = FindBlockByHeight(height);
+ CBlockIndex *pb = chainActive[height];
if (pb == NULL || !pb->nHeight)
return 0;
@@ -148,7 +145,7 @@ Value getmininginfo(const Array& params, bool fHelp)
"Returns an object containing mining-related information.");
Object obj;
- obj.push_back(Pair("blocks", (int)nBestHeight));
+ obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize));
obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx));
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
@@ -192,10 +189,10 @@ Value getwork(const Array& params, bool fHelp)
static CBlockIndex* pindexPrev;
static int64 nStart;
static CBlockTemplate* pblocktemplate;
- if (pindexPrev != pindexBest ||
+ if (pindexPrev != chainActive.Tip() ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
{
- if (pindexPrev != pindexBest)
+ if (pindexPrev != chainActive.Tip())
{
// Deallocate old blocks since they're obsolete now
mapNewBlock.clear();
@@ -209,7 +206,7 @@ Value getwork(const Array& params, bool fHelp)
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
- CBlockIndex* pindexPrevNew = pindexBest;
+ CBlockIndex* pindexPrevNew = chainActive.Tip();
nStart = GetTime();
// Create new block
@@ -328,7 +325,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
static CBlockIndex* pindexPrev;
static int64 nStart;
static CBlockTemplate* pblocktemplate;
- if (pindexPrev != pindexBest ||
+ if (pindexPrev != chainActive.Tip() ||
(nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
{
// Clear pindexPrev so future calls make a new block, despite any failures from here on
@@ -336,7 +333,7 @@ Value getblocktemplate(const Array& params, bool fHelp)
// Store the pindexBest used before CreateNewBlock, to avoid races
nTransactionsUpdatedLast = nTransactionsUpdated;
- CBlockIndex* pindexPrevNew = pindexBest;
+ CBlockIndex* pindexPrevNew = chainActive.Tip();
nStart = GetTime();
// Create new block