粗略分析hyperledger-fabric之e2e_cli是如何开启网络

2023-12-27 18:38

本文主要是介绍粗略分析hyperledger-fabric之e2e_cli是如何开启网络,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、sudo ./network_setup.sh up

这条命令是如何为我们开启网络?通过几天的查看,我大致理清了他的顺序。在这里分享出来,如有不对,还望指出。
我们还是先看看这个shell文本里的内容:

#!/bin/bash
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#UP_DOWN="$1"
CH_NAME="$2"
CLI_TIMEOUT="$3"
IF_COUCHDB="$4": ${CLI_TIMEOUT:="10000"}COMPOSE_FILE=docker-compose-cli.yaml
COMPOSE_FILE_COUCH=docker-compose-couch.yaml
#COMPOSE_FILE=docker-compose-e2e.yamlfunction printHelp () {echo "Usage: ./network_setup <up|down> <\$channel-name> <\$cli_timeout> <couchdb>.\nThe arguments must be in order."
}function validateArgs () {if [ -z "${UP_DOWN}" ]; thenecho "Option up / down / restart not mentioned"printHelpexit 1fiif [ -z "${CH_NAME}" ]; thenecho "setting to default channel 'mychannel'"CH_NAME=mychannelfi
}function clearContainers () {CONTAINER_IDS=$(docker ps -aq)if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" = " " ]; thenecho "---- No containers available for deletion ----"elsedocker rm -f $CONTAINER_IDSfi
}function removeUnwantedImages() {DOCKER_IMAGE_IDS=$(docker images | grep "dev\|none\|test-vp\|peer[0-9]-" | awk '{print $3}')if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" = " " ]; thenecho "---- No images available for deletion ----"elsedocker rmi -f $DOCKER_IMAGE_IDSfi
}function networkUp () {if [ -f "./crypto-config" ]; thenecho "crypto-config directory already exists."else#Generate all the artifacts that includes org certs, orderer genesis block,# channel configuration transactionsource generateArtifacts.sh $CH_NAMEfiif [ "${IF_COUCHDB}" == "couchdb" ]; thenCHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH up -d 2>&1elseCHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1fiif [ $? -ne 0 ]; thenecho "ERROR !!!! Unable to pull the images "exit 1fidocker logs -f cli
}function networkDown () {docker-compose -f $COMPOSE_FILE down#Cleanup the chaincode containersclearContainers#Cleanup imagesremoveUnwantedImages# remove orderer block and other channel configuration transactions and certsrm -rf channel-artifacts/*.block channel-artifacts/*.tx crypto-config
}validateArgs#Create the network using docker compose
if [ "${UP_DOWN}" == "up" ]; thennetworkUp
elif [ "${UP_DOWN}" == "down" ]; then ## Clear the networknetworkDown 
elif [ "${UP_DOWN}" == "restart" ]; then ## Restart the networknetworkDownnetworkUp
elseprintHelpexit 1
fi

阅读这个shell需要一些基础,我也是刚看完shell的一些基本语法才勉强理解,下面我用一张图表示他的启动顺序。
这里写图片描述
那么这里面最关键的地方有那些呢?首先这条语句:

source generateArtifacts.sh $CH_NAME

无形之间将我们带到了另一个shell文本,那就是同目录下的generateArtifacts.sh,下面我们接着往下看。

#!/bin/bash +x
#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
##set -eCHANNEL_NAME=$1
: ${CHANNEL_NAME:="mychannel"}
echo $CHANNEL_NAMEexport FABRIC_ROOT=$PWD/../..
export FABRIC_CFG_PATH=$PWD
echoOS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')## Using docker-compose template replace private key file names with constants
function replacePrivateKey () {ARCH=`uname -s | grep Darwin`if [ "$ARCH" == "Darwin" ]; thenOPTS="-it"elseOPTS="-i"ficp docker-compose-e2e-template.yaml docker-compose-e2e.yamlCURRENT_DIR=$PWDcd crypto-config/peerOrganizations/org1.example.com/ca/PRIV_KEY=$(ls *_sk)cd $CURRENT_DIRsed $OPTS "s/CA1_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yamlcd crypto-config/peerOrganizations/org2.example.com/ca/PRIV_KEY=$(ls *_sk)cd $CURRENT_DIRsed $OPTS "s/CA2_PRIVATE_KEY/${PRIV_KEY}/g" docker-compose-e2e.yaml
}## Generates Org certs using cryptogen tool
function generateCerts (){CRYPTOGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/cryptogenif [ -f "$CRYPTOGEN" ]; thenecho "Using cryptogen -> $CRYPTOGEN"elseecho "Building cryptogen"make -C $FABRIC_ROOT releasefiechoecho "##########################################################"echo "##### Generate certificates using cryptogen tool #########"echo "##########################################################"$CRYPTOGEN generate --config=./crypto-config.yamlecho
}## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions
function generateChannelArtifacts() {CONFIGTXGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/configtxgenif [ -f "$CONFIGTXGEN" ]; thenecho "Using configtxgen -> $CONFIGTXGEN"elseecho "Building configtxgen"make -C $FABRIC_ROOT releasefiecho "##########################################################"echo "#########  Generating Orderer Genesis block ##############"echo "##########################################################"# Note: For some unknown reason (at least for now) the block file can't be# named orderer.genesis.block or the orderer will fail to launch!$CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.blockechoecho "#################################################################"echo "### Generating channel configuration transaction 'channel.tx' ###"echo "#################################################################"$CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAMEechoecho "#################################################################"echo "#######    Generating anchor peer update for Org1MSP   ##########"echo "#################################################################"$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSPechoecho "#################################################################"echo "#######    Generating anchor peer update for Org2MSP   ##########"echo "#################################################################"$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSPecho
}generateCerts
replacePrivateKey
generateChannelArtifacts

此文件主要是用来生成主要的配置文件如私钥和证书,有通道证书之类的。下面这张图是它执行的顺序。
这里写图片描述
其次语句:

CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1

其实就是:docker-compose -f docker-compose-cli.yaml up是不是感觉很熟悉呢?接下来我们接着看docker-compose-cli.yaml文件。

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#version: '2'services:orderer.example.com:extends:file:   base/docker-compose-base.yamlservice: orderer.example.comcontainer_name: orderer.example.compeer0.org1.example.com:container_name: peer0.org1.example.com#environment:#- CORE_LEDGER_STATE_STATEDATABASE=CouchDB#- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer0.org1.example.com:5984#- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin#- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=passwordextends:file:  base/docker-compose-base.yamlservice: peer0.org1.example.compeer1.org1.example.com:container_name: peer1.org1.example.com#environment:#- CORE_LEDGER_STATE_STATEDATABASE=CouchDB#- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer1.org1.example.com:5984#- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin#- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=passwordextends:file:  base/docker-compose-base.yamlservice: peer1.org1.example.compeer0.org2.example.com:container_name: peer0.org2.example.com#environment:#- CORE_LEDGER_STATE_STATEDATABASE=CouchDB#- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer0.org2.example.com:5984#- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin#- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=passwordextends:file:  base/docker-compose-base.yamlservice: peer0.org2.example.compeer1.org2.example.com:container_name: peer1.org2.example.com#environment:#- CORE_LEDGER_STATE_STATEDATABASE=CouchDB#- CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS=peer1.org2.example.com:5984#- CORE_LEDGER_STATE_COUCHDBCONFIG_USERNAME=admin#- CORE_LEDGER_STATE_COUCHDBCONFIG_PASSWORD=passwordextends:file:  base/docker-compose-base.yamlservice: peer1.org2.example.comcli:container_name: cliimage: hyperledger/fabric-toolstty: trueenvironment:- GOPATH=/opt/gopath
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_ID=cli
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
      - CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'volumes:- /var/run/:/host/var/run/
        - ../chaincode/go/:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
        - ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/
        - ./scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
        - ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
    depends_on:- orderer.example.com
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer0.org2.example.com
      - peer1.org2.example.com

这个文件的作用就是启动一系列的容器,当你看到下面内容的时候,就是此配置文件的作用:

