排查Hyperledger Fabric部署脚本中“Using organization 1”日志的输出来源
Hey there! Let's break down where that "Using organization X" message comes from when you run ./network.sh deployCC in the Hyperledger Fabric test network.
The Root Cause: The setGlobals Function in network.sh
The message is printed by a custom bash function called setGlobals inside the test-network/network.sh script. This function's job is to switch the terminal context to target a specific organization's peer node (like Org1 or Org2) by setting critical environment variables (such as CORE_PEER_ADDRESS, CORE_PEER_LOCALMSPID, and TLS/MSP paths).
Here's a simplified snippet of what that function looks like:
function setGlobals() { local org=$1 if [ $org -eq 1 ]; then # Set Org1-specific environment variables CORE_PEER_LOCALMSPID="Org1MSP" CORE_PEER_ADDRESS=localhost:7051 CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp echo "Using organization 1" # This line outputs the message you see elif [ $org -eq 2 ]; then # Set Org2-specific environment variables CORE_PEER_LOCALMSPID="Org2MSP" CORE_PEER_ADDRESS=localhost:9051 CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp echo "Using organization 2" # This line outputs the Org2 message fi }
When Does This Get Triggered?
In the deployCC workflow:
- Before installing the chaincode on
peer0.org1, the script callssetGlobals 1to configure the terminal to talk to Org1's peer. This triggers theecho "Using organization 1"line. - Next, when installing on
peer0.org2, the script callssetGlobals 2, which triggers theecho "Using organization 2"line.
This message is just a helpful indicator to let you know the script has switched its context to target a different organization's peer node for the upcoming chaincode operation.
内容的提问来源于stack exchange,提问作者hyper1003

