Understanding Hyperledger Fabric: Architecture, Chaincode, Membership, Consensus

Introduction

Hyperledger Fabric is an enterprise-grade blockchain solution. It is different from other blockchains because it is permissioned, unlike Bitcoin or Ethereum. We can decide who can see certain data.

In this blog, we will be discussing the following topics:

  1. Architecture

  2. Chaincode Development

  3. Membership Services

  4. Consensus

  5. Conclusion

1. Architecture

Fabric consists of the following main components:

  1. Peers: They are nodes on the network that maintain a copy of the ledger and execute transactions. Peers play an important role in the consensus process to ensure that the ledger is updated with valid transactions.

  2. Endorsing Peers: These peers execute transactions and apply the corresponding chaincode, then send an endorsement of the result to the client. These endorsements are used in the consensus process to ensure that all transactions are validated by the required parties.

  3. Ordering Service: The component that orders transactions into a block and broadcasts the block to the peers. The ordering service uses a consensus algorithm to ensure that all blocks are ordered consistently across the network.

  4. Membership Service Provider: Manages the identities and access control policies of network participants. This component helps in verifying the identity of participants.

  5. Chaincode: Chaincode is the business logic of the network. Chaincode is validated as part of the consensus process to ensure that it is executing correctly across the network.

  6. Channels: Private subnetworks within the Hyperledger Fabric network that allow multiple parties to transact privately and securely.

  7. Ledger: A log of all transactions that have been executed on the network. The consensus mechanism is used to ensure that all peers have an identical copy of the ledger.

2. Chaincode

Chaincode is a type of smart contract that is specific to Hyperledger Fabric. It provides a way for developers to define and execute the rules of a transaction. It is a program that runs on a peer node and interacts with the ledger to read or write data.

Chaincode can be written in a programming language such as Go, Java, or Node.js, and is installed on peer nodes in the network.

3. Membership Services

Membership services in Hyperledger Fabric are like security guards at a club. They control who gets in and who doesn't.

In other words, membership services are responsible for managing the network membership and access control policies. They make sure that only authorized parties can participate in the network and access the resources they are entitled to. This is achieved through the use of cryptographic certificates (complying with X.509 standard) that are issued to network participants by Certificate Authority.

4. Ordering Service

The ordering service uses consensus algorithms like Raft or Kafka to make sure that everyone is on the same page and that the ledger is accurate. Without the ordering service, the entire network would be in chaos and transactions will be added in the wrong order or not at all.

5. Consensus

So, the consensus in Hyperledger Fabric is the way in which all the nodes on the network agree on what the latest state of the ledger should be. It's really important because it makes sure that transactions are processed securely and reliably. The cool thing is that Fabric gives you the ability to choose from different consensus algorithms, like Kafka or Raft, depending on what you need.

Raft Consensus Algorithm

Let's look at recommended consensus algorithm i.e. Raft.

There are 3 main components in the Raft algorithm:

  1. Leader

  2. Follower

  3. Candidate

It's like having a designated "leader" or "coordinator" who's in charge of keeping everyone on the same page. The leader is responsible for receiving requests from all the other nodes (followers) and then giving a decision that everyone can agree on.

The leader is selected by a process called leader election. Each node in the network is a candidate for leader and can send out a message saying "vote me". The node that receives the most votes becomes the leader.

But sometimes the leader can become disconnected or fail, which can cause problems in the network. That's where timeouts come in.

Each node has a timer. If it doesn't receive a message from the leader within a certain amount of time, it assumes the leader has failed and initiates a new leader election process. This ensures that the network can quickly recover from failures and maintain consistency in the ledger.

TL;DR

Hyperledger Fabric is an enterprise blockchain solution that is permissioned, meaning access to the data can be restricted. Its main components include peers, endorsing peers, ordering service, membership service provider, chaincode, channels, and ledger. The Raft consensus algorithm is recommended and involves an elected leader who receives and processes requests from other nodes i.e. followers and proposes a decision that everyone can agree on.

Resources

  1. Documentation: Link

  2. GitHub: GitHub Repo