Creating peer1.org2.example.com ... done
Creating cli ... done
Creating orderer.example.com ...
Creating peer0.org2.example.com ...
Creating peer1.org1.example.com ...
Creating peer0.org1.example.com ...
Creating cli ...

这个配置文件中还有一个地方需要我们关注,那就是:base/docker-compose-base.yaml,我们接着看看当前目录下的base文件夹里的docker-compose-base.yaml文件。

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#version: '2'services:orderer.example.com:container_name: orderer.example.comimage: hyperledger/fabric-ordererenvironment:- ORDERER_GENERAL_LOGLEVEL=debug
      - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
      - ORDERER_GENERAL_GENESISMETHOD=file
      - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/orderer/orderer.genesis.block
      - ORDERER_GENERAL_LOCALMSPID=OrdererMSP
      - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp
      # enabled TLS- ORDERER_GENERAL_TLS_ENABLED=true
      - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key
      - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt
      - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt]
    working_dir: /opt/gopath/src/github.com/hyperledger/fabriccommand: orderervolumes:- ../channel-artifacts/genesis.block:/var/hyperledger/orderer/orderer.genesis.block
    - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp:/var/hyperledger/orderer/msp
    - ../crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/:/var/hyperledger/orderer/tls
    ports:- 7050:7050
peer0.org1.example.com:container_name: peer0.org1.example.comextends:file: peer-base.yamlservice: peer-baseenvironment:- CORE_PEER_ID=peer0.org1.example.com
      - CORE_PEER_ADDRESS=peer0.org1.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer0.org1.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:- /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls:/etc/hyperledger/fabric/tls
    ports:- 7051:7051
      - 7052:7052
      - 7053:7053
peer1.org1.example.com:container_name: peer1.org1.example.comextends:file: peer-base.yamlservice: peer-baseenvironment:- CORE_PEER_ID=peer1.org1.example.com
      - CORE_PEER_ADDRESS=peer1.org1.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer1.org1.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org1.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org1.example.com:7051
      - CORE_PEER_LOCALMSPID=Org1MSP
    volumes:- /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls:/etc/hyperledger/fabric/tls
ports:- 8051:7051
      - 8052:7052
      - 8053:7053
peer0.org2.example.com:container_name: peer0.org2.example.comextends:file: peer-base.yamlservice: peer-baseenvironment:- CORE_PEER_ID=peer0.org2.example.com
      - CORE_PEER_ADDRESS=peer0.org2.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer0.org2.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:- /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls:/etc/hyperledger/fabric/tls
    ports:- 9051:7051
      - 9052:7052
      - 9053:7053
peer1.org2.example.com:container_name: peer1.org2.example.comextends:file: peer-base.yamlservice: peer-baseenvironment:- CORE_PEER_ID=peer1.org2.example.com
      - CORE_PEER_ADDRESS=peer1.org2.example.com:7051
      - CORE_PEER_CHAINCODELISTENADDRESS=peer1.org2.example.com:7052
      - CORE_PEER_GOSSIP_EXTERNALENDPOINT=peer1.org2.example.com:7051
      - CORE_PEER_GOSSIP_BOOTSTRAP=peer0.org2.example.com:7051
      - CORE_PEER_LOCALMSPID=Org2MSP
    volumes:- /var/run/:/host/var/run/
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/msp:/etc/hyperledger/fabric/msp
        - ../crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls:/etc/hyperledger/fabric/tls
    ports:- 10051:7051
      - 10052:7052
      - 10053:7053

这个配置文件就比较明显了,Ordererpeer的配置文件,细心的你肯定也发现了file: peer-base.yaml,那就看看同目录下的peer-base.yaml文件吧。

# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#version: '2'
services:peer-base:image: hyperledger/fabric-peerenvironment:- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same# bridge network as the peers# https://docs.docker.com/compose/networking/- CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2ecli_default
      #- CORE_LOGGING_LEVEL=ERROR- CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peercommand: peer node start

这我就不多解释了。
最后还有一个文件,在刚才的docker-compose-cli.yaml文件中有一句`command: /bin/bash -c './scripts/script.sh ${CHANNEL_NAME}; sleep $TIMEOUT'什么意思呢?就是./scripts/script.sh这个shell脚本生效,一起去看看吧。

#!/bin/bash
# Copyright London Stock Exchange Group All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
echo
echo " ____    _____      _      ____    _____           _____   ____    _____ "
echo "/ ___|  |_   _|    / \    |  _ \  |_   _|         | ____| |___ \  | ____|"
echo "\___ \    | |     / _ \   | |_) |   | |    _____  |  _|     __) | |  _|  "
echo " ___) |   | |    / ___ \  |  _ <    | |   |_____| | |___   / __/  | |___ "
echo "|____/    |_|   /_/   \_\ |_| \_\   |_|           |_____| |_____| |_____|"
echoCHANNEL_NAME="$1"
: ${CHANNEL_NAME:="mychannel"}
: ${TIMEOUT:="60"}
COUNTER=1
MAX_RETRY=5
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pemecho "Channel name : "$CHANNEL_NAMEverifyResult () {if [ $1 -ne 0 ] ; thenecho "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="echoexit 1fi
}setGlobals () {if [ $1 -eq 0 -o $1 -eq 1 ] ; thenCORE_PEER_LOCALMSPID="Org1MSP"CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crtCORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/mspif [ $1 -eq 0 ]; thenCORE_PEER_ADDRESS=peer0.org1.example.com:7051elseCORE_PEER_ADDRESS=peer1.org1.example.com:7051fielseCORE_PEER_LOCALMSPID="Org2MSP"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.crtCORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/mspif [ $1 -eq 2 ]; thenCORE_PEER_ADDRESS=peer0.org2.example.com:7051elseCORE_PEER_ADDRESS=peer1.org2.example.com:7051fifienv |grep CORE
}createChannel() {setGlobals 0if [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; thenpeer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx >&log.txtelsepeer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txtfires=$?cat log.txtverifyResult $res "Channel creation failed"echo "===================== Channel \"$CHANNEL_NAME\" is created successfully ===================== "echo
}updateAnchorPeers() {PEER=$1setGlobals $PEERif [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; thenpeer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx >&log.txtelsepeer channel update -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txtfires=$?cat log.txtverifyResult $res "Anchor peer update failed"echo "===================== Anchor peers for org \"$CORE_PEER_LOCALMSPID\" on \"$CHANNEL_NAME\" is updated successfully ===================== "sleep 5echo
}## Sometimes Join takes time hence RETRY atleast for 5 times
joinWithRetry () {peer channel join -b $CHANNEL_NAME.block  >&log.txtres=$?cat log.txtif [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; thenCOUNTER=` expr $COUNTER + 1`echo "PEER$1 failed to join the channel, Retry after 2 seconds"sleep 2joinWithRetry $1elseCOUNTER=1fiverifyResult $res "After $MAX_RETRY attempts, PEER$ch has failed to Join the Channel"
}joinChannel () {for ch in 0 1 2 3; dosetGlobals $chjoinWithRetry $checho "===================== PEER$ch joined on the channel \"$CHANNEL_NAME\" ===================== "sleep 2echodone
}installChaincode () {PEER=$1setGlobals $PEERpeer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 >&log.txtres=$?cat log.txtverifyResult $res "Chaincode installation on remote peer PEER$PEER has Failed"echo "===================== Chaincode is installed on remote peer PEER$PEER ===================== "echo
}instantiateChaincode () {PEER=$1setGlobals $PEER# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),# lets supply it directly as we know it using the "-o" optionif [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; thenpeer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR   ('Org1MSP.member','Org2MSP.member')" >&log.txtelsepeer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "OR    ('Org1MSP.member','Org2MSP.member')" >&log.txtfires=$?cat log.txtverifyResult $res "Chaincode instantiation on PEER$PEER on channel '$CHANNEL_NAME' failed"echo "===================== Chaincode Instantiation on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "echo
}chaincodeQuery () {PEER=$1echo "===================== Querying on PEER$PEER on channel '$CHANNEL_NAME'... ===================== "setGlobals $PEERlocal rc=1local starttime=$(date +%s)# continue to poll# we either get a successful response, or reach TIMEOUTwhile test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0dosleep 3echo "Attempting to Query PEER$PEER ...$(($(date +%s)-starttime)) secs"peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txttest $? -eq 0 && VALUE=$(cat log.txt | awk '/Query Result/ {print $NF}')test "$VALUE" = "$2" && let rc=0doneechocat log.txtif test $rc -eq 0 ; thenecho "===================== Query on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "elseecho "!!!!!!!!!!!!!!! Query result on PEER$PEER is INVALID !!!!!!!!!!!!!!!!"echo "================== ERROR !!! FAILED to execute End-2-End Scenario =================="echoexit 1fi
}chaincodeInvoke () {PEER=$1setGlobals $PEER# while 'peer chaincode' command can get the orderer endpoint from the peer (if join was successful),# lets supply it directly as we know it using the "-o" optionif [ -z "$CORE_PEER_TLS_ENABLED" -o "$CORE_PEER_TLS_ENABLED" = "false" ]; thenpeer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txtelsepeer chaincode invoke -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}' >&log.txtfires=$?cat log.txtverifyResult $res "Invoke execution on PEER$PEER failed "echo "===================== Invoke transaction on PEER$PEER on channel '$CHANNEL_NAME' is successful ===================== "echo
}## Create channel
echo "Creating channel..."
createChannel## Join all the peers to the channel
echo "Having all peers join the channel..."
joinChannel## Set the anchor peers for each org in the channel
echo "Updating anchor peers for org1..."
updateAnchorPeers 0
echo "Updating anchor peers for org2..."
updateAnchorPeers 2## Install chaincode on Peer0/Org1 and Peer2/Org2
echo "Installing chaincode on org1/peer0..."
installChaincode 0
echo "Install chaincode on org2/peer2..."
installChaincode 2#Instantiate chaincode on Peer2/Org2
echo "Instantiating chaincode on org2/peer2..."
instantiateChaincode 2#Query on chaincode on Peer0/Org1
echo "Querying chaincode on org1/peer0..."
chaincodeQuery 0 100#Invoke on chaincode on Peer0/Org1
echo "Sending invoke transaction on org1/peer0..."
chaincodeInvoke 0## Install chaincode on Peer3/Org2
echo "Installing chaincode on org2/peer3..."
installChaincode 3#Query on chaincode on Peer3/Org2, check if the result is 90
echo "Querying chaincode on org2/peer3..."
chaincodeQuery 3 90echo
echo "===================== All GOOD, End-2-End execution completed ===================== "
echoecho
echo " _____   _   _   ____            _____   ____    _____ "
echo "| ____| | \ | | |  _ \          | ____| |___ \  | ____|"
echo "|  _|   |  \| | | | | |  _____  |  _|     __) | |  _|  "
echo "| |___  | |\  | | |_| | |_____| | |___   / __/  | |___ "
echo "|_____| |_| \_| |____/          |_____| |_____| |_____|"
echoexit 0

我觉得终于到了你最希望看得的地方了,对于初学者而言的我们,看到good的时候就会心情很好,对吧?前面都为我们准备好了各节点,创世块,证书等内容!在这里这个文件为我们创建通道并且让各peer节点加入通道,安装、初始化、query准备好的chaincode!下图就是大致过程。
这里写图片描述
文件夹下还有许多的其他配置文件,其中如图。
这里写图片描述
下面用一张图总结一下:
这里写图片描述
大致过程基本如上,但感觉还差了一点什么!批评指正,批评指正!

这篇关于粗略分析hyperledger-fabric之e2e_cli是如何开启网络的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/544003

相关文章

hadoop开启回收站配置

开启回收站功能,可以将删除的文件在不超时的情况下,恢复原数据,起到防止误删除、备份等作用。 开启回收站功能参数说明 (1)默认值fs.trash.interval = 0,0表示禁用回收站;其他值表示设置文件的存活时间。 (2)默认值fs.trash.checkpoint.interval = 0,检查回收站的间隔时间。如果该值为0,则该值设置和fs.trash.interval的参数值相等。

性能分析之MySQL索引实战案例

文章目录 一、前言二、准备三、MySQL索引优化四、MySQL 索引知识回顾五、总结 一、前言 在上一讲性能工具之 JProfiler 简单登录案例分析实战中已经发现SQL没有建立索引问题,本文将一起从代码层去分析为什么没有建立索引? 开源ERP项目地址:https://gitee.com/jishenghua/JSH_ERP 二、准备 打开IDEA找到登录请求资源路径位置

Linux 网络编程 --- 应用层

一、自定义协议和序列化反序列化 代码: 序列化反序列化实现网络版本计算器 二、HTTP协议 1、谈两个简单的预备知识 https://www.baidu.com/ --- 域名 --- 域名解析 --- IP地址 http的端口号为80端口,https的端口号为443 url为统一资源定位符。CSDNhttps://mp.csdn.net/mp_blog/creation/editor

ASIO网络调试助手之一:简介

多年前,写过几篇《Boost.Asio C++网络编程》的学习文章,一直没机会实践。最近项目中用到了Asio,于是抽空写了个网络调试助手。 开发环境: Win10 Qt5.12.6 + Asio(standalone) + spdlog 支持协议: UDP + TCP Client + TCP Server 独立的Asio(http://www.think-async.com)只包含了头文件,不依

poj 3181 网络流,建图。

题意: 农夫约翰为他的牛准备了F种食物和D种饮料。 每头牛都有各自喜欢的食物和饮料,而每种食物和饮料都只能分配给一头牛。 问最多能有多少头牛可以同时得到喜欢的食物和饮料。 解析: 由于要同时得到喜欢的食物和饮料,所以网络流建图的时候要把牛拆点了。 如下建图: s -> 食物 -> 牛1 -> 牛2 -> 饮料 -> t 所以分配一下点: s  =  0, 牛1= 1~

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

MOLE 2.5 分析分子通道和孔隙

软件介绍 生物大分子通道和孔隙在生物学中发挥着重要作用,例如在分子识别和酶底物特异性方面。 我们介绍了一种名为 MOLE 2.5 的高级软件工具,该工具旨在分析分子通道和孔隙。 与其他可用软件工具的基准测试表明,MOLE 2.5 相比更快、更强大、功能更丰富。作为一项新功能,MOLE 2.5 可以估算已识别通道的物理化学性质。 软件下载 https://pan.quark.cn/s/57

poj 3068 有流量限制的最小费用网络流

题意: m条有向边连接了n个仓库,每条边都有一定费用。 将两种危险品从0运到n-1,除了起点和终点外,危险品不能放在一起,也不能走相同的路径。 求最小的费用是多少。 解析: 抽象出一个源点s一个汇点t,源点与0相连,费用为0,容量为2。 汇点与n - 1相连,费用为0,容量为2。 每条边之间也相连,费用为每条边的费用,容量为1。 建图完毕之后,求一条流量为2的最小费用流就行了

poj 2112 网络流+二分

题意: k台挤奶机,c头牛,每台挤奶机可以挤m头牛。 现在给出每只牛到挤奶机的距离矩阵,求最小化牛的最大路程。 解析: 最大值最小化,最小值最大化,用二分来做。 先求出两点之间的最短距离。 然后二分匹配牛到挤奶机的最大路程,匹配中的判断是在这个最大路程下,是否牛的数量达到c只。 如何求牛的数量呢,用网络流来做。 从源点到牛引一条容量为1的边,然后挤奶机到汇点引一条容量为m的边

衡石分析平台使用手册-单机安装及启动

单机安装及启动​ 本文讲述如何在单机环境下进行 HENGSHI SENSE 安装的操作过程。 在安装前请确认网络环境,如果是隔离环境,无法连接互联网时,请先按照 离线环境安装依赖的指导进行依赖包的安装,然后按照本文的指导继续操作。如果网络环境可以连接互联网,请直接按照本文的指导进行安装。 准备工作​ 请参考安装环境文档准备安装环境。 配置用户与安装目录。 在操作前请检查您是否有 sud