How does pool mining work and how is it different from solo mining?
In this article, we will explain what is the difference between pool and solo mining. We already talked about pool mining and solo mining. But in this article we are going to go a bit deeper.
We have talked about Proof of Work in this article. We have learned that the miner is using a nonce number to manipulate the hash output until the correct solution is found. This only (partially) applies in a case that the miner is solo mining - participating in solving/validating the block of transactions on his own - old way of mining before the pools.
If we start talking about mining in a pool, things start to get a little more complicated. All the work that the miner did when solo mining must be distributed to other miners and prevent two or more miners solving the same nonce.
Once you understand the principle of distributing the work from the pool to miners all will become clear and easy to understand what a mining job is.
How does the miner guess nonce numbers when solo mining?
First, let's refresh our knowledge of solo mining.
The node (which is also actually a miner on the blockchain) will “collect” all of the transactions that are waiting to be processed and include them in a block. This is a so-called block of transactions. It will only include a certain amount of transactions because a Bitcoin block has a limit of how many transactions can be included in the block.
Then the miner will start guessing the nonce number until the hash output of the transactions and nonce number starts with a certain amount of zeroes (network difficulty).
Once the correct hash output is found, the miner broadcasts the solution to the network and if everything is correct, he gets the block reward.
You can use the below form and guess the nonce number until the correct hash output is found. Start with inputting random data in the DATA field and then guess the nonce number until the form turns green. Or you can press the MINE button to find the nonce number automatically.
How does the miner guess nonce numbers when mining in a pool?
Okay, now we know that the miner must guess/manipulate the nonce numbers in order to get the correct hash output. But what happens if the required difficulty (number of zeroes on the above form) gets too big? The miner that was solo mining will have a lower chance of finding the correct nonce number and thus lower frequency of hitting a block.
The solo miner comes up with a solution to ask his friends to start mining as a group of miners - a group of miners is known as a pool. Now the pool of miners will appear stronger on the blockchain and will have a higher chance of finding the correct nonce number and getting the block reward thus increasing the payout frequency.
But how can the pool operator make sure that the miners are not guessing the same nonce? If 2 or more miners are guessing the same range of nonces, or they have the same starting position (e.g. they all start guessing the nonce at 0 and increment it by 1) then they would be guessing the same nonce numbers. If all miners had the same speed of guessing (hashrate) then it would make no difference to mine together as they would all find the solution at approximately the same time.
Instead, the pool operator would spread the “starting position” of the nonce to each worker. The pool can distribute the work between all the workers by splitting the nonce number in two parts. This allows the pool to send one part of the nonce range to the first miner and the other part to the second miner. Thus more range is covered faster.
Detailed Explanation
As seen on the form above, nonce is a random number that is being guessed. For the sake of simplicity, we will say that the nonce number that solves the imaginary block of transaction can range from 0 to 100 000.
If we have one miner, solo mining, he will start guessing the nonce at 0 and work his way up to 100 000. One of the nonce numbers between 0 and 100 000 will create a hash output that matches the target difficulty (amount of zeros at the start of the hash output). Once the miner finds the correct nonce, he gets the reward.
If the pool distributes the work to multiple miners, the pool will split the nonce range in two parts. The first part of the message will be a fixed value that the miner receives, e.g. 20 000 (the 20 thousand range). The second part of the message (variable part) will be the 20 000 (hundreds) which can be manipulated by the miner. The miner will be responsible for only guessing the second part.
Examples of nonces that one of the miners will be guessing in our case is: 20+001, 20+002, 20+003, up to 20+999. The second miner could be guessing nonces in the 30 000 (the 30 thousand) range. For example 30+001, 30+002 up to 30+999. In our hypothetical example, there could be 99 (01 000 to 99 000) miners in total connected to the pool.
How is the nonce splitted?
Nonce is splitted in two parts called extranonce1 and extranonce2.
The first message is called extranonce1 and it is always different, but fixed, for each miner connected to the pool.
The second message is called extranonce2 and this is the part of the nonce that should be manipulated by the miner in order to try to solve the block input data.
We can say that the difference in hashing between solo mining and pool mining is that the miner is guessing the full nonce range when solo mining, while the miner mining to a pool is only guessing one part of the nonce range.
Another important part of pool mining is difficulty. When it comes to solo mining, the solo miner is only concerned with the target network difficulty. Whilst the pool miners use target difficulty provided by the pool and not network. Target pool difficulty is always lower than the target network difficulty.
For example, if the target network difficulty requires 10 zeros at the start of the hash output, the pool target difficulty might require only 2 zeros at the start of the hash output. In this case the hash output must start with 2 zeros, but not exactly 2 zeros. The nonce that matches pool difficulty could also match network difficulty. If this happens, the poll will hit the block and distribute the rewards to all the miners based on the work contributed.
In a case that the miner exhausted the full nonce range that he was assigned from the pool before finding the solution then the target pool difficulty is too high for the miner (or opposite, the miner hashrate is very high)
You can check this form and see how miners are contributing work to the pool. First, input random data to the Transaction Data field, then select desired Network Difficulty and click MINE.
The miners will guess or loop through all the available extranonce2 until the solution is found. If no solution is found, the extranonce1 must be increased.
Note that the form is missing the pool difficulty because of easier representation. Pool difficulty would allow miners to find shares faster and thus get accepted shares before finding a block (network difficulty). If pool difficulty is matched, it does not necessarily mean that the network difficulty will be matched or found. But it could be. Accepted shares allows the pool to know how much work each miner contributed and to distribute the reward fairly.
Note that the above examples are over simplified and are used for easier representation.
As always, feel free to join our Discord server and subreddit!