mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-26 11:35:10 +00:00
Stop using deprecated outputAnchorPeersUpdate in test-network
FAB-18381 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
This commit is contained in:
parent
df752bfc7b
commit
da540b9a39
14 changed files with 289 additions and 290 deletions
|
|
@ -52,7 +52,6 @@ function printHelp () {
|
|||
|
||||
# Create Organziation crypto material using cryptogen or CAs
|
||||
function generateOrg3() {
|
||||
|
||||
# Create crypto material using cryptogen
|
||||
if [ "$CRYPTO" == "cryptogen" ]; then
|
||||
which cryptogen
|
||||
|
|
@ -95,7 +94,7 @@ function generateOrg3() {
|
|||
|
||||
echo
|
||||
echo "##########################################################"
|
||||
echo "##### Generate certificates using Fabric CA's ############"
|
||||
echo "##### Generate certificates using Fabric CA ############"
|
||||
echo "##########################################################"
|
||||
|
||||
IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA_ORG3 up -d 2>&1
|
||||
|
|
@ -154,7 +153,6 @@ function Org3Up () {
|
|||
|
||||
# Generate the needed certificates, the genesis block and start the network.
|
||||
function addOrg3 () {
|
||||
|
||||
# If the test network is not up, abort
|
||||
if [ ! -d ../organizations/ordererOrganizations ]; then
|
||||
echo
|
||||
|
|
@ -169,11 +167,8 @@ function addOrg3 () {
|
|||
generateOrg3Definition
|
||||
fi
|
||||
|
||||
CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /fabric-tools/) {print $1}')
|
||||
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
|
||||
echo "Bringing up network"
|
||||
echo "Bringing up Org3 peer"
|
||||
Org3Up
|
||||
fi
|
||||
|
||||
# Use the CLI container to create the configuration transaction needed to add
|
||||
# Org3 to the network
|
||||
|
|
@ -181,7 +176,7 @@ function addOrg3 () {
|
|||
echo "###############################################################"
|
||||
echo "####### Generate and submit config tx to add Org3 #############"
|
||||
echo "###############################################################"
|
||||
docker exec Org3cli ./scripts/org3-scripts/step1org3.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
|
||||
docker exec cli ./scripts/org3-scripts/updateChannelConfig.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR !!!! Unable to create config tx"
|
||||
exit 1
|
||||
|
|
@ -189,19 +184,17 @@ function addOrg3 () {
|
|||
|
||||
echo
|
||||
echo "###############################################################"
|
||||
echo "############### Have Org3 peers join network ##################"
|
||||
echo "############### Join Org3 peers to network ##################"
|
||||
echo "###############################################################"
|
||||
docker exec Org3cli ./scripts/org3-scripts/step2org3.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
|
||||
docker exec cli ./scripts/org3-scripts/joinChannel.sh $CHANNEL_NAME $CLI_DELAY $CLI_TIMEOUT $VERBOSE
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "ERROR !!!! Unable to have Org3 peers join network"
|
||||
echo "ERROR !!!! Unable to join Org3 peers to network"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
# Tear down running network
|
||||
function networkDown () {
|
||||
|
||||
cd ..
|
||||
./network.sh down
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,3 +123,25 @@ services:
|
|||
- 9051:9051
|
||||
networks:
|
||||
- test
|
||||
|
||||
cli:
|
||||
container_name: cli
|
||||
image: hyperledger/fabric-tools:$IMAGE_TAG
|
||||
tty: true
|
||||
stdin_open: true
|
||||
environment:
|
||||
- GOPATH=/opt/gopath
|
||||
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
|
||||
- FABRIC_LOGGING_SPEC=INFO
|
||||
#- FABRIC_LOGGING_SPEC=DEBUG
|
||||
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
|
||||
command: /bin/bash
|
||||
volumes:
|
||||
- /var/run/:/host/var/run/
|
||||
- ../organizations:/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations
|
||||
- ../scripts:/opt/gopath/src/github.com/hyperledger/fabric/peer/scripts/
|
||||
depends_on:
|
||||
- peer0.org1.example.com
|
||||
- peer0.org2.example.com
|
||||
networks:
|
||||
- test
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export PATH=${PWD}/../bin:$PATH
|
|||
export FABRIC_CFG_PATH=${PWD}/configtx
|
||||
export VERBOSE=false
|
||||
|
||||
source scriptUtils.sh
|
||||
. scripts/utils.sh
|
||||
|
||||
# Obtain CONTAINER_IDS and remove them
|
||||
# TODO Might want to make this optional - could clear other containers
|
||||
|
|
@ -131,7 +131,6 @@ function checkPrereqs() {
|
|||
|
||||
# Create Organization crypto material using cryptogen or CAs
|
||||
function createOrgs() {
|
||||
|
||||
if [ -d "organizations/peerOrganizations" ]; then
|
||||
rm -Rf organizations/peerOrganizations && rm -Rf organizations/ordererOrganizations
|
||||
fi
|
||||
|
|
@ -176,10 +175,9 @@ function createOrgs() {
|
|||
|
||||
fi
|
||||
|
||||
# Create crypto material using Fabric CAs
|
||||
# Create crypto material using Fabric CA
|
||||
if [ "$CRYPTO" == "Certificate Authorities" ]; then
|
||||
|
||||
infoln "Generate certificates using Fabric CA's"
|
||||
infoln "Generate certificates using Fabric CA"
|
||||
|
||||
IMAGE_TAG=${CA_IMAGETAG} docker-compose -f $COMPOSE_FILE_CA up -d 2>&1
|
||||
|
||||
|
|
@ -240,7 +238,6 @@ function createOrgs() {
|
|||
|
||||
# Generate orderer system channel genesis block.
|
||||
function createConsortium() {
|
||||
|
||||
which configtxgen
|
||||
if [ "$?" -ne 0 ]; then
|
||||
fatalln "configtxgen tool not found."
|
||||
|
|
@ -267,7 +264,6 @@ function createConsortium() {
|
|||
|
||||
# Bring up the peer and orderer nodes using docker compose.
|
||||
function networkUp() {
|
||||
|
||||
checkPrereqs
|
||||
# generate artifacts if they don't exist
|
||||
if [ ! -d "organizations/peerOrganizations" ]; then
|
||||
|
|
@ -289,10 +285,10 @@ function networkUp() {
|
|||
fi
|
||||
}
|
||||
|
||||
## call the script to join create the channel and join the peers of org1 and org2
|
||||
# call the script to create the channel, join the peers of org1 and org2,
|
||||
# and then update the anchor peers for each organization
|
||||
function createChannel() {
|
||||
|
||||
## Bring up the network if it is not already up.
|
||||
# Bring up the network if it is not already up.
|
||||
|
||||
if [ ! -d "organizations/peerOrganizations" ]; then
|
||||
infoln "Bringing up network"
|
||||
|
|
@ -307,20 +303,16 @@ function createChannel() {
|
|||
if [ $? -ne 0 ]; then
|
||||
fatalln "Create channel failed"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
## Call the script to deploy a chaincode to the channel
|
||||
function deployCC() {
|
||||
|
||||
scripts/deployCC.sh $CHANNEL_NAME $CC_NAME $CC_SRC_PATH $CC_SRC_LANGUAGE $CC_VERSION $CC_SEQUENCE $CC_INIT_FCN $CC_END_POLICY $CC_COLL_CONFIG $CLI_DELAY $MAX_RETRY $VERBOSE
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
fatalln "Deploying chaincode failed"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
source scriptUtils.sh
|
||||
source scripts/utils.sh
|
||||
|
||||
function createOrg1() {
|
||||
|
||||
|
|
|
|||
61
test-network/scripts/configUpdate.sh
Executable file
61
test-network/scripts/configUpdate.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright IBM Corp. All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# import utils
|
||||
. scripts/envVar.sh
|
||||
|
||||
# fetchChannelConfig <org> <channel_id> <output_json>
|
||||
# Writes the current channel config for a given channel to a JSON file
|
||||
# NOTE: this must be run in a CLI container since it requires configtxlator
|
||||
fetchChannelConfig() {
|
||||
ORG=$1
|
||||
CHANNEL=$2
|
||||
OUTPUT=$3
|
||||
|
||||
setGlobals $ORG
|
||||
|
||||
infoln "Fetching the most recent configuration block for the channel"
|
||||
set -x
|
||||
peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
infoln "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
||||
set -x
|
||||
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
||||
# createConfigUpdate <channel_id> <original_config.json> <modified_config.json> <output.pb>
|
||||
# Takes an original and modified config, and produces the config update tx
|
||||
# which transitions between the two
|
||||
# NOTE: this must be run in a CLI container since it requires configtxlator
|
||||
createConfigUpdate() {
|
||||
CHANNEL=$1
|
||||
ORIGINAL=$2
|
||||
MODIFIED=$3
|
||||
OUTPUT=$4
|
||||
|
||||
set -x
|
||||
configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
|
||||
configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
|
||||
configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
|
||||
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
|
||||
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
|
||||
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
||||
# signConfigtxAsPeerOrg <org> <configtx.pb>
|
||||
# Set the peerOrg admin of an org and sign the config update
|
||||
signConfigtxAsPeerOrg() {
|
||||
ORG=$1
|
||||
CONFIGTXFILE=$2
|
||||
setGlobals $ORG
|
||||
set -x
|
||||
peer channel signconfigtx -f "${CONFIGTXFILE}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
source scriptUtils.sh
|
||||
# imports
|
||||
. scripts/envVar.sh
|
||||
. scripts/utils.sh
|
||||
|
||||
CHANNEL_NAME="$1"
|
||||
DELAY="$2"
|
||||
|
|
@ -11,38 +13,16 @@ VERBOSE="$4"
|
|||
: ${MAX_RETRY:="5"}
|
||||
: ${VERBOSE:="false"}
|
||||
|
||||
# import utils
|
||||
. scripts/envVar.sh
|
||||
|
||||
if [ ! -d "channel-artifacts" ]; then
|
||||
mkdir channel-artifacts
|
||||
fi
|
||||
|
||||
createChannelTx() {
|
||||
|
||||
set -x
|
||||
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/${CHANNEL_NAME}.tx -channelID $CHANNEL_NAME
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
if [ $res -ne 0 ]; then
|
||||
fatalln "Failed to generate channel configuration transaction..."
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
createAnchorPeerTx() {
|
||||
|
||||
for orgmsp in Org1MSP Org2MSP; do
|
||||
|
||||
infoln "Generating anchor peer update transaction for ${orgmsp}"
|
||||
set -x
|
||||
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/${orgmsp}anchors.tx -channelID $CHANNEL_NAME -asOrg ${orgmsp}
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
if [ $res -ne 0 ]; then
|
||||
fatalln "Failed to generate anchor peer update transaction for ${orgmsp}..."
|
||||
fi
|
||||
done
|
||||
verifyResult $res "Failed to generate channel configuration transaction..."
|
||||
}
|
||||
|
||||
createChannel() {
|
||||
|
|
@ -53,7 +33,7 @@ createChannel() {
|
|||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||
sleep $DELAY
|
||||
set -x
|
||||
peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock ./channel-artifacts/${CHANNEL_NAME}.block --tls --cafile $ORDERER_CA >&log.txt
|
||||
peer channel create -o localhost:7050 -c $CHANNEL_NAME --ordererTLSHostnameOverride orderer.example.com -f ./channel-artifacts/${CHANNEL_NAME}.tx --outputBlock $BLOCKFILE --tls --cafile $ORDERER_CA >&log.txt
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
let rc=$res
|
||||
|
|
@ -64,8 +44,9 @@ createChannel() {
|
|||
successln "Channel '$CHANNEL_NAME' created"
|
||||
}
|
||||
|
||||
# queryCommitted ORG
|
||||
# joinChannel ORG
|
||||
joinChannel() {
|
||||
FABRIC_CFG_PATH=$PWD/../config/
|
||||
ORG=$1
|
||||
setGlobals $ORG
|
||||
local rc=1
|
||||
|
|
@ -74,7 +55,7 @@ joinChannel() {
|
|||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||
sleep $DELAY
|
||||
set -x
|
||||
peer channel join -b ./channel-artifacts/$CHANNEL_NAME.block >&log.txt
|
||||
peer channel join -b $BLOCKFILE >&log.txt
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
let rc=$res
|
||||
|
|
@ -84,31 +65,9 @@ joinChannel() {
|
|||
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
||||
}
|
||||
|
||||
updateAnchorPeers() {
|
||||
setAnchorPeer() {
|
||||
ORG=$1
|
||||
setGlobals $ORG
|
||||
local rc=1
|
||||
local COUNTER=1
|
||||
## Sometimes Join takes time, hence retry
|
||||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||
sleep $DELAY
|
||||
set -x
|
||||
peer channel update -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ./channel-artifacts/${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
let rc=$res
|
||||
COUNTER=$(expr $COUNTER + 1)
|
||||
done
|
||||
cat log.txt
|
||||
verifyResult $res "Anchor peer update failed"
|
||||
successln "Anchor peers updated for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME'"
|
||||
sleep $DELAY
|
||||
}
|
||||
|
||||
verifyResult() {
|
||||
if [ $1 -ne 0 ]; then
|
||||
fatalln "$2"
|
||||
fi
|
||||
docker exec cli ./scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
|
||||
}
|
||||
|
||||
FABRIC_CFG_PATH=${PWD}/configtx
|
||||
|
|
@ -117,11 +76,8 @@ FABRIC_CFG_PATH=${PWD}/configtx
|
|||
infoln "Generating channel create transaction '${CHANNEL_NAME}.tx'"
|
||||
createChannelTx
|
||||
|
||||
## Create anchorpeertx
|
||||
infoln "Generating anchor peer update transactions"
|
||||
createAnchorPeerTx
|
||||
|
||||
FABRIC_CFG_PATH=$PWD/../config/
|
||||
BLOCKFILE="./channel-artifacts/${CHANNEL_NAME}.block"
|
||||
|
||||
## Create channel
|
||||
infoln "Creating channel ${CHANNEL_NAME}"
|
||||
|
|
@ -134,10 +90,10 @@ infoln "Join Org2 peers to the channel..."
|
|||
joinChannel 2
|
||||
|
||||
## Set the anchor peers for each org in the channel
|
||||
infoln "Updating anchor peers for org1..."
|
||||
updateAnchorPeers 1
|
||||
infoln "Updating anchor peers for org2..."
|
||||
updateAnchorPeers 2
|
||||
infoln "Setting anchor peer for org1..."
|
||||
setAnchorPeer 1
|
||||
infoln "Setting anchor peer for org2..."
|
||||
setAnchorPeer 2
|
||||
|
||||
successln "Channel successfully joined"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
source scriptUtils.sh
|
||||
source scripts/utils.sh
|
||||
|
||||
CHANNEL_NAME=${1:-"mychannel"}
|
||||
CC_NAME=${2}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright IBM Corp All Rights Reserved
|
||||
#
|
||||
|
|
@ -6,7 +7,8 @@
|
|||
|
||||
# This is a collection of bash functions used by different scripts
|
||||
|
||||
source scriptUtils.sh
|
||||
# imports
|
||||
. scripts/utils.sh
|
||||
|
||||
export CORE_PEER_TLS_ENABLED=true
|
||||
export ORDERER_CA=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||
|
|
@ -14,13 +16,6 @@ export PEER0_ORG1_CA=${PWD}/organizations/peerOrganizations/org1.example.com/pee
|
|||
export PEER0_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||
export PEER0_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||
|
||||
# Set OrdererOrg.Admin globals
|
||||
setOrdererGlobals() {
|
||||
export CORE_PEER_LOCALMSPID="OrdererMSP"
|
||||
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp
|
||||
}
|
||||
|
||||
# Set environment variables for the peer org
|
||||
setGlobals() {
|
||||
local USING_ORG=""
|
||||
|
|
@ -55,11 +50,31 @@ setGlobals() {
|
|||
fi
|
||||
}
|
||||
|
||||
# Set environment variables for use in the CLI container
|
||||
setGlobalsCLI() {
|
||||
setGlobals $1
|
||||
|
||||
local USING_ORG=""
|
||||
if [ -z "$OVERRIDE_ORG" ]; then
|
||||
USING_ORG=$1
|
||||
else
|
||||
USING_ORG="${OVERRIDE_ORG}"
|
||||
fi
|
||||
if [ $USING_ORG -eq 1 ]; then
|
||||
export CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||
elif [ $USING_ORG -eq 2 ]; then
|
||||
export CORE_PEER_ADDRESS=peer0.org2.example.com:9051
|
||||
elif [ $USING_ORG -eq 3 ]; then
|
||||
export CORE_PEER_ADDRESS=peer0.org3.example.com:11051
|
||||
else
|
||||
errorln "ORG Unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
# parsePeerConnectionParameters $@
|
||||
# Helper function that sets the peer connection parameters for a chaincode
|
||||
# operation
|
||||
parsePeerConnectionParameters() {
|
||||
|
||||
PEER_CONN_PARMS=""
|
||||
PEERS=""
|
||||
while [ "$#" -gt 0 ]; do
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
#
|
||||
# Copyright IBM Corp All Rights Reserved
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# This is a collection of bash functions used by different scripts
|
||||
|
||||
ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||
PEER0_ORG1_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
|
||||
PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
|
||||
PEER0_ORG3_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||
|
||||
# Set OrdererOrg.Admin globals
|
||||
setOrdererGlobals() {
|
||||
CORE_PEER_LOCALMSPID="OrdererMSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp
|
||||
}
|
||||
|
||||
# Set environment variables for the peer org
|
||||
setGlobals() {
|
||||
ORG=$1
|
||||
if [ $ORG -eq 1 ]; then
|
||||
CORE_PEER_LOCALMSPID="Org1MSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
|
||||
elif [ $ORG -eq 2 ]; then
|
||||
CORE_PEER_LOCALMSPID="Org2MSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
|
||||
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
|
||||
elif [ $ORG -eq 3 ]; then
|
||||
CORE_PEER_LOCALMSPID="Org3MSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA
|
||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
|
||||
CORE_PEER_ADDRESS=peer0.org3.example.com:11051
|
||||
else
|
||||
echo "================== ERROR !!! ORG Unknown =================="
|
||||
fi
|
||||
|
||||
if [ "$VERBOSE" == "true" ]; then
|
||||
env | grep CORE
|
||||
fi
|
||||
}
|
||||
|
||||
verifyResult() {
|
||||
if [ $1 -ne 0 ]; then
|
||||
echo $'\e[1;31m'!!!!!!!!!!!!!!! $2 !!!!!!!!!!!!!!!!$'\e[0m'
|
||||
echo
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# This script is designed to be run in the org3cli container as the
|
||||
# This script is designed to be run in the cli container as the
|
||||
# second step of the EYFN tutorial. It joins the org3 peers to the
|
||||
# channel previously setup in the BYFN tutorial and install the
|
||||
# chaincode as version 2.0 on peer0.org3.
|
||||
|
|
@ -26,39 +26,47 @@ COUNTER=1
|
|||
MAX_RETRY=5
|
||||
|
||||
# import environment variables
|
||||
. scripts/org3-scripts/envVarCLI.sh
|
||||
. scripts/envVar.sh
|
||||
|
||||
## Sometimes Join takes time hence RETRY at least 5 times
|
||||
joinChannelWithRetry() {
|
||||
# joinChannel ORG
|
||||
joinChannel() {
|
||||
ORG=$1
|
||||
setGlobals $ORG
|
||||
|
||||
local rc=1
|
||||
local COUNTER=1
|
||||
## Sometimes Join takes time, hence retry
|
||||
while [ $rc -ne 0 -a $COUNTER -lt $MAX_RETRY ] ; do
|
||||
sleep $DELAY
|
||||
set -x
|
||||
peer channel join -b $CHANNEL_NAME.block >&log.txt
|
||||
peer channel join -b $BLOCKFILE >&log.txt
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
cat log.txt
|
||||
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
|
||||
let rc=$res
|
||||
COUNTER=$(expr $COUNTER + 1)
|
||||
echo "peer0.org${ORG} failed to join the channel, Retry after $DELAY seconds"
|
||||
sleep $DELAY
|
||||
joinChannelWithRetry $PEER $ORG
|
||||
else
|
||||
COUNTER=1
|
||||
fi
|
||||
done
|
||||
cat log.txt
|
||||
verifyResult $res "After $MAX_RETRY attempts, peer0.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
||||
}
|
||||
|
||||
setAnchorPeer() {
|
||||
ORG=$1
|
||||
scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
|
||||
}
|
||||
|
||||
setGlobalsCLI 3
|
||||
BLOCKFILE="${CHANNEL_NAME}.block"
|
||||
|
||||
echo "Fetching channel config block from orderer..."
|
||||
set -x
|
||||
peer channel fetch 0 $CHANNEL_NAME.block -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt
|
||||
peer channel fetch 0 $BLOCKFILE -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME --tls --cafile $ORDERER_CA >&log.txt
|
||||
res=$?
|
||||
{ set +x; } 2>/dev/null
|
||||
cat log.txt
|
||||
verifyResult $res "Fetching config block from orderer has Failed"
|
||||
|
||||
joinChannelWithRetry 3
|
||||
joinChannel 3
|
||||
|
||||
echo "Setting anchor peer for org3..."
|
||||
setAnchorPeer 3
|
||||
echo "===================== peer0.org3 joined channel '$CHANNEL_NAME' ===================== "
|
||||
|
||||
echo
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright IBM Corp. All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# This script is designed to be run in the org3cli container as the
|
||||
# first step of the EYFN tutorial. It creates and submits a
|
||||
# configuration transaction to add org3 to the test network
|
||||
#
|
||||
|
||||
CHANNEL_NAME="$1"
|
||||
DELAY="$2"
|
||||
TIMEOUT="$3"
|
||||
VERBOSE="$4"
|
||||
: ${CHANNEL_NAME:="mychannel"}
|
||||
: ${DELAY:="3"}
|
||||
: ${TIMEOUT:="10"}
|
||||
: ${VERBOSE:="false"}
|
||||
COUNTER=1
|
||||
MAX_RETRY=5
|
||||
|
||||
|
||||
# import environment variables
|
||||
. scripts/org3-scripts/envVarCLI.sh
|
||||
|
||||
|
||||
# fetchChannelConfig <channel_id> <output_json>
|
||||
# Writes the current channel config for a given channel to a JSON file
|
||||
fetchChannelConfig() {
|
||||
ORG=$1
|
||||
CHANNEL=$2
|
||||
OUTPUT=$3
|
||||
|
||||
setOrdererGlobals
|
||||
|
||||
setGlobals $ORG
|
||||
|
||||
echo "Fetching the most recent configuration block for the channel"
|
||||
set -x
|
||||
peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL --tls --cafile $ORDERER_CA
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
echo "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
||||
set -x
|
||||
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
||||
# createConfigUpdate <channel_id> <original_config.json> <modified_config.json> <output.pb>
|
||||
# Takes an original and modified config, and produces the config update tx
|
||||
# which transitions between the two
|
||||
createConfigUpdate() {
|
||||
CHANNEL=$1
|
||||
ORIGINAL=$2
|
||||
MODIFIED=$3
|
||||
OUTPUT=$4
|
||||
|
||||
set -x
|
||||
configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
|
||||
configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
|
||||
configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
|
||||
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
|
||||
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
|
||||
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
||||
# signConfigtxAsPeerOrg <org> <configtx.pb>
|
||||
# Set the peerOrg admin of an org and signing the config update
|
||||
signConfigtxAsPeerOrg() {
|
||||
PEERORG=$1
|
||||
TX=$2
|
||||
setGlobals $PEERORG
|
||||
set -x
|
||||
peer channel signconfigtx -f "${TX}"
|
||||
{ set +x; } 2>/dev/null
|
||||
}
|
||||
|
||||
echo
|
||||
echo "========= Creating config transaction to add org3 to network =========== "
|
||||
echo
|
||||
|
||||
# Fetch the config for the channel, writing it to config.json
|
||||
fetchChannelConfig 1 ${CHANNEL_NAME} config.json
|
||||
|
||||
# Modify the configuration to append the new org
|
||||
set -x
|
||||
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb
|
||||
createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb
|
||||
|
||||
echo
|
||||
echo "========= Config transaction to add org3 to network created ===== "
|
||||
echo
|
||||
|
||||
echo "Signing config transaction"
|
||||
echo
|
||||
signConfigtxAsPeerOrg 1 org3_update_in_envelope.pb
|
||||
|
||||
echo
|
||||
echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= "
|
||||
echo
|
||||
setGlobals 2
|
||||
set -x
|
||||
peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA}
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
echo
|
||||
echo "========= Config transaction to add org3 to network submitted! =========== "
|
||||
echo
|
||||
|
||||
exit 0
|
||||
64
test-network/scripts/org3-scripts/updateChannelConfig.sh
Executable file
64
test-network/scripts/org3-scripts/updateChannelConfig.sh
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright IBM Corp. All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# This script is designed to be run in the cli container as the
|
||||
# first step of the EYFN tutorial. It creates and submits a
|
||||
# configuration transaction to add org3 to the test network
|
||||
#
|
||||
|
||||
CHANNEL_NAME="$1"
|
||||
DELAY="$2"
|
||||
TIMEOUT="$3"
|
||||
VERBOSE="$4"
|
||||
: ${CHANNEL_NAME:="mychannel"}
|
||||
: ${DELAY:="3"}
|
||||
: ${TIMEOUT:="10"}
|
||||
: ${VERBOSE:="false"}
|
||||
COUNTER=1
|
||||
MAX_RETRY=5
|
||||
|
||||
|
||||
# imports
|
||||
. scripts/envVar.sh
|
||||
. scripts/configUpdate.sh
|
||||
|
||||
echo
|
||||
echo "Creating config transaction to add org3 to network"
|
||||
echo
|
||||
|
||||
# Fetch the config for the channel, writing it to config.json
|
||||
fetchChannelConfig 1 ${CHANNEL_NAME} config.json
|
||||
|
||||
# Modify the configuration to append the new org
|
||||
set -x
|
||||
jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"Org3MSP":.[1]}}}}}' config.json ./organizations/peerOrganizations/org3.example.com/org3.json > modified_config.json
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
# Compute a config update, based on the differences between config.json and modified_config.json, write it as a transaction to org3_update_in_envelope.pb
|
||||
createConfigUpdate ${CHANNEL_NAME} config.json modified_config.json org3_update_in_envelope.pb
|
||||
|
||||
echo
|
||||
echo "========= Config transaction to add org3 to network created ===== "
|
||||
echo
|
||||
|
||||
echo "Signing config transaction"
|
||||
echo
|
||||
signConfigtxAsPeerOrg 1 org3_update_in_envelope.pb
|
||||
|
||||
echo
|
||||
echo "========= Submitting transaction from a different peer (peer0.org2) which also signs it ========= "
|
||||
echo
|
||||
setGlobals 2
|
||||
set -x
|
||||
peer channel update -f org3_update_in_envelope.pb -c ${CHANNEL_NAME} -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${ORDERER_CA}
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
echo
|
||||
echo "========= Config transaction to add org3 to network submitted! =========== "
|
||||
echo
|
||||
|
||||
exit 0
|
||||
58
test-network/scripts/setAnchorPeer.sh
Executable file
58
test-network/scripts/setAnchorPeer.sh
Executable file
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright IBM Corp. All Rights Reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
# import utils
|
||||
. scripts/envVar.sh
|
||||
. scripts/configUpdate.sh
|
||||
|
||||
|
||||
# NOTE: this must be run in a CLI container since it requires jq and configtxlator
|
||||
createAnchorPeerUpdate() {
|
||||
infoln "Fetching channel config for channel $CHANNEL_NAME"
|
||||
fetchChannelConfig $ORG $CHANNEL_NAME ${CORE_PEER_LOCALMSPID}config.json
|
||||
|
||||
infoln "Generating anchor peer update transaction for Org${ORG} on channel $CHANNEL_NAME"
|
||||
|
||||
if [ $ORG -eq 1 ]; then
|
||||
HOST="peer0.org1.example.com"
|
||||
PORT=7051
|
||||
elif [ $ORG -eq 2 ]; then
|
||||
HOST="peer0.org2.example.com"
|
||||
PORT=9051
|
||||
elif [ $ORG -eq 3 ]; then
|
||||
HOST="peer0.org3.example.com"
|
||||
PORT=11051
|
||||
else
|
||||
errorln "Org${ORG} unknown"
|
||||
fi
|
||||
|
||||
set -x
|
||||
# Modify the configuration to append the anchor peer
|
||||
jq '.channel_group.groups.Application.groups.'${CORE_PEER_LOCALMSPID}'.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "'$HOST'","port": '$PORT'}]},"version": "0"}}' ${CORE_PEER_LOCALMSPID}config.json > ${CORE_PEER_LOCALMSPID}modified_config.json
|
||||
{ set +x; } 2>/dev/null
|
||||
|
||||
# Compute a config update, based on the differences between
|
||||
# {orgmsp}config.json and {orgmsp}modified_config.json, write
|
||||
# it as a transaction to {orgmsp}anchors.tx
|
||||
createConfigUpdate ${CHANNEL_NAME} ${CORE_PEER_LOCALMSPID}config.json ${CORE_PEER_LOCALMSPID}modified_config.json ${CORE_PEER_LOCALMSPID}anchors.tx
|
||||
}
|
||||
|
||||
updateAnchorPeer() {
|
||||
peer channel update -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c $CHANNEL_NAME -f ${CORE_PEER_LOCALMSPID}anchors.tx --tls --cafile $ORDERER_CA >&log.txt
|
||||
res=$?
|
||||
cat log.txt
|
||||
verifyResult $res "Anchor peer update failed"
|
||||
successln "Anchor peer set for org '$CORE_PEER_LOCALMSPID' on channel '$CHANNEL_NAME'"
|
||||
}
|
||||
|
||||
ORG=$1
|
||||
CHANNEL_NAME=$2
|
||||
setGlobalsCLI $ORG
|
||||
|
||||
createAnchorPeerUpdate
|
||||
|
||||
updateAnchorPeer
|
||||
Loading…
Reference in a new issue