aboutsummaryrefslogtreecommitdiff
path: root/src/pow.cpp
diff options
context:
space:
mode:
authorRoss Nicoll <[email protected]>2015-02-21 12:57:44 +0000
committerRoss Nicoll <[email protected]>2015-02-21 13:14:19 +0000
commit34e5015cd21e27c1bf635d92531afac93f553096 (patch)
tree0497bd7f74f211fd261ec173225ab8eca1760fdb /src/pow.cpp
parentRevert "Make nicer pull request merge messages" (diff)
downloaddiscoin-34e5015cd21e27c1bf635d92531afac93f553096.tar.xz
discoin-34e5015cd21e27c1bf635d92531afac93f553096.zip
Add unit tests for next difficulty calculations
Split GetNextWorkRequired() into two functions to allow the difficulty calculations to be tested without requiring a full blockchain. Add unit tests to cover basic difficulty calculation, plus each of the min/max actual time, and maximum difficulty target conditions.
Diffstat (limited to 'src/pow.cpp')
-rw-r--r--src/pow.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/pow.cpp b/src/pow.cpp
index 6dd5c4c12..b75b293c9 100644
--- a/src/pow.cpp
+++ b/src/pow.cpp
@@ -48,8 +48,13 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
pindexFirst = pindexFirst->pprev;
assert(pindexFirst);
+ return CalculateNextWorkRequired(pindexLast, pindexFirst->GetBlockTime());
+}
+
+unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime)
+{
// Limit adjustment step
- int64_t nActualTimespan = pindexLast->GetBlockTime() - pindexFirst->GetBlockTime();
+ int64_t nActualTimespan = pindexLast->GetBlockTime() - nFirstBlockTime;
LogPrintf(" nActualTimespan = %d before bounds\n", nActualTimespan);
if (nActualTimespan < Params().TargetTimespan()/4)
nActualTimespan = Params().TargetTimespan()/4;