All Bitcoin transactions are recorded into the blockchain. Throughout the remainder of this series, we’ll refer to the Bitcoin ledger as the blockchain.
The reason for its name is that new transactions are appended to the ledger in large chunks, or blocks. Whenever a new Bitcoin transaction is broadcast to the network, computers on the network add it to a growing pool of other new transactions. Then, about every 10 minutes, the transactions in that pool are bundled into a block and added to the blockchain.
To function properly, all Bitcoin wallet programs need access to an up-to-date copy of the blockchain, and every time a block is added, the wallet programs copy and add the block to their own blockchain.
The thousands of computers on the Bitcoin network that collect transactions and add them to the blockchain are called miners. We’ll explain miners and the details of what they do later in the chapter. For now, keep in mind that anyone can be a miner (including you) by running open source Bitcoin-mining software on a computer that is connected to the Bitcoin network.
At any given moment, tens of thousands of miners are connected to the Bitcoin network. All volunteer their computers for the purpose of adding new transactions to the blockchain (we’ll explain why they do this in a moment).
Every block added to the blockchain is added by a single miner on the network. Then everyone else on the Bitcoin network follows suit and updates their own copy of the blockchain (this includes other miners and Bitcoin wallet programs). Why does only one miner add a block, and how is it decided which of the thousands of miners it is? This is where Bitcoin gets interesting—and a little technical.
Let’s first consider why anyone would want to update the blockchain.
Certainly, if you wanted to complete transactions, your Bitcoin wallet program would need the latest copy of the blockchain. However, you might not want to send or receive bitcoins for months, so why bother updating your copy of the blockchain in the meantime? For the Bitcoin system to work, many people need to keep up-to-date copies of the blockchain. The reason is that if only one person had the latest copy, she could manipulate the number of bitcoins people had on record. Therefore, good will alone isn’t sufficient to keep the system running. But the lure of a reward is always an attraction.
THE BLOCKCHAIN LOTTERY
As an incentive for users to update the blockchain as frequently as possible, Bitcoin uses a lottery-based reward system. Many people become miners and try to be the first to add a block to the blockchain. Then, based on some probability, a winner is chosen and gets to add a block.
What is the purpose of using a lottery like this to run Bitcoin? Well, let’s imagine Crowley wants to buy a $10,000 car from Clarice.
Using traditional currency, two people engaging in this transaction would probably go to a bank and have the money transferred between their bank accounts (or use a cashier’s check, which is analogous to this.
They would do this at a bank because they need a trusted third party (a “banker”) that manages a “money ledger” and moves the money on the ledger from one person’s account to another. The banker’s job is to make an announcement that Crowley and Clarice can trust; that is, to affirm that the ledger has been updated correctly. (The banker may or may not be sporting a monocle, wearing a top hat, and smoking a cigar.)
With Bitcoin, we also need a person to adjust a ledger, which in this case means adjusting the blockchain by adding a block to it. It turns out anyone can fill this role, as long as he is not connected with either party in the transaction, because that could lead to a conflict of interest. Picking a person randomly through a lottery helps accomplish this. So with Bitcoin, a lottery picks a random miner, who then announces to the network that certain Bitcoin transactions are valid.
Of course, there’s always a small chance this miner does know one of the persons involved in a recent transaction. This is why blocks are arranged in a chain: In roughly 10 minutes, when the next lottery winner is announced, this winner also confirms, as part of her announcement, that she agrees with all the transactions of the previous lottery winner.
In the process, each winner in the Bitcoin-mining lottery receives a reward, which is a certain amount of bitcoins. The reward includes all of the transaction fees for the transactions in that block, which motivates miners to collect as many transactions into a block as possible, increasing their reward. To be eligible for the reward from the next block, which is added 10 minutes later, a miner needs to have the latest copy of the blockchain to participate in the next round. This process is done automatically by open source Bitcoin-mining software that runs on computers controlled by the people involved in mining. Because of this incentive structure, thousands of miners constantly help process the transactions of Bitcoin users, making sure that the blockchain is always up-to-date.
The reward lottery is run by the community; no central authority exists to choose a winner. We’ll skip the technical details for now and just say that miners generate random numbers continuously, until they fi nd a winning one. This takes about ten minutes.
The community then verifi es (also through cryptography) that the number found by the individual miner is the winner, and the miner adds a new block to the blockchain and collects the reward. When this happens, the phrase commonly used is that a miner has found a block.
Blockchain Forking
The lottery system works as expected most of the time. But occasionally two miners find a block at the same time, and the blockchain becomes forked, resulting in two different branches (see Figure 2-13).
Consider the following scenario as an example: Imagine that Crowley and Satoshi are miners and find the winning number within seconds of each other. If they are located far apart on the Bitcoin network (say, on opposite sides of Earth), one part of the network will identify Crowley as the winner and another part will identify Satoshi as the winner. In this case, Crowley and Satoshi will each add a block to the blockchain (each thinking that he is the winning miner for that round). The problem occurs when one part of the network copies Crowley’s block and the other copies Satoshi’s.
As a result, now two blockchains disagree!
Recall that your Bitcoin wallet program needs an up-to-date copy of the blockchain to function, but it doesn’t know how to resolve a forked blockchain. Miners and Bitcoin wallet programs must decide which of the two versions of the blockchain to use. Forking is resolved by waiting to see which of the two branches adds yet another block first, which will happen about 10 minutes later. Then the longer branch will be considered the true blockchain, and the shorter branch will be ignored, or orphaned, by the entire Bitcoin network.
For most users, the process of forking and ignoring orphaned blocks goes completely unnoticed and has no negative impact on the use of Bitcoin.
In our example, only the losing miner, Crowley, experiences a considerable impact because only one of the two miners involved can receive the reward.
The losing miner is undoubtedly disappointed, but miners expect this to happen from time to time, so it comes as no surprise when it does.
Transaction Confirmations, Double Spending , and Irreversibility
A transaction confirmation is a common concept in Bitcoin. Some online merchants that accept bitcoins may require one or more transaction confirmations before delivering their good or service. Every transaction exists in some block on the blockchain. The blocks behind it are older, and the blocks ahead of it are newer. The position of a block relative to the tip of the blockchain is known as the block depth. The most recently added block has a depth of 1, the block behind it has a depth of 2, and so on. The number of confirmations a transaction has is equal to the depth of its block.
So a transaction that has not been added to the blockchain (yet) has zero confirmations; it has one confirmation when it is added in a new block; it has two confirmations when a block is added ahead of it; and so on. The concept is simple enough, but why do merchants require transaction confirmations?
For low-value transactions, such as buying a cup of coffee, merchants normally forgo the transaction confirmation. You just send your bitcoins, grab your coffee, and go on your way. In general, Bitcoin transactions are irreversible, and merchants know within a few seconds after you click Send that you’ve paid for your drink (or whatever you’re buying). However, if a merchant sells a high-priced item, such as a car, it becomes critical to consider transaction confirmations.
A malicious user with very significant computational resources (think of a James Bond–style supervillain) can try to double spend his bitcoins, which is essentially an attempt to trick the receiver into accepting bitcoins that were simultaneously sent to someone else as well (the “someone else” could be another Bitcoin address controlled by the supervillain). When miners on the Bitcoin network detect two transactions that spent the same bitcoins (but were sent to different addresses), they usually accept whichever one they received first and ignore the second. More important, it’s impossible for both transactions to be added to a block because one contradicts the other. The supervillain’s intent is for the merchant to ship the car but have the transaction be ignored and not added to the blockchain.
Fortunately, this devious scheme is usually unsuccessful because many merchants use special monitoring software and can recognize when two conflicting Bitcoin transactions are broadcast at the same time (at which point the supervillain may be kicked out of the car dealership). An even simpler solution for merchants to prevent this kind of payment fraud is to wait 10 minutes until the transaction has at least one confirmation before agreeing to ship the car. However, if a supervillain possesses truly extraordinary resources, such as many millions of dollars of computer hardware, he can attempt to make the Bitcoin network orphan the newest block in the blockchain, resulting in a single transaction confirmation being ignored.
To cope with this remote possibility, merchants who sell high-end goods typically wait until a transaction has two confirmations before handing over the keys to the buyer. In general, the higher the value of the item being transacted, the more confirmations a merchant can demand before considering the transaction to be settled. The cost for a malicious villain to double spend those bitcoins rises exponentially with each confirmation.
Now that you know the basic function and concepts of the Bitcoin blockchain, you’ll learn about mining bitcoins, which is perhaps the most mysterious aspect of Bitcoin.
For more on Bitcoin for the Befuddled look for the sixth and final article in this series called The mysteries of mining Bitcoins in a future edition of CDN Now.
About the Author
Conrad Barski has an M.D. from the University of Miami, as well as nearly 20 years of programming experience. Barski is a cartoonist, programmer, and the author of Land of Lisp. He’s been using bitcoins since 2011.
Chris Wilmer holds a Ph.D. in chemical engineering from Northwestern University and is a professor at the University of Pittsburgh. Wilmer’s first purchase with bitcoin was a bag of honey caramels from a farm in Utah. They were delicious.
You are confusing miners and users who run full nodes.
Miners use specialized computers that work on the Bitcoin blockchain and add new transactions (“blocks”) to the blockchain ledger. They have to run full nodes for functionality.
Many other users who run the full software are running full Bitcoin “nodes.” These nodes enforce the consensus rules of Bitcoin. They decide whether to propagate transactions to the miners. They also decide whether to propagate new “blocks” created by the miners. If you have user creating bad transactions or you have a miner trying to add bad transactions to the blockchain then those things do not get propagated. If the miners blocks don’t get propagated they won’t get the block rewards. These full nodes also share the blockchain database so if you load the full software it connects to other nodes and downloads the blockchain to your computer.