Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Hyperledger Fabric

Overview

This Git project comprises two main deployments. The 'fabric-samples' folder includes the documentation and source code necessary for deploying Hyperledger Fabric, offering examples and templates for setting up and managing a Fabric network. The 'FabricRest' folder contains all the documentation and source code for a REST API server designed to interact with the blockchain, facilitating seamless communication between users and the blockchain network.

Authors

(2024)

This implementation is a modification of the Hyperledger Fabric public repository -> https://github.com/hyperledger/fabric-samples

Specific changes and modifications have been made by:

Hyperledger Fabric Documentation

What is a Blockchain?

A blockchain is an immutable transaction ledger, maintained within a distributed network of peer nodes. These nodes each maintain a copy of the ledger by applying transactions that have been validated by a consensus protocol, grouped into blocks that include a hash that bind each block to the preceding block.

What is Hyperledger Fabric?

Hyperledger Fabric is an open-source enterprise-grade permissioned distributed ledger technology (DLT) platform, designed for use in enterprise contexts, that delivers some key differentiating capabilities over other popular distributed ledger or blockchain platforms. Hyperledger Fabric was established under the Linux Foundation and is governed by a diverse set of maintainers from multiple organizations.

One of the main features of Hyperledger Fabric is its modular and configurable architecture, enabling innovation, versatility, and optimization for a broad range of industry use cases. Another key feature is that Fabric is the first distributed ledger platform to support smart contracts authored in general-purpose programming languages such as Java, Go, and Node.js, meaning that most enterprises will have the skill set needed to develop smart contracts/chaincodes. Smart contracts/chaincodes contain the business logic of the blockchain application.

The Fabric platform is permissioned, meaning that the participants are known to each other, rather than anonymous, and therefore fully untrusted as with Bitcoin or Ethereum.

Another platform's differentiator is its support for pluggable consensus protocols that enable the platform to be more effectively customized to fit particular use cases and trust models, such as crash fault-tolerant (CFT) when Fabric is deployed within a single enterprise or byzantine fault tolerant (BFT) when Fabric is deployed in a multi-party, decentralized use case.

Also, Fabric can leverage consensus protocols that do not require a native cryptocurrency, thus reducing significant risk/attack vectors, and the absence of cryptographic mining operations.

These features make Fabric one of the better-performing platforms available today in terms of transaction processing and transaction confirmation latency, and it enables privacy and confidentiality of transactions and the smart contracts (called 'chaincode' in Fabric) that implement them.

hyperledgerFabric-Architecture

Fabric Contract APIs

Hyperledger Fabric offers some APIs to support developing smart contracts (chaincode) in various programming languages. Smart contract APIs are available for Go, Node.js, and Java. For more info, check:

Fabric Application APIs

Hyperledger Fabric offers a Fabric Gateway client API to support developing applications in Go, Node.js, and Java. This API uses the Gateway peer capability introduced in Fabric v2.4 to interact with the Fabric network. The Fabric Gateway client API is the preferred API for developing applications for Fabric v2.4 onwards.

Legacy application SDKs also exist for various programming languages and can be used with Fabric v2.4. These application SDKs support versions of Fabric before v2.4, and do not require the Gateway peer capability. They also include some functionality, such as administrative actions for managing enrollment of identities with a Certificate Authority (CA), that are not offered by the Fabric Gateway API. Application SDKs are available for Go, Node.js, and Java.

Prerequisites for developing with the SDKs can be found in the Node.js SDK README, Java SDK README, and Go SDK README.

In addition, there is one other application SDK that has not yet been officially released for Python, but is still available for downloading and testing:

Run

The deployment of a Hyperledger Fabric instance proposed in this project requires of two steps:

1 - Deployment of Hyperledger Fabric

First, the different components of Hyperledger Fabric are deployed, using Docker to create the network and containers.

Please go to fabric-samples/README.md file and follow the instructions.

After completing this step, Hyperledger Fabric will be ready to support the functionality offered by the REST API "layer."

2 - Deployment of REST API server

Once Hyperledger Fabric is deployed and configured, the next step is to run the REST API server to provide access to third parties via HTTP requests:

  • Go API-REST: This API-REST server is developed in Go. It consumes much less resources than the other API-REST server. To deploy the API-REST server developed in Go, please go to FabricREST-Go/README.md file and follow the README instructions.

3 - Blockchain Machine Monitoring (Statistics)

Optionally, activity monitoring tools can be implemented for the environment where Hyperledger Fabric is deployed (virtual machine, ...). In this sense, a monitoring package, based on the Prometheus and Grafana tools, can be used

To deploy this monitoring environment, please go to prometheus-grafana/README.md file and follow the README instructions.

4 - Backups

Regular backups are essential to maintaining the security and continuity of your Hyperledger Fabric deployment. These backups allow for quick restoration of the blockchain network in the event of unexpected issues or system failures. This section provides the steps to create and restore a backup for your Hyperledger Fabric deployment.

Backups created following these steps will include all necessary files, folders, and configurations required for a complete restoration, ensuring the network can resume operations as expected. Be aware that different deployments may require updating specific components, such as REST-API server certificates, to ensure full functionality after restoration.

Creation of the backup file

The backup is performed every Saturday at 00:00, which means once every 7 days. the script responsible for the backup can be found in backup_script/backup.sh. A cron job has been configured in /etc/crontab to execute the backup script every 7 days by adding the following line:

# Backups
0 0     * * 6   root    /home/odins/hyperledger-fabric/backup_script/backup.sh

The script performs a backup of specific Hyperledger Fabric directories and files, including orderer files, channel artifacts, and peer directories. It dynamically identifies peer folders based on a naming convention and adds them to the backup list. The selected files are then compressed preserving permissions into a tarball with the name HyperledgerFabric_<hostname>_<date>.tar.gz where <hostname> is the name of the machine where Hyperledger Fabric is deployed, and <date> is the actual date in YYY-MM-DD format when the script is executed. After creating the backup file, it securely transfers it to a remote server using SCP and removes the local backup file. This ensures that all critical data is safely stored on the remote server without leaving residual files locally.

The reason to execute the script using the 'root' user is that some files and folders require root permissions to be copied, so if the script is not executed by the 'root' user there will be some files that will not be copied in the backup file, and therefore it will not be possible to restore the Blockchain. Also, even if the 'root' user executes the script, the copied files and folders keep the same permissions and owners.

Restore Blockchain using backup file

First of all, before restoring a Blockchain instance, you must be sure that no Hyperledger Fabric deployments are running in the machine where you want to restore a Blockchain instance. To do that, go to fabric-samples/odins-network and execute:

./runFabric.sh down

After that, to restore a Blockchain instance using a backup file, go back to the root directory of the repository and execute:

sudo ./restore.sh <backup_tar>

Where <backup_tar> is the tar.gz file with the backup of the Blockchain you want to restore.

This script will extract files from the backup file, copy all files and folders to their respective locations, change ownership of files and folders, and start all the containers. Please note that the Smart Contracts containers will take some time to create, so please do not interact with the Blockchain until you see all Smart Contract containers deployed.

After this, your Hyperledger Fabric deployment is fully operational and should work as it always does.

(OPTIONAL) Update certs in API-REST server

After restoring your Hyperlewdger Fabric deployment, if it's a different deployment than the previous one, the certificates from the REST-API server will have to be updated.