Author

Topic: Difficulty with Difficulty (Read 221 times)

newbie
Activity: 4
Merit: 0
May 31, 2018, 08:20:07 AM
#7
Now, once I have figured how to handle the very large numbers in PHP I should be in good shape.
Can you use bc (see PHP: BC Math?

Code:
echo 26959535291011309493156476344723991336010898738574164086137773096960 / 4306949573981.513 | bc
6259542822111301937734005144785305510317670759324150579



The actual arithmetic (floating point) was not too much of a problem, the challenge was converting the result to hex. I managed to find a bit of code on the web which did the job a treat.

https://stackoverflow.com/questions/5301034/how-to-generate-random-64-bit-value-as-decimal-string-in-php/5302533#5302533

(Section 2 of the above link.)
legendary
Activity: 3290
Merit: 16489
Thick-Skinned Gang Leader and Golden Feather 2021
May 30, 2018, 02:17:52 PM
#6
Now, once I have figured how to handle the very large numbers in PHP I should be in good shape.
Can you use bc (see PHP: BC Math?

Code:
echo 26959535291011309493156476344723991336010898738574164086137773096960 / 4306949573981.513 | bc
6259542822111301937734005144785305510317670759324150579

newbie
Activity: 4
Merit: 0
May 30, 2018, 09:49:50 AM
#5
Excellent response. Thank you. I found that the digits to the right of the decimal point in the value returned from Getdifficulty can safely be ignored.

Now, once I have figured how to handle the very large numbers in PHP I should be in good shape.
legendary
Activity: 1624
Merit: 2481
May 30, 2018, 07:06:25 AM
#4
First, you need to convert your decimal number into hex.
Then you will have a packed represantation of the target.

Thanks for the quick reply. A problem I have is how to interpret the number returned, for example

4306949573981.513

What does the period represent? Is it simply a decimal point? If so, do I ignore the digits to the right of the decimal point when converting the number to hex?

Does the period represent a floating point number?


I have to correct my statement, please ignore those two sentences.


getDifficulty() returns the factor (decimal) which describes how much more difficult it is to find a block, relative to the difficulty at the highest possible target (highest target = lowest difficulty).

Difficulty = largest possible target / current target.


So to calculate the target you have to divide the largest possible target (0x00000000FFFF0000000000000000000000000000000000000000000000000000) by the difficulty.



In your case:


Largest possible target:
(0x00000000FFFF0000000000000000000000000000000000000000000000000000)16 = (26959535291011309493156476344723991336010898738574164086137773096960)10

Largest target / difficulty:
26959535291011309493156476344723991336010898738574164086137773096960) / 4306949573981.513 = 6.2595428 * 1054

Converted into hex: 0x415A48FC207EB1A005D72938CFF3FCCF0A000000000000

Now padding with leading 0's until length = 64: 0x000000000000000000415A48FC207EB1A005D72938CFF3FCCF0A000000000000


So the current target is :
000000000000000000415A48FC207EB1A005D72938CFF3FCCF0A000000000000
The hash of the latest block is
0000000000000000003424388ace9f93daaaf2980e41fcf0408e0c6f10800de9
newbie
Activity: 4
Merit: 0
May 30, 2018, 04:27:36 AM
#3
First, you need to convert your decimal number into hex.
Then you will have a packed represantation of the target.

Thanks for the quick reply. A problem I have is how to interpret the number returned, for example

4306949573981.513

What does the period represent? Is it simply a decimal point? If so, do I ignore the digits to the right of the decimal point when converting the number to hex?

Does the period represent a floating point number?
legendary
Activity: 1624
Merit: 2481
May 30, 2018, 04:02:52 AM
#2
~~Edit: Statement corrected, calculation in second post~~



For example:
If the packed target from the block is 0x1b0404cb, the target you are looking for is:

Code:
0x0404cb * 2**(8*(0x1b - 3)) = 0x00000000000404CB000000000000000000000000000000000000000000000000


Source: https://en.bitcoin.it/wiki/Difficulty#How_is_difficulty_stored_in_blocks.3F
newbie
Activity: 4
Merit: 0
May 30, 2018, 03:44:40 AM
#1
I am using Bitcoin Core 64-bit, 0.16.0 (on Windows 7) and I am playing around with PHP to access Bitcoin client with RPC.

It's all going quite well but I have hit a bit of a roadblock trying to process Difficulty.

The "GetDifficulty" RPC call returns a value like
4306949573981.513


How do I transform this value into an actual target like 0x1b0404cb ?
Jump to: