A Distributed Consensus With Blockchain

Bouwe Ceunen
Nov 24, 2018 · 10 min read

A lot is going on lately in blockchain-land, but what exactly is a blockchain and what does it mean to “mine” blocks. How are blocks “chained” together? Are there multiple blockchains? All is explained from my personally gathered understanding of blockchains in the past couple of months.

Photo by Christian Fregnan on Unsplash

Blockchain Basics

There are several things you need to understand about blockchain first before we can do a deeper dive in more complex matters like a 51% attack, blockchain reorgs or hard forks. Let’s start with explaining what blockchain represents and how a distributed consensus is made through miners and nodes.

Block — chain

First things first, what is a Blockchain and why is it called that way. Blocks contain transactions and are linked together to form a chain, hence Blockchain. Now how are they chained together and what does that mean? Chaining blocks together is done by integrating information about the previous block into the next block. This means that if someone wants to change the contents of a previous block, he will also have to change all the blocks that come after it. This is what makes it hard to alter information once it is deep enough in the blockchain and that is what makes it so secure.

Blockchain protocol

There is a clear difference between a blockchain itself and the protocol that drives it. Blockchain in itself is just a protocol put into action, the protocol is rather interesting, it answers the question to “How can we build a secure distributed ledger of transactions?”. The blockchain protocol is build on verifying if transactions are valid or not and the way to do this is finding a way so that everyone in the world can decide whether someone tries to do malicious transactions or not. If everyone in the world can decide on something, chances are that faking transactions becomes harder, you will have to convince more than half of the people to vote for the malicious transactions. You can compare it with a contest and a jury, if you have a jury of 1 person, it is rather easy to bribe the jury and make sure the wrong person wins. If you have a jury of 10 people, it becomes more difficult, you will have to bribe 5 people in order to get the majority vote. If you have even more people in the jury, it becomes harder and harder. So how can we make sure that the biggest amount of people can have a vote whether to include a block of transactions into the blockchain or not? Something we have abundant access to these days, computers. Everyone can participate if they have computing power. Let computers do the work and reward those who set up the computers to take a vote in reaching a blockchain consensus. These computers who validate and decide which blocks to add to the blockchain are called miners.

Block confirmations

Block confirmations are the amount of blocks that come after the block with your transaction. The deeper your transaction goes in the chain, the safer your transactions are. Exchanges wait for a number of confirmations, if your transaction has 10 confirmations, it means that your transaction is contained in the tenth previous block and that there are 9 blocks after it. The reason that it is safer the deeper you go is because if you want to alter a transaction in the hundredth previous block, you will also have to alter all the 99 blocks after that.

Miners & nodes

Miners vote which block of transactions to include in the chain and which block to reject. Miners are the workhorses of the blockchain if the miners stop, so does the creation of new blocks and thus your blockchain comes down to a halt. Miners essentially find solutions for each block of transactions. They pick up unconfirmed transactions, build a block from it and start finding a solution for that block. If a solution is found, it is broadcasted through the network to all other miners. The other miners then verify that the solution found by the miner truly is a solution for that specific block. If it is valid, all miners add it to their locally stored blockchain (each miner has its own blockchain, because the blockchain protocol is distributed, so there is no one machine that contains the true blockchain). Each of the miners have their own local blockchain which they sync with each other. They get rewarded in cryptocurrency for putting in the hard work to find a solution. Miners get rewarded for what they do, so this gives an incentive to mine. It ensures that people are willing to run miners to keep the blockchain alive. Miners and nodes both have a local blockchain, but miners also actively add blocks to their chain, nodes only sync to provide redundancy and backup.

Block times & sizes

The average block time for most blockchains varies between 10 seconds and 10 minutes depending on the chain, now why is that? Why isn’t it shorter in order to process more transactions? Well, all stands or falls with the fact that miners can reach all other miners before another miner finds a new block. When a miner finds a solution it is going to broadcast this through the network of miners. Now let’s say another miner finds a solution of another block before the message of the miner has reached it. It does not know a block is already been found, so it will also broadcast its solution and a consensus has to be made which block to keep. If blocks are found let’s say every second and it takes approximately 10 seconds to broadcast a solution to the rest of the miner network, how will a consensus be made which block is block 10000 and which is 10001 and so on, it would be a giant mess to reach a consensus about which blocks are contained in the one true blockchain. This is why most block times are quite long, to guarantee stability because short block times can cause an orphaned block, a block that has no parent because it is not added to any chain, I will dig deeper into orphaned blocks later. Block times and sizes are merely a compromise of the community, chances are as the blockchain protocol evolves that the most optimal block time will be found and used.

Mining difficulty

Mining difficulty is needed to keep the block time constant. If the solution of a block is found too soon, the difficulty rises. If block solutions are found too late, difficulty lowers. Mining difficulty mostly rises over time because more and more miners enter the market and more and more transactions need to be put into the blockchain (unless everyone decides that cryptocurrency is dead and that everyone shuts down their miners).

Blockchain Branching

The next few subjects are a little more difficult, they all build on the fact that blockchains are not linear, they branch regularly. Because everything is decentralized, there is no one machine that holds the true blockchain and local copies of the chain on each machine can vary. We will look into what causes them to branch, which implications this has and the weird side effects that can occur because of this.

Photo by Zach Reiner on Unsplash

Branching

I prefer the term branching over the term split. There is a small subtlety between those two words. When thinking about a branch you realize that a new branch emerges from another branch and that the branch does not ‘split’ into branches, a new one emerges from it in another direction while the parent branch keeps growing straight.

Branching of the chain happens when some miners have different mining software running, when there is a bug in the mining software or that someone malicious is planning a 51% attack. This results in a moment in time that a new chain emerges, both starting from the same parent block. If all miners are working on one branch of the chain, the other branch just stays the way it is, the last block on an abandoned branch is called a stale block. But if a portion of the miners work on one branch and a portion work on the other, both chains stay active. It is up to the community to validate which branches to support or to try and fix their mistake if the branching was unintentional.

Hard & soft chain forks

Branching of the chain can occur when there is a soft fork or a hard fork. Don’t let the terminology fool you, a soft fork or hard fork does not necessarily cause a fork. Correlation does not imply causation. Chain branching correlates with forks but forks do not necessarily cause them. A soft fork is a minor update to the blockchain protocol that doesn’t invalidate previously mined blocks, the chain can keep growing without interruption. A hard fork is a major update to the blockchain protocol and can be used to deliberately cause a branch, although remember that this does not necessarily has to be. After a planned hard fork, with the intention to start a new branch, a new branch emerges when miners have updated their software to work on the new branch. This is needed in order to keep it alive if this is what the community wants. This recently happened with the hard fork of the Sia blockchain.

Stale blocks vs Orphan blocks

It happens from time to time that two miners find a solution to their block just moments apart. It is usually not such a big deal, the first block that has been found is mostly kept and the other block is going to be an orphaned block. Orphan blocks have no known parent in the longest chain. This happens when more than 1 block is found at approximately the same time, the network of miners then decide which block to add to the chain, leaving the other mined block parentless. You can also imagine that a lot of orphaned blocks are a waste of energy and is discouraging for the miners who put in useless work to find its block solution. A block reward is not given to the miner who mined this block, it is only given when the block is added to the chain.

Stale blocks are the last blocks on a branch to which no blocks are being added to because no miners are working on that branch. This happens when the blockchain branches and one branch is completely abandoned by the miners and the community.

Note that transactions in orphaned blocks are never lost, they return to the unconfirmed transaction pool. This is not a big deal if the orphaned block has never been a port of the blockchain, blocks which are not added to the chain are not yet executed. Orphaned blocks are a big deal if they were already added to the blockchain, this can cause transactions to be done twice. I will elaborate this when talking about blockchain reorganisations.

51% hashrate attack

A 51% attack only says something about the hashrate being controlled by one party, not necessarily about what kind of attack. An attack can happen by faking the majority vote as explained further or by mining a chain faster than the main chain and causing a blockchain reorganization as explained below. A 51% attack can result in the following scenario. Let’s say I spend 1 BTC, it gets mined and is added to the blockchain. I cash in and get a lot of money. YES, MONEY! If a reorganization happens to the block before the block in which I withdrew the 1 BTC and all the blocks in the other chain become orphaned, I suddenly see that I have, again, 1 BTC in my account. YES, MONEY AGAIN! This is also known as the double-spend problem.

Faking the majority vote and including potentially malicious blocks, and thus transactions into the main chain can happen when under a 51% attack. This could happen when a malicious entity controls 51% of the hashrate and can thus decide which blocks to add and which to reject by controlling the majority vote. Miners vote on blocks if the contained transactions in the blocks contradict each other and more than 1 block is found at the same time. It is not possible to fake a majority vote if you don’t have control over more than half the total hashrate on the chain. Each community monitors that no one is able to control the majority of the hashrate, companies like InnoSilicon or Bitmain have the capacity to do this (not implying that they will).

Chain reorganizations

Blockchain reorganizations happen when the majority of miners decide to switch to a previously shorter chain which has become the longest chain recently. If a chain reorganization happens, the blocks in the old branch become orphaned blocks. This can happen when the chain gets overloaded and the miners struggle to find a consensus on what chain they will vote as the main chain to mine on. This happened quite recently to the Bitcoin Cash hard fork.

Chain reorganizations can also result when a 51% attack is happening when blocks are orphaned because your malicious miners mined a branch faster than the main branch and that branch took over. All of those transactions are brought back to the unconfirmed transaction pool and get added again to the main chain after some time.

Different kinds of chains

There are multiple blockchains in existence, each of them are a little different than the other. For example, the Ethereum blockchain has a block time of 14 seconds, whereas the Bitcoin blockchain has a block time of 10 minutes. Block sizes can be different, these decisions are up to the community and they do what they think is best. It also happens that hard fork it implemented and that the block size increases on one branch because a part of the community thinks this is better. This happened to Bitcoin and Bitcoin Cash. Other examples of blockchain protocol implementations are; Neo, Litecoin, Stellar, Sia, etc. Each have their own different implementation of the blockchain protocol with their own adjustments and tweaking.

Blockchain is a protocol, a way of working. The protocol can change and vary over time as more and more insight is gathered which parameters work best to produce as much stability and performance. The current blockchain protocol will probably be a lot different as the blockchain protocol in 10 years. The one true blockchain is also just something abstract, because of its decentralised nature, it cannot be said that one particular machine holds the one true blockchain.

Axons

Conveying information about high-end technology and science.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store