Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hyperledger Cookbook

You're reading from   Hyperledger Cookbook Over 40 recipes implementing the latest Hyperledger blockchain frameworks and tools

Arrow left icon
Product type Paperback
Published in Apr 2019
Publisher Packt
ISBN-13 9781789534887
Length 310 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Authors (3):
Arrow left icon
Chuangfeng Zhang Chuangfeng Zhang
Author Profile Icon Chuangfeng Zhang
Chuangfeng Zhang
Zhibin (Andrew) Zhang Zhibin (Andrew) Zhang
Author Profile Icon Zhibin (Andrew) Zhang
Zhibin (Andrew) Zhang
Xun (Brian) Wu Xun (Brian) Wu
Author Profile Icon Xun (Brian) Wu
Xun (Brian) Wu
Arrow right icon
View More author details
Toc

Table of Contents (12) Chapters Close

Preface 1. Working with Hyperledger Fabric FREE CHAPTER 2. Implementing Hyperledger Fabric 3. Modeling a Business Network Using Hyperledger Composer 4. Integrating Hyperledger Fabric with Explorer 5. Working with Hyperledger Sawtooth 6. Operating an Ethereum Smart Contract with Hyperledger Burrow 7. Working with Hyperledger Iroha 8. Exploring the CLI with Hyperledger Indy 9. Hyperledger Blockchain Scalability and Security 10. Hyperledger Blockchain Ecosystem 11. Other Books You May Enjoy

Adding an organization to a channel

This recipe serves as an extension to the BYFN recipe. We will demonstrate how to add a new organization Org3 to the application's channel (mychannel).

Getting ready...

To run this recipe, you need complete the Reviewing the Hyperledger Fabric architecture and components recipe in this chapter to install Hyperledger Fabric with samples and binaries on the AWS EC2 instance.

How to do it...

Since we need add the new organization, Org3, to BYFN, we will first bring up the BYFN network. Follow these steps:

  1. Bring up the first network using the following command:
        $ cd ~
$ cd fabric-samples/first-network
$ sudo ./byfn.sh generate
$ sudo ./byfn.sh up

  1. Execute the script to add Org3 into the mychannel channel:
    $ cd ~
$ cd fabric-samples/first-network
$ sudo ./eyfn.sh up

The following screenshot confirms org3 is added to mychannel successfully:

We can test this by running a query against Org3 peer0.

  1. To shut down and clean up the network, execute the following:
        $ cd fabric-samples/first-network
$ sudo ./eyfn.sh down
$ sudo ./byfn.sh down

How it works...

Like what we did in the Building the Fabric network recipe, the eyfn.sh script is a good resource to understand how things work.

We will also look into the command-line steps to see the internal building blocks to add an organization to a channel:

  1. Generate the org3 certificates:
        $ cryptogen generate --config=./org3-crypto.yaml
  1. Generate the org3 configuration materials:
        $ configtxgen -printOrg Org3MSP
  1. Generate and submit the transaction configuration for organization 3:
         $ peer channel fetch config config_block.pb -o 
orderer.example.com:7050 -c mychannel --tls --cafile
/opt/gopath/src/github.com/hyperledger/fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
$ configtxlator proto_encode --input config.json
--type common.Config
$ configtxlator proto_encode --input modified_config.json
--type common.Config
$ configtxlator compute_update --channel_id mychannel
--original original_config.pb --updated modified_config.pb
$ configtxlator proto_decode --input config_update.pb
--type common.ConfigUpdate

  1. Configure the transaction to add org3, which has been created:
        $ peer channel signconfigtx -f org3_update_in_envelope.pb
  1. Submit the transaction from a different peer (peer0.org2), who also signs it:
        $ peer channel update -f org3_update_in_envelope.pb -c mychannel -o 
orderer.example.com:7050 --tls --cafile
/opt/gopath/src/github.com/hyperledger/fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/
msp/tlscacerts/tlsca.example.com-cert.pem
  1. Get the org3 peer to join the network:
        $ peer channel fetch 0 mychannel.block -o orderer.example.com:7050 
-c mychannel --tls --cafile /opt/gopath/src/github.com/
hyperledger/fabric/peer/
crypto/ordererOrganizations/
example.com/orderers/orderer.example.com/

msp/tlscacerts/tlsca.example.com-cert.pem
$ peer channel join
-b mychannel.blockcd fabric-samples/first-network
  1. Install and update the chaincode:
         $ peer chaincode install -n mycc -v 2.0 -l golang -p    
github.com/chaincode/chaincode_example02/go/
$ peer chaincode upgrade -o orderer.example.com:7050
--tls true --cafile /opt/gopath/src/github.com/hyperledger/
fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/
msp/tlscacerts/tlsca.example.com-cert.pem
-C
mychannel -n mycc -v 2.0 -c
'{"Args":["init","a","90","b","210"]}'

-P 'AND ('\''Org1MSP.peer'\'','\''Org2MSP.peer'\'',
'\''Org3MSP.peer'\'')'
  1. Query peer0 org3:
        $ peer chaincode query -C mychannel -n mycc 
-c '{"Args":["query","a"]}'
  1. Invoke the transaction to move 10 from a to b again on a different peer:
        $ peer chaincode invoke -o orderer.example.com:7050 --tls true 
--cafile
/opt/gopath/src/github.com/hyperledger/fabric/peer/
crypto/ordererOrganizations/example.com/orderers/
orderer.example.com/
msp/tlscacerts/tlsca.example.com-cert.pem
-C
mychannel -n mycc --peerAddresses peer0.org1.example.com:7051
--tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/
fabric/peer/crypto/
peerOrganizations/org1.example.com/peers/
peer0.org1.example.com
/tls/ca.crt
--peerAddresses peer0.org2.example.com:7051

--tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/
fabric/peer/
crypto/peerOrganizations/org2.example.com/peers/
peer0.org2.example.com/tls/ca.crt
--peerAddresses peer0.org3.example.com:7051
--tlsRootCertFiles/opt/gopath/src/github.com/hyperledger/
fabric/
peer/crypto/peerOrganizations/org3.example.com/peers/
peer0.org3.example.com/tls/ca.crt
-c '{"Args":["invoke","a","b","10"]}'


This concludes how to add an organization to an existing network in a channel. We will look at how to use CouchDB to review transactions in the next recipe.

Following all the previous steps will create our first network, which consists of two organizations, two peers per organization, and single Solo ordering service. In this recipe, we showed you how to add a third organization to an application channel with its own peers to an already running first network, and then join it to the new channel.

When you view the log file, you will be able to see details in the following order:

  • Generating Org3 config material
  • Generating and submitting config tx to add Org3
  • Creating config transaction to add Org3 to the network
  • Installing jq
  • Config transaction to add Org3 to the network
  • Signing the config transaction
  • Submitting the transaction from a different peer (peer0.org2), which also signs it
  • Configure transaction to add Org3 to network submitted
  • Having Org3 peers join the network
  • Getting Org3 on to your first network
  • Fetching the channel config block from orderer
  • peer0.org3 joined the mychannel channel
  • peer1.org3 joined the mychannel channel
  • Installing chaincode 2.0 on peer0.org3
  • Upgrading chaincode to have Org3 peers on the network
  • Finishing adding Org3 to your first network
  • Chaincode is installed on peer0.org1
  • Chaincode is installed on peer0.org2
  • Chaincode is upgraded on peer0.org1 on the mychannel channel
  • Finished adding Org3 to your first network!

Updating modification policies or altering batch sizes or any other channel configuration can be updated using the same approach but for now we will focus solely on the integration of a new organization.

There's more...

The following block shows the org3-crypto.yaml section for Org3:

# --------------------------------------------------------------------------
# "PeerOrgs" - Definition of organizations managing peer nodes
# ---------------------------------------------------------------------------
PeerOrgs:
# ---------------------------------------------------------------------------
# Org3
# ---------------------------------------------------------------------------
- Name: Org3
Domain: org3.example.com
EnableNodeOUs: true
Template:
Count: 2
Users:
Count: 1

The following block shows the configtx.yaml section for Org3:

#################################################################################
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:
- &Org3
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: Org3MSP
# ID to load the MSP definition as
ID: Org3MSP
MSPDir: crypto-config/peerOrganizations/org3.example.com/msp
AnchorPeers:
# AnchorPeers defines the location of peers which can be used for cross org gossip #communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: peer0.org3.example.com
Port: 7051

In the next recipe, we will look at how smart contracts work with CouchDB.

You have been reading a chapter from
Hyperledger Cookbook
Published in: Apr 2019
Publisher: Packt
ISBN-13: 9781789534887
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image