En previous articles we have analyzed the technology blockchain y how it is constituted. We also have an article dedicated to blocks that make up the blockchain and another dedicated to Transactions, which in turn make up the blocks. If you do not know these terms, we invite you to take a look at these three articles before continuing to have a clearer and more comprehensive knowledge of these elements that will help you understand: How do you mine a block?
In the blockchain system, miners are in charge of generating the new blocks by adding them to the end of the chain. And as the protocol establishes Bitcoin, they must carry out this process approximately every 10 minutes. Each mined block contains a detailed record of the different transactions carried out in each period. And that when added to the end of the blockchain they update their registration.
Block mining process
To create a new block, miners must go through a process to solve a math problem. When finding a valid solution for the network, a new block can be taken for granted that will be added to the blockchain by consensus. And for which, the miner who found the solution, will receive a reward for the new block. This reward is known as the block reward.
About every 10 minutes a new block is generated in Bitcoin. So every time one is found, it means the start of mining for another. Whether these are mathematically related or chained together. But let's see in more detail how this process is done:
First stage: Transaction
The process of mining a new block starts when a user wants to send a certain amount of cryptocurrency to another person. So send bliss transaction with the data from your wallet, waiting for the network to do and confirm. They remain there until a block is mined where they can be included and validated.
Second stage: Compilation
These pending transactions on the network are collected and grouped into a block of transactions by mining nodes. Multiple miners are likely to collect the same transactions. And they will all be unconfirmed until the block is mined.
Third stage: Training
Each miner will select the transactions they want to include and build their own block. If there are transactions already validated and included in the previous block, they will be eliminated from it. This new block is known as a candidate, as it is not yet valid because it does not have a valid proof of work.
In the formation of this new block, a header must be included that contains the hash from the previous block, the merkle root and data for mining competition. I mean, the timestamp, the objective of the algorithm of PoW for that block (the bits), the software version and the nuncio.
Stage Four: Proof of Work
Once each miner has formed their own transaction block, they will need to find a valid signature for that block. In other words, carry out a proof of work. Each miner must carry out a mathematical calculation process that is unique to each block they formed. So, although the procedure is the same, the result will be totally different for each one. This complex calculation involves a lot of computational power, and therefore, a large expenditure of electrical energy. Which will also depend on the system difficulty for the time of mining.
The solution miners must find is known as hash. This function is very difficult to find, but once found, it is easy to verify by others. nodes. So that they can verify that the output hash comply with the established system conditions.
To find a valid output hash, the miners perform the mathematical calculations repetitively over and over again using a nuncio. Which is a random number that is constantly used and changed until an exit signature or hash is found that is valid depending on the condition. There is no way to predict that nonce will solve the problem, so they should employ as many as necessary. And we are talking about billions of values !, incredible right?
In the case of the Bitcoin network, the system determines that the output hash must contain a certain number of zeros at the beginning of the hash.
Fifth stage: Transmission
When a mining node manages to find a valid output hash for a block, it transmits that block together with the signature to the other nodes in the network so that they can validate it.
Right now, as long as they haven't issued the 21 million bitcoins, the miner receives the reward set by the mining, putting new bitcoins into circulation. This is registered in its own node, the rest of the network nodes will do it in the next step.
In addition, regardless of whether all the bitcoins have been issued or not, the miner also receives all the mining commissions that users have put in the transactions that make up this block.
Sixth stage: Verification
The other nodes of the network are in charge of validating and verifying that the block and the hash comply with the conditions of the system, verifying its legitimacy and whether it really contains the established number of zeros.
Here also the proof of work is confirmed, that is, the computational power spent to find the solution, and it is noted that the miner who discovered the block can effectively make use of the recently received bitcoins.
Seventh stage: Confirmation
Once the new block is added to the blockchain, all the others that are added to it will count as a confirmation. At this point, we may come to think that since each miner started the process with his own block, they can continue mining. But it's not like that. Once a block is generated, all mining nodes must begin the process by forming a new transaction block. They cannot continue mining the previous block because each block must add the output hash of the preceding block.
This is why we know this technology as a blockchain or blockchain. So when the miner gets a valid hash a number of new blocks may have been mined. So the output hash of your extracted block will not match the output hash of the last added block in the chain. It will be rejected. Also, it is very likely that all or most of the transactions included in that block have already been added to others. Even if you manage to mine the block, most of your included transactions cannot be validated or confirmed.