Hyperledger workshop for z Systems customers

IBM and Vicom Infinity hosted a small group customer workshop for Hyperledger/blockchain.

During this workshop we explained basics of Hyperledger and blockchain services, use cases, then hosted hands-on labs to experience deploying Hyperledger fabric onto LinuxONE community cloud and ran marbles app demo, followed by Hyperledger Fabric-composer lab that clients could code/deploy actual blockchain network and run sample transactions.

 

Attached is the materials from the workshop.

Fabric to Marbles Lab – Alex Kim_revised 0516

Get your own Mainframe Hyperledger fabric and demo app running in no time

If you are considering implementing a blockchain applications with Hyperledger Fabric, where would you start from and where do you want to deploy it on?

There are various platform choices to run a Hyperledger fabric and its applications. You can have it on your own laptop/server, or a virtual/real machine on a cloud. But when it comes to an ‘enterprise grade’ platform, nothing compares to IBM z Systems™ and IBM LinuxONE™ for its highest level of security, scalability, high availability and performance.

 

IBM announced Enterprise-ready Blockchain service for Hyperledger Fabric v1.0 on its Bluemix cloud during Interconnect 2017 conference in March 2017. There are many informative sessions that are recorded and you can watch most of them online. You can find a good summary from this blog. I personally liked Ross Mauri’s keynote about blockchain service on HSBN and many others. He goes into the very key of security benefits of IBM HSBN services and explores the technical aspects of it too.

 

Now, you may already know but there is a free blockchain development environment for Hyperledger Fabric v1.0 available through IBM Bluemix™. If you are an application developer, IBM Bluemix for Hyperledger services is a good place to start and deploy blockchain as you don’t have to worry about maintaining complex infrastructure of blockchain services. It also comes with pretty good tools and SDK that you can jump right into development with other Bluemix services. But if you are an explorer who wants to try your own blockchain infrastructure on IBM z Systems™ or IBM LinuxONE™ without getting into your company’s mainframe, there is a way – and I will walk you thru step-by-step instruction how to implement Hyperledger Fabric v0.6 and run sample demo app(marbles) in ten minutes or more(depends on your skills and wait time for getting community cloud ready) .

First, you want to apply for a free 120-day LinuxONE server available through IBMLinuxONE Community Cloud here. Once you have an access to the server(or one of your on premise Linux on z Systems), follow the steps below to get the fabric running in no time.  I’ve tested it with SLES12 SP1 and RHEL 7.2, but if you experience any issues, please add comment below and I will try to answer as much as I can.

 

Thanks, and enjoy!

Yongkook(Alex) Kim

 

[1] Install/setup Hyperledger Fabric

Following steps will guide you to install/run Hyperledger Fabric on your server. You can either run it with {a single peer + membership services} OR {four peers + membership services}

Reference: https://hub.docker.com/r/ibmblockchain/fabric-peer/

1.1 Switch user to root:

During the lab, all the commands will be entered as ‘root’ user id unless specified otherwise. If you are not currently switched to root yet, please enter: ‘sudo su –‘  at the shell command line.

1.2 Pre-requisites (details in above link for installation guide)

git version 2.12 or higher (source management tool, git information)

Docker version 1.12 or higher (git information)

Docker-compose version 1.11.2 or higher  (follow steps in below site for s390x)

https://github.com/linux-on-ibm-z/docs/wiki/Building-Docker-Compose

About Docker:

Docker is a container/virtualization technology and a key component of Hyperledger. It is not required to know during the lab but it is important to understand basics operations if you want to continue working with Hyperledger.

If you want to learn more about Docker, please refer to https://docs.docker.com/

There is a very nice all-inclusive playground website you can learn and try on Docker technology in here: http://training.play-with-docker.com/

1.3 Clone docker-compose files and bring up the fabric

Change directory to where you want to copy Hyperledger fabric configuration files. For this lab go to /data:

Please enter ‘ cd /data ’,

and then enter ‘ git clone https://github.com/IBM-Blockchain/fabric-images.git

Now you will see ‘git’ is cloning files from github site down to your local directory. Once you get prompt back, change directory to /data/fabric-images/docker-compose/

Enter ‘cd fabric-images/docker-compose

 

Once changed the directory,  enter ‘  . setenv.sh

-> make sure you enter dot(.) and space. This will check what HW platform the fabric will be running on. We are running on z Systems(s390x). Now bring up the fabric by entering following.

Enter ‘ docker-compose -f four-peer-ca.yaml up

Docker-compose is a command to invoke multiple docker images to bring up, and connect them together to make a ‘service’ or ‘services’. Note that you are bringing up a Hyperledger network with four peers and one membership services. You can also just have one peer + membership services if you specify ‘single-peer-ca.yaml’ instead of ‘four-peer-ca.yaml’.

Now you will see a lot of messages scrolling and most of time it is hard to see – not to worry about them for now. Once you see dockercompose_baseimage_1 exited with code 0(1st screenshot), and about a minute or so later you will see a message ‘Discovery knows about:’ for each peer.

Now Hyperledger fabric is ready to take an action! Let’s verify if the fabric is working with a quick command line interface commands.

1.4 Testing and verifying your local network using CLI interface

(reference: https://hub.docker.com/r/ibmblockchain/fabric-peer)

Now you have the Hyperledger fabric running, you want to test it out. There are many ways to test the network – command line interface(CLI), RestAPI tool like PostMAN, running a sample app and HFC SDK and we will show you each of cases.

Leave above shell window open, then open another shell window.

From command shell, enter ‘ docker ps ’, and now you will see there are four peers(vp0_1~vp3_1) and one membersrvc running as docker containers.

Enter ‘ docker exec -it dockercompose_vp0_1 bash

It will let you enter vp0 peer docker container with bash shell prompt.

Enter l following for a user “test_user0” to enroll who is already hardcoded in the membersrvc.yml file:

peer network login test_user0 -p MS9qrN8hFjlE

Deploying an example chaincode by entering following commands in sequence:

peer chaincode deploy -u test_user0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 -c ‘{“Args”: [“init”,”a”, “100”, “b”, “200”]}’

peer chaincode invoke -u test_user0 -n ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539 -c ‘{“Args”: [“invoke”, “a”, “b”, “10”]}’

peer chaincode query -u test_user0 -n ee5b24a1f17c356dd5f6e37307922e39ddba12e5d2e203ed93401d7d05eb0dd194fb9070549c5dc31eb63f4e654dbd5a1d86cbb30c48e3ab1812590cd0f78539 -c ‘{“Args”: [“query”, “a”]}’

 

Check out the Query Results after the last command. You can change the value for the second command and verify value changes using the 3rd command again.

[2] Running Marbles App

Assuming you completed the first lab successfully, we will deploy a sample app called ‘Marbles’. It’s a very intuitive GUI based blockchain app to create/trade marbles. Marbles represent assets, and whenever an asset gets created and traded, a new block will be created and shown in the console. You can ask your peers to connect to your website and simulate multi-user based blockchain network communication.

Following steps will guide you to install/run Marbles app demo for Hyperledger on your server. You can install Marbles app either locally or at the IBM Bluemix easily with instruction described in github below, but to minimize errors we will provide you an docker image already integrated with all components needed.

https://github.com/ibm-blockchain/marbles/tree/v2.0

FYI, our implementation of Marbles app is a bit different from the original IBM Marbles. We(Vicom Infinity) modified GUI so that we can simulate four-peer blockchain network. We actually had a good summer intern spent a few weeks to work on it – he had no prior blockchain experience. Since HSBN and IBM Bluemix came with four peer networks, I thought to having four users may help people playing roles on each peer.

Again, this is the lab based on Linux for IBM z Systems™ or IBM LinuxONE ™, so the binary file for docker image is for s390x architecture. It was tested with SLES12 SP1 as well as RHEL7.2 and Ubuntu Xenial Xerus. If you like to get a docker image for x86, please contact us.

2.1 Map port 3000 to open and listen

Since we are using Docker container for the app and it connects to a local fabric also on docker containers, we will make marbles app to use host network and interface external ip address/port. To enable it we will need to enter following iptables command. If you like to know more about why please refer to this web site ( http://www.dasblinkenlichten.com/docker-networking-101-host-mode/)

iptables -I INPUT  -p tcp -m tcp – -dport 3000 -j ACCEPT

(note for two dashes for – -dport)

2.2. Run marbles app using docker run

Now enter following command to download already installed marbles app from the docker hub, and invoke webservices.

From any directory enter:  docker run – -net=host likepunk/marbles (note for two dashes for – -net)

You will see following start-up logs. Wait until you see a message like —Websocket Up—

2.3. Play Marbles!

Now bring any web browser and type IP address of your server with port number 3000. If you don’t know your host server ip, then type following: ip addr show|grep eth0

Now connect to your marbles app using the ip shown above with port 3000 at the brower:

http://<your ip>:3000  and you will see Marbles web page shows as following:

 

Click on ‘CREATE’ on the center then create a marble asset of your choice

You can see a large green marble gets created, at the same time a new block is added to the blockchain. You can see it in action by clicking ‘VIEW TX BLOCKS’. It will show you details of the block(chaincode ID, payload etc).

Now try to switch ID to INFINITY(or ask other people to connect using another browser/PC or mobile device), and create marbles. You can move marbles by drag&drop.

Explorer further more with trading menu. To get more information about it please see below github site. There is also a newer version of Marbles app works with Hyperledger Fabric v1.0.

https://github.com/ibm-blockchain/marbles/tree/v2.0

 

 

Extra Information/Debugging

If you experience an error that complains about Chaincode not being deployed in the fabric logs or Marbles app showing it can’t find the Hyperledger fabric, try insert following into ‘four-peer-ca.yaml’ file under fabric-images/docker-compose :

    – CORE_CHAINCODE_DEPLOYTIMEOUT=500000

The error is due to the fabric takes too long to get the chaincode deployed unto its peer(timeout). As we are referencing the code from github, depends on the network condition it may exceed default time that was set to time out to wait. This never happened to me until there was an outage at AWS cloud a few months ago – I can’t prove anything but just strange it happened right after the outage(and git is one of the user of Amazon AWS =).

Once edited and saved, stop prior docker processes and remove all of the containers from cache by entering:

 

# docker stop $(docker ps -a -q)

# docker rm -f $(docker ps -a -q)

 

After you get the prompt back, type following commands to bring up the fabric as well as run marbles demo(you will need two shell screens).

 

# docker-compose -f four-peer-ca.yaml up

# docker run – -net=host likepunk/marbles

 

What is Hyperledger?

What is Hyperledger?

Yongkook(Alex) Kim

Systems Solutions Architect

Vicom Infinity

 

In a simple term, Hyperledger is an internet meta database protocol that utilizes blockchain technology to securely maintain digital ledgers – in a distributed fashion, sometimes called ‘decentralized ledger’.  There are tons of information out there if you search for it on the internet, but major source I like to visit and get updates are from Linux Foundation’s website(www.hyperledger.org) for overall Hyperledger projects and Readthedoc site(hyperledger-fabric.readthedocs.io) for fabric details.

Now, there is a very popular term you probably heard about already – blockchain. Blockchain is the core technology of Hyperledger and a key to make shared databases securely and publicly/privately over different systems.  When people talk about blockchain, most cases it refers to the blockchain that was introduced with Bitcoin – a crypto currency that created a lot of new possibilities in financial world since 2008. The blockchain mechanism that was used with Bitcoin is somewhat similar to a blockchain used in Hyperledger, but the core of application interface and validation of transaction are very different. For that reason, either of blockchains cannot understand each other nor mixed in a same network. If you like to understand blockchain used for Bitcoin, I found this YouTube video very helpful.

Blockchain contains data payload called ‘block’ that is encrypted with hash function, and each block can represent pointer to transnational data. When new transaction occurs, new block gets created and this new block inherits prior block’s information and gets encrypted – like daisy chain. This ‘chaining’ mechanism makes this ‘block-chain’ data not modifiable, as if prior data set gets modified all of the followed data sets will be invalidated.

Hyperledger’s blockchain was created to fill some gaps from what enterprises such as financial institutes or supply chain industry wanted to deploy but Bitcoin’s blockchain lacks of.  They wanted to have privately shared blockchains, with rules defined by them. They wanted to have permissions to join the network. For that reason, many engineers such as from IBM, DTCC , DAH and Linux Foundations gathered to create open source blockchain project called ‘Hyperledger’.

Blockchain in Hyperledger also uses hash function to generate new block of information from prior block, but the validation part of transaction is very different from Bitcoin’s. Also, they added many enterprise grade infrastructure requirements to the protocol so that the blockchain systems can be supported for high availability, scalable, and maximum strengthened security. The core networking part of the Hyperledger is called ‘fabric’. It is a building block of Hyperledger blockchain network that integrate different systems and makes many different implementations for various business applications. The name ‘fabric’ is perfect as it is a fundamental component to weave and make any type of clothing (or business application).

Since production ready Hyperledger v1.0 was announced in March 2017, it would be ideal to start testing with v1.0 fabric components, however there are so many good demos and articles that work with v0.6 fabric.  I have linked three Hyperledger demo apps based on v0.6 fabric running on our mainframe server. As I get to spend more time on v1.0 and try outs I plan to share more information about it in the future.

I also plan to demonstrate why it is important to understand having Hyperledger fabric run on the most secure hardware platform in the world, which is IBM z Systems(a.k.a mainframe).

Please feel free to share any comments and ideas how we can make the world a better and smarter place.

Thank you,

Alex

Latest update on Hyperledger

Hyperledger fabric v1.0 is officially announced and now available for service from IBM Bluemix!

For more details, visit https://www.hyperledger.org/news/2017/03/20/3-20-17-forbes-ibm-and-hyperledger-launch-enterprise-ready-blockchain

 

Fabric-composer will  help application developers and business to develop blockchain applications easier than ever.

For more details – https://fabric-composer.github.io

You can also try free all-in-one demo from  – http://composer-playground.mybluemix.net