Fullstack Wizard 3. Hyperledger Iroha.

avatar

fstkwzrd.png

Welcome to the third installment of this journey in which we try to get a grip on what means to be a full-stack developer, what technologies you should use, and how we should go about mixing all the elements of backend and frontend in order to create a full-stack application.

While our tutorial on Vue.js must wait a bit until it's ready, today we are going to explore another interesting topic that probably many of you will be excited about. We are going to talk a little bit about blockchain, how we can incorporate it in our applications and I'll present to you my solution and the technologies I use.

blockchain.png

1. Public vs Private blockchains

Most people are familiar with what's called a public blockchain which is usually used to provide some sort of financially valuable asset, like a coin. Those blockchains must be open and public in order to be used in an environment where trust has no place. You don't want to trust entities when using such digital assets because the whole point of using blockchain-based technology is to create a system that's fair and secure without the need of trusting central entities as we do with banks.

There are however situations where a public ledger might not be desirable. Let's suppose we run a company where we have multiple goods providers. In a business environment, it's unlikely we're going to treat everyone the same even though they give us the same kind of goods. We might take into account things like how long we've worked with a certain vendor or the quality of the shipped goods when coming up with deals.

A private blockchain allows us to create different such deals with the vendors without them knowing, as otherwise, we'd only create animosity.

iroha.png

2. What is Hyperledger Iroha

Iroha is a project that's mainly developed by a Japanese company called Soramitsu and is part of a family of blockchain projects(Hyperledger) developed under the wing of the Linux Foundation. Some of the big names involved with Hyperledger are Intel, IBM, Airbus, and Accenture. They are actively involved in the creation of open-source blockchain technologies that can be used both as public and private distributed ledgers.

Hyperledger Iroha is one of the easiest solutions from the Hyperledger family and has a great API that you can use to create permissions for different accounts on the blockchain.

Today I'm going to teach you how to bring up an Iroha node and start the network.

3. Needed tools

The tool you need is a very popular one among full-stack developers, it's called Docker and is used to create containers. Think of containers as very compact development environments that come with preinstalled tools. Those containers can communicate with each other, as well as with the outside world.

Below are a couple of tutorials on how to install Docker on popular Linux distributions:

  1. Ubuntu -- https://linuxconfig.org/how-to-install-docker-on-ubuntu-20-04-lts-focal-fossa
  2. Fedora -- https://fedoramagazine.org/docker-and-fedora-32/
  3. Manjaro -- https://linuxconfig.org/manjaro-linux-docker-installation + sudo pacman -S docker-compose

Windows is not included because you need the Pro version + HyperV enabled. Tutorials can be found on the internet for those of you have a Pro license.

docker.png

4. Docker Compose

docker-compose is a tool that allows us to write a single configuration file that specifies what containers to create, how they interact with each other, and how they interact with the outside. It's a powerful tool that allows for container orchestration all from a single .yaml file.

We are going to create a file, I named it docker-compose.yaml where we'll tell docker to create an Iroha container, a PostgreSQL container, which is a dependency of Iroha, we'll help the two communicate with each other and we'll expose some ports to the outside.

Here is the file:

version: "3.8"

# Defining the behaviour of the containers
services:

  # The database where all the info is stored
  postgresDB:
    image: library/postgres:latest
    restart: always
    ports:
      - "5432:5432"
    networks:
      - instrumentality-iroha-blockchain
    environment:
      - POSTGRES_USER=orchestrator
      - POSTGRES_PASSWORD=instrumentality-test-pass
      - POSTGRES_DB=instrumentality

  # The Iroha container
  irohaNode:
    image: hyperledger/iroha:latest
    restart: always
    networks:
      - instrumentality-iroha-blockchain
    ports:
      - "50051:50051"
    volumes:
      - "./iroha:/opt/iroha_data"
      - "blockstore:/tmp/block_store"
    environment:
      - IROHA_POSTGRES_HOST=postgresDB
      - POSTGRES_PORT=5432
      - POSTGRES_PASSWORD=instrumentality-test-pass
      - POSTGRES_USER=orchestrator
      - KEY=genesisNode
    depends_on:
      - postgresDB

networks:
  instrumentality-iroha-blockchain:

volumes:
  blockstore:

Let's break it down!

The version is important because different docker-compose formats support different features. 3.8 is the latest version at this time.

Next up are the services. Here we define containers and their behavior. Each service has a name, like 'irohaNode', and an image which is the environment docker will pull from its repositories. The two images we're using are library/postgres:latest and hyperledger/iroha:latest.

The networks section is used to define a bridge between those two containers. Containers in the same network can talk to one another. The ports section is the one that binds ports in the container network to ports in your machine so that you can access the containers from outside.

We have an environment section on both services where we define different values like the database account, password, etc. We also specify that the Iroha container is dependent on the PostgreSQL one so docker can know in which order to set up the containers.

5. Iroha data

Every Iroha node expects to find some data in /opt/iroha_data folder. More to the point, it expects to find a key pair for the node, a configuration file for the Docker container, and obviously a configuration of the genesis block.

5.1 Generate a key pair

Iroha is using it's own key generation algorithm which is based on Ed_25519 with SHA3. Getting a key pair is fairly easy though. You can either use python:

pip install iroha
python -c "from iroha import *; private_key = IrohaCrypto.private_key().decode('utf-8'); print('private:', private_key, 'public:', IrohaCrypto.derive_public_key(private_key).decode('utf-8'))"

or you can download a cli-utility which you can find here https://github.com/Warchant/ed25519-cli/releases. Download the Linux version that uses sha3 and just run:

./ed25519-cli keygen

Save the keys in two different files. I saved mine as genesisNode.pub and genesisNode.priv. The .pub and .priv extensions are important. As you've probably noticed, genesisNode is the name that I passed to the KEY environment variable of the irohaNode service.

5.2 Docker configuration

Yes, more Docker configs. Getting the container running is not enough for Iroha. We need to create a folder called iroha right where we made the docker-compose.yaml file. Inside the iroha folder create a file called config.docker and place the following content inside:

{
  "block_store_path": "/tmp/block_store",
  "torii_port": 50051,
  "internal_port": 10001,
  "database": {
    "host": "postgresDB",
    "port": 5432,
    "user": "orchestrator",
    "password": "instrumentality-test-pass",
    "working database": "instrumentality",
    "maintenance database": "postgres"
  },
  "max_proposal_size": 32,
  "proposal_delay": 5000,
  "vote_delay": 1000,
  "mst_enable": false
}

More about this Iroha config file can be found in the official docs. Most of those options are similar to the ones already present in the docker-compose.yaml file, the ones related to the database connection. The other options are related to the network behavior: maximum number of proposals, vote delay, multi-signature options, and there are many others which you can use.

5.3 Genesis block

Some of you familiar with blockchain technologies have probably heard about genesis blocks and what they do. They are the first transaction that happens on the network and sometimes they set the way the whole blockchain is going to work. Each node that wants to join the network must use the same genesis block as a base for setting up their node.

This is the case with Iroha as well. The configuration file of the genesis block is a JSON file with commands that will run at the initialization of the distributed ledger.

A great example provided by the Iroha team can be found here https://github.com/hyperledger/iroha/blob/master/example/genesis.block.

I'll now show you how I transformed that example for my own project:

{
  "block_v1": {
    "payload": {
      "transactions": [
        {
          "payload": {
            "reducedPayload": {
              "commands": [
                {
                  "addPeer": {
                    "peer": {
                      "address": "localhost:10001",
                      "peerKey": "964a46a822f4a37b8bd841a53b77296461a66a46fe57d6f319df14e30a5aa28d"
                    }
                  }
                },
                {
                  "createRole": {
                    "roleName": "Company",
                    "permissions": [
                      "can_transfer",
                      "can_get_domain_acc_detail",
                      "can_get_domain_accounts",
                      "can_get_my_acc_detail",
                      "can_get_my_account",
                      "can_get_domain_acc_ast",
                      "can_get_my_acc_ast",
                      "can_get_my_acc_ast_txs",
                      "can_get_peers"
                    ]
                  }
                },
                {
                  "createRole": {
                    "roleName": "SkillMaker",
                    "permissions": [
                      "can_create_asset",
                      "can_add_asset_qty",
                      "can_subtract_asset_qty"
                    ]
                  }
                },
                {
                  "createRole": {
                    "roleName": "Orchestrator",
                    "permissions": [
                      "can_create_account",
                      "can_create_domain",
                      "can_add_peer",
                      "can_remove_peer",
                      "can_append_role",
                      "can_create_role",
                      "can_detach_role"
                    ]
                  }
                },
                {
                  "createRole": {
                    "roleName": "Developer",
                    "permissions": [
                      "can_receive",
                      "can_get_my_acc_detail",
                      "can_get_my_account",
                      "can_get_my_acc_ast",
                      "can_get_my_acc_ast_txs",
                      "can_get_my_acc_txs",
                      "can_get_my_txs"
                    ]
                  }
                },
                {
                  "createDomain": {
                    "domainId": "Instrumentality",
                    "defaultRole": "Developer"
                  }
                },
                {
                  "createAccount": {
                    "accountName": "alexandru_balan",
                    "domainId": "Instrumentality",
                    "publicKey": "3fdaadfdfd373b670e9f08c62b082d96c0338a6d68f3927e772a26f2c9793d0b"
                  }
                },
                {
                  "appendRole": {
                    "accountId": "alexandru_balan@Instrumentality",
                    "roleName": "Orchestrator"
                  }
                },
                {
                  "appendRole": {
                    "accountId": "alexandru_balan@Instrumentality",
                    "roleName": "SkillMaker"
                  }
                },
                {
                  "appendRole": {
                    "accountId": "alexandru_balan@Instrumentality",
                    "roleName": "Company"
                  }
                }
              ],
              "quorum": 1
            }
          }
        }
      ],
      "txNumber": 1,
      "height": "1",
      "prevBlockHash": "0000000000000000000000000000000000000000000000000000000000000000"
    }
  }
}

With all those components in place you just need to run docker-compose -f docker-compose.yaml up to start the node and initialize the Iroha ledger.

id.png

6. My use case

As promised in the beginning I'll share with you what I'm doing with Iroha, and how it integrates with my project called Instrumentality.

Instrumentality will be a platform that aims to make recruitment of developers easier by creating a digital profile with statistics of their skills. The main idea is to create a platform where companies and developers register, the companies can create tasks for their employees specifying simple skills needed to solve the task(like js, c++, java, etc.) and when the task is done the developer automatically gets rewarded on the blockchain.

Unlike mainstream blockchains, the digital assets here will be the skills. If you solve a task that requires C++ for example your quantity of C++ increases meaning that you've gained some experience in that field.

I devised this project for three reasons:

  1. Companies have no idea how to recruit developers. Asking for 12 years of experience with Node.js when Node.js has been around for only 11 years. This way they'll start measuring experience in something more meaningful than years.
  2. Developers can lose jobs because they fail a test once. This way, high-quality developers are not hired because some automated test failed. A lot of companies don't go over the code analyzing its quality and instead rely on automated tests to evaluate the code if it runs or not. Bugs can happen and sometimes it takes more than the allocated 30 minutes to detect them.
  3. Everyone can lie about their numbers. Because the recruitment process is so bad, a lot of developers just inflate their numbers so 3 years of C++ experience suddenly become 5 and so on. That doesn't benefit the company or the developer in the long run.

Due to the rich permission mechanism of Iroha, I decided to create my solution with their tools. I was also impressed by how easy it was to use Iroha and I love their community which is more than willing to help you if you run into trouble.


The end...

What do you think of my idea? Have you ever had trouble with recruitment as a developer? Would you like a blockchain-based solution that can keep track in a fair way of how much you work with a certain technology?

If you have any ideas on how to improve mine, please give me feedback, I'm open to all ideas.

My current project is hosted on GitLab and GitHub and contains the whole Iroha configuration as well as a Python(Flask) API that wraps it. The API has just entered development so it's not much to see, but if you are interested in creating your own Iroha solution you can surely take a look.



0
0
0.000
4 comments
avatar

I ro ha ni ho he to 😆

0
0
0.000
avatar

I have no idea what this means 🙃. Btw, what does Soramitsu mean? Does it have some kind of meaning or it's just a name like any other?

0
0
0.000
avatar

I just had to say something lol. Soramitsu could be somebody’s name....

0
0
0.000
avatar

Congratulations @alexbalan! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You received more than 700 upvotes. Your next target is to reach 800 upvotes.

You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Support the HiveBuzz project. Vote for our proposal!
0
0
0.000