Good afternoon, dear habrovchane.
I am the developer of the IBM Science and Technology Center in Moscow. We are developing IBM products with other laboratories around the world. If time allows and there is a desire, then we are allowed to use part of the working time for projects that are not the main employment. This approach broadens the mind and supports creative mood. For me, this area is the development of blockchain solutions on Hyperledger Fabric. Moreover, such projects have become in demand in our market.
I hope that the article will not be about the blockchain, but about what we use to develop such solutions, but nevertheless it is still worth starting with the subject area.
The article does not claim to be complete and aims to create a working cloud environment for the development of blockchain projects at Hyperledger Composer. As a result of our practical research, we must obtain the following infrastructure:
There are a large number of blockchain platforms that can be compared to infinity. Most likely, there is no universal platform, there is one selected for the current task. For myself, I chose Hyperledger Fabric from blockchain platforms. On the one hand, because the platform is interesting to me from a technical point of view, on the other - IBM is actively participating in the Hyperledger consortium.
Hyperledger is a consortium of the Linux Foundation project. Hyperledger Fabric (HLF) is the implementation of blockchain technology for building various solutions. It is a blocked access-controlled platform. This means that the addition of new members is controlled. Participants are defined at the network design stage and may have different roles. The most understandable scenarios for such networks are supply chains, in which many independent companies participate. For example, you can explore the experience of Walmart, JD.com, IBM, and Tsinghua University in organizing the food supply chain .
From a technical point of view, each participant has a deployed network segment in his organization (or in the cloud infrastructure), but does not have access to the network segments deployed in other companies.
As can be seen from the diagram, each participant has:
In the application, users are authorized using their keys or a bunch of login and password and get access to the smart contract.
A smart contract is a programmed business logic and rules for interacting with data that are located in a distributed register (ledger). The registry contains a chain of transaction blocks that network members have committed. Each subsequent block stores the hash of the previous block, thereby ensuring the impossibility of changing part of the information. The process of agreeing on the correctness of a block and adding it to a distributed registry is called consensus. Different blockchain platforms have different consensus mechanisms: proof of work (PoW) , proof of stake (PoS) , byzantine fault tolerance (BFT), and others.
Starting from version 1.0, the HLF is specific to the presence of the Ordering Service, which is a cluster distributed among the participants and is responsible for the sequence of transactions in the emerging block. According to the configured parameters, it collects transactions in the network and forms a block. In case of failure of the Ordering Service, transactions in the network will cease to be registered, but the data itself will remain unchanged.
Now, having understood the basic concepts, we can proceed to practice.
All HLF components work in Docker containers and can be deployed using either Docker Compose or Kubernetes . In addition, the smart contracts themselves are also launched in Docker containers.
In order to deploy the HLF, you can use an already existing kubernetes network, minikube, or use one of the cloud Kubernetes as a Service.
In the IBM cloud infrastructure, you can deploy your kubernetes network for free.
To start using IBM Cloud, you must:
After registering with the IBM Cloud, you will have access to a graphical interface for managing your infrastructure. You will have access to hundreds of services and dozens of approaches to host your applications (Cloud Foundry, Kubernetes, OpenWhisk, virtual machines and dedicated servers). To use virtual machines and dedicated servers, you need to add a credit card, but a small piece of kubernetes can be obtained for free (with a coupon above).
To do this, in the upper left corner, click on the menu button and select Containers .
You will see the cluster control panel kubernetes, Docker registry and helm-charts .
Choosing the Cluster item on the left of the menu, you will see the interface for creating the kubernetes cluster and choosing the region in which the cluster will be deployed. You can create a free cluster in each region.
After clicking the Create cluster button, you should select the cluster type Free and create a name for it.
Creating a cluster will take some time, which you can spend on switching to the console (you will not have time to make coffee). After installing the IBM Cloud CLI (bx tool) you need to configure it to work with your account:
bx plugin install container-service -r Bluemix
bx login -a https://api.eu-gb.bluemix.net
bx cs region-set uk-south
bx cs cluster-config mycluster
export KUBECONFIG=/path/mycluster/kube-config-mil01-mycluster.yml
bx cs workers mycluster
Now you are ready to start using your kubernetes cluster for any purpose. The cluster is free, and there are some limitations in its functionality that will not prevent us from deploying our blockchain network:
For those who use kubernetes for the first time, it may be worth experimenting with deploying the first Deployment and services . Those who are ready to plunge into the world of development of blockchain projects can proceed to the next steps.
For those who work with Docker and Kubernetes not so long ago, let me remind you that in order to deploy any application in kubernetes we need 2 things:
The open source community of developers Hypeledger Fabric has done this work for us. Docker Images from HLF are already on DockerHub and automatically loaded into our cluster. And the whole yaml configuration is in the github repository . At the time of this writing, the repository contains the configuration for Hyperledger Fabric 1.0.3. We return to the console and execute the following commands:
git clone https://github.com/IBM-Blockchain/ibm-container-service.git cd ibm-container-service/cs-offerings/scripts/ ./create_all.sh --with-couchdb
The --with-couchdb
required so that instead of the default database, we will have CouchDB deployed. With it, we can use queries to retrieve data from the HLF Composer.
Composer is a tool for blockchain solutions developers. With it, you can increase the speed of development of blockchain solutions from months to weeks. There is an online sandbox Composer Playground , but all the business logic designed in it will run in your browser (blockchain emulation). In our case, Composer will be connected to a working Hyperledger Fabric network deployed in kubernetes.
To create a model in Hyperledger Composer, you must describe the participants (participant), assets (assets) and transactions (transaction). This approach allows you to translate the development of a blockchain project into the terms of your task, rather than the chosen platform or tool used. The transaction code (business logic) is written in JavaScript, and when you launch a new smart contract, a new Docker container is not created, and the transaction code is passed to the existing container for interpretation.
Another advantage of Hyperledger Composer is the automatic creation of REST interfaces based on the described assets and transactions, which allows you to immediately start writing the user interface (and thus get the MVP).
After launching the Hyperledger Composer in the IBM Cloud, you can access its web interface at <public_ip_of_k8s_cluste>: 31080. By default, all the necessary Docker containers are forwarded to public access using NodePort technology (we do not forget that we are deploying the environment for the developer).
Composer is connected to github-proetu , and you can deploy one of the existing projects or start developing your own.
As a result, we received a free cloud environment for developing projects based on Hyperledger Fabric.
As in any technically difficult project there are always a lot of details and additional things. This article is an introductory and is intended to help at the very beginning of the study. I hope that time and effort will allow me to write several articles with more detailed information both on kubernetes in the IBM Cloud, and about the development for Hyperledger Fabric.
Docker, Kubernetes, IBM Cloud
Ibm cloud
docker documentation
Kubernetes documentation
helm
telegram channel Enterprise containers
Blockchain, Hyperledger, IBM Blockchain Project
official documentation hyperledger fabric
Hyperledger Composer documentation
Hyperledger project sample
telegram channel about modern technologies and blockchain in particular
Source: https://habr.com/ru/post/351808/
All Articles