Blockchain DevOps on AWS with The Hyperledger Fabric Model and Golang (1)
Tags: blockchain, go, aws, devops
Published: 2022-02-20 20:20:02

# The Blockchain

The Blockchain is an encrypted database of transactions stored in a distributed ledger.

Blockchain transactions are exchanges of value in the form of digital money, and the transactions are stored on a ledger to record the transactions. Transactions are immutable, verifiable, and incorruptible.

Blockchains operate with decentralized technology, hence have no single point of failure. 

Smart Contracts are pieces of code that control actions on a blockchain network. They are similar to the business logic of Web2.0.

To add entries to a shared ledger, a smart contract must be executed. Consensus protocols are what regulate and decide which node/computer/peer can add entries to a blockchain. Consensus protocols are what empower these nodes to be able to agree upon:

- the transactions that get added
- the order of transactions to be added

Once nodes accept a blockchain transaction, the transaction gets stored permanently on the blockchain network.

### The Hyperledger Project

Hyperledger is not a blockchain, company, or cryptocurrency.

It is a parent project of open-source blockchains and tools started in December 2015 by the Linux Foundation.

It is made up of three components:

- Developers and communities
- Frameworks and tools
- Industries like finance, IoT, supply chain, and manufacturing

**Developers**

The developers of the Hyperledger Projects are blockchain specialists who are also developers working in different industries and who want to see the blockchain technology used in diverse fields.

**Frameworks and Tools**

Frameworks include the following:

- Hyperledger Fabric by IBM
- Hyperledger Sawtooth
- Hyperledger Iroha for mobile apps
- Hyperledger Burrow built to support the EVM
- Hyperledger Indy which supports independent identities on distributed ledgers
- Hyperledger Cello for deployment
- Hyperledger Composer for UI
- Hyperledger Caliper for benchmarking
- Hyperledger Explorer for monitoring application status

**Industries**

IBM, Intel, Wells Fargo, etc., are examples of companies who are involved in the Hyperledger Project

## Deep Dive in Comparison

Ethereum is an open-source, public blockchain-based platform that is used to build smart contracts. Ethereum has a cryptocurrency called Ether, used to reward nodes for work done on the network. The smart contracts are written with language such as Solidity.

Ethereum has problems with scaling and speed. The Proof-of-Work algorithm consumes relatively more computing power and resources. Also, each transaction in the Ethereum network gets broadcasted to all nodes in the network, discouraging the idea of confidentiality. 

These issues are behind the creation of the Hyperledger Project.

### Hyperledger Fabric

The Hyperledger Fabric framework is an open-source, enterprise-grade, permissioned distributed ledger technology platform designed for use in an enterprise application. Hyperledger Fabric is used to build private blockchain networks where all nodes are known and verified. “Known” does not mean trustworthy, but that the peers on the network are not anonymous.

### Advantages of Hyperledger Fabric

The following are advantages of the Hyperledger Fabric framework:

**1. It is permissioned**

Unknown peers are not allowed to participate, and there are private channels between the peers. Membership Service Providers (MSPs) are used to regulate the peers who join the network. Verification is important and compulsory in Hyperledger Fabric. Channels can also be set up to allow for private communication between subsets of nodes. These private channels have private ledgers that no external node can access.

**2. Transactions are fast**

There is low latency and high throughput for verifying and accepting transactions. Transactions on Hyperledger Fabric are executed using smart contracts also, but they are called Chaincodes in Hyperledger Fabric. Hyperledger Fabric Chaincodes are written in languages such as Golang, or NodeJS. They are not written with contract-purpose programming languages like Solidity. 

Chaincodes have standard interfaces with two methods: the `init` and `invoke` methods to initialize the smart contract and to invoke or execute the smart contract, respectively. 

The execution of a transaction through a smart contract is done by a few endorsing peers. The percentage of the peers endorsing the transaction is determined by an Endorsement Policy. However, the execution does not update the actual ledger. Instead, endorsed transactions are passed down to Orderers.

Orderers determine the sequence of the transaction. Ordering is of different types:

