Hyperledger Fabric “Building Your First Network” Tutorial 2

View at Medium.com

In part 1 of this tutorial set, I was introducing the files in BYFN. In part 2, I am going to introduce the remaining files.

Recap the File List

Let’s recap our list of files:

  1. docker-compose-cli.yaml (Part 1)
  2. base/docker-compose-base.yaml (Part 2)
  3. base/peer-base.yaml (Part 2)
  4. channel-artifacts/ (Part 2)
  5. crypto-config.yaml (Part 2)
  6. configtx.yaml (Part 2)
  7. byfn.sh (Part 2)
  8. scripts/script.sh (Part 2)
  9. scripts/utils.sh (Part 2)

We will finish all the remaining files in this part.

2.2 base/docker-compose-base.yaml

In part 1, we have introduceddocker-compose-cli.yaml, which is to define our (virtual) Fabric network. We review a part of docker-compose-cli.yaml:

The base file is similar to docker-compose-cli.yaml.

Lines 3 to 28 define a template node called orderer.example.com, and docker-compose-cli.yaml extends it and add some extra configurations based on this template.

Line 5 specifies which image this node uses. In our case, the node uses an image from Hyperledger official — hyperledger/fabric-orderer. That $IMAGE_TAG is the image version, such as 1.4.

Other keywords and configurations are similar to docker-compose-cli.yaml. The point of having a base file is just to group common configurations to a base file to make them reusable.

Notice that in line 32, there is also an extends keyword, that is, again, to extend or reuse another base file,base/peer-base.yaml, which we will quickly take a look.

The syntax of this file is more or less the same as docker-compose-cli.yaml and base/peer-base.yaml. Again, why do we need these base files? Because of reusability, though it is not mandatory.


2.4 channel-artifacts/

Notice that this is an empty directory currently. This directory will be used to store some configuration transactions and a genesis block. More details later.


2.5 crypto-config.yaml

This is a file to define certifications and keys to be generated and used in the network.

In Hyperledger Fabric, we have a set of certifications and keys for users and nodes. For example, Peer needs to have a set of certificates and keys to perform endorsement, prove itself as a member in the Blockchain network, do signing, etc.

Line 4 OrdererOrgs is defining certificates and keys generation for organization related to Orderer nodes.

Line 22 Template > Count specifies how many nodes in Org1 (organization 1), while 29 Users > Count specifies how many users in Org1.


2.6 configtx.yaml

This is a file to define the configurations of the Blockchain network, though later they could be updated.

This is a long file, so I don’t embed into the blog post. You could refer to it here.

Let’s look at some parts of this file:

So, overall, there are three organizations, OrdererOrg, Org1, and Org2. You may refer to here for more details of configtx.yaml.


2.7 byfn.sh

This is a convenient script file by Hyperledger Fabric to start the network.

We use it this way to bring up the network (we will run together later):

Basically, it does the followings:

  1. Generate certificates and keys based on crypto-config.yaml
  2. Generate channel artifacts based on configtx.yaml, outputs will be stored in channel-artifacts/
  3. Bring up the (virtual) Fabric network based on docker-compose-cli.yaml
  4. Create Hyperledger Fabric channel, mychannel
  5. Join Peer nodes into the channel
  6. Install the Smart Contract (Chaincode) in Peer nodes
  7. Instantiate the Smart Contract (Chaincode) in one of the Peer nodes

2.8 scripts/script.sh & scripts/utils.sh

  • scripts/script.sh is a script used by byfn.sh for steps 4 to 7 above.
  • scripts/utils.sh is a script used by scripts/script.sh. It contains some common utility functions, such as installing Smart Contract (Chaincode)

Starting from the next part, we will continue some practical steps.

./byfn.sh up

Hyperledger Fabric “Building Your First Network” Tutorial

Why “BYFN” Again? Isn’t there an official one?

