Creating And Adding Hyperledger Peers to Channels

Follow

Create and join a peer to a channel

Prerequisites

In this example, we will assume the new channel will be named MyChannel

Generate a channel genesis block

Consult the README for system requirements

Gather public keys into a MSP for genesis block creation and create configtx.yaml

This adds the PeerAdmin to the new channel as an ADMIN by putting its public key into msp/admincerts

In these examples, we assume the PeerOrg admin has been enrolled and its MSP is in PeerAdmin/msp

cp config.env-example config.env

Edit config.env. Set NETWORK_ID to your <NetworkID>, and ANCHOR_PEERS to a quote enclosed, space separated list of at least two <NodeID>s.

In these examples, <NodeID> is the ID of a peer node and <NetworkID> is the ID of the network as shown in the Network connect page. Omit the <>'s, e.g. NETWORK_ID="abcdefgh"ANCHOR_PEERS should have at leleast two nodes!

Create configtx.yaml

make configtx.yaml 

Gather public keys into an MSP for genesis block creation

This adds the PeerAdmin to the new channel as an ADMIN by putting its public key into msp/admincerts

mkdir -p mychannel/msp/cacerts/ mychannel/msp/admincerts/
cp -f PeerAdmin/msp/cacerts/*.pem mychannel/msp/cacerts/
cp -f PeerAdmin/msp/signcerts/cert.pem mychannel/msp/admincerts/

Generate genesis block and anchor peer update

mkdir -p artifacts/
configtxgen -configPath $PWD -profile SingleMSPChannel -outputCreateChannelTx artifacts/mychannel.txn -channelID mychannel
configtxgen -configPath $PWD -profile SingleMSPChannel -outputAnchorPeersUpdate artifacts/mychannel-anchor-peers.txn -channelID mychannel -asOrg PeerOrg

Make the PeerAdmin an admin of the local peer instances we will be running

mkdir -p PeerAdmin/msp/admincerts
cp -f PeerAdmin/msp/signcerts/* PeerAdmin/msp/admincerts

Create/update/join channel

Note that fetch/join has to be done for every <NodeID> peer you wish to join to a channel, as specified in the config.env ANCHOR_PEERS setting for the configtx.yaml created above. 

. config.env

export FABRIC_CFG_PATH=$PWD
export CORE_PEER_MSPCONFIGPATH="PeerAdmin/msp"
export CORE_PEER_LOCALMSPID="${NETWORK_ID}-peerOrg"
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_TLS_ROOTCERT_FILE="${PWD}/tlsca-${NETWORK_ID}.pem"

export CORE_PEER_ADDRESS="peer-${ANCHOR_PEERS[0]}.${NETWORK_ID}.bdnodes.net:7051"
peer channel create -c mychannel -f ./artifacts/mychannel.txn --tls -o orderer.${NETWORK_ID}.bdnodes.net:7050 --cafile=${CORE_PEER_TLS_ROOTCERT_FILE}
peer channel update -c mychannel -f ./artifacts/mychannel-anchor-peers.txn --tls -o orderer.${NETWORK_ID}.bdnodes.net:7050 --cafile=${CORE_PEER_TLS_ROOTCERT_FILE}

for NODE_ID in $ANCHOR_PEERS; do
    export CORE_PEER_ADDRESS="peer-${NODE_ID}.${NETWORK_ID}.bdnodes.net:7051"
    peer channel join -b ./mychannel.block
done

 

 

0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.