aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp46
1 files changed, 3 insertions, 43 deletions
diff --git a/src/pow.cpp b/src/pow.cpp
index 5ace3fbc9b..058404f357 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -1,5 +1,5 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2014 The Bitcoin Core developers
+// Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -9,7 +9,6 @@
#include "chain.h"
#include "primitives/block.h"
#include "uint256.h"
-#include "util.h"
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params)
{
@@ -57,7 +56,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
// Limit adjustment step
int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
- LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < params.nPowTargetTimespan/4)
nActualTimespan = params.nPowTargetTimespan/4;
if (nActualTimespan > params.nPowTargetTimespan*4)
@@ -75,12 +73,6 @@ unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nF
if (bnNew > bnPowLimit)
bnNew = bnPowLimit;
- /// debug print
- LogPrintf("GetNextWorkRequired RETARGET\n");
- LogPrintf("params.nPowTargetTimespan = %d nActualTimespan = %d\n", params.nPowTargetTimespan, nActualTimespan);
- LogPrintf("Before: %08x %s\n", pindexLast->nBits, bnOld.ToString());
- LogPrintf("After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString());
-
return bnNew.GetCompact();
}
@@ -94,43 +86,11 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&
// Check range
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.powLimit))
- return error("CheckProofOfWork(): nBits below minimum work");
+ return false;
// Check proof of work matches claimed amount
if (UintToArith256(hash) > bnTarget)
- return error("CheckProofOfWork(): hash doesn't match nBits");
+ return false;
return true;
}
-
-arith_uint256 GetBlockProof(const CBlockIndex& block)
-{
- arith_uint256 bnTarget;
- bool fNegative;
- bool fOverflow;
- bnTarget.SetCompact(block.nBits, &fNegative, &fOverflow);
- if (fNegative || fOverflow || bnTarget == 0)
- return 0;
- // We need to compute 2**256 / (bnTarget+1), but we can't represent 2**256
- // as it's too large for a arith_uint256. However, as 2**256 is at least as large
- // as bnTarget+1, it is equal to ((2**256 - bnTarget - 1) / (bnTarget+1)) + 1,
- // or ~bnTarget / (nTarget+1) + 1.
- return (~bnTarget / (bnTarget + 1)) + 1;
-}
-
-int64_t GetBlockProofEquivalentTime(const CBlockIndex& to, const CBlockIndex& from, const CBlockIndex& tip, const Consensus::Params& params)
-{
- arith_uint256 r;
- int sign = 1;
- if (to.nChainWork > from.nChainWork) {
- r = to.nChainWork - from.nChainWork;
- } else {
- r = from.nChainWork - to.nChainWork;
- sign = -1;
- }
- r = r * arith_uint256(params.nPowTargetSpacing) / GetBlockProof(tip);
- if (r.bits() > 63) {
- return sign * std::numeric_limits<int64_t>::max();
- }
- return sign * r.GetLow64();
-}