Right, in Hyperledger Fabric document, there is a “Building Your First Network” Tutorial, but I think it is not detailed enough. This tutorial set is more or less the same as the official one, but with some more explanations on files.

In case you are not so familar with Blockchain, I recommend that you could take a look here. That covers what Blockchain, Hyperledger Fabric and Smart Contract (Chaincode) are conceptually.

But you might also read my short summary at the moment:

Basically, Blockchain is a cryptographically linked list of data blocks. Hopefully, it is unmodifiable and decentralised, following a certain consensus. In Fabric, Orderer is the consensus, Peer maintains the Blockchain data.

Hyperledger Fabric is one of implementations of Blockchain, and it is intended to use in business context, where there is a group of organisations joining in the Blockchain network (each organisation then contributes some nodes in the network).

Smart Contract (Chaincode) is a program that is interacting with the Blockchain following certain business logics. In Fabric, Peer is the node to run it.


Hyperledger Fabric — The Transaction Flow

Here is the simplified transaction flow in Hyperledger Fabric (how a transaction is submitted and written into the Blockchain ledger, I assume that there is no error):

  1. The client sends a transaction request to Backend with Hyperledger Fabric SDK. (Client → SDK)
  2. Backend forms a transaction proposal and sends it to the Peer Node. (SDK → Peer)
  3. Peer node executes smart contract (chaincode) and sends the result to Backend. (Peer → SDK)
  4. Backend sends the transaction to Orderer node. (SDK → Orderer)
  5. Orderer node will collect some number of transactions (or trigger timeout) and orders for those transactions. Then, it packs those transactions into a Block and broadcasts to Peer nodes. (Orderer → Peer)
  6. Peer nodes validate the transaction, commit the transaction into the Blockchain ledger, and send transaction committed notification to Backend. (Peer → SDK)
  7. Backend sends success notification to the Client. (SDK → Client)

Overall, the flow: Client → SDK → Peer → SDK → Orderer → Peer → SDK → Client. The path is kind of long…


1. Install Prerequisites

We use Hyperledger Fabric v1.4 in this tutorial.

First of all, you could install prerequisites by following the official instructions:

  1. Install prerequisites
  2. Install samples, programs, and docker images from Hyperledger Fabric

2. Files Structure

In this part 1 tutorial, I am going to introduce files in BYFN. I plan to introduce all files in 2 parts. Then, we continue some practical steps.

Let’s switch to BYFN directory (*supposed that you finish the prerequisite part, you should have all needed files and directories):

cd fabric-samples/first-network

This is the file or directory list that we will study:

  1. docker-compose-cli.yaml (Part 1)
  2. base/docker-compose-base.yaml
  3. base/peer-base.yaml
  4. channel-artifacts/
  5. crypto-config.yaml
  6. configtx.yaml
  7. byfn.sh
  8. scripts/script.sh
  9. script/utils.sh

There are other files in fabric-samples/first-network/, but they are not directly related to BYFN, we will ignore them.


2.1 docker-compose-cli.yaml

In order to develop Blockchain application, we need to have a Blockchain network first, right? This is a file related to setting up the network.

This is a Docker compose file, which defines your (virtual) Fabric network, such as what nodes are in the network, their internal use domain names, etc.

Below is docker-compose-cli.yaml

Line 1 defines our Docker network name, such that our nodes could have a “place” to talk to each other. And this “place” is named byfn.

Line 4 defines a list of nodes in the network.

Line 5 defines a node in our network — Orderer, which helps decide how transactions and blocks are ordered in the Blockchain network.

You see in line 6, there is an extends, which is to re-use another base Docker compose file. I could smell the odor of “Inheritance” in programming.

Line 9 defines this node’s name in the network. Finally, line 10 defines which network this node belongs to.

And line 13–43 are similar, but they define another type of nodes in our network — Peer, which is to maintain the Blockchain ledger, validate the transaction, execute smart contract (chaincode) in the Blockchain network.

Line 45 defines the cli, that is, command line interface, to control (send commands to) network nodes. Line 47 indicates the image of this cli, just like a Windows 10 image for a Windows 10 virtual machine.

Line 48 tty is to make sure that the cli keeps running. Line 50 we are defining some environment variables used by some programs for the cli, such as GOPATH — where the go library is.

Line 62 specifies what the default location is when we access the cli. Line 63 specifies that when the cli starts, executes this Linux command automatically.

Line 64 defines mount points for the cli. That is, we map some directories in our local machine, probably your Linux, to some directories in the cli (which is a virtual machine, called container in Docker).

Line 70 specifies that the cli depends on some other containers, like: without them, without me.


That’s all for part 1. Hopefully, I could finish introducing files and directories within 2 parts. Then we can continue some practical steps.

2018 Year in Review with AMO

Sibelius Monument, Finland

Each one of us have some goals to complete, things to learn, and places to visit. With the year getting ended, it is time to lock back and see what all did we do for the last 365 days.

Well, 2018 have been a phenomenal year for me. Working with Addons aka AMO Team is where the major part of 2018 was spent. I have learned how to work remotely with a cross-cultural team. I have met some super awesome people like Caitlin , Rebecca and many more. I fixed ~50 Bugs in AMO. I got to meet a lot of great people, built connections and learned things. I am really happy to see few of my goals getting completed. I failed of the things miserably too.

Here is everything I did in the last year.

January

  • Got the idea for create-web-ext — a scaffolding tool for browser extensions.
  • Talked to my mentor Trishul about it.

February

  • Pitched the idea of create-web-ext to Mozilla Addons team and asked to submit it as GSoC Project.
  • Declined as GSoC Project. Decided to go ahead to develop it.
  • Made team with my Mentor Trishul and Tushar to start working on the project.
  • First International Flight to Finland for Methane Hack. Won 1500 Euros.

March

  • Spent many sleepless nights with Trishul, Tushar to work on create-web-ext.
  • Made the prototype of create-web-ext. Trishul pitched it in Addons Show & Tell Meeting. Got good feedback about it 🌟.

April

  • My first code contribution to AMO, a small patch for amo-frontend.
  • Was working on another patch, sadly never completed it, huh.
  • Applied for the Featured Addons Advisory Board. REJECTED 😎

May

  • Fixed 8 bugs in addons-server and amo-frontend
  • Was working on twitter card implementation for addons, sadly never completed it. Felt demotivated so many times due to this bug.

June

  • Send 9 patches to addons-server and amo-frontend. Learned about the css property: word-wrap: break-word;
  • Went to Finland again to OuluHack Hackathon. Won 1000 Euros 💵

July

  • Sent 3 patches in amo-frontend.
  • Made the dropdown on AMO better. Learned about test assertions.

August

  • Fixed 6 bugs in addons-server and amo-frontend.
  • Deployed Static themes on production on AMO Frontend.
  • Learned that RTL means Right to Left and LTR Left to Right.
  • Wrote code in SQL for the first time ever for AMO Server.
  • Gave talk about browser extensions in DevConf
  • Met dgplug members Farhaan, Sayan and many others in DevConf’18.

September

  • Fixed 10 bugs in addons-server and amo-frontend.
  • First patch to Webextensions API.
  • Went through many sleepless night to setup Gecko on my laptop for the patch. Took more than 15 days. 🤓
  • Decided to dual boot with Fedora OS for Gecko.
  • Sat next through to Wifi router for ~8 Hours to setup Gecko.

October

  • Sent 5 patches to addons-server and amo-frontend.
  • Added developer policies in footer of AMO.
  • PyCon India, my 2nd time , which I attended as a volunteer.
  • Met dgplug members again in PyCon.
  • Applied for Mozilla Addons Reviewer. Rejected. Lesson learned — need to work on my JS Skills.

November & December

  • College Exams, practical and lot of college useless stuff.
  • Managed to solve 5 bugs in the mean time only.
  • Joined Featured Addons Advisory Board for next 6 months.

My plans for 2019

  • Helping beginners For 2019, I am looking to help few handful new code contributor to AMO Project because I feel while contributing in code you get to learn a lot of things like how to communicate, code is just one part of it .
  • More patches. I am looking to submit patches to Addon Manager and Webextensions API in Firefox.
  • Eat, sleep, code, gym, repeat. Being a software developer you are most likely to keep sitting on your chair for the major part of your day. This year I want to take out more time for physical activities.

MozAMU: Mozilla Addons Development at AMU

I am writing after a long time, have pending a lot of blogs, too 😦 Initially, I would like to tell you how the planning of this event took place. In Pycon India 2017, where Sanyam meets Rahul and his friends during Dev Sprints where Sanyam was sharing his journey and experience of FOSS. Rahul was asked to host Sanyam for a session on Open Source Contribution.

About one week after all this, Sanyam asked me to join him for this event, and give talk on Add-on Development in AMU. I said yes, but I was tensed as how to pitch and stage fear too 😦 . Even though I joined Shashank and Sanyam for it. My college exams were going on too so I get one of the bestest reason to ditch exams 😉 for Mozilla :P. So let’s talk about event.

Why you should contribute to FOSS?

Sanyam started the event with the concept of FOSS. He then further  explained the basics knowledge one needs and etiquette to contribute to FOSS. Moreover, he also focused on the problems faced by individuals in building community. The session was very much interactive in which we have two way talk.

Mozilla Rep Sanyam Khurana

Shashank on Mozilla Web Extension

After a small break,Shashank started his session about Mozilla Web Extension. He started with explaining Extension SDK and cross browser extension.Then he discussed manifest.json and it’s importance. Then we made  a simple addon — borderify, which displays a border across Mozilla pages. I helped students while they were developing this and got to learn about some new bugs and error we can face during development of Web Extension. The two way talks helped students as well as us in keeping the session interesting and grabbed new experience, too.

How do I start contributing to Open Source?

After the addons session , Sanyam explained  about how can a new bie start contributing to Open Source. He talked about how to find bugs on different projects through Bugzilla & Bugsahoy of Mozilla. At last, he introduced himself and discussed about his contribution to various Open Source projects.

During the session, we meet lot of buddies who themselves created addon and got huge responses. Even the beginners stood stunning and leave no stone unturned to prove them. A lot of them modified their previously created borderify addon to do more stuff and advanced it.

So its already 5 PM , we move to a nearby restaurent for Lunch with organising team.

moz-addons-amu-10.jpg

Before leaving Aligarh, we clicked a photograph 🙂

moz-addons-amu-6.jpg

Thanks to organising team for inviting us . All arrangements were awesome .

Hope to meet soon 🙂

 

Web extensions, Womoz and Privacy @IGDTUW

Hey guys!

So this time we were in Indira Gandhi Delhi Technical University for Women(IGDTUW) for Web Extensions, Womoz and Privacy awareness sessions.

Trishul started with a Web Extensions session by explaining what web extensions are and why they are useful. He showed some web extensions built by the community. All the participants were then asked to build, run and debug their own extension called borderify (A demo extension for participants new to Web extensions).

igdtu-trishul

Faye taking a session on women in mozilla, talking about improving women’s visibility and involvement in Free/Open Source and Mozilla, and to increase the number of women contributors.

faye-igdtu

Following it, Sanyam and Shashikanth talked about open source in general and importance of privacy respectively.

Here is a mandatory group photo:

igdtu-group

Thanks a lot to Tanya Vedi for such excellent arrangements.

Thanks for reading.

Cheers!

 

Moz Hack Day

Hello Everyone ,

This post is about a hackathon “ Moz Hack Day ” which was held in USIT for every student who was interested in A-Frame on 16 December 2017.

Agenda:-

  • Talking About VR, WebVR & A-Frame.
  • Demo of basic A-Frame scenes.
  • Basic concepts of A-Frame.
  • Addons Concepts & implementation.
  • Hands-On Addons development.

The event was started by the introduction speech, following with introduction of A-Frame and speaker also gave a look-up to attendees upon previously created ideas with A-Frame.

I, first of all, introduced myself and interacted with students by sharing my experience.I then started the event by introducing some basic stuff about WebVR like Mozilla and it’s mission of better and safe web,  Mozilla’s initiative on making web more approachable, later also told them about MozActivate initiative and then, explained virtual reality, hardware compatible headsets and their technology, friction of  VR ecosystem.

I also explained what is WebVR, and how amazing it’s development process and results could be by showing them some cool a-scenes stuff I developed before then, Explained A-Frame documentation and gave it’s website source which is (aframe.io), I requested attendees to have a view over A-Frame documentation but later explained it.

then explained and showed them the basic example “ Hello World ” of A-Frame, which helped them to understand the basics of A-Frame development. Some Students raised there questions and it was good to see their doubts and curiosity to know better and understand deeply the concepts and those doubts were cleared.

I then explained about languages we need with A-Frame.I explained then about entity component system, about a-painter, then about registry, and at last about community.Then, we had our first refreshment break which included Tea, cold-drinks and wafers (according to attendees), then we started our development process.

After Tea break now, attendees started coding and creating their ideas and imaginations. Few of the students were good with A-Frame development and were creating really good stuff, which includes 360 image and 360 video scenes which were great. Now it was the time for Lunch break.

Now after lunch attendees again started coding what they were left before lunch and developers and students who were creating some good stuff were coding faster for completing their project, and it was good to see students collaborating which feels like a hackathon or an informative session.

As the session was just getting finished and there were just 30 minutes left, most of the developers had finished their development process and they were getting ready for submitting what they had created.

Now session concluded and I thanked all the attendees and developers who were coding and created great stuff.

Thanks for reading 😀 .

 

 

IRC and IRC Bouncer

What is IRC?

[Internet Relay Chat] – IRC is a protocol that provides a way to communicate in real time with people from all over the world,was invented before the World Wide Web.  It is very similar to text messaging, but designed around communicating with large groups of users instead of one on one. It consists of various separate networks (or “nets”) of IRC servers, machines that allow users to connect to IRC.

What is IRC Clients?

An IRC client is the vehicle that connects you to the global network of IRC servers. A variety of applications are available, like WeeChat , HexChat , XChat, Chatzilla etc. Personally i am using HexChat. Its awesome and easy to use. We will use HexChat here in this blog for EliteBNC setup. You can download it from here .

So if you have used IRC before, you must know that unlike other chat systems, IRC doesn’t keep when you’re offline. In order to be notified of relevant communications you can either look at the channel logs or setup an IRC bouncer.

What is a IRC bouncer or BNC?

An IRC bouncer is a middleman between you and an IRC network. It connects to a network like a normal client and instead of connecting directly to an IRC network we can connect to it.

How to setup IRC Bouncer?

Either you can install it on your own server or get a free BNC from some BNC provider.

A list of bouncer software.

  • JBouncer for IRC, written in Java. Supports logging.
  • psyBNC is said to be the oldest and most well-known IRC bouncer.It is easy to use, runs on Linux and became popular on FreeBSD, supports IPv4, IPv6, SSL, logging, multiple users and networks etc.
  • bnc is the original IRC bouncer.
  • ZNC  is easy to use, supports SSL connections, IPv6 and logging and offers a web interface. It is extendible by modules and scripts in C++, Python, Perl and Tcl.
  • Matrix and Riot  has a bouncer included, simple solution is to get an account on riot.im as they have client for Android too.
  • EliteBNC is the one which we will setup in this blog. Its awesome and easy to use . I am using it. Its well maintained. Thanks to Robby 🙂

How to get Bouncer from EliteBNC?

In HexChat you can setup the EliteBNC by following steps. 🙂

  1. Open HexChat and Join #elitebnc channel on Freenode. Command to join any channel on IRC , just type /join # .
  2. type !list it will show all available commands.
  3. There are three ways or commands to request BNC, !request !easyreq and  !emailreq
  4. To get BNC for Freenode, send !easyreq <email>

Now wait for some time to get approval of request. *DO NOT* make multiple request else Robby will kick you from EliteBNC 😛 . Once your request gets approved you will receive an email, go ahead and login to your account. The link would be like https://xxxx.elitebnc.org:1338

where xxxx is server name, which will be mentioned in the mail sent by EliteBNC eg. Sigma, Theta.

WhatsApp Image 2017-11-22 at 11.41.43 PM

Go to ‘Your settings’ and edit the Freenode network, enable the nickserv module so that Freenode will identify you.

You can edit other details in ‘Your settings’

You can use https://webchat.freenode.net to join the channel if you don’t have any IRC client.

How to connect HexChat to EliteBNC?

Add new network in HexChat and follow the screenshots.

To do that go to HexChat->Network List or press Ctrl + S .Add new network and Edit it.

1

We will be using port 1338, as it is port for SSL (secured) connection.

2

Finally you have setup an IRC bouncer. Enjoy 🙂

You can follow me at GitHub or Twitter.

If some one needs any help feel free to ask 🙂

Also published on Medium.

 

 

 

 

 

 

 

 

 

 

 

Moz WebD SIG 30 Sep

Dussehra, Saturday, Sept 30th, while many students were enjoying the festival week at their places, Moz-NIEC conducted the class, it commenced at 11 am, sharp, as the team came before the scheduled time and hence, were ready to teach the basics of JS.

I, frankly, thought that, conducting class on Dussehra wasn’t a good idea, as many students have already made plans with their family and would not prefer the class over their famliy. But to my surprise, around 55 students came, despite saying ‘no’ in the WhatsApp group.

Each team member told about their personal experience, working with JavaScript, and how it is useful in the modern day browser. Some students haven’t even studied C/C++, so we started with basics of every programming language, If, else. First, team wrote the code and showed it to the class, by using the projector, then, explained each and every word of the code, and, for some reason, someone is not able to understand the code, the team members, spread out in the class, go to their desks and, if the doubt is something important that the member, who was teaching, hadn’t emphasized a lot on. The doubt is then, cleared on the projector for everyone to see. This repo has been updated as promised.

Students, who were attending the class for the first time, were given links to read through, and each team member were assigned the new students to help them understand whatever was taught in the previous classes and were added in the group so that, they may discuss their doubts.

We gave them some tasks as homework. At the very end, We told them that Mozilla-NIEC is conducting a hackathon Moz-Hack on Oct 14 2017, and invites all developers and hackathon enthusiasts to participate in the hackathon. The next class is scheduled to be on next weekend. We intend to continue javascript in that session.

This time we also have some swags from Mozilla Community for all 🙂

swag

Thanks for reading. Cheers. Be Mozillian 🙂

Moz WebD SIG 24 Sep

Sunday, Sept 24th, a day after our first term exams got over, we thought that the turnout of the students would be less, but, to our surprise, almost 50 students came.
We had set the projectors, laptops,extensions cords, etc quicker than the last time, and also before time as moz niec team came early.
Moz-NIEC team taught different styling and, customising the look and feel of the website, and sending all the code into an external file i.e. CSS file. And gave a hint about the next class on JS.
Many new students came, so, the team members went to their desk and personally made them understand all that was being taught in the class. Presently, many students ask their doubts in the WhatsApp group, and from the team, whoever is free, solves their doubts. This repo has been updated as promised.