diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-10-10 23:07:44 +0200 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-10-11 23:25:50 +0200 |
commit | 4c6d41b8b653ef90639b1a32f6aab0bb1cef90c5 (patch) | |
tree | 3e29135e08fa64984cd47fdfeda42d55e7e51ad8 /src/rpcmining.cpp | |
parent | c74b6c3d8fcc1750fa0861ae851b353a7f3495d2 (diff) |
Refactor/encapsulate chain globals into a CChain class
Diffstat (limited to 'src/rpcmining.cpp')
-rw-r--r-- | src/rpcmining.cpp | 17 |
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 |