Decentralized Ordering Service with Peer-Org-Owned Orderers

Overview

Quick Review of Ordering Service

Three Ordering Service Implementations in Hyperledger Fabric Release 1.4
Raft-based implementation supports single Orderer Organization and Peer-Org owned orderer setup

Setup up Overview

Demonstration Setup

Step 1: Prepare two Fabric Hosts in AWS

Bring up two fabric nodes

Step 2: Prepare a Docker Swarm environment

docker swarm init --advertise-addr <host-1 ip address>
docker swarm join-token manager
<output from join-token manager> --advertise-addr <host-2 ip address>
docker network create --attachable --driver overlay first-network
Overlay first-network appears in both hosts in a Docker Swarm environment

Step 3: Generate crypto material

cd fabric-samples
mkdir raft-2node
cd raft-2node
../bin/cryptogen generate --config=./crypto-config.yaml

Step 4: Generate channel artifacts

export FABRIC_CFG_PATH=$PWDmkdir channel-artifacts../bin/configtxgen -profile OrdererGenesis -outputBlock ./channel-artifacts/genesis.block -channelID byfn-sys-channel../bin/configtxgen -profile Channel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel../bin/configtxgen -profile Channel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP../bin/configtxgen -profile Channel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP

Step 5: Prepare Docker-Compose files for the two hosts

cp ../first-network/.env .

Step 6: Copy the whole directory to Host 2

cd fabric-samples
tar cf raft-2node.tar raft-2node/
scp -i <key> ubuntu@<host-1 ip>:/home/ubuntu/fabric-samples/raft-2node.tar .scp -i <key> raft-2node.tar ubuntu@<host 2 ip>:/home/ubuntu/fabric-samples/
cd fabric-samples
tar xf raft-2node.tar
cd raft-2node
docker-compose -f docker-compose-host1.yaml up -d
docker-compose -f docker-compose-host2.yaml up -d
The running containers in both hosts.

Step 8: Bring up Channels

docker exec cli peer channel create -o orderer0.org1.example.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/orderer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem
# for peer0.org1
docker exec cli peer channel join -b mychannel.block
# for peer1.org1
docker exec -e CORE_PEER_ADDRESS=peer1.org1.example.com:7051 -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt cli peer channel join -b mychannel.block
docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/mychannel.block .
scp -i <key> ubuntu@<host-1 ip>:/home/ubuntu/fabric-samples/raft-2node/mychannel.block .
scp -i <key> mychannel.block ubuntu@<host 2 ip>:/home/ubuntu/fabric-samples/raft-2node/
docker cp mychannel.block cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/
# for peer0.org2
docker exec cli peer channel join -b mychannel.block
# for peer1.org2
docker exec -e CORE_PEER_ADDRESS=peer1.org2.example.com:7051 -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt cli peer channel join -b mychannel.block

Step 9: Use Fabcar to Test the Ordering Service

docker exec cli peer chaincode install -n mycc -p github.com/chaincode/fabcar/go -v 0
docker exec cli peer chaincode install -n mycc -p github.com/chaincode/fabcar/go -v 0
docker exec cli peer chaincode instantiate -o orderer0.org1.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/orderer0.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem -C mychannel -n mycc -v 0 -c '{"Args": []}' -P "OR('Org1MSP.member','Org2MSP.member')"
docker exec cli peer chaincode invoke -o orderer1.org1.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/orderer1.org1.example.com/msp/tlscacerts/tlsca.org1.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["initLedger"]}'
docker exec cli peer chaincode query -C mychannel -n mycc -c '{"Args":["queryCar","CAR0"]}'
docker exec cli peer chaincode query -C mychannel -n mycc -c '{"Args":["queryCar","CAR0"]}'
docker exec cli peer chaincode invoke -o orderer0.org2.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/orderer0.org2.example.com/msp/tlscacerts/tlsca.org2.example.com-cert.pem -C mychannel -n mycc -c '{"Args":["changeCarOwner","CAR0","KC"]}'

Step 10: Clean up

docker-compose -f docker-compose-host1.yaml down -v
docker rm $(docker ps -aq)
docker rmi $(docker images dev-* -q)
docker-compose -f docker-compose-host2.yaml down -v
docker rm $(docker ps -aq)
docker rmi $(docker images dev-* -q)

Summary

Visit http://www.ledgertech.biz/kcarticles.html for all my works. Reach me on https://www.linkedin.com/in/ktam1/ or follow me @kctheservant in Twitter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store