1. SOLO Ordering
2. Kafka distributing system
3. Practical Byzantine-Fault Tolerance

Next, the transaction is passed on to Committing peers. The Committing peers of that particular Hyperledger Fabric network are responsible for validation and “merging” or committing the transaction to their private ledger copy.

They only accept/validate correctly endorsed transactions, and verify that the transaction is valid with the latest version of the shared ledger. If the transaction is found wanting, they are invalidated by the Committed peers.

The lifecycle of a transaction on the Hyperledger Fabric network makes the issue of double-spending inexistent and makes sure that the sender has the asset they want to send.

**3. Easy to Plug**

It is designed to be modular, so developers can use different databases, membership service providers, consensus algorithms, etc.

## A Transaction’s Lifecycle on the Hyperledger Fabric

A client application submits a transaction proposal to Endorsing peers through a Chaincode or smart contract. The Endorsing peers execute the Chaincode and endorse the transaction. The transaction is then sent back to the client application with signatures. The client application then sends the signed transaction to Orderers. 

Once the Orderers order the transaction, they pass it on to the Committing peers who perform their duty as explained above and add the transaction to their private copy of the ledger. The Committing peers then send the Confirmation of the transaction to the client application.

Transactions involve hardware assets or software assets; apparently anything of monetary value that can be exchanged between two parties.

## Hyperledger Fabric vs Ethereum

The following are highlights of the differences between Hyperledger Fabric and Ethereum

1. Ethereum is permission-less, Hyperledger Fabric is permissioned

2. Peers have to be verified, known, and approved to be part of the private Hyperledger Fabric platform.

3. In Hyperledger Fabric, not all users can validate or endorse transactions, but it is so on Ethereum.

4. Hyperledger Fabric does not have a cryptocurrency to incentivize nodes for reward of work done. Ethereum has the Ether cryptocurrency for this.

5. In Hyperledger Fabric, transaction execution mechanism is with Chaincodes and not Smart Contracts as in Ethereum.

6. The transaction lifecycle on Hyperledger Fabric involves: execute transaction —> order the transaction —> validate the transaction. In Ethereum, it involves: order the transaction —> then execute the transaction. Validation does not exist separately in Ethereum.

7. Transactions can be kept private from some peers in the Hyperledger Fabric network, but in Ethereum, all transactions are broadcasted to all nodes in the network.

8. General-purpose languages like Go, Node.js and Java are supported on Hyperledger Fabric, but contract-purposed, domain-specific language like Solidity is used on Ethereum.

9. On Hyperledger Fabric, the consensus protocol is broad and generic. On Ethereum, it is Proof-of-Work (soon, Proof-of-Scale).

10. Little effort and resource is wasted in Hyperledger, making it scale far more easily than Ethereum which consumes much more effort and resource.

# AWS Blockchain Templates

AWS Blockchain Templates supports two blockchains (Verify this):

1. Ethereum
2. Hyperledger Fabric

Only build on the Hyperledger Fabric if you want to a private network for your organization, as only known and verified peers are allowed.

AWS Blockchain Templates specify the network components of your blockchain platform, with a network configuration file.  You can also run Chaincode or DApps on the AWS Cloud.

The following are tools on the AWS Cloud that will be used in building the Hyperledger Fabric platform:

1. AWC EC2 to configure peers, orderers, and the ledger
2. AWS ECR Docker container registry to provision containers for nodes
3. Amazon VPC to provide private network access to cloud resources
4. AWS Security Groups for controlling traffic flows to and from the network.
5. AWS Roles for access control
6. AWS CloudFormation Stack for the blockchain network

# Conclusion

This article presents a swift guide to the Hyperledger Blockchain platform. The Hyperledger Fabric framework is explained and compared to the popularly adopted Ethereum blockchain.

The next article will take a more technical approach to practice some DevOps principles using the AWS Blockchain Template explained in this article, to build a private Hyperledger Fabric network with the Go programming language.

You can learn more about the [Hyperledger Project here](https://www.techtarget.com/searchcio/definition/Hyperledger).