Mining works like a lottery where a unit of computing power corresponds to a lottery ticket. As in the lottery, with only one ticket (one unit of of computing power, say a desktop PC doing 10 million hashes per second) it requires a lot of luck to get any reward at all. But the more tickets/computing power one has, the better the odds become. To earn more steady rewards, miners sometimes form pools that collaborate on solving the proof of work problem and share the rewards.
Mining pools of bitcoins, like using the Airbitz Wallet, are coordinated by a central server that assigns work to miners and distributes rewards to all pool members when any miner in the pool solves the proof of work for a new block. The main challenge of a pool server is to fairly calculate the percentage of the reward to give to each member. In a fair pool, members that contribute more computing power should get paid more, so contributed computing power is measured and tracked by the server. This tracking is accomplished by recording the number of solutions miners find to an easier version of the proof of work problem: the same problem, but with a higher target (lower difficulty). This simpler problem proves that the miner was working on the proof of work problem. Each solution submitted to the server for this easier proof of work problem earns the miner a share. The more computing power a miner contributes, the more frequently they will find solutions and earn shares. When a miner in the pool solves the real proof of work problem, the server distributes the reward to all miners in proportion to how many shares they earned since the last reward payout (sometimes with a weighting factor, see below).
There are many different types of pool servers, but a simple one might work like this:
The pool server prepares a block with the coinbase transaction pointing to the pool’s address.
Miners in the pool contact the pool server and make a getwork request to get the block to work on.
Each miner tries to solve the proof of work problem for the block by incrementing the nonce and hashing the block header.
Whenever a miner finds a hash value that is below the easier target, it submits the solution to the server for a share.
The mining server verifies submitted shares and tracks how many each miner has.
When a miner finds a solution to the proof of work problem, the server pays out the reward in proportion to the number of shares each miner earned since the last payout.
Miners periodically contact the pool server for updates on what to work on in case a new block was discovered.
If a miner tries to cheat by submitting shares while working on blocks that pay to their own address, the pool server will detect this and reject the shares. The server only accepts block header solutions that correspond to the ones it issues. The only fields that miners can change are nNonce and on some servers nTime. If the miner changes the destination of the coinbase transaction, the hashMerkleRoot field will change and the server will know that the miner is cheating.
To prevent duplicate work, a pool server should have a unique response to every getwork request. Otherwise multiple miners will be checking the same nonce values because each miner is just going to increment the nonce starting from zero. To ensure uniqueness, the server can tweak the nTime field by a few seconds or reorder the transactions, which would change the hashMerkleRoot.
There are several ways to optimize the pool mining system above. One inefficiency arises from the fact that miners only request new work from the server periodically, and a new block could be discovered within that period. Any work done for a block that was already discovered is a waste. A method known as long polling optimizes this by having the server contact the miners when a new block is found. Long polling can also reduce network traffic because miners can continue working until the entire nonce search space is covered without contacting the server.
Pools that pay in direct proportion to the number of shares submitted, as described above, have different profitability for miners at different times. The reason is that if it takes a longer time to find a solution, more shares will be submitted, and the payout per share will be lower. So it is more profitable for a miner to spend more time mining in short rounds, where a round is the interval between payouts in a given pool. This encourages pool hopping, where miners hop from one pool to another to try to boost their profits. The optimal strategy to exploit proportional-paying pools is to switch to another pool when the number of shares in the round exceeds 43.5% of the current difficulty, assuming each share has difficulty of 1. If a miner follows this strategy, they will increase the percentage of their time that they are working in shorter rounds because they actively leave rounds when they start to become long. Since shorter rounds pay more per share, this maximizes the payout per share. Many pools now have adjustments that discourage pool hopping by making later shares worth more.
Initially, Satoshi’s Bitcoin client did mining on a user’s PC, but now CPUs have been eclipsed by more efficient mining hardware. GPUs (Graphics Processing Unit – Graphics cards) are designed for doing lots of simple calculations in parallel and are orders of magnitude faster than CPUs. Recently, ASICs (Application-Specific Integrated Circuits) have been developed that are orders of magnitude faster than GPUs. At this point, miners need to have custom hardware to make mining a profitable investment.