r/Bitcoin•
alphabytes

ELI5: what is a target? and how it is calculated?

hi all,

I tried referring to the wiki but did not understand it completely... also i am unsure on how the bitcoin client know about what to hash and how to submit the hash? and what determines the "difficulty"? i know that It is recalculated every 2016 blocks. but did not get this statement from the wiki "It is recalculated every 2016 blocks to a value such that the previous 2016 blocks would have been generated in exactly two weeks had everyone been mining at this difficulty."

sorry if i am asking the wrong questions but i am super confused.

Posted Nov 25, 2013, 10:12 AM UTC

211
vbenes•

Target is (some big) number. Miners are trying to find a block that has hash (see 'hash' here) lower than this number (this is the reason why block hashes start with zeroes). If you make target smaller, it will be harder for miners to find the block... Harder => it will take longer. So - by changing the target you can fine tune the average time to get next block from the network...

It's similar as if we play this little game:

We have a hat with numbers from 0 to 9999. I give you a target - say 2500 - and your task is to pull a number from the hat that is lower than this... On average, you would need four tries to get number which is under 2500...

Now - if pulling one number takes you 15 seconds on average for example and I want to keep you busy for 10 minutes, I will choose 250 as target. ...so that's it. ;)

...if you improve your number-pulling skill and you can manage to pull & check one number in 3 seconds, the target would need to be five times smaller (i.e. 50) for the new round of the game so it takes you 10 minutes again (with target 50, you have the 1 in 200 chance => 200 x 3 [s] is 10 [min]).

1
alphabytesOP•

so by your example, if the target is narrow then the time you required is more to pick out the card which is less then the target.

so who sets this target value?

currently it is 00000000000000070BFB00000000000000000000000000000000000000000000

but who decides that this is the target!... is it decided by all the people participating in mining or by an individual who is going to calculate the hash?

1
vbenes•

Every full node in the network (i.e. every computer that runs the classic Bitcoin-Qt client) is performing the calculation of the target for itself. If new block (incoming from somewhere) is not matching the condition (hash is lower than target), the block is considered invalid - which means it is not relayed to other nodes.

or by an individual who is going to calculate the hash?

There is no special individual in the Bitcoin network.

Technical details: I believe the calculation is in the GetNextWorkRequired() function here:

https://github.com/bitcoin/bitcoin/blob/master/src/main.cpp#L1026

1
alphabytesOP•

thanx for the reply.

  • correct me if i am wrong, i (as in my client) have set the target to say 7 and i compute the hash which is below this target and pass it on to the network.

  • then say X is the guy(client) who has its target set to say 5. but my hash is not below the target specified by X. then my hash value will be discarded from the network.

  • but if it is below the target set by X then i will be again forwarded in the network.

  • if the hash generated is satisfying all the target set by all the clients in the network it will be accepted by the network.

and can you tell me what this means, i am referring to the wiki. (difficulty) (It) is recalculated every 2016 blocks to a value such that the previous 2016 blocks would have been generated in exactly two weeks had everyone been mining at it

"There is no special individual in the Bitcoin network." lol, sorry i sometimes refer computer/app/module as that special individual.

1
vbenes•

"There is no special individual in the Bitcoin network." lol, sorry i sometimes refer computer/app/module as that special individual.

Computers/apps/modules/whatever in Bitcoin network are individuals, but not special individuals - every (full) node in Bitcoin network is the same as all other nodes. If you shut down randomly chosen 98 % of nodes, the network will be working without problems. There is no special individual, no center.

i (as in my client) have set the target to say 7 and i compute the hash which is below this target and pass it on to the network. (...) then say X is the guy(client) who has its target set to say 5.

This should not happen - ideally, all the nodes should have the same version of bitcoin client - so all the targets on all nodes are the same number. Your thoughts are certainly interesting - because what will happen when there are clients with different versions? (I.e. full nodes that work differently than others?) I am not completely sure - but I think you can have full spectrum of outcomes - if the new version is backward compatible, Bitcoin network will be working more or less the same (the new features/optimizations will not work on older nodes) ...if nodes differ more, it can lead to more severe consequences - eventually into split of Bitcoin network into two (if you are interested in these things, you can continue study with march blockchain fork).

(It) is recalculated every 2016 blocks to a value such that the previous 2016 blocks would have been generated in exactly two weeks had everyone been mining at it

There is no other way to know how fast the mining network is than looking at how fast the blocks are coming. Block creation time is quite random (but 99%+ falls into 0..120 min interval) - so you need to average the block times => we take last 2016 blocks. Then we calculate the average block time...

Let's say the average block time is 7.5 minutes (in the moment of difficulty recalculation) - we know that we want block time to be 10 minutes (2016 blocks in 2 weeks) - so we know that the new target should be 75 % of the target we had...

You can look here:

http://bitcoinwisdom.com/bitcoin/difficulty

see the bottom chart ("Bitcon Block Generation Speed vs Difficulty") - you see there how the difficulty jumps every 2016 blocks. It jumps precisely to the value that moves the blue line (2016 blocks average to the value of 600 [s]) - i.e. this is what I described above - if the mining network cease to grow in the moment of difficulty recalculation, blocks will be coming in 10 min each on average. However, mining network grows, so the (2016) block average time jumps to 600 seconds, but then the average goes down (difficulty is the same, mining network gets faster)... You can observe this also here:

https://blockchain.info

just before difficulty change, mining of the last 7 blocks takes usually 40 - 60 minutes. Just after the next difficulty increase, the last blocks take usually 50 - 70 minutes...

1