From af693176a3e7f9f34fe900619afd3627715889fe Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 29 Aug 2013 03:52:46 +0400 Subject: [PATCH] Split getmininginfo implementation --- src/bitcoinrpc.h | 4 +++ src/rpcblockchain.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletions(-) diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 49a2ffd..736f362 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -127,6 +127,10 @@ extern int64 nWalletUnlockTime; extern int64 AmountFromValue(const json_spirit::Value& value); extern json_spirit::Value ValueFromAmount(int64 amount); extern double GetDifficulty(const CBlockIndex* blockindex = NULL); + +extern double GetPoWMHashPS(); +extern double GetPoSKernelPS(); + extern std::string HexBits(unsigned int nBits); extern std::string HelpRequiringPassphrase(); extern void EnsureWalletIsUnlocked(); diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index fae3e45..2226bbb 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -10,6 +10,7 @@ using namespace json_spirit; using namespace std; extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, json_spirit::Object& entry); +extern enum Checkpoints::CPMode CheckpointsMode; double GetDifficulty(const CBlockIndex* blockindex) { @@ -42,6 +43,54 @@ double GetDifficulty(const CBlockIndex* blockindex) return dDiff; } +double GetPoWMHashPS() +{ + int nPoWInterval = 72; + int64 nTargetSpacingWorkMin = 30, nTargetSpacingWork = 30; + + CBlockIndex* pindex = pindexGenesisBlock; + CBlockIndex* pindexPrevWork = pindexGenesisBlock; + + while (pindex) + { + if (pindex->IsProofOfWork()) + { + int64 nActualSpacingWork = pindex->GetBlockTime() - pindexPrevWork->GetBlockTime(); + nTargetSpacingWork = ((nPoWInterval - 1) * nTargetSpacingWork + nActualSpacingWork + nActualSpacingWork) / (nPoWInterval + 1); + nTargetSpacingWork = max(nTargetSpacingWork, nTargetSpacingWorkMin); + pindexPrevWork = pindex; + } + + pindex = pindex->pnext; + } + + return GetDifficulty() * 4294.967296 / nTargetSpacingWork; +} + +double GetPoSKernelPS() +{ + int nPoSInterval = 72; + double dStakeKernelsTriedAvg = 0; + int nStakesHandled = 0, nStakesTime = 0; + + CBlockIndex* pindex = pindexBest;; + CBlockIndex* pindexPrevStake = NULL; + + while (pindex && nStakesHandled < nPoSInterval) + { + if (pindex->IsProofOfStake()) + { + dStakeKernelsTriedAvg += GetDifficulty(pindex) * 4294967296.0; + nStakesTime += pindexPrevStake ? (pindexPrevStake->nTime - pindex->nTime) : 0; + pindexPrevStake = pindex; + nStakesHandled++; + } + + pindex = pindex->pprev; + } + + return dStakeKernelsTriedAvg / nStakesTime; +} Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool fPrintTransactionDetail) { @@ -237,7 +286,17 @@ Value getcheckpoint(const Array& params, bool fHelp) pindexCheckpoint = mapBlockIndex[Checkpoints::hashSyncCheckpoint]; result.push_back(Pair("height", pindexCheckpoint->nHeight)); result.push_back(Pair("timestamp", DateTimeStrFormat(pindexCheckpoint->GetBlockTime()).c_str())); - result.push_back(Pair("policy", GetArg("-cppolicy", "strict").c_str())); + + // Check that the block satisfies synchronized checkpoint + if (CheckpointsMode == Checkpoints::STRICT) + result.push_back(Pair("policy", "strict")); + + if (CheckpointsMode == Checkpoints::ADVISORY) + result.push_back(Pair("policy", "advisory")); + + if (CheckpointsMode == Checkpoints::PERMISSIVE) + result.push_back(Pair("policy", "permissive")); + if (mapArgs.count("-checkpointkey")) result.push_back(Pair("checkpointmaster", true)); -- 1.7.1