How Blocks are Created
What is a “block”? Perhaps the simplest analogy for understanding blocks in a blockchain is to think about sheets of paper in a notebook. Imagine an audience sitting in front of a stage. Each member of the audience has been given an identical notebook and a pen. Anytime a transaction is to be recorded on the ledger, the participants will walk up on the stage and announce their transaction to the audience. The audience will then record the transaction in their notebook, one transaction per line.
Eventually, an entire page in the notebook will be filled with transaction data. At this point, the audience will compare their current sheet of paper with the current sheet of paper held by all the other audience members. If the audience, collectively, finds a version of the data that more than 50% agree on or share, this data is the truth. If the audience can find a version of the transaction data shared by most of the audience, then two things happen:
1) Participants who do not hold the same identical data as the majority will discard their block and obtain a new copy from those in the majority, thus putting them back in sync with the rest of the participants.
2) Once everyone is synced up, each participant will begin the process again by recording announced transactions on a fresh sheet of paper.
If this process makes sense, congratulations! You now understand a core concept of blockchain technology!
Two items to note:
Blocks within the blockchain are just like sheets of paper in the sense that neither has to know or care what type of data is recorded on it. Paper works equally well to store financial data, graphic data, musical data, weather data, etc. Data points of vastly different types with no relation to one another can happily co-exist on a block or a piece of paper. The block or sheet of paper is just a simple record-keeping device.
In this example we assumed that transactions are recorded until the sheet of paper is full, then that sheet is validated by the entire audience. Blocks are mined on a schedule. Imagine the same scenario as above, but in this revision, there’s a timer that buzzes at regular intervals of X seconds. When this buzzer goes off the audience compares their sheets of paper.
How are Blocks “Chained” Together?
All blockchain data is stored in blocks and the average block size varies from 1.1 MB to 1.3 MB. Each block will have a previous block ‘hash’ stored in the current block. All previous block transactions will create a value of ‘Hash’ (encrypted, for example, with SHA256) that will be stored in the next block. Hence, Blockchain’s name.
Data within a block is submitted to a function usually called ‘cryptographic hash’. It will generate a unique hash value of validated data in the previous block, which is stored in the header of the next block. Any time data is changed in a block, the ‘unique hash’ will be changed and so will not match the hash stored in the header for the next block In this way, data tampering can be detected in the blockchain.
Changing the data on any block in a Blockchain will result in a completely different hash, and the new hash will not match the hash in the next block header thus breaking the Blockchain and invalidating all blocks linked to where the change was made. This gives Blockchain its property of immutability (can’t be changed) and makes it highly censorship resistant.
The height of a block within the blockchain simply refers to the number of blocks on the chain after the one in question. Block height is an indicator of the security of the data on the block. Data tampering in a block can’t be possible until data in all subsequent blocks are changed. Changing data in any block requires an attacker to change every subsequent block. The higher the number of blocks, the more blocks the attacker must alter and the harder it becomes to pull off an attack.
Mining a Block
Blockchains are distributed when computers download the blockchain. These computers are known as nodes. When a block is filled up, it is validated through group consensus before it can be added to the chain of previously validated blocks. There are several Blockchain consensus mechanisms but regardless of the consensus type used, it is important to note that all transaction data on a chained block is assumed to be trustworthy and the chained data has not been tampered with due to the validation of data by group consensus
A blockchain gets more secure over time. If there are more blocks confirmed that means that there would be a smaller chance of a different chain being selected as the primary one. A fork is a change of protocol. There are two types of forks, a hard and a soft fork. A hard fork is a fork where the data is not backward compatible. This results in a new blockchain being created. A soft fork occurs when data is backward compatible, resulting in a change that would not create a new blockchain.