Author

Topic: Getwork/Mining, I sorta get it.... (Read 1559 times)

full member
Activity: 140
Merit: 100
December 24, 2011, 06:03:06 PM
#4
Thank you very much. That's pretty much what I'd suspected...

Over the next week (or a little more, I have many other projects) I'll build up a simple cpu based miner and build up some documentation from there.

You never know, it might turn into a much bigger project, I do fancy building a miner anyway....
donator
Activity: 1218
Merit: 1079
Gerald Davis
December 24, 2011, 04:26:55 PM
#3
The extra nonce is put in the coinbase field of the coinbase transaction.  Essentially any value change there results in a new transaction hash and thus a new merkle tree root.  This is done by the mining pool server.

So simplified.
1) You send getwork to pool
2) Pool returns data as you describe
3) You begin w/ nonce of 0.
4) Load nonce into block header and perform double sha-256 hash.
6) If the hash is < target for difficulty 1 you submit it to the server as a share (pool checks each share to see if it meets full difficulty)
7) Increment hash and go to step 4.  If you reach max nonce (2^32 -1) then goto step 1

In solo mining it works very similar except there is no "server" you are sending requests directly to the bitcoind.


Now "good" miners do some efficiency improvements.  They request getworks pre-emptively but that is the basics on miner pool communications.  Also on a longpool you need to discard any stale getworks and work on new data.

So it requires at least one getwork per 2^32 hashes (1 share).  To make it a little more complex there is a method called n-time-rolling which allows the miner to simply increment the time locally.  This allows multiple runs through the nonce range on one getwork request.
full member
Activity: 140
Merit: 100
December 24, 2011, 04:16:03 PM
#2
Bump.

I will be documenting this fully to help people in the future. But I want to be sure that I understand it fully before I start in case I miss something important out!
full member
Activity: 140
Merit: 100
December 21, 2011, 08:12:15 PM
#1
Maybe I'm being stupid (and it's a high probability) or maybe I'm just tired...

I'm sat here writing a simple bitcoin miner to teach myself about how it all works...

This things I understand:

You "getwork" from the server, which gives you a message with midstate, data, hash1 and target in it.
I know that "data" is the important one.
Data splits up into Version, Previous Hash, Merkle Root, Timestamp, target/"bits", Nonce.
I know that you then do the SHA256 hashing bit (and I know about the double hashing) then increment the nonce and rehash and repeat until you find the "answer"


What I don't get is that when the nonce overflows you need to increment "extraNonce" and reset the nonce back to 0... WHERE is the extra nonce and HOW do you do it? Or is it just a case of sending another getwork request? Also, does this method change if you're solo mining or on a pool...

I did a search of the forums, but I didn't really understand what I was reading... Please put it in terms that idiots would understand Smiley Or give a nice example of some sort, lol

Thanks in advance.
Jump to: