In many articles about blockchain, people may often read that the blockchain is forked at a certain block height. So, what is the block height? Why is it forked at a certain block height? Now, we’d like to talk about the block height in this article.
Blockchain and Account Book
Block height, as the name suggests, is the height of the block, specifically the number of blocks connected to the blockchain. So, in order to understand what is the block height, we have to know what the blockchain is first. If we compare the blockchain to an account book, then the block is just like the page inside.
On the pages of the account book, every transaction is clearly recorded. To ensure that transaction cannot to be tampered as well as the openness and transparency, the accounting on the blockchain is recorded collectively.
Block Height and Pages of Accounting Book
Since the blockchain is like a small account book, the transactions recorded on every page (block) is limited. In order to distinguish and find out on which block the transaction is recorded, we naturally come up with the idea of marking numbers on all the pages. Therefore, if the blockchain is like a small account book, the block height is just like the page number.
Now, we’d like to ask our readers a question. In the case of the blockchain with only one longest chain, assuming that the number of the current page is 3, what’s the serial number of this block in the whole blockchain? The answer is: the 4th block.
Some readers may wonder why it is not the 3rd block? The reason is that there is also a block with the height 0 in the blockchain, which is also known as the Genesis Block. Its page number is 0, so when it comes to a block with the number 3, it means the three blocks ahead, which is also called the ancestor number of the blocks. So, it’s the 4th block in the chain itself.
Block Generation and Page Generation
After understanding what the block height is, we’d like to explain how the block height is generated. In the blockchain with mining mechanism, the page number of blockchain is generated based on the competition of the mining workers. For example, the current block height is 3. Once one worker is lucky enough to solve the calculation problem, he will get the page 4 of account (that is, the block with the height 4) as well as a certain reward.
At this moment, the block will record the transaction packaged and confirmed by the worker. Once this block has been generated, the workers will continue to compete for the block with the height 5 based on the block with the height 4.
Fork and Duplication
As we have just mentioned, the workers can solve the calculation problem to get the accounting right for the next block. Then here’s one problem. If the current block height is 2 while the two workers are both lucky enough to solve the calculation problem at the same time, then they will both obtain the accounting right for the block with the height 3.
That’s to say, the worker Mr. White holds a page numbered 3 while the worker Mr. Black also holds a page numbered 3. Although their page numbers are the same, the contents recorded on the two papers are not exactly the same.
However, according to the rules, there’re no problems for the two pages held by Mr. White and Mr. Black. So, which one should be selected for the account book? Some workers may choose Mr. White and go on to “seek” the next page after the serial number 4, while other workers may choose to do so after Mr. Black.
It means that on the page numbered 2 two account books are divided. In the blockchain, this behavior is called fork. However, there’s a principle of “the longest chain” in the blockchain and the workers will choose the longest chain as the main chain to continue the mining. For example, in the chain of Mr. White, Mr. Red mined the block with the height 4 first, then the chain of Mr. Black will be abandoned. All the workers will choose to continue mining along the chain of Mr. White.
We have introduced above that the block height is used to identify which block a transaction belongs to. But now there are two blocks with the same height in the chain. How should we identify them?
In the blockchain, in fact, block hash is used to identify every unique block instead of the block height, because even if the block height is the same, the contents recorded are not exactly the same, so the hash in every block (calculated by block content) should not be the same. Therefore, we can use the hash to identify every unique block.
In a word, the blockchain is like an account book and the blocks are like the pages. The block height is equivalent to the page number. When two identical pages appear at the same time, the fork will happen.