Book Image

Advanced Blockchain Development

By : Imran Bashir, Narayan Prusty
Book Image

Advanced Blockchain Development

By: Imran Bashir, Narayan Prusty

Overview of this book

Blockchain technology is a distributed ledger with applications in industries such as finance, government, and media. This Learning Path is your guide to building blockchain networks using Ethereum, JavaScript, and Solidity. You will get started by understanding the technical foundations of blockchain technology, including distributed systems, cryptography and how this digital ledger keeps data secure. Further into the chapters, you’ll gain insights into developing applications using Ethereum and Hyperledger. As you build on your knowledge of Ether security, mining, smart contracts, and Solidity, you’ll learn how to create robust and secure applications that run exactly as programmed without being affected by fraud, censorship, or third-party interference. Toward the concluding chapters, you’ll explore how blockchain solutions can be implemented in applications such as IoT apps, in addition to its use in currencies. This Learning Path also highlights how you can increase blockchain scalability, and discusses the future scope of this fascinating and powerful technology. By the end of this Learning Path, you'll be equipped with the skills you need to tackle pain points encountered in the blockchain life cycle and confidently design and deploy decentralized applications.
Table of Contents (25 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
15
Blockchain - Outside of Currencies
16
Scalability and Other Challenges
Index

CAP theorem and blockchain


CAP theorem, also known as Brewer's theorem, was introduced by Eric Brewer in 1998 as conjecture. In 2002, it was proven as a theorem by Seth Gilbert and Nancy Lynch. The theory states that any distributed system cannot have consistency, availability, and partition tolerance simultaneously:

  • Consistency is a property which ensures that all nodes in a distributed system have a single, current, and identical copy of the data.
  • Availability means that the nodes in the system are up, accessible for use, and are accepting incoming requests and responding with data without any failures as and when required. In other words, data is available at each node and the nodes are responding to requests.
  • Partition tolerance ensures that if a group of nodes is unable to communicate with other nodes due to network failures, the distributed system continues to operate correctly. This can occur due to network and node failures.

It has been proven that a distributed system cannot have consistency, availability, and partition tolerance simultaneously. This is explained with the following example. Let's imagine that there is a distributed system with two nodes. Now let us apply the three theorem properties on this smallest of possible distributed systems only with two nodes.

  • Consistency is achieved if both nodes have the same shared state; that is, they have the same up-to-date copy of the data.
  • Availability is achieved if both nodes are up and running and responding with the latest copy of data.
  • Partition tolerance is achieved if communication does not break down between two nodes (either due to network issues, Byzantine faults, and so forth), and they are able to communicate with each other.

Now think of scenario where a partition occurs and nodes can no longer communicate with each other. If no new updated data comes in, it can only be updated on one node only. In that case, if the node accepts the update, then only that one node in the network is updated and therefore consistency is lost. Now, if the update is rejected by the node, that would result in loss of availability. In that case due to partition tolerance, both availability and consistency are unachievable.

This is strange because somehow blockchain manages to achieve all of these properties—or does it? This will be explained shortly. To achieve fault tolerance, replication is used. This is a standard and widely-used method to achieve fault tolerance. Consistency is achieved using consensus algorithms in order to ensure that all nodes have the same copy of the data. This is also called state machine replication. The blockchain is a means for achieving state machine replication. In general, there are two types of faults that a node can experience. Both of these types fall under the broader category of faults that can occur in a distributed system:

  • Fail-stop fault: This type of fault occurs when a node merely has crashed. Fail-stop faults are the easier ones to deal with of the two fault types. Paxos protocol, introduced earlier in this chapter, is normally used to deal with this type of fault. These faults are simple to deal with
  • Byzantine faults: The second type of fault is one where the faulty node exhibits malicious or inconsistent behavior arbitrarily. This type is difficult to handle since it can create confusion due to misleading information. This can be a result of an attack by adversaries, a software bug, or data corruption. State machine replication protocols such as PBFT was developed to address this second type of faults.

Strangely, it seems that the CAP theorem is violated in the blockchain, especially in its most successful implementation, Bitcoin. However, this is not the case. In blockchains, consistency is sacrificed in favor of availability and partition tolerance. In this scenario, Consistency (C) on the blockchain is not achieved simultaneously with Partition tolerance (P) and Availability (A), but it is achieved over time. This is called eventual consistency, where consistency is achieved as a result of validation from multiple nodes over time. The concept of mining was introduced in Bitcoin for this purpose. Mining is a process that facilitates the achievement of consensus by using the PoW consensus algorithm. At a higher level, mining can be defined as a process that is used to add more blocks to the blockchain. More on this later in Chapter8, Introducing Bitcoin.