Skip to content

Latest commit

 

History

History

docker-netop1

Sample Fabric network

This sample network can be used to verify the crypto data generated by using CA client scripts.

Start CA server and generate crypto for sample org, netop1

cd ../ca
./start-ca.sh netop1 docker
./bootstrap.sh netop1 docker
./stop-ca.sh netop1 docker

These steps starts CA server for the default sample org, netop1, and use fabric-ca-client to generate crypto data. The result is stored in the folder netop1.com.

Generate Orderer genesis block and app channel tx

To run the following tests, you need to install Hyperledger Fabric binaries, i.e.,

curl -sSL http://bit.ly/2ysbOFE | bash -s -- 1.4.3

Refer Hyperledger docs for more details about how to use the Hyperledger Fabric tools.

For development, generate orderer genesis block for solo consensus:

cd ../docker-netop1
configtxgen -profile OneOrgOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block

Or, for production, generate orderer genesis block for etcdraft consensus:

cd ../docker-netop1
configtxgen -profile EtcdRaftOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block

Generate config tx for creating app channel:

cd ../docker-netop1
configtxgen -profile OneOrgChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
configtxgen -profile OneOrgChannel -outputAnchorPeersUpdate ./channel-artifacts/anchors.tx -channelID mychannel -asOrg Org1

The result is stored in the folder channel-artifacts. Optionally, you may convert the generated config tx files to human-readable JSON format as follows:

configtxlator proto_decode --input ./channel-artifacts/genesis.block --type common.Block --output ./channel-artifacts/genesis.json
configtxlator proto_decode --input ./channel-artifacts/channel.tx --type common.Envelope --output ./channel-artifacts/channel.json

Start sample Fabric network

For development, you may start Fabric network using solo consensus:

docker-compose -f docker-compose.yaml up -d

However, if you generated the genesis block for etcdraft consensus in the previous step, you can start Fabric network using etcdraft consensus and couchdb:

docker-compose -f docker-compose.yaml -f docker-compose-etcdraft.yaml -f docker-compose-couch.yaml up -d

Create channel and test chaincode

Start cli docker container shell:

docker exec -it cli bash

In the cli container, verify that the following environment variables are already configured.

CORE_PEER_LOCALMSPID="Org1"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/peer-0/tls/ca.crt
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/users/[email protected]/msp
CORE_PEER_ADDRESS=peer-0.netop1.com:7051

Test the fabric network using the cli container as follows.

# create channel and join the node peer-0 to the channel, and then update the anchor peer
peer channel create -o orderer-0.netop1.com:7050 -c mychannel -f ./channel-artifacts/channel.tx --tls --cafile $ORDERER_CA
peer channel join -b mychannel.block
peer channel update -o orderer-0.netop1.com:7050 -c mychannel -f ./channel-artifacts/anchors.tx --tls --cafile $ORDERER_CA

# optionally, fetch the resulting channel config block and convert it to human-readable JSON format
peer channel fetch config ./channel-artifacts/mychannel.pb -o orderer-0.netop1.com:7050 -c mychannel --tls --cafile $ORDERER_CA
configtxlator proto_decode --input ./channel-artifacts/mychannel.pb --type common.Block --output ./channel-artifacts/mychannel.json

# install and instantiate a sample chaincode
peer chaincode install -n mycc -v 1.0 -l golang -p ${CC_SRC_PATH}
peer chaincode instantiate -o orderer-0.netop1.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -l golang -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1.peer')"

# invoke and query the chaincode, query returns 100
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer-0.netop1.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
# query returns 90
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

# exit cli container when test is done
exit

Stop the sample network and cleanup

docker-compose -f docker-compose.yaml -f docker-compose-etcdraft.yaml -f docker-compose-couch.yaml down --volumes --remove-orphans
docker rm $(docker ps -a | grep dev-peer | awk '{print $1}')
docker rmi $(docker images | grep dev-peer | awk '{print $3}')