Learn Blockchain

Note

If you are new to the field of information technology, taking our Introduction to Information Technology and its Career Roadmaps and Introduction to Cloud Technology with DevOps, Docker and Kubernetes (free self-paced) courses is highly recommended. Also, for a comprehensive coverage of blockchain concepts and its use cases, taking our Introduction to Blockchain Technology course is highly recommended.

Recap

In our previous article (How Proof-of-work Consensus Works in Blockchain), we learn about Proof of Work consensus algorithm that is currently used in the Ethereum blockchain applications.
In this article, we discuss how Proof of Stake or PoS consensus algorithm works in blockchain.

Consensus algorithms are one of major components of a blockchain system and they play a vital role in the blockchain performance and security. Originally, Ethereum adopted Proof of Work or PoW consensus algorithm from Bitcoin. While Ethereum currently uses PoW, due to its deficiencies, Ethereum community is moving toward Proof of Stake or PoS algorithm which outperforms its PoW. In this article, I start off explaining what is PoS followed by discussing soft and hard forking for adding new blocks to the blockchain.

 

Proof of Stake

As opposed to PoW consensus, where miners are rewarded for solving cryptographic puzzles, in the PoS consensus algorithm, a pool of selected validators take turns proposing new blocks. The validator is chosen in a deterministic way, depending on its wealth, also defined as a stake. Anyone who deposits their coins as a stake can become a validator. The chance to participate may be proportional to the stakes they put in. Let’s say, Alice, Bob, Catherine, and David put in 40 Ether, 30 Ether, 20 Ether, and 10 Ether stakes to participate respectively; they will get a 40%, 30%, 20%, and 10% chance of being selected as the block creator.

The following is how it works in the PoS consensus mechanism. As shown in the following diagram, the blockchain keeps track of a set of validators, sometimes also called block creators or forgers. At any time, whenever new blocks need to be created, the blockchain randomly selects a validator. The selected validator verifies the transactions and proposes new blocks for all validators to agree on. New blocks are then voted on by all current validators. Voting power is based on the stake the validator puts in. Whoever proposes invalid transactions or blocks or votes maliciously, which means they intentionally compromise the integrity of the chain, may lose their stakes. Upon the new blocks being accepted, the block creator can collect the transaction fee as the reward for the work of creating new blocks:

Ethereum and Proof of Stake
PoS is considered more energy-efficient and environment-friendly compared with the PoW mechanism. It is also perceived as more secure too. It essentially reduces the threat of a 51% attack since malicious validators would need to accumulate more than 50% of the total stakes in order to take over the blockchain network.

Similar to PoW, total decentralization may not be fully possible in the PoS-based public blockchain. This is because a few wealthy nodes can monopolize the stakes in the network. Those who put in more stakes can effectively control most of the voting. Both algorithms are subject to the social and economic issue that it makes the rich richer.

 

Forking

A temporary fork occurs when two competing blocks are added to the blockchain. As shown in the following screenshot, this can continue until the majority of the nodes see the longest chain. Newer blocks will be appended to the longest chain. Blocks added to the shortleaf of the forked chain will be discarded, and those transactions will go back to the transaction pool and will be picked again for reprocessing. Eventually, the blockchain will comprise all conforming blocks, chained together using cryptographic hashes pointing to its ancestor:

Ethereum and Proof of Stake
Just like software development, forking is a common practice in blockchain. Forking takes place when a blockchain bifurcates into two separate paths. The following events, intentionally or accidentally, can trigger a blockchain fork:

  • New features are added, requiring a change in blockchain protocol, such as block size, mining algorithm, and consensus rules.
  • Hacking or software bugs.
  • A temporary fork occurs when competing for blocks with the same block height.

A general forking scenario in a blockchain may look like the following screenshot:

Ethereum and Proof of Stake

Depending on the nature of such events, the actions to fix the issues could be a hard fork or a soft fork or, in the case of a temporary fork, doing nothing and allowing the network to self-heal.

