aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2011-05-26 23:35:00 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2011-05-26 23:35:00 +0200
commit5e1e458ecb0f5d8e42e1a7fc3b8f9e1d37f52e46 (patch)
tree2347755d1781c9b11a4702a594dad8ace403f0c8
parentdb69432dcdc8bcf9fcc4b2554593d9e0fac4918a (diff)
downloadbitcoin-5e1e458ecb0f5d8e42e1a7fc3b8f9e1d37f52e46.tar.xz
loss of significance in difficulty (by lfm)
For instance any nBits compressed value from 0x1a44b800 thru 0x1a44b9ff will show as difficulty 244139.4816. This patch will more accurately convert the nBits compressed values to the double difficulty. This will display any of the recent difficulty levels slightly differently though. Early difficulties and testnet difficulties are not large enough to trigger this bug. None of the actual targets or compressed targets are changed, only the conversion to the floating point difficulty is changed and afaik it is only ever displayed, never converted back so the patch does not effect the target calculations, binary files, databases nor the binary protocol.
-rw-r--r--src/rpc.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/rpc.cpp b/src/rpc.cpp
index 9efcbbb15a..530bef4a43 100644
--- a/src/rpc.cpp
+++ b/src/rpc.cpp
@@ -199,12 +199,26 @@ double GetDifficulty()
{
// Floating point number that is a multiple of the minimum difficulty,
// minimum difficulty = 1.0.
+
if (pindexBest == NULL)
return 1.0;
- int nShift = 256 - 32 - 31; // to fit in a uint
- double dMinimum = (CBigNum().SetCompact(bnProofOfWorkLimit.GetCompact()) >> nShift).getuint();
- double dCurrently = (CBigNum().SetCompact(pindexBest->nBits) >> nShift).getuint();
- return dMinimum / dCurrently;
+ int nShift = (pindexBest->nBits >> 24) & 0xff;
+
+ double dDiff =
+ (double)0x0000ffff / (double)(pindexBest->nBits & 0x00ffffff);
+
+ while (nShift < 29)
+ {
+ dDiff *= 256.0;
+ nShift++;
+ }
+ while (nShift > 29)
+ {
+ dDiff /= 256.0;
+ nShift--;
+ }
+
+ return dDiff;
}
Value getdifficulty(const Array& params, bool fHelp)