What is the Blockchain?
This article is intended to help you understand the Blockchain technology and how Bitcoin works. Every person running Bitcoin has a copy of this global database/ledger. It enables the Bitcoin software to verify that every spend is accounted for and that no rules are being broken. You consent to the mathematical rules of the bitcoin system when you join, and likewise, you enforce compliance from others. For this, the software needs the books for doing the accounting.
This database is appended only. The database can only be extended- never changed. When a new piece is created, it is joined to the end. Then subsequent new additions will build on the end of this piece. Each piece is colloquially termed a block. This chain of joined blocks is termed the blockchain.
Each block contains a bunch of new transactions. For example, if the first block contains a transaction saying “A sent 10 BTC to B” and the third block contains a transaction saying “B sent 2 BTC to C”, we know that B has (10 – 2) = 8 BTC and C has 2 BTC. We know this from examining the blockchain.
Blocks birthed from math.
Creating new blocks is not trivial. A block is born from the solution to a mathematical riddle. This riddle is chosen collaboratively by the network according to a mathematical algorithm. When bitcoin nodes solve this riddle, they mint a new block, appending it to the end of the blockchain.
Nodes solving this riddle are called miners or generators, although the terms are misnomers; mining conjures visions of money being invented from nowhere; generators does not convey anything. A better term is validators. Each newly created block contains a new set of transactions that are accepted by the network. The creators of this block- the validators, gather up these transactions and validate they are correct in anticipation of the next block they are about to create.
When you download the blockchain, you must validate the correctness of the blocks and the transactions within them:
- Was this transaction already spent?
- Does this spend have enough of a balance to cover it?
- Are there any anomalies?
Blockchain is another misnomer! Blocktree would be more accurate as validators can build off earlier blocks (if they wish). However, the hardest to compute the chain (nearly always the longest chain) is the currently accepted history of events in the network.
In practice, the blockchain rarely branches and only ever one block deep. However, the most extended branch was six blocks deep! This is why we casually call it a blockchain- it is a long chain with short stubby branches.
Computing a block involves solving the mathematical riddle. Solving this riddle means your computer is processing numbers. Processing numbers means you are using electricity. Electricity costs money.
As a reward for this valuable service of validating transactions, these validators get a subsidy of 50 BTC. This type of transaction is called a coinbase transaction.
The theory says that if:
50 * BTC exchange rate – the cost of electricity > 0
Then you will make a profit.
There are other externalities like initial hardware costs and your time, but we will ignore them here.
As more people try to join the network and solve these riddles and generate new blocks, the rate of new blocks appended to the blockchain will increase. The network reconvenes and decides to raise the difficulty of creating new blocks. By raising the difficulty, a validator has to expend more electricity to create a new block which lowers their profit. If blocks are being computed too slowly, then the network will reduce the difficulty. Difficulty changes are done every 2016 blocks trying to aim for an ideal of a new block every 10 minutes. 2016 * 10 minutes is around once every two weeks.
Every two weeks, the network reconvenes to decide on the new difficulty adjustment. The difficulty is adjusted to either slow or hasten the generation of new blocks towards a goal of 10 minutes.
Making a new block is not an easy task. That is why it is impossible to rewrite the blockchain. For example, if I wish to reverse block 10 in a blockchain 20 blocks long, not only do I have to reverse block 10, but I must reverse block 11, 12, 13, 14, 15, 16, 17, 18, 19 and 20 expending all the power and money that went into creating those blocks. As it stands now, the total amount of computation in the bitcoin blockchain is immense and unlikely ever to be reversed.
Occasionally though, two validators will create a new block at the same time. We say they are in a race. It is now a gamble depending on which block the next block is built off. Which block is built off is down to mostly luck and externalities (like whether the right people discover the block at the right time).
The next block is critical. Mathematics shows us that the probability of a block being reversed drops exponentially with each new block added to the end. For example, if appending a new block decreases the chance of reversal to 50%, then adding two blocks will decrease the chance to 50%*50% = 25%, three blocks by 50%*50%*50% = 12% and it very quickly tends towards 0 but never quite reaching it.
With the odds against him, if he doesn’t make a lucky lunge forward early on, his chances become vanishingly small as he falls further behind.
For more information, see Satoshi’s paper where he models new blocks using the gamblers risk of ruin with a Poisson distribution.
Linear vs polynomial.
Blocks take time to be checked for correctness when we download them. That is why the blockchain is slow. Not because downloading blocks takes time. Downloading the entire blockchain can be done in a matter of minutes on a good internet connection. It is the checking that takes time. Checking to ensure we have not been cheated.
Transactions in new blocks are checked to ensure they connect up with an old transaction. Unfortunately, this connecting of transactions is the biggest slowdown of all (the ConnectInputs(…) function).
When bitcoin tries to connect a transaction up with its predecessor, it must search for it in the blockchain. As the blockchain increases from 100 blocks to 1000 blocks, so too does the number of potential blocks increase from 100 to 1000 that the predecessor transaction may exist in.
This is why the blockchain is slow. Searching the entire blockchain for a transaction only becomes worse as the blockchain grows. Luckily we have rising hardware specifications and programmer ingenuity to overcome this in the future.
With our simple model, we could say that for every new block added to the blockchain, the time to check that block increases linearly. As the time for checking one block increases linearly, the time for checking the entire blockchain increases polynomially.