Hard fork

hard fork happens when radical changes in the blockchain protocol are introduced and it makes historical blocks non-conformant with new protocols or rules. Some are planned.

Developers and operators agree with protocol changes and upgrades to new software. Blocks following the old protocol will be rejected, and blocks following the new protocol will become the longest chain moving forward.

But, in some cases, this is controversial and heavily debated in the blockchain community, as was the case with the Bitcoin fork on 6 August 2010 or the fork between Ethereum and Ethereum Classic. In such contentious hard fork cases, as long as there are miners maintaining the old and new software, the blocks created by the old and new software will diverge into separate blockchains.

The following screenshot illustrates both planned and contentious hard forks:

Ethereum and Proof of Stake

 

During a contentious hard fork of blockchain, a new cryptocurrency will be created to fuel the new blockchain. The owner of the existing crypto-assets may stay in the current network or move to the new network. When moving to the new network, they will receive a proportional amount of new cryptocurrency in the new network. Hard forks often create pricing volatility. The conversion rate between the old and new fork may be determined by the market. It is important to know the context and details of a hard fork, and understand the crypto-economic impacts of such a fork to both cryptocurrencies in order to take advantage of such sudden and drastic changes.

Once forked, nodes will start with separate paths moving forward. Nodes would need to decide which blockchain network they want to stay in. For example, Bitcoin Cash diverged from Bitcoin due to a disagreement within the Bitcoin community as to how to handle the scalability problem. As a result, Bitcoin Cash became its own chain and shares the transaction history from the genesis block up to the forking point. As of September 2 2019, Bitcoin Cash’s market cap is around $5 billion, ranking fourth, versus Bitcoin’s $215 billion.

Soft fork

A soft fork, by contrast, is any change of rules that is backward-compatible between two versions of the software and the blocks. It goes both ways. In the soft fork case, existing historical blocks are still considered valid blocks by the new software. At the same time, the new blocks created through new software can still be recognized as valid ones by the old software. In the decentralized network, not all nodes upgrade their software at the same time. Nodes staying with an older version of the blockchain software continue creating new blocks using the older software. Nodes upgraded to the newer version of blockchain software will create new blocks using new software. Eventually, when the majority of the network hashing capacity upgrades to a newer version of the software, in theory more blocks will be created with the newer version and make it the longest chain. Nodes with older software can still create new blocks. Since it is not in the longest chain, as illustrated in the following screenshot, similar to the temporary fork case, these blocks will soon be overtaken by the new chain:

Ethereum and Proof of Stake

Where more nodes are stuck on the older version, as illustrated in the following screenshot, new blocks created from an older version of blockchain software may become longer and longer; it will take a while for the new software to be effective:

Ethereum and Proof of Stake

 

Summary

Now that we learned how PoS and forks work in Ethereum (which is a permissionless blockchain platform), we can continue our journey by exploring what Byzantine Fault Tolerance or BFT consensus algorithm is and how Hyperledger uses BFT for processing enterprise blockchain transactions in its private networks. Perhaps in my next article, I will dive into BFT.

 

 

This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.

Resources

Free Webinars on Blockchain

Here is the list of our free webinars that are highly recommended:

 

Free Courses

Here is the list of our 10 free self-paced courses that are highly recommended:

 

Self-Paced Blockchain Courses

If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:

  1. Intro to Blockchain Technology
  2. Blockchain Management in Hyperledger for System Admins
  3. Hyperledger Fabric for Developers
  4. Intro to Blockchain Cybersecurity
  5. Learn Solidity Programming by Examples
  6. Introduction to Ethereum Blockchain Development
  7. Learn Blockchain Dev with Corda R3
  8. Intro to Hyperledger Sawtooth for System Admins

 

Live Blockchain Courses

If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:

 

Articles and Tutorials on Blockchain Technology

If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:

 

Articles and Tutorials on Ethereum and Solidity

If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Hyperledger Family

If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on R3 Corda

If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Other Blockchain Platforms

If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: