Post
Topic
Board Development & Technical Discussion
Re: Questions behind mining
by
gmaxwell
on 17/06/2011, 20:33:51 UTC
As far as I see, the basic idea of mining, is that we get piece of data, where we need to try all variants of 4 specific bytes = 2^32 variants, we hash this data using SHA256 and if we get value meeting our difficulty requirements we "win"(?)

I wonder how does this work on lower level:

1) How it's made that different clients does not work on the same variants?
2) How it is prevented that client who found solution would "steal" 50BTC, instead of submitting solution to the pool server?
3) How does pool software process this solution to get 50BTC and notify whole system that everyone (including other pools & individuals) need to work on next block?
4) Is that correct that all fees associated with newly generated solution are "payed" to the owner of this solution in the nearest minutes after it's generation?

Sorry for dumb questions, and thanks :-)

(1) There are 640 bits of input— the whole block header. It includes a version number, a timestamp, the hash of the prior block, the hash of the hashes of the the transactions, and the 32bit part you sweep (the nonce).    Most work doesn't have any solutions at all. You can think of the whole process as throwing dice. (yes, the hash is deterministic, but no two throws will ever be the same).    Inside the coinbase txn there is an extra nonce value where the creator of the block header can increment some more (e.g. if it needs more candidate blocks than the timestamp resolution * nonce space would allow for).

(this is, e.g. why mining isn't a race, everyone is working on something completely different and someone else solving a block doesn't throw out the work you did, or prevent you from solving one)

(2) The solution is bound to the identity of the key that gets paid the 50btc via the included hash. Change the payment address and you'd invalidate your solution.

(3) Imagine you are throwing dice the pool has given you. The dice have the pools name written on them.  You throw and throw. A throw of 1 solves the block. The pool asks you to report any throws you get <=3, you do this and it proves you are working. Sometimes your <=3 throw is a 1 and the pool announces it to the world.   Everyone else can trivially see that the "throw" is the required value, so they treat that solution as good (by running the hash once) and continue building the next block in the chain after it.  They simply announce it to all the bitcoin nodes they're talking to, who announce it to all their peers, and so on.

(4)  No. It's not award minutes after, it's 'awarded'  either "instantly" or "after several hours" depending on how you want to look at it.  When the block is formed all the transactions are groomed up, any time the inputs to a TXN are greater than their outputs in value the excess is the fee.   The miner adds this fee to the 50BTC the network rules allow them to create out of thin air, and specify it in the coinbase transaction (called 'generated' in most software) that transaction specifies that the funds be paid to a key they hold.   So it's an instant thing.    Alternatively,  the network won't let you spend from a generated txn until it is at least 100 blocks old— this is to avoid massive drama should their be a long chain split an the block not end up as part of the longest chain. If block ends up being excluded from the longest chain all spends originating in the coin made in that block would be invalidated. So the fees (and the reward) are only paid, or at least only available to be spent, until many hours later.