Bitcoin Forum

Bitcoin => Mining support => Topic started by: pacojones on November 11, 2013, 06:38:16 PM



Title: Where does it start?
Post by: pacojones on November 11, 2013, 06:38:16 PM
I'm not even sure how to ask this question so here goes:

The bitcoin mining network is hashing away and pool X finds a block - question:  once a miner sees that a block is solved, how does it know where to start mining the next block?

Example:
- block found
- network notified
- Miner 1 > starts to brute force the next block by trying 1111, 1112, 1113, 1114
- Miner 2 > starts to brute force the new block by trying ??????
- Miner 3 > starts to brute force the new block by trying ??????
- Miner 4 > starts to brute force the new block by trying ??????
- Miner 5 > starts to brute force the new block by trying ??????

What's to keep all 5 miners from starting at the same starting position and therefore (basically) finding the 'solution' at the same time?  Is there some sort of randomization calculator built into the software so the miners all start at a different point??  I mean if I have 5 miners going myself and they are all trying to solve the same problem and they are all starting at the same start position they would all be doing the same work!

I hope this makes sense - sorry for the crude example!


Title: Re: Where does it start?
Post by: ineedit on November 11, 2013, 06:45:14 PM
I'm not even sure how to ask this question so here goes:

The bitcoin mining network is hashing away and pool X finds a block - question:  once a miner sees that a block is solved, how does it know where to start mining the next block?

Example:
- block found
- network notified
- Miner 1 > starts to brute force the next block by trying 1111, 1112, 1113, 1114
- Miner 2 > starts to brute force the new block by trying ??????
- Miner 3 > starts to brute force the new block by trying ??????
- Miner 4 > starts to brute force the new block by trying ??????
- Miner 5 > starts to brute force the new block by trying ??????

What's to keep all 5 miners from starting at the same starting position and therefore (basically) finding the 'solution' at the same time?  Is there some sort of randomization calculator built into the software so the miners all start at a different point??  I mean if I have 5 miners going myself and they are all trying to solve the same problem and they are all starting at the same start position they would all be doing the same work!

I hope this makes sense - sorry for the crude example!


You might want to start here http://codinginmysleep.com/bitcoin-mining-in-plain-english/


Title: Re: Where does it start?
Post by: os2sam on November 11, 2013, 07:16:26 PM
And here, or hear :)

https://media.grc.com/sn/sn-287-lq.mp3


Title: Re: Where does it start?
Post by: DeathAndTaxes on November 11, 2013, 07:34:39 PM
Your example is too crude to provide anything to correct.

First of all if you are mining for a pool you really aren't a "miner" you are a SHA-2 hashpower provider (independent contractor), your pool makes sure there is no duplicate work.  For the purpose of this explanation, only entities which construct the block headers are "miners" (pool operators, solo miners, and some unique situations like p2pool).

No miner is working on the same "work".  You aren't just hashing a single number.  That would be beyond pointless it wouldn't provide any security.  What does the number 123456 hashed mean?  Absolutely nothing.  How would it prevent modifying the blockchain?  It wouldn't.  

You are hashing a blockheader which consists of 6 values only one of which is "the number" which is called a nonce.  The nonce is simply a way to add entropy so you can make multiple tries without changing anything else in the blockheader.

So what is in the blockheader?

Code:
Field	        Purpose	                                                    Updated when
Version        Block version number                                    You upgrade the software and it specifies a new version
hashPrevBlock 256-bit hash of the previous block header            A new block comes in
hashMerkleRoot 256-bit hash based on all of the transactions in the block  A transaction is accepted
Time        Current timestamp as seconds since 1970-01-01T00:00 UTC    Every few seconds
Bits        Current target in compact format                    The difficulty is adjusted
Nonce        32-bit number (starts at 0)                            A hash is tried (increments)
https://en.bitcoin.it/wiki/Block_hashing_algorithm

If ANY of these values are different the hash will be different.  Miners routinely attempt the same nonce.  Your own individual miners will attempt the same nonce millions of times.  The nonce is only 32 bit, there are only 4 billion possibilities.  A KNC Jupiter for example will exhaust the nonce range in less than 1/100th of a second.  Even a low end GPU will try all possible nonces (for a given blockheader) in a few seconds.

The "hashMerkleRoot" is a unique hash which represents all the transactions in the block.   If you add, remove, or change ONE transaction in the block you will end up with a different Merkle Root hash.  One of those transactions is the "coinbase" where miners receive their reward.  Even two miners (solo miners, pools, p2pool users) which have the exact same set of other transactions will still have a unique coinbase txs and thus have different Merkle Root hashes.

Different Merkle Root Hash = Different Block Header = Different Hash.

No two miners on the planet are ever working on the same work (with the exception of a bug in a pool server issuing duplicate work to its workers).


Title: Re: Where does it start?
Post by: pacojones on November 12, 2013, 12:18:47 AM
If ANY of these values are different the hash will be different.  Miners routinely attempt the same nonce.  Your own individual miners will attempt the same nonce millions of times.  The nonce is only 32 bit, there are only 4 billion possibilities.  A KNC Jupiter for example will exhaust the nonce range in less than 1/100th of a second.  Even a low end GPU will try all possible nonces (for a given blockheader) in a few seconds.

The "hashMerkleRoot" is a unique hash which represents all the transactions in the block.   If you add, remove, or change ONE transaction in the block you will end up with a different Merkle Root hash.  One of those transactions is the "coinbase" where miners receive their reward.  Even two miners (solo miners, pools, p2pool users) which have the exact same set of other transactions will still have a unique coinbase txs and thus have different Merkle Root hashes.

Different Merkle Root Hash = Different Block Header = Different Hash.


https://en.bitcoin.it/wiki/Block_hashing_algorithm
Given just those fields, people would frequently generate the exact same sequence of hashes as each other and the fastest CPU would almost always win. However, it is (nearly) impossible for two people to have the same Merkle root because the first transaction in your block is a generation "sent" to one of your unique Bitcoin addresses. Since your block is different from everyone else's blocks, you are (nearly) guaranteed to produce different hashes. Every hash you calculate has the same chance of winning as every other hash calculated by the network.

This is starting to make sense - thank you


Title: Re: Where does it start?
Post by: DeathAndTaxes on November 12, 2013, 12:53:37 AM
Yes.  Given the size of the hash space (2^256) we can drop the "nearly" from the impossible & guaranteed.  The block headers will be unique.  The probability of two unique block headers producing the same has are 1 in 2^256 which for all practical intents in purposes is 0.

There is one additional "field" which is more useful to pools.  The coinbase input field has no use in Bitcoin so it can hold any arbitrary psuedo random value.  This is used by pools as an "extra nonce" field so they can give two wokers different blockheaders despite having the same tx set.  Changing the extra nonce in the coinbase tx will change the tx hash which will change the merkle tree root hash.  This way by incrementing the extra-nonce field a pool can quickly assign unique (but very similar) work to thousands of workers if necessary.