Hyperledger Fabric -Practices
Ranjeet Bhargava ?
Software Delivery Manager @ YourNXT Technologies LLP | Strategic Cloud Development for SW Projects- Disciplined Agile Practitioner -Tech Lead - DevOps SAaaS PaaS, IaaS, Data Orchestration Platform .Net Developer-IA
Introduction
In the previous session, you learnt about the architecture, components and transaction flow in Hyperledger Fabric using the example of the tuna supply chain problem.??
?In this session
In this session, you will learn in slightly more detail about various concepts such as channels, gossip protocol, private data, etc. Also, you will learn about some important characteristics of Hyperledger Fabric.
Guidelines for in-module questions
The in-video and in-content questions for this module are not graded. Note that graded questions are given on a separate page labelled 'Graded Questions' at the end of this session. These graded questions will adhere to the following guidelines:
Questionnaires
Important Concepts of Fabric
In this segment, you will go through some concepts that you learnt in the previous sessions and also learn some new concepts such as gossip protocol and private data. In the video below, We will walk you through the concepts such as channels, state storage and MSP.
Play Video 589394
Based on the concepts studied in the above video answer the following questions.
Question 3/3Mandatory Question 1
Channel Which of the following statements are true about ‘Channels”?
?1-It allows compartmentalizing the data.?
? Correct
Feedback:
2-Channels compartmentalise the data of the network.
There can be any number of channels inside a Fabric network.
? Correct
Feedback:
In a Fabric network, the peers can form any number of channels amongst them.
3-A peer can also be part of more than one channel in the network.
? Correct
Feedback:
In a Fabric network, as there can be any number of channels this implies the fact that one peer can be a part of more than just 1 channel.
4-There is a common ledger between two different channels.
Your answer is Correct.Correct
Question 2
Database What is the differentiating fact between the LevelDB and the CouchDB?
1-The functionalities of LevelDB and CouchDB are different.
2-The LevelDB stores the values in a key-value pair format, whereas, CouchDB?CouchDB stores the values in JSON objects.?
? Correct
Feedback:
This is the correct option.?
Your answer is Correct. Correct
Question 3 CA
The Certificate Authority issues the certificate that is responsible for identifying the different peers, orderers or client applications in the network. Which of the following versions is created by enterprises on their own?
1-FabricCA
2-ExternalCA
? Correct
Feedback:
Enterprises using the Hyperledger Fabric network are open to implementing their own versions of FabricCA; this is called an ExternalCA implementation.
Your answer is Correct. Correct
Let us now listen to our Instructor as he explains?other important concepts in the video below.
Play Video 589394
Gossip protocol is a procedure or process of peer-to-peer communication that is based on the way epidemics spread or rumors spread in an office.?To know more about it refer to the additional resource provided at the bottom of the page.
Question 2/2Mandatory
Question 1 Gossip Protocol
Which of the following statements are true for Gossip Protocol?
1-Peers use Gossip Protocol to discover the new peers joining the network.
? Correct
Feedback:
Peers use Gossip Protocol to discover the new peers joining the network. This is the correct option
2-Peers use Gossip Protocol to let other peers know if any peer has been turned off.
? Correct
Feedback:
Peers use Gossip Protocol to let other peers know if any peer has been turned off. This is the correct option
3-Peers use Gossip Protocol to validate any block.
4-Peers use Gossip Protocol to distribute the ledger data.
? Correct
Feedback:
Peers use Gossip Protocol to distribute the ledger data. This is correct option.
Your answer is Correct.Correct
Question 2 Anchor peer
What does the anchor peer do?
1-It is responsible for cross-organisation communication.
? Correct
Feedback:
The responsibility of one anchor peer is to talk to the other anchor peers in different organisations and share which are the other peers available in the other organisations. Thus, the anchor peer allows cross-organisation communication between the peers across the network.
2-It is responsible for?enabling communication with the ordering service.
Your answer is Correct. Correct
Let us now take a look at the concept of private data in the video below.
Play Video 589394
In the video above, you learnt about Private Data. To know more about it refer to the additional resource provided at the bottom of the page.?
Question 2/2Mandatory
Question 1 Private Data
When to use Channel and when to use Private Data?
-Word Count?11
-Word Limit?10?-?200
Suggested Answer
The channel is used when the transactions and its details are needed to be kept within only the members of that channel and not all the peers.
The private data collection is used the transaction is shared amongst all the peers in the network but some information of the transaction is kept visible to a subset of peers of that network.
Submitted
Question 2 Private Data
Which of the following is responsible for recovering the private data if it has been tampered with?
1-Leader peer
2-Hash of the private data
? Correct
Feedback:
A hash of the private data is added to the transaction and is transferred to all the other peers in the network so that the private data can be recovered if it is tampered with.
3-Gossip protocol
Your answer is Correct.Correct
Additional Resource:
Characteristics of Fabric
It is important to learn the characteristics of any?blockchain as it gives you an insight into the benefits that a particular blockchain offers. In the previous sessions and segment, you learnt about Hyperledger Fabric components, transaction flow, gossip protocol, private data, etc. To complete the learning about the Hyperledger Fabric, let us now dive deep into its characteristics.
Play Video 589394
The characteristics of Hyperledger Fabric studied in the above video are:
?
Basis the concepts taught in the above video,?answer the following questions.
Question 3/3Mandatory
Question 1 Flexibilty
Which of the following characteristics imparts?flexibility to the Hyperledger Fabric architecture?
1-Permissioned Network
? Incorrect
Feedback:
The Fabric network allows any peer to enter a network if that peer has the right credentials and identities. This is incorrect option
2-Modularity
? Correct
Feedback:
Modularity is beneficial because it imparts flexibility to the architecture, as components of the network can be added or changed as per the requirement.
Your answer is Wrong. Incorrect
Question 2 Consensus process
Which of the following consensus processes does Ethereum follow?
1-Order-Execute
? Correct
Feedback:
Ethereum follows Order-Execute, whereas Hyperledger follows the Execute-Order-Validate consensus process. In Order-Execute process, when a transaction comes in it is ordered in a block. This block is then shared with all the peers in the network which then execute these transactions on their own copy of the ledger.
2-Execute-Order-Validate
Your answer is Correct. Correct
Question 3 Transaction
After giving input to a transaction, if the expected result does not remain?the same across all the peers, then the transaction is said to be:?
1-Deterministic
2-Non-Deterministic
? Correct
Feedback:
When an input X is given to a non-deterministic transaction, the expected result Y?or Z is not the same for all the peers in the network.?
Your answer is Correct. Correct
Let's now go through the remaining characteristics.
The characteristics highlighted in the above video are -
Graded Questions
Question 1/3Mandatory
Hyperledger Fabric
Which one of the following is?NOT?a feature of a Fabric blockchain?
1-Privacy and confidentiality
2-Modularity
3-Performance and scalability
4- Anonymity
? Correct
Feedback:
Fabric aims to provide a trusted network of known participants. As enterprise businesses have to know the identities of the participants of a transaction and their customers, each member of the Fabric network is explicitly identified.
Your answer is Correct.
Question 2/3Mandatory
Components of Hyperledger Fabric
Match the different Fabric components with their roles:
A. Orderer
B. Endorser
C. MSP
D. Client
1. Validates the identities of nodes
2. Orders the transactions into blocks
3. Simulates the?transactions
4. Generates transaction proposals
Choose the correct option:
A-1, B-2, C-3, D-4
A-2, B-3, C-2, D-4
A-2, B-3, C-1, D-4
? Correct
Feedback:
This option is correct. An orderer is the node that orders and confirms the transactions in one block. An endorser peer is responsible for simulating transactions and, in turn, preventing unstable or non-deterministic transactions from passing through the network. The Membership Service Provider is an entity that is used to identify the participants of the network, i.e., it is the identity-issuing authority of the network. The client is the one who wishes to perform a transaction and, hence, generates a transaction proposal in the network.
A-3, B-2, C-1, D-4
Your answer is Correct.
Question 3/3Mandatory
Endorsement Policy
In your company, a mobile application is being modified. The company policy states that?any change implemented needs to be verified by the tech lead, application lead and client. You wish to implement a change in the UI of the application. The changes are sent to both the tech lead and the application lead, as well as to the client. The client and the tech lead agree to the changes; however, the application lead does not approve. Consider this scenario analogous to the Hyperledger Fabric network where the application lead, tech lead and client are analogous to endorsers. Will you be able to implement these changes, given the endorsement policy of the company?
Yes
No
? Correct
Feedback:
In the Hyperledger Fabric network, transactions are verified by the endorsers. Here, the tech lead, application lead and client act as the endorsers. As mentioned in endorsement policy in the question, any change needs to be verified by all three to be implemented. Here, the application lead does not approve, meaning he/she does not endorse the change. As per the endorsement policy rule, you need all three of them to endorse the transaction for it to take effect; otherwise, the change/transaction is rejected. Hence, your changes will not be implemented.
Your answer is Correct.
Attempt 1 of 1 Continue
Comprehension
Consider this case: A chicken flu outbreak in Los Angeles resulted in many people becoming infected. In order to combat the disease, the Los Angeles Food Association (LAFA) decided to use a Hyperledger Fabric network to track the quality of chickens at every step. The architecture of the network is as follows:
A. All the poultry farms in the network enter the details of the chickens that they wish to sell in the ledger, using an application known as 'trackChicken'.?
B. Then the application sends a request to?LAFA, which?checks?the quality of each chicken?on?parameters such as weight, age and the vaccines that the chicken?has been?administered. If the chicken passes all the tests, it is approved and can be sold; otherwise, not. The?results of the tests are sent back to the application.
C. On receiving a result, the application sends it to the?local meat vendor?who receives all the requests from the different poultry?farms?adds the chickens to the ledger if they have?passed the quality check.
D. The?local meat supplier?then sends the added chickens to a block and sends the block to all the poultry farms so that they can update their corresponding ledgers. Basically, it then tells all the poultry farms whether their chickens are accepted or rejected as per the quality control measures.?
?
Based on the comprehension above, answer the following questions:
Question 1/4Mandatory
Roles in Hyperledger Fabric
Which one of the following acts as an endorser in the network?
trackChicken
Chicken
LAFA
? Correct
Feedback:
You are already aware that an endorser is the one that verifies and validates a transaction in the network. Here,??a chicken passing all the tests is the transaction. The chicken validation is done by LAFA.?Hence, LAFA verifies the transactions and acts as an endorser.
Local meat supplier
Your answer is Correct.
Roles in Hyperledger Fabric
Question 2 Who is a client in the mentioned case?
trackChicken
? Correct
Feedback:
A client is the one that interacts with the user and invokes the transaction request on behalf of the user. Here, the trackChicken app interacts with the user and all the chickens to be sold are entered via the app into the network. Hence, the trackChicken app acts as a client.
Chicken
LAFA
Local meat supplier
Your answer is Correct.
QUESTION 3 What is the role of the local meat supplier? Choose the correct option.
It acts as a normal peer in the network.
It acts as an orderer peer in the network.
? Correct
Feedback:
The local meat supplier collects all the requests via the trackChicken app and adds them to the ledger. The job of an orderer?node in the network is to collect data from the clients in the form of a block of data and send them to the other peers in the network so that they can add it to their corresponding ledgers. In this case, all the transactions, which are?defined as passing all the quality control tests, are received by the orderer. It collects those transactions, forms a block and sends it to all the peers to be added to their respective blockchains. All of them now have an updated blockchain telling which chickens have passed the test and which have not.?Hence, the local meat supplier acts as an orderer.
It acts as an anchor peer in the network.
领英推荐
Your answer is Correct.
QUESTION 4 Roles in Hyperledger Fabric
There is a requirement in the network that different chicken farms have different chicken requirements due to their customer demands. However, none of the poultry farms wants to disclose their chicken requirements to the other farms as that would give away their customer requests. Each poultry farm wants to make sure that the communication between them and the local meat supplier cannot be seen by the other farms. Which of the following characteristics of Hyperledger Fabric would help them achieve this?
Modularity
Separate channels
? Correct
Feedback:
Yes, channels provide a means to induce data confidentiality in the network by sharing information only between the entities present in the channel and not the entire network. Each poultry farm can create a separate channel and then use it so that the other farms do not have access to their data.
Membership Service Provider
Your answer is Correct.
Installation of Fabric using Virtual Box
To create a blockchain network with Hyperledger Fabric, please follow the steps mentioned in the attached document. The document is a step-wise installation guide to how to install Virtual box and also contains a link to a disk image which has Hyperledger Fabric binaries installed?with all its prerequisites on Ubuntu18.04 operating system. The installation guide is applicable for all the operating systems (Linux, MAC or Windows).
Note:
1. The disc?file shared?has?all the hyperledger binaries along with all its prerequisites pre-installed.?
2. The disc?file shared with you is around 6GB in size which will require you to have a stable internet connection.
3. If you are using Virtual Box for running Hyperledger,?please ensure that your system has a minimum of 8 GB of RAM.?
4. If you do not have the configurations required for a Virtual Box, then you will have to manually install Hyperledger Fabric binaries along with its prerequisites on your local system. The resources for this are provided in the "Additional Resource" of this module.?
Installation Guide
Ubuntu Installation
You will have to install Ubuntu to run Private Ethereum Blockchain. Please watch the following video for Ubuntu installation on your system?in case you have Windows OS installed. You need to have Windows 10 for this.?Please note that Mac users or users who already have?Ubuntu installed do not need to go through this.
?Installing Hyperledger Fabric on Ubuntu
To create a blockchain network with Hyperledger Fabric, you require to install all the prerequisites. In this section, you will learn the installation procedure for the Hyperledger Fabric on?Ubuntu Operating System. Follow the steps below to set up your machine for running a blockchain network/application using Hyperledger Fabric.
Installation of cURL
You will need to install the latest version of cURL if you don't already have it. Follow the steps below:
?Installation of Docker
The next important tool that you need to install is docker. To install Docker CE, you need the 64-bit version of one of these Ubuntu versions:
Follow the steps below to install docker on your machine:
?Step 1: Uninstall old versions of docker
The first step?would be to uninstall?previous versions of docker, if any.?You can do this by running the?command below on your Ubuntu terminal:
$ sudo apt-get remove docker docker-engine docker.io containerd runc
?
Step 2: Install the docker community edition
There are multiple ways of installing the docker community edition; it?depends on the need of the project. For our application, we will install docker by setting up a docker repository, as it is the most recommended approach. Follow the steps below to install the docker via a repository:
?Step 1:?Set the repository using the following steps:
?1.1. Update the?apt?package index:
$ sudo apt-get update
1.2. Install packages to allow?apt?to use a repository over HTTPS:
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
1.3. Add the docker’s official GPG key:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Verify that you now have the key with the fingerprint9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
$ sudo apt-key fingerprint 0EBFCD88
1.4. Use the following command to set up the?stable?repository.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
?
Step 2:?Install the Docker CE:
?
2.1. Update the?apt?package index:
$ sudo apt-get update
2.2. Install the?latest?version?of Docker CE and containers:?
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
2.3. Give permissions to your current user(non-root user) to use docker using the following command.
sudo usermod -a -G docker $USER
2.4 Restart your system using the following command in the terminal.
reboot
?
Once you have followed?the?steps above, your docker should be installed. Run the following command in Ubuntu terminal to check whether the docker is installed correctly:
docker version
?
You should get something like this as the output:
Installation of Docker Compose
After the successful installation of the docker, you will need to install docker-compose. Follow the?steps below to install docker-compose:
?
1. Run this command to download the current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
2. Apply executable permissions to the binary:
sudo chmod +x /usr/local/bin/docker-compose
3. Test the installation using the following command:
$ docker-compose --version
?
Installation of the Go Programming Language
Hyperledger uses the Go programming language. Follow the?steps below to install the Go language on your system.
Step 1:?Update the system using the following commands:
sudo apt-get update
sudo apt-get -y upgrade
?
Step 2:?Install Go using the following command:
cd /tmp
wget https://dl.google.com/go/go1.11.linux-amd64.tar.gz
?
Step 3:?Extract the downloaded archive and install it to the desired location on the system using the following command:
sudo tar -xvf go1.11.linux-amd64.tar.gz
sudo mv go /usr/local
Note: You can store it anywhere else as well?except the /usr/local. However, this is the standard suggested way.
Step 4:?Set the environment variables in the?.
p
r
o
f
i
≤
.?????≤
?file by appending the following?variables to?the end of the file:
export GOROOT=/usr/local/go
export GOPATH=$HOME/go
export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
Note: In case you are unable to find the .profile file, use the following command to find and open the file:
gedit ~/.profile
?
Step 5:?Update current shell session:
source ~/.profile
?
Step 6:?Verify the installation using the following command:
go version
?
You should get the following output:
####outputs$$$$$$?
Installation of NodeJS??
Step 1: Go to?https://nodejs.org/en/download/:
Step 2: Download the node setup corresponding to your machine (x64 of Linux Binaries).
Step 3: Once the installer is downloaded, click on it to install.
Step 4: Once the installation is successful, go to the command prompt and type the following command to check the version of the node installed:?
node -v
Note:?In case you get a message that node does not?exist, you need to reinstall the node in your system.
?
You can also install the node in Ubuntu using the following command:
sudo apt install nodejs
?
Installation of Python
You will also require Python to be installed. Follow the steps below to install Python:
Step 1:?Check whether you have Python already installed, using the following command:
python --version
?
Step 2:?In case it?is not installed, install?python?using the following command:
sudo apt-get install python
?
Step 5:?Check the version of Python installed using the following command:
python --version
?
Installation of Hyperledger Fabric Samples, Binaries and Docker Images
The next step is to get the Fabric samples, binaries and the required docker images that you would use for the development of the blockchain network.?Follow the steps below to do so:
Step 1:?Choose a location for the Fabric repository and create a new folder workspace inside that using the following commands:
mkdir workspace?
cd? workspace
?
?Step 2:?Run the following command to install hyperledger binaries along with all the required docker images.
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 1.4.3 1.4.3 0.4.18
This command will download the latest version of fabric-binaries.
?
Step 3:?To test the installation, run the sample network using the following commands:
cd first-network
./byfn.sh generate
?
To start running the network, use this command:
./byfn.sh up
or
sudo ./byfn.sh up
?
You should get the following output:
To stop running the network, use the following command:
./byfn.sh down?
or
sudo ./byfn.sh down
?
You should get the following?output:
If you are correctly able to start and stop the network, your setup is complete.
***********Installing Hyperledger Fabric on MAC
To create a blockchain network with Hyperledger Fabric, you are required to install all the prerequisites. In this section, you will learn the installation procedure for Hyperledger Fabric on MAC. Follow the steps below to set up your machine for running a blockchain network/application using Hyperledger Fabric.
Installing Curl
?
./configure --prefix=/usr/local/curl
make
sudo make install
?
Install Docker for Mac
?
Install GoLang for Mac
?
Install Node.js for?Mac
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
?
Install Node.js on?macOS
brew install node
?
Installing Python on macOS
brew install python
?
Install Hyperledger Fabric and its dependencies
curl -sSL https://bit.ly/2ysbOFE | bash -s -- 1.4.3 1.4.3 0.4.18
?Docker Basics
Please note that this is to give you a basic idea of the docker that you just installed. Those who are from non-development background and do not know anything about docker should definitely go through this. We also?strongly recommend that you watch the video shared at the end of this segment.?
?
Imagine a scenario wherein you write the code for an application. The application runs fine in your laptop but not on your mobile. This often happens in software development due to software incompatibility or difference in the versions of the same software. Every software application is not a single entity but an array or stack of various software components. A typical software application looks like this:
?
?
There are multiple components such as front-end application, database, server, etc. in a software application. So, how do you ensure that all these components work on every system that the software could be potentially run on??This is where docker comes into the picture.?
?
Docker is a tool designed to make it easier to create, deploy, and run applications independent of the systems that they run on.
?
Now, how does docker do that?
Docker implements containers to ensure that applications run on all systems regardless of any customised settings that machine might have that could differ from the machine used for writing and testing the code.
?
Let's take an example to understand docker containers better. Suppose you run a food export business, wherein you send different food items to different parts of the world. Now, different food items can be of varying sizes, shapes and nature; for example, exporting rice is different from exporting mangoes. The type of packaging to be used for rice may be different from the packaging supposed to be used for mangoes.??So, how do you ensure that they reach their destination intact irrespective of the size, shape, or other properties? A simple approach is to manufacture?containers. Making standard?containers for the export, in which everything can be packaged, ensures that the contents are intact and reach the destination safely. You then should not worry whether?these items will be shipped by air, water, or some other means. These standard containers work for every case.?Docker containers work in the same way.
?
Docker containers allow a developer to package an application with all of the parts that it needs, such as libraries and other dependencies, and ship it as one package. It enables any software application to run smoothly on any platform irrespective of any difference in the hardware or software. Hence, a developer builds an application, puts it in a docker container, and then ships it to different systems for testing or running.?
?
How does docker work?
Docker runs on a docker file, which lists down all the dependencies and requirements of the application. The docker file creates an image of the application containing all the dependencies. This image when run, creates a docker container. You can think of such a container?as the runtime instance of the docker images that store all the application details as well as its dependencies. The docker images are stored Docker Hub, which is a cloud-based repository,?and are called whenever required. Whenever the images are pulled from the repository, they create a container that ensures that the application runs smoothly in any environment.
?
?
Docker Containerisation
Let's understand the concept of containerisation in docker in more detail. Docker uses containerisation instead of virtualisation. Why? Let's find out.
?
Virtualisation is achieved by building an operating system on top of the host machine known as a virtual system to run applications. The virtual system?does not use the host machine?but?creates a guest operating system?and operates on that. This creates overhead on the host machine, as each virtual machine needs to be allocated memory. In contrast to virtualisation, containerisation has a container engine to run applications which uses the host operating system to run different applications. Containerisation uses the host resources as per requirement and, hence, is fast and lightweight.?
?
?
So, you understood what docker is and how it works. Docker is used extensively in building Hyperledger applications. Let's find out why.?
?
Docker in Hyperledger
Hyperledger has different network participants such as peers, orderers, anchor peers, endorser peers, committer peers, MSP, etc.?Hyperledger aims to provide a platform that can be utilised to create an open-source enterprise-scale blockchain framework with code bases. To do so, the Hyperledger Fabric community has created and published stable, tested docker images for different network entities. These docker images can be directly pulled, and containers can be created based on these images. So, does that mean that all Hyperledger blockchain networks that use these images will have the same participant properties? Not really.?Hyperledger sets certain variables for the images, and the containers are created based on those variables. This implies that you can customise your docker containers as per your requirement. Let's understand this with the help of an example.?
For developing applications on different platforms, you need different settings; for example, for developing an application on your local machine, all you would need is to enable the local host port, and you need not necessarily have a secure connection. However, for deploying the same application in a production environment, you would need a lot more than a local host such as certificates for encryption, protocols for a secure connection, etc. In case you use the same docker image, how do you distinguish???This is done by setting the environment variables.?They specify the environment for the docker image, and the containers are created as per these variables. You will learn how to build a container using these environment variables in detail when you develop the Hyperledger Fabric network in the next module.?Please go through the video below to deepen?your understanding of docker.?
BTech Computer Science Finalist|Freelance Writer|Thinker|Lover of Photography,Art,Nature;all things aesthetic.
8 个月Hie How are You... If I may ask a question, in developing a front end for my Hyper ledger fabric network, can I use a framework like laravel for say a web app, and how?