Exploring Gossip when Starting a Fabric Network

Introduction

Overview

Gossip Bootstrap Configuration

Configuration of gossip bootstrap

Leader

Leader setting in peers

Anchor Peer

First Network and Script byfn.sh

Each peer knows other channel members, in its own organization and others

Demonstration

Step 0: Preparation

cd fabric-samples
cp -r first-network kc-first-network
Comment out the depends_on

Step 1: Generate crypto material and channel artifacts

cd kc-first-network
./byfn.sh generate

Step 2: Bring up Orderer and CLI

docker-compose -f docker-compose-cli.yaml up -d orderer.example.com cli

Step 3: Bring Up peer0.org1

docker-compose -f docker-compose-cli.yaml up -d peer0.org1.example.com
docker logs -f peer0.org1.example.com
peer0.org1.example.com: gossip instance started
peer0.org1.example.com: reaching gossip bootstrap

Step 4: Bring Up peer1.org1

docker-compose -f docker-compose-cli.yaml up -d peer1.org1.example.com
peer1.org1.example.com: gossip instance started
peer1.org1.example.com: it reaches gossip bootstrap
peer0.org1.example.com: it locates the gossip bootstrap

Step 5: Bring up Peers of Org2

docker-compose -f docker-compose-cli.yaml up -d peer0.org2.example.com peer1.org2.example.com

Step 6: Prepare Genesis Block for mychannel

docker exec cli peer channel create -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 -c mychannel -f ./channel-artifacts/channel.tx

Step 7: Join peer0.org1 to mychannel

docker exec cli peer channel join -b mychannel.block
peer0.org1.example.com: elected as leader after joining the channel

Step 8: Join peer1.org1 to mychannel

docker exec -e CORE_PEER_ADDRESS=peer1.org1.example.com:8051 -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
peer1.org1.example.com: it sees another leader after joining the channel

Step 9: Peers of Org1 Learn Channel Membership

peer0.org1.example.com: learn peers in its own organization as channel members
peer1.org1.example.com: learn peers in its own organization as channel members

Step 10: Joining Peers of Org2 to mychannel

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -e CORE_PEER_ADDRESS=peer0.org2.example.com:9051 -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt cli peer channel join -b mychannel.blockdocker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -e CORE_PEER_ADDRESS=peer1.org2.example.com:10051 -e CORE_PEER_LOCALMSPID="Org2MSP" -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
peer0.org2.example.com: elected as leader and learn peers in its own organization
peer1.org2.example.com: not a leader, and also learn peers in its own organization
Without anchor peer, peer has no knowledge of cross-organization channel members

Step 11: Update Anchor Peer for Org1

docker exec cli peer channel update -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 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx
tcpdump: connection between orderer to both peer0.org1 and peer0.org2, leaders of organizations
peer0.org1.example.com
peer1.org1.example.com
peer0.org2.example.com
peer1.org2.example.com
peer0.org1.example.com: learn all channel members
peer1.org1.example.com: learn all channel members
peer0.org2.example.com: learn all channel members
peer1.org2.example.com: learn all channel members
With just one anchor peer, peer now knows all channel members

Step 12: Update Anchor Peer for Org2

docker exec -e CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp -e CORE_PEER_ADDRESS=peer0.org2.example.com:9051 -e CORE_PEER_LOCALMSPID="Org2MSP" -e CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt cli peer channel update -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 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx

Variation

Removing Gossip Bootstrap from Peer Configuration

peer0.org1.example.com
peer1.org1.example.com
peer0.org2.example.com
peer1.org2.example.com
peer0.org1.example.com: know all channel members
peer1.org1.example.com: know all channel members
peer0.org2.example.com: know all channel members
peer1.org2.example.com: know all channel members
peer0.org1.example.com stops being leader
peer0.org2.example.com stops being leader

Having Anchor Peer Update before Joining another Organization

peer0.org2.example.com
peer0.org2.example.com: learn channel member in Org1 as anchor peer already exists in channel
peer0.org1.example.com: learn peer0.org2.example.com
peer1.org1.example.com: learn peer0.org2.example.com

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