This article explains Bitcoin mining bitcoin merkle root details, right down to the hex data and network traffic. If you’ve ever wondered what really happens in Bitcoin mining, you’ve come to the right place. I manually created a Bitcoin transaction and sent it into the system.
In this article, I show what happens next: how a transaction gets mined into a block. Bitcoin mining is often thought of as the way to create new bitcoins. But that’s really just a secondary purpose. The primary importance of mining is to ensure that all participants have a consistent view of the Bitcoin data.
Because Bitcoin is a distributed peer-to-peer system, there is no central database that keeps track of who owns bitcoins. Instead, the log of all transactions is distributed across the network. The main problem with a distributed transaction log is how to avoid inconsistencies that could allow someone to spend the same bitcoins twice. 10 minutes, which makes them official. Conflicting or invalid transactions aren’t allowed into a block, so the double spend problem is avoided. Although mining transactions into blocks avoid double-spending, it raises new problems: What stops people from randomly mining blocks? How do you decide who gets to mine a block?
How does the network agree on which blocks are valid? It takes an insanely huge amount of computational effort to mine a block, but it is easy for peers on the network to verify that a block has been successfully mined. Each mined block references the previous block, forming an unbroken chain back to the first Bitcoin block. This blockchain ensures that everyone agrees on the transaction record. It also ensures that nobody can tamper with blocks in the chain since re-mining all the following blocks would be computationally infeasible. As long as nobody has more than half the computational resources, mining remains competitive and nobody can control the blockchain.
As a side-effect, mining adds new bitcoins to the system. 15,000 every 10 minutes, there is a lot of money in mining. Mining requires a task that is very difficult to perform, but easy to verify. With a cryptographic hash, there’s no way to get a hash value you want without trying a whole lot of inputs.
But once you find an input that gives the value you want, it’s easy for anyone to verify the hash. Thus, cryptographic hashing becomes a good way to implement the Bitcoin “proof-of-work”. In more detail, to mine a block, you first collect the new transactions into a block. Then you hash the block to form a 256-bit block hash value. Bitcoin network and the hash becomes the identifier for the block.