Conteúdo do Curso
Introduction to Blockchain
Introduction to Blockchain
Mining Blocks
The mining process in Bitcoin and other cryptocurrencies is a critical mechanism that performs two essential functions:
- adding new transactions to the blockchain (thereby securing and verifying them);
- introducing new bitcoins into circulation.
Let's sum up what we've already learned about it and take a more detailed look at how the mining process works:
1. Transaction Verification
Miners begin the process by collecting transactions from the Bitcoin network's memory pool. These are transactions that have been made by users and are waiting to be confirmed and added to the blockchain. Miners select which transactions to include in the next block based on transaction fees, among other factors; transactions with higher fees are typically prioritized. Once a miner has selected the transactions, they compile them into a block.
Let's take a look at the following picture to clarify this:
First, users (suppose there are 'n' users) submit their transactions, each accompanied by a fee they are willing to pay for the transaction to be processed. These transactions are sent to the memory pool (also known as the mempool), which is a holding area for transactions before they are confirmed by miners. The transactions in the mempool are denoted as Tx1 to Txm, where 'm' could be any number of transactions waiting in the pool. Finally, miners select transactions from the memory pool to include in a new block based on their fees.
2. Solving the Proof of Work
The core of the mining process involves solving a cryptographic puzzle, known as proof of work (PoW). This puzzle requires computational effort and is designed to be difficult to solve but easy to verify and involves finding a hash that is below a certain target value.
As we have already mentioned, the nonce is a number that miners change with each attempt to solve the puzzle. By altering the nonce and hashing the block's information, miners generate different hashes.
The goal is to find a nonce that produces a hash that is lower than or equal to the target hash set by the network. The first miner to find a nonce that produces a valid hash wins the right to add the new block to the blockchain.
3. Block Confirmation and Reward
Once a miner successfully solves the puzzle, they broadcast the new block to the rest of the network for verification. Other nodes in the network check the validity of the block, including the correctness of the transactions and the hash. If the block is valid, it is added to the blockchain, and the miner is rewarded with newly minted bitcoins (the block reward) and the transaction fees from the transactions included in the block.
As you can see, there is nothing complicated here. Once a block is mined, propagated and verified, it is added to the blockchain right after the last block.
Difficulty Adjustment
The Bitcoin network automatically adjusts the difficulty of the mining puzzle approximately every two weeks, or every 2,016 blocks. This adjustment ensures that the average time to find a new block remains about 10 minutes, regardless of the total mining power on the network. If more miners join the network and the hash rate increases, the difficulty will increase. Conversely, if miners leave the network and the hash rate decreases, the difficulty will decrease.
Obrigado pelo seu feedback!