A Multi Organization Application in Hyperledger Fabric
In this article, I will demonstrate a Multi Organization application that I have developed using Hyperledger Fabric Go SDK. I will provide the complete step by step installation and building process in this article.
MultiOrgLedger is a web application written in Go to demonstrate the Multi Organization setup in a Hyperledger Fabric network. The blockchain network consists of four organizations joined with a single channel. The ledger data created in an organization can be accessible by the other participating organization in the network.
First, we need to follow a series of installations in the local PC environment to get the project running.
MultiOrgLedger requires Go and Docker to be running the system.
$ sudo apt install docker.io
$ sudo apt install docker-compose
$ sudo apt-get update
$ sudo apt-get install golang-go
or else you can directly download the golang distribution package from the below link
I am working on the Linux machine for this POC, so we will be installing Linux Go binary in the local environment.
Add these following variables into the profile
$ export GOPATH=$HOME/go
$ export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
$ source ~/.profile
$ go version
$ go version go1.11 linux/amd64
Setup the Host
In the case of a multi-organization network running in the local environment, it’s required to map all the organization’s peer domain with the localhost of the system. So, we need add the followings in /etc/hosts.
Setup the Blockchain network
MultiOrgLedger is a four organization based Hyperledger application and each organization supports two peer nodes. There are few prerequisites to follow to set up and install a blockchain network in the docker container.
Few binaries need to be download to create the network.
Command Reference Guide : https://hyperledger-fabric.readthedocs.io/en/release-1.4/command_ref.html
You can choose any of the following links based on your operating system and hardware architecture of your system.
Hyperledger Fabric requires few artifacts to be run as a configuration element for an organization in the network. So, We need to write certain config yaml and these will be used to generate the artifacts.
crypto-config.yaml: This configuration file will generate a few certificates and keys for the organization. The Cryptogen binary will take the config file as input and will create a crypto-config folder in the config directory, which will contain all the generated certificates and keys.
./bin/cryptogen generate --config=./crypto-config.yaml
configtx.yaml: This config file will contain configuration element details of a channel and will also create organization anchor artifacts for all four organizations.
orderer.genesis.block: This will initialize the network’s orderer.
./bin/configtxgen -profile FourOrgsOrdererGenesis -outputBlock ./artifacts/orderer.genesis.block
multiorgledger.channel.tx: This is the channel between peers to communicate in a network.
./bin/configtxgen -profile FourOrgsChannel -outputCreateChannelTx ./artifacts/multiorgledger.channel.tx -channelID multiorgledger
These are the anchor artifacts for each four organization. These artifacts will be used to communicate among organizations in the blockchain network.
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org1MSPanchors.tx -channelID multiorgledger -asOrg Org1MSP#Org2
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org2MSPanchors.tx -channelID multiorgledger -asOrg Org2MSP#Org3
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org3MSPanchors.tx -channelID multiorgledger -asOrg Org3MSP#Org4
./bin/configtxgen -profile FourOrgsChannel -outputAnchorPeersUpdate ./artifacts/Org4MSPanchors.tx -channelID multiorgledger -asOrg Org4MSP
Now, we need to download certain images from the Docker cloud such as hyperledger/fabric-ca, hyperledger/fabric-peer, hyperledger/fabric-orderer, hyperledger/fabric-couchdb. All these images will store in the local docker container. So, we need to write a docker-compose.yaml file, where all these required images will be defined.
docker-compose up -d // the docker-compose.yaml has to be located at same command location
Update the Certificate Keys
You can find newly generated certificate keys at crypto-config/ORG_DOMAIN/ca/_sk file. Add these key names in the following variables at each docker-compose-org[1,2,3,4].yaml.
[FABRIC_CA_SERVER_CA_KEYFILE , FABRIC_CA_SERVER_TLS_KEYFILE] and fabric-ca-server command parameter.
Deploy the network
There is a sequence of steps to follow to completely set up the multi-organization in the blockchain network.
Initialize SDKs for each Organization
Every organization will have its Org SDK and will be initialized with config.yaml. The initialization process will create CA clients, MSP clients, Resource Management clients, signing identity.
The channel will create by Orderer and will use all the signing identities of the organization admins.
Create Anchor Peers
Each organization admins will create anchor peers for their organization using the anchor peer artifacts.
- After creating the channel, each anchor peer will join the channel and remember Orderer will only create the channel and he can’t join the channel.
- s.Resmgmt — is the resource management client created during Org SDK initialization. So, each organization resource management client will execute the join channel action individually.
- Installing chaincode for the organization will use the same chaincode id & version unless it requires to be different for an organization on specific circumstances.
- InstallCCRequest will be the same for all organizations but the request will be used by the individual resource management client of the organizations. So, the chaincode will be installed under all the organization independently.
- Chaincode instantiation under a multi org environment will be performed only once. It will be initiated by one organization’s peers and will specify certain endorsement policy considering all the organization network configurations.
- In this POC, the chaincode policy as mentioned below
the policy specifies that any member of any one of the organizations needs to sign a transaction before committing a block to the blockchain so another member of the organization will get a copy of the ledger data.
Affiliate an Organization
- In Hyperledger Fabric by default “org1 & org2” are affiliated as Certificate Authority organizations.
- But in the case of other organizations like “org3 & org4", they need to be affiliated using following CA Client API.
So, these are the essential steps for deploying multi-organization in the Hyperledger Fabric Blockchain network.
- Hyperledger Fabric-Go-SDK is still in development. If you do dep ensure for each Gopkg.toml in MultiOrgLedger and Chaincode, it will download the govendor folder for each module but it will have some compilation issues while building the project. So I have corrected the errors for both MultiOrgLedger and Chaincode folder.
- Please download the vendor folder and add it in your project directory.
Add vendor folders at the location where Gopkg.toml file is located
Run the application
- Compile the application and generate the multiorgledger binary for the application.
- Run the multiorgledger binary in the command line, you can see the server is running at PORT 6000.
- Now, open your browser and type http://localhost:6000
So, this is the complete step by step tutorial to run the multi-organization application in a local environment using Hyperledger Fabric Go SDK.
I hope you find this article useful :)