From e48b3c616e44b82f1a5b9666efe3824d44a9caad Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Thu, 25 Nov 2021 17:29:13 +0530 Subject: [PATCH 01/10] new Orderer script Signed-off-by: sapthasurendran --- .../docker/docker-compose-new-orderer.yaml | 50 ++++ .../cryptogen/crypto-config-orderer-new.yaml | 25 ++ .../scripts/addNewOrderer.sh | 249 ++++++++++++++++++ 3 files changed, 324 insertions(+) create mode 100644 fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml create mode 100644 fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml create mode 100755 fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh diff --git a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml new file mode 100644 index 0000000..93898e0 --- /dev/null +++ b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml @@ -0,0 +1,50 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +version: '2' + +volumes: + orderer6.example.com: + + +networks: + test: + name: fabric_test + +services: + + orderer6.example.com: + container_name: orderer6.example.com + image: hyperledger-fabric.jfrog.io/fabric-orderer:amd64-latest + environment: + - FABRIC_LOGGING_SPEC=DEBUG + - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 + - ORDERER_GENERAL_LISTENPORT=7056 + - 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] + - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:17056 + working_dir: /opt/gopath/src/github.com/hyperledger/fabric + command: orderer + volumes: + - .../channel-artifacts/latest_config.block:/var/hyperledger/orderer/orderer.genesis.block + - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/msp:/var/hyperledger/orderer/msp + - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/:/var/hyperledger/orderer/tls + - orderer6.example.com:/var/hyperledger/production/orderer + ports: + - 7056:7056 + - 17056:17056 + networks: + - test \ No newline at end of file diff --git a/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml b/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml new file mode 100644 index 0000000..d260ff0 --- /dev/null +++ b/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml @@ -0,0 +1,25 @@ +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# --------------------------------------------------------------------------- +# "OrdererOrgs" - Definition of organizations managing orderer nodes +# --------------------------------------------------------------------------- +OrdererOrgs: + # --------------------------------------------------------------------------- + # Orderer + # --------------------------------------------------------------------------- + - Name: Orderer + Domain: example.com + EnableNodeOUs: true + # --------------------------------------------------------------------------- + # "Specs" - See PeerOrgs for complete description + # --------------------------------------------------------------------------- + Specs: + - Hostname: orderer + SANS: + - localhost + - Hostname: orderer6 + SANS: + - localhost \ No newline at end of file diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh new file mode 100755 index 0000000..6caef4f --- /dev/null +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -0,0 +1,249 @@ +#!/bin/bash +# +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 +# + +# import utils +. scripts/envVar.sh + +# fetchChannelConfig +# 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 + +COMPOSE_FILES=docker-compose-new-orderer.yaml +FABRIC_CFG_PATH=$PWD/../config/ +export CH_NAME='mychannel' + +startNewOrderer(){ + # # generate artifacts if they don't exist + # if [ ! -d "organizations/ordererOrganizations/example.com/orderers/orderer6.example.com" ]; then + # createOrgs + # createConsortium + # fi + + docker-compose ${COMPOSE_FILES} up -d + + docker ps -a + if [ $? -ne 0 ]; then + fatalln "Unable to start network" + fi + +} +# Create Organziation crypto material using cryptogen or CAs +function generateOrdererCrypto() { + # Create crypto material using cryptogen + + which cryptogen + if [ "$?" -ne 0 ]; then + fatalln "cryptogen tool not found. exiting" + fi + infoln "Generating certificates using cryptogen tool" + + infoln "Creating orderer Identities" + + set -x + cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer-new.yaml --output="${PWD}/organizations" + res=$? + { set +x; } 2>/dev/null + if [ $res -ne 0 ]; then + fatalln "Failed to generate certificates..." + fi +} + + +fetchChannelConfig() { + timestamp + ORG=$1 + CHANNEL=$2 + OUTPUT=$3 + setOrderer $ORG + export FABRIC_CFG_PATH=$PWD/../config/ + + infoln "$(timestamp) Fetching the most recent configuration block for the channel" + set -x + peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com --tls --cafile $ORDERER_CA -c ${CHANNEL} + { 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 --output ${OUTPUT}.json + { set +x; } 2>/dev/null +} + + +# createConfigUpdate +# 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 +createConfigUpdateTLS() { + infoln "$(timestamp) Creating config update" + CHANNEL=$1 + ORIGINAL=$2 + MODIFIED=$3 + OUTPUT=$4 + + TLS_FILE=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/server.crt + echo ${TLS_FILE} + echo 'path' ${PWD} + + set -x + # filter requird data + jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" + #copy config to modified config + # cp config.json modified_config.json + # edit orderer address + echo "{\"client_tls_cert\":\"$(cat $TLS_FILE | base64)\",\"host\":\"orderer6.example.com\",\"port\":7056,\"server_tls_cert\":\"$(cat $TLS_FILE | base64)\"}" > $PWD/org6consenter.json + jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" config.json > modified_config.json + + configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output config.pb + configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb + configtxlator compute_update --channel_id $CHANNEL --original config.pb --updated modified_config.pb --output config_update.pb + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output 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 "${OUTPUT}" + + { set +x; } 2>/dev/null + infoln " $(timestamp) Completed creating config update " +} + +createConfigUpdateEndpoint() { + infoln "$(timestamp) Creating config update" + CHANNEL=$1 + ORIGINAL=$2 + MODIFIED=$3 + OUTPUT=$4 + + set -x + # filter requird data + jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" + #copy config to modified config + # cp config.json modified_config.json + # edit orderer address + + jq ".channel_group.groups.Orderer.groups.OrdererOrg.values.Endpoints.value.addresses += [\"orderer6.example.com:7056\"]" config.json > modified_config.json + configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output config.pb + configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb + configtxlator compute_update --channel_id $CHANNEL --original config.pb --updated modified_config.pb --output config_update.pb + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output 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 "${OUTPUT}" + + { set +x; } 2>/dev/null + infoln " $(timestamp) Completed creating config update " +} + +# docker exec orderer-cli sh -c 'jq ".channel_group.values.OrdererAddresses.value.addresses += [\"orderer2.example.com:7050\"]" config.json > modified_config.json' +# docker exec orderer-cli sh -c 'configtxlator proto_encode --input config.json --type common.Config --output config.pb' +# docker exec orderer-cli sh -c 'configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb' +# docker exec orderer-cli sh -c 'configtxlator compute_update --channel_id system-channel --original config.pb --updated modified_config.pb --output config_update.pb' +# docker exec orderer-cli sh -c 'configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json' +# docker exec orderer-cli sh -c 'echo "{\"payload\":{\"header\":{\"channel_header\":{\"channel_id\":\"system-channel\", \"type\":2}},\"data\":{\"config_update\":"$(cat config_update.json)"}}}" | jq . > config_update_in_envelope.json' +# docker exec orderer-cli sh -c 'configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output config_update_in_envelope.pb' +# docker exec orderer-cli sh -c 'peer channel update -f config_update_in_envelope.pb -c system-channel -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA' + + +# signConfigtxAsPeerOrg +# Set the peerOrg admin of an org and sign the config update +signConfigtxAsPeerOrg() { + infoln "Signing config update transaction" + + ORG=$1 + CONFIGTXFILE=$2 + setOrderer $ORG + set -x + echo 'CORE_PEER_LOCALMSPID' $CORE_PEER_LOCALMSPID + echo 'CORE_PEER_TLS_ROOTCERT_FILE' $CORE_PEER_TLS_ROOTCERT_FILE + echo 'CORE_PEER_MSPCONFIGPATH' $CORE_PEER_MSPCONFIGPATH + echo 'CORE_PEER_TLS_CERT_FILE' $CORE_PEER_TLS_CERT_FILE + echo 'CORE_PEER_TLS_KEY_FILE' $CORE_PEER_TLS_KEY_FILE + echo 'CORE_PEER_ADDRESS' $CORE_PEER_ADDRESS + peer channel signconfigtx -f "${CONFIGTXFILE}" + { set +x; } 2>/dev/null + infoln " $(timestamp) Completed signing the config update process" + +} +# Submit the config update transaction +submitConfigUpdateTransaction(){ + + infoln "Submitting config update transaction" + ORG=$1 + CHANNEL=$2 + CONFIGTXFILE=$3 + setOrderer $ORG + set -x + echo 'CORE_PEER_LOCALMSPID' $CORE_PEER_LOCALMSPID + echo 'CORE_PEER_TLS_ROOTCERT_FILE' $CORE_PEER_TLS_ROOTCERT_FILE + echo 'CORE_PEER_MSPCONFIGPATH' $CORE_PEER_MSPCONFIGPATH + echo 'CORE_PEER_TLS_CERT_FILE' $CORE_PEER_TLS_CERT_FILE + echo 'CORE_PEER_TLS_KEY_FILE' $CORE_PEER_TLS_KEY_FILE + echo 'CORE_PEER_ADDRESS' $CORE_PEER_ADDRESS + peer channel update -f $CONFIGTXFILE -c $CHANNEL -o localhost:7050 --tls --cafile $ORDERER_CA + { set +x; } 2>/dev/null + infoln " $(timestamp) Submit config update process done" +} + +verifyChannelConfig() { + timestamp + ORG=$1 + CHANNEL=$2 + OUTPUT=$3 + + + setGlobals $ORG + export FABRIC_CFG_PATH=$PWD/../config/ + infoln "Fetching the most recent configuration block for the channel" + set -x + peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.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 --output config_block.json + + # filter requird data + jq .data.data[0].payload.data.config config_block.json > "${OUTPUT}" + + + { set +x; } 2>/dev/null +} +echo '-----------------------------------------------------------------------------------------------------' +generateOrdererCrypto +echo '-----------------------------------------------------------------------------------------------------' +# fetch channel config +fetchChannelConfig 1 'system-channel ' 'config_block' +echo '-----------------------------------------------------------------------------------------------------' +createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +echo '-----------------------------------------------------------------------------------------------------' +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +echo '-----------------------------------------------------------------------------------------------------' + +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' +echo '-----------------------------------------------------------------------------------------------------' + + + +# Bring up new orderer +# startNewOrderer + + +# fetch latest channel config +# fetchChannelConfig 1 'system-channel ' 'config_block' +# createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' + +# submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' + +# fetchChannelConfig 1 'mychannel ' 'config_block' +# createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' + + +# fetchChannelConfig 1 'mychannel ' 'config_block' +# createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' + + From 9924686ef16833fb0ce5519b17e13cde74a5b643 Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Mon, 29 Nov 2021 16:14:16 +0530 Subject: [PATCH 02/10] update scripts Signed-off-by: sapthasurendran --- .../docker/docker-compose-new-orderer.yaml | 2 +- .../scripts/addNewOrderer.sh | 132 ++++++++---------- 2 files changed, 60 insertions(+), 74 deletions(-) diff --git a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml index 93898e0..dadf16d 100644 --- a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml +++ b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml @@ -39,7 +39,7 @@ services: working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - - .../channel-artifacts/latest_config.block:/var/hyperledger/orderer/orderer.genesis.block + - ../channel-artifacts/latest_config.block:/var/hyperledger/orderer/orderer.genesis.block - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/msp:/var/hyperledger/orderer/msp - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/:/var/hyperledger/orderer/tls - orderer6.example.com:/var/hyperledger/production/orderer diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 6caef4f..6df6b77 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -17,13 +17,8 @@ FABRIC_CFG_PATH=$PWD/../config/ export CH_NAME='mychannel' startNewOrderer(){ - # # generate artifacts if they don't exist - # if [ ! -d "organizations/ordererOrganizations/example.com/orderers/orderer6.example.com" ]; then - # createOrgs - # createConsortium - # fi - docker-compose ${COMPOSE_FILES} up -d + docker-compose -f docker/${COMPOSE_FILES} up -d docker ps -a if [ $? -ne 0 ]; then @@ -44,7 +39,7 @@ function generateOrdererCrypto() { infoln "Creating orderer Identities" set -x - cryptogen generate --config=./organizations/cryptogen/crypto-config-orderer-new.yaml --output="${PWD}/organizations" + cryptogen extend --config=./organizations/cryptogen/crypto-config-orderer-new.yaml --input="${PWD}/organizations" res=$? { set +x; } 2>/dev/null if [ $res -ne 0 ]; then @@ -61,15 +56,18 @@ fetchChannelConfig() { setOrderer $ORG export FABRIC_CFG_PATH=$PWD/../config/ - infoln "$(timestamp) Fetching the most recent configuration block for the channel" + infoln "$(timestamp) Fetching the most recent configuration block for the channel ${CHANNEL}" set -x peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com --tls --cafile $ORDERER_CA -c ${CHANNEL} { 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 --output ${OUTPUT}.json { set +x; } 2>/dev/null + + } @@ -91,8 +89,7 @@ createConfigUpdateTLS() { set -x # filter requird data jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" - #copy config to modified config - # cp config.json modified_config.json + # edit orderer address echo "{\"client_tls_cert\":\"$(cat $TLS_FILE | base64)\",\"host\":\"orderer6.example.com\",\"port\":7056,\"server_tls_cert\":\"$(cat $TLS_FILE | base64)\"}" > $PWD/org6consenter.json jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" config.json > modified_config.json @@ -118,8 +115,7 @@ createConfigUpdateEndpoint() { set -x # filter requird data jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" - #copy config to modified config - # cp config.json modified_config.json + # edit orderer address jq ".channel_group.groups.Orderer.groups.OrdererOrg.values.Endpoints.value.addresses += [\"orderer6.example.com:7056\"]" config.json > modified_config.json @@ -134,31 +130,19 @@ createConfigUpdateEndpoint() { infoln " $(timestamp) Completed creating config update " } -# docker exec orderer-cli sh -c 'jq ".channel_group.values.OrdererAddresses.value.addresses += [\"orderer2.example.com:7050\"]" config.json > modified_config.json' -# docker exec orderer-cli sh -c 'configtxlator proto_encode --input config.json --type common.Config --output config.pb' -# docker exec orderer-cli sh -c 'configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb' -# docker exec orderer-cli sh -c 'configtxlator compute_update --channel_id system-channel --original config.pb --updated modified_config.pb --output config_update.pb' -# docker exec orderer-cli sh -c 'configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json' -# docker exec orderer-cli sh -c 'echo "{\"payload\":{\"header\":{\"channel_header\":{\"channel_id\":\"system-channel\", \"type\":2}},\"data\":{\"config_update\":"$(cat config_update.json)"}}}" | jq . > config_update_in_envelope.json' -# docker exec orderer-cli sh -c 'configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output config_update_in_envelope.pb' -# docker exec orderer-cli sh -c 'peer channel update -f config_update_in_envelope.pb -c system-channel -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA' + # signConfigtxAsPeerOrg # Set the peerOrg admin of an org and sign the config update signConfigtxAsPeerOrg() { - infoln "Signing config update transaction" + infoln "Signing config update transaction" ORG=$1 CONFIGTXFILE=$2 setOrderer $ORG set -x - echo 'CORE_PEER_LOCALMSPID' $CORE_PEER_LOCALMSPID - echo 'CORE_PEER_TLS_ROOTCERT_FILE' $CORE_PEER_TLS_ROOTCERT_FILE - echo 'CORE_PEER_MSPCONFIGPATH' $CORE_PEER_MSPCONFIGPATH - echo 'CORE_PEER_TLS_CERT_FILE' $CORE_PEER_TLS_CERT_FILE - echo 'CORE_PEER_TLS_KEY_FILE' $CORE_PEER_TLS_KEY_FILE - echo 'CORE_PEER_ADDRESS' $CORE_PEER_ADDRESS + peer channel signconfigtx -f "${CONFIGTXFILE}" { set +x; } 2>/dev/null infoln " $(timestamp) Completed signing the config update process" @@ -173,77 +157,79 @@ submitConfigUpdateTransaction(){ CONFIGTXFILE=$3 setOrderer $ORG set -x - echo 'CORE_PEER_LOCALMSPID' $CORE_PEER_LOCALMSPID - echo 'CORE_PEER_TLS_ROOTCERT_FILE' $CORE_PEER_TLS_ROOTCERT_FILE - echo 'CORE_PEER_MSPCONFIGPATH' $CORE_PEER_MSPCONFIGPATH - echo 'CORE_PEER_TLS_CERT_FILE' $CORE_PEER_TLS_CERT_FILE - echo 'CORE_PEER_TLS_KEY_FILE' $CORE_PEER_TLS_KEY_FILE - echo 'CORE_PEER_ADDRESS' $CORE_PEER_ADDRESS + peer channel update -f $CONFIGTXFILE -c $CHANNEL -o localhost:7050 --tls --cafile $ORDERER_CA { set +x; } 2>/dev/null infoln " $(timestamp) Submit config update process done" } -verifyChannelConfig() { - timestamp - ORG=$1 - CHANNEL=$2 - OUTPUT=$3 +fetchConfigBlock(){ + + infoln "Fetch latest block from channel ${2}" + ORG=$1 + CHANNEL=$2 + setOrderer $ORG + peer channel fetch config channel-artifacts/latest_config.block -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com -c ${CHANNEL} --tls --cafile $ORDERER_CA + docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/latest_config.block ./channel-artifacts/latest_config.block + + +} - setGlobals $ORG - export FABRIC_CFG_PATH=$PWD/../config/ - infoln "Fetching the most recent configuration block for the channel" - set -x - peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.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 --output config_block.json - # filter requird data - jq .data.data[0].payload.data.config config_block.json > "${OUTPUT}" - { set +x; } 2>/dev/null -} -echo '-----------------------------------------------------------------------------------------------------' generateOrdererCrypto -echo '-----------------------------------------------------------------------------------------------------' -# fetch channel config + + fetchChannelConfig 1 'system-channel ' 'config_block' -echo '-----------------------------------------------------------------------------------------------------' createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -echo '-----------------------------------------------------------------------------------------------------' signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -echo '-----------------------------------------------------------------------------------------------------' + + +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' + + +fetchConfigBlock 1 'system-channel' + + +startNewOrderer + + + + +fetchChannelConfig 1 'system-channel ' 'config_block' + + +createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' + +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' + submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' -echo '-----------------------------------------------------------------------------------------------------' -# Bring up new orderer -# startNewOrderer +fetchChannelConfig 1 'mychannel ' 'config_block' -# fetch latest channel config -# fetchChannelConfig 1 'system-channel ' 'config_block' -# createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' -# fetchChannelConfig 1 'mychannel ' 'config_block' -# createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -# submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -# fetchChannelConfig 1 'mychannel ' 'config_block' -# createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -# submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' + + +fetchChannelConfig 1 'mychannel ' 'config_block' + + +createConfigUpdateEndpoint +createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' + +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' From fe1aa4332dd3daed6058ad8001584f487be2d50e Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Mon, 29 Nov 2021 17:27:41 +0530 Subject: [PATCH 03/10] updated gitignore and code cleanup Signed-off-by: sapthasurendran --- .../scripts/addNewOrderer.sh | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 6df6b77..47e4546 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -179,56 +179,46 @@ fetchConfigBlock(){ - +# generate crypto for new orderer generateOrdererCrypto - +# fetch latest config block from sysytem channel fetchChannelConfig 1 'system-channel ' 'config_block' +# create config update for system channel createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# sign the config update signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' - +# submit update in system channel submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' - +# fetch latest config and move the config block to channel artifacts fetchConfigBlock 1 'system-channel' - +# start new orderer container startNewOrderer - - +# fetch latest config block from sysytem channel fetchChannelConfig 1 'system-channel ' 'config_block' - - +# update endpoint info in sysytem channel createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' - +# sign the update signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' - - +# submit update in system channel submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' - +# Application channel updates fetchChannelConfig 1 'mychannel ' 'config_block' - - createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' - - signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' - - submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' - - fetchChannelConfig 1 'mychannel ' 'config_block' createConfigUpdateEndpoint createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' - signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' From fcefc13ec8ddb4c72136a3588d17fda1f2de4c6e Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Tue, 30 Nov 2021 19:55:22 +0530 Subject: [PATCH 04/10] change peeraddress Signed-off-by: sapthasurendran --- .../scripts/addNewOrderer.sh | 28 +++++++++---------- .../docker-based-syschannel/scripts/envVar.sh | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 47e4546..cafb502 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -64,7 +64,7 @@ fetchChannelConfig() { infoln "Decoding config block to JSON and isolating config to ${OUTPUT}" set -x - configtxlator proto_decode --input config_block.pb --type common.Block --output ${OUTPUT}.json + configtxlator proto_decode --input config_block.pb --type common.Block --output ${OUTPUT} { set +x; } 2>/dev/null @@ -83,8 +83,7 @@ createConfigUpdateTLS() { OUTPUT=$4 TLS_FILE=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/server.crt - echo ${TLS_FILE} - echo 'path' ${PWD} + set -x # filter requird data @@ -92,7 +91,7 @@ createConfigUpdateTLS() { # edit orderer address echo "{\"client_tls_cert\":\"$(cat $TLS_FILE | base64)\",\"host\":\"orderer6.example.com\",\"port\":7056,\"server_tls_cert\":\"$(cat $TLS_FILE | base64)\"}" > $PWD/org6consenter.json - jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" config.json > modified_config.json + jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" ${ORIGINAL} > ${MODIFIED} configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output config.pb configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb @@ -151,11 +150,11 @@ signConfigtxAsPeerOrg() { # Submit the config update transaction submitConfigUpdateTransaction(){ - infoln "Submitting config update transaction" - ORG=$1 - CHANNEL=$2 - CONFIGTXFILE=$3 - setOrderer $ORG + infoln "Submitting config update transaction" + ORG=$1 + CHANNEL=$2 + CONFIGTXFILE=$3 + setOrderer $ORG set -x peer channel update -f $CONFIGTXFILE -c $CHANNEL -o localhost:7050 --tls --cafile $ORDERER_CA @@ -183,7 +182,7 @@ fetchConfigBlock(){ generateOrdererCrypto # fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel ' 'config_block' +fetchChannelConfig 1 'system-channel ' 'config_block.json' # create config update for system channel createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the config update @@ -204,7 +203,7 @@ fetchChannelConfig 1 'system-channel ' 'config_block' # update endpoint info in sysytem channel createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the update -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' # submit update in system channel submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' @@ -212,14 +211,15 @@ submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' fetchChannelConfig 1 'mychannel ' 'config_block' createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' fetchChannelConfig 1 'mychannel ' 'config_block' createConfigUpdateEndpoint createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' - +#verify latest block +fetchChannelConfig 1 'mychannel ' 'latest.json' diff --git a/fabric-network/docker-based-syschannel/scripts/envVar.sh b/fabric-network/docker-based-syschannel/scripts/envVar.sh index 0b340e7..020843a 100755 --- a/fabric-network/docker-based-syschannel/scripts/envVar.sh +++ b/fabric-network/docker-based-syschannel/scripts/envVar.sh @@ -187,7 +187,7 @@ setOrderer(){ export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER5_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp - export CORE_PEER_ADDRESS=orderer4.example.com:7054 + export CORE_PEER_ADDRESS=orderer5.example.com:7054 else errorln "ORG Unknown" fi From 6da48745e80157a4f723bfeeed1dcf35cb47f941 Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Tue, 7 Dec 2021 12:40:06 +0530 Subject: [PATCH 05/10] split script Signed-off-by: sapthasurendran --- .../scripts/configUpdate.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fabric-network/docker-based-syschannel/scripts/configUpdate.sh b/fabric-network/docker-based-syschannel/scripts/configUpdate.sh index 63d6845..489b18d 100755 --- a/fabric-network/docker-based-syschannel/scripts/configUpdate.sh +++ b/fabric-network/docker-based-syschannel/scripts/configUpdate.sh @@ -23,7 +23,8 @@ fetchChannelConfig() { 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}" + configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json + jq .data.data[0].payload.data.config config_block.json > "${OUTPUT}" { set +x; } 2>/dev/null } @@ -38,12 +39,12 @@ createConfigUpdate() { 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}" + configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output original_config.pb + configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb + configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb --output config_update.pb + configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output 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 "${OUTPUT}" { set +x; } 2>/dev/null } From cb9227201601f7f141aeb5a7da6581294d6649d2 Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Tue, 7 Dec 2021 12:54:28 +0530 Subject: [PATCH 06/10] filename change Signed-off-by: sapthasurendran --- .../scripts/addNewOrderer.sh | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index cafb502..541c7ab 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -184,12 +184,12 @@ generateOrdererCrypto # fetch latest config block from sysytem channel fetchChannelConfig 1 'system-channel ' 'config_block.json' # create config update for system channel -createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope1.pb' # sign the config update -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +signConfigtxAsPeerOrg 1 'config_update_in_envelope1.pb' # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope1.pb' # fetch latest config and move the config block to channel artifacts fetchConfigBlock 1 'system-channel' @@ -199,27 +199,27 @@ startNewOrderer # fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel ' 'config_block' +fetchChannelConfig 1 'system-channel ' 'config_block.json' # update endpoint info in sysytem channel -createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config2.json' 'config_update_in_envelope2.pb' # sign the update -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope2.pb' # Application channel updates -fetchChannelConfig 1 'mychannel ' 'config_block' -createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' +fetchChannelConfig 1 'mychannel ' 'config_block.json' +createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json3' 'config_update_in_envelope3.pb' +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope3.pb' fetchChannelConfig 1 'mychannel ' 'config_block' createConfigUpdateEndpoint -createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' +createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json4' 'config_update_in_envelope4.pb' +signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope4.pb' #verify latest block fetchChannelConfig 1 'mychannel ' 'latest.json' From a9a0fc7635d9fa6c38077eca1700fd3aa2f5763c Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Tue, 7 Dec 2021 18:02:12 +0530 Subject: [PATCH 07/10] reorder script Signed-off-by: sapthasurendran --- .../cryptogen/crypto-config-orderer-new.yaml | 3 - .../scripts/addNewOrderer.sh | 86 ++++++++++++++----- .../docker-based-syschannel/scripts/envVar.sh | 11 ++- 3 files changed, 73 insertions(+), 27 deletions(-) mode change 100644 => 100755 fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml diff --git a/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml b/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml old mode 100644 new mode 100755 index d260ff0..056e88b --- a/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml +++ b/fabric-network/docker-based-syschannel/organizations/cryptogen/crypto-config-orderer-new.yaml @@ -17,9 +17,6 @@ OrdererOrgs: # "Specs" - See PeerOrgs for complete description # --------------------------------------------------------------------------- Specs: - - Hostname: orderer - SANS: - - localhost - Hostname: orderer6 SANS: - localhost \ No newline at end of file diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 541c7ab..656cf07 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -8,14 +8,13 @@ # import utils . scripts/envVar.sh -# fetchChannelConfig -# 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 + COMPOSE_FILES=docker-compose-new-orderer.yaml FABRIC_CFG_PATH=$PWD/../config/ export CH_NAME='mychannel' + startNewOrderer(){ docker-compose -f docker/${COMPOSE_FILES} up -d @@ -48,6 +47,10 @@ function generateOrdererCrypto() { } +# fetchChannelConfig +# 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() { timestamp ORG=$1 @@ -55,10 +58,10 @@ fetchChannelConfig() { OUTPUT=$3 setOrderer $ORG export FABRIC_CFG_PATH=$PWD/../config/ - + echo '--------------------' $ORDERER infoln "$(timestamp) Fetching the most recent configuration block for the channel ${CHANNEL}" set -x - peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com --tls --cafile $ORDERER_CA -c ${CHANNEL} + peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com --tls --cafile $ORDERER -c ${CHANNEL} { set +x; } 2>/dev/null @@ -157,7 +160,7 @@ submitConfigUpdateTransaction(){ setOrderer $ORG set -x - peer channel update -f $CONFIGTXFILE -c $CHANNEL -o localhost:7050 --tls --cafile $ORDERER_CA + peer channel update -f $CONFIGTXFILE -c $CHANNEL -o localhost:7050 --tls --cafile $ORDERER { set +x; } 2>/dev/null infoln " $(timestamp) Submit config update process done" } @@ -169,7 +172,7 @@ fetchConfigBlock(){ ORG=$1 CHANNEL=$2 setOrderer $ORG - peer channel fetch config channel-artifacts/latest_config.block -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com -c ${CHANNEL} --tls --cafile $ORDERER_CA + peer channel fetch config channel-artifacts/latest_config.block -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com -c ${CHANNEL} --tls --cafile $ORDERER docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/latest_config.block ./channel-artifacts/latest_config.block @@ -184,42 +187,79 @@ generateOrdererCrypto # fetch latest config block from sysytem channel fetchChannelConfig 1 'system-channel ' 'config_block.json' # create config update for system channel -createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope1.pb' +createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the config update -signConfigtxAsPeerOrg 1 'config_update_in_envelope1.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' + + + + +echo $CORE_PEER_MSPCONFIGPATH +echo $CORE_PEER_ADDRESS +echo $CORE_PEER_LOCALMSPID +echo $CORE_PEER_TLS_ROOTCERT_FILE +echo $ORDERER + # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope1.pb' +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' # fetch latest config and move the config block to channel artifacts fetchConfigBlock 1 'system-channel' -# start new orderer container -startNewOrderer # fetch latest config block from sysytem channel fetchChannelConfig 1 'system-channel ' 'config_block.json' # update endpoint info in sysytem channel -createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config2.json' 'config_update_in_envelope2.pb' +createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the update -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' + + +echo $CORE_PEER_MSPCONFIGPATH +echo $CORE_PEER_ADDRESS +echo $CORE_PEER_LOCALMSPID +echo $CORE_PEER_TLS_ROOTCERT_FILE +echo $ORDERER # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope2.pb' +submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' + + +# start new orderer container +startNewOrderer # Application channel updates fetchChannelConfig 1 'mychannel ' 'config_block.json' -createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json3' 'config_update_in_envelope3.pb' -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope3.pb' -fetchChannelConfig 1 'mychannel ' 'config_block' +createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +echo $CORE_PEER_MSPCONFIGPATH +echo $CORE_PEER_ADDRESS +echo $CORE_PEER_LOCALMSPID +echo $CORE_PEER_TLS_ROOTCERT_FILE +echo $ORDERER -createConfigUpdateEndpoint -createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json4' 'config_update_in_envelope4.pb' -signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope4.pb' +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' + + +fetchChannelConfig 1 'mychannel ' 'config_block.json' +# createConfigUpdateEndpoint +createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' +# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' + +echo $CORE_PEER_MSPCONFIGPATH +echo $CORE_PEER_ADDRESS +echo $CORE_PEER_LOCALMSPID +echo $CORE_PEER_TLS_ROOTCERT_FILE +echo $ORDERER + + +submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' #verify latest block fetchChannelConfig 1 'mychannel ' 'latest.json' + +#verify system block +fetchChannelConfig 1 'system-channel ' 'latestsys.json' diff --git a/fabric-network/docker-based-syschannel/scripts/envVar.sh b/fabric-network/docker-based-syschannel/scripts/envVar.sh index 020843a..990b25b 100755 --- a/fabric-network/docker-based-syschannel/scripts/envVar.sh +++ b/fabric-network/docker-based-syschannel/scripts/envVar.sh @@ -24,6 +24,10 @@ export PEER1_ORG2_CA=${PWD}/organizations/peerOrganizations/org2.example.com/pee export PEER1_ORG3_CA=${PWD}/organizations/peerOrganizations/org3.example.com/peers/peer1.org3.example.com/tls/ca.crt export PEER1_ORG4_CA=${PWD}/organizations/peerOrganizations/org4.example.com/peers/peer1.org4.example.com/tls/ca.crt + + + + # Set environment variables for the peer0 org setGlobals() { local USING_ORG="" @@ -38,6 +42,7 @@ setGlobals() { export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp export CORE_PEER_ADDRESS=localhost:8051 + elif [ $USING_ORG -eq 2 ]; then export CORE_PEER_LOCALMSPID="Org2MSP" export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA @@ -166,28 +171,32 @@ setOrderer(){ export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp + export ORDERER=$ORDERER_CA export CORE_PEER_ADDRESS=orderer1.example.com:7050 elif [ $USING_ORG -eq 2 ]; then export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER2_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp export CORE_PEER_ADDRESS=orderer2.example.com:7051 - + export ORDERER=$ORDERER2_CA elif [ $USING_ORG -eq 3 ]; then export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER3_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp export CORE_PEER_ADDRESS=orderer3.example.com:7052 + export ORDERER=$ORDERER3_CA elif [ $USING_ORG -eq 4 ]; then export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER4_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp export CORE_PEER_ADDRESS=orderer4.example.com:7053 + export ORDERER=$ORDERER4_CA elif [ $USING_ORG -eq 5 ]; then export CORE_PEER_LOCALMSPID="OrdererMSP" export CORE_PEER_TLS_ROOTCERT_FILE=$ORDERER5_CA export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp export CORE_PEER_ADDRESS=orderer5.example.com:7054 + export ORDERER=$ORDERER5_CA else errorln "ORG Unknown" fi From f240f2c10fc468c6e5a8c5f354fec48caf67d821 Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Thu, 9 Dec 2021 17:59:58 +0530 Subject: [PATCH 08/10] removed orderer env var Signed-off-by: sapthasurendran --- .../docker/docker-compose-new-orderer.yaml | 2 -- .../scripts/addNewOrderer.sh | 14 +++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml index dadf16d..dba3dfb 100644 --- a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml +++ b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml @@ -32,8 +32,6 @@ services: - 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] - - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:17056 working_dir: /opt/gopath/src/github.com/hyperledger/fabric diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 656cf07..2751444 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -12,7 +12,7 @@ COMPOSE_FILES=docker-compose-new-orderer.yaml FABRIC_CFG_PATH=$PWD/../config/ -export CH_NAME='mychannel' +# export CH_NAME='mychannel' startNewOrderer(){ @@ -185,7 +185,7 @@ fetchConfigBlock(){ generateOrdererCrypto # fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel ' 'config_block.json' +fetchChannelConfig 1 'system-channel' 'config_block.json' # create config update for system channel createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the config update @@ -210,7 +210,7 @@ fetchConfigBlock 1 'system-channel' # fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel ' 'config_block.json' +fetchChannelConfig 1 'system-channel' 'config_block.json' # update endpoint info in sysytem channel createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # sign the update @@ -231,7 +231,7 @@ startNewOrderer # Application channel updates -fetchChannelConfig 1 'mychannel ' 'config_block.json' +fetchChannelConfig 1 'mychannel' 'config_block.json' createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' @@ -244,7 +244,7 @@ echo $ORDERER submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' -fetchChannelConfig 1 'mychannel ' 'config_block.json' +fetchChannelConfig 1 'mychannel' 'config_block.json' # createConfigUpdateEndpoint createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' # signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' @@ -259,7 +259,7 @@ echo $ORDERER submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' #verify latest block -fetchChannelConfig 1 'mychannel ' 'latest.json' +fetchChannelConfig 1 'mychannel' 'latest.json' #verify system block -fetchChannelConfig 1 'system-channel ' 'latestsys.json' +fetchChannelConfig 1 'system-channel' 'latestsys.json' From f17df2654a6860bc5736d49972d9a9510b2f730e Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Fri, 10 Dec 2021 14:43:13 +0530 Subject: [PATCH 09/10] start orderer with genesis block Signed-off-by: sapthasurendran --- .../docker/docker-compose-new-orderer.yaml | 5 +- .../scripts/addNewOrderer.sh | 193 +++++++----------- 2 files changed, 73 insertions(+), 125 deletions(-) diff --git a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml index dba3dfb..07c73e0 100644 --- a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml +++ b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml @@ -34,13 +34,14 @@ services: - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_OPERATIONS_LISTENADDRESS=0.0.0.0:17056 + - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - - ../channel-artifacts/latest_config.block:/var/hyperledger/orderer/orderer.genesis.block + - ../system-genesis-block/genesis.block:/var/hyperledger/orderer/orderer.genesis.block - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/msp:/var/hyperledger/orderer/msp - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/:/var/hyperledger/orderer/tls - - orderer6.example.com:/var/hyperledger/production/orderer ports: - 7056:7056 - 17056:17056 diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index 2751444..a55f054 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -8,26 +8,23 @@ # import utils . scripts/envVar.sh - - COMPOSE_FILES=docker-compose-new-orderer.yaml -FABRIC_CFG_PATH=$PWD/../config/ -# export CH_NAME='mychannel' - +export FABRIC_CFG_PATH=$PWD/../config/ +export CH_NAME='mychannel' +export PATH=${PWD}/../bin:$PATH startNewOrderer(){ - docker-compose -f docker/${COMPOSE_FILES} up -d docker ps -a if [ $? -ne 0 ]; then fatalln "Unable to start network" fi - } + # Create Organziation crypto material using cryptogen or CAs function generateOrdererCrypto() { - # Create crypto material using cryptogen + # Create crypto material using cryptogen which cryptogen if [ "$?" -ne 0 ]; then @@ -38,7 +35,7 @@ function generateOrdererCrypto() { infoln "Creating orderer Identities" set -x - cryptogen extend --config=./organizations/cryptogen/crypto-config-orderer-new.yaml --input="${PWD}/organizations" + cryptogen extend --config=./organizations/cryptogen/crypto-config-orderer-new.yaml --input="./organizations" res=$? { set +x; } 2>/dev/null if [ $res -ne 0 ]; then @@ -53,13 +50,17 @@ function generateOrdererCrypto() { fetchChannelConfig() { timestamp + ORG=$1 CHANNEL=$2 OUTPUT=$3 + setOrderer $ORG export FABRIC_CFG_PATH=$PWD/../config/ + echo '--------------------' $ORDERER infoln "$(timestamp) Fetching the most recent configuration block for the channel ${CHANNEL}" + set -x peer channel fetch config config_block.pb -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com --tls --cafile $ORDERER -c ${CHANNEL} { set +x; } 2>/dev/null @@ -70,7 +71,8 @@ fetchChannelConfig() { configtxlator proto_decode --input config_block.pb --type common.Block --output ${OUTPUT} { set +x; } 2>/dev/null - + #cleanup temp files + rm config_block.pb } @@ -79,77 +81,72 @@ fetchChannelConfig() { # which transitions between the two # NOTE: this must be run in a CLI container since it requires configtxlator createConfigUpdateTLS() { - infoln "$(timestamp) Creating config update" - CHANNEL=$1 - ORIGINAL=$2 - MODIFIED=$3 - OUTPUT=$4 + infoln "$(timestamp) Creating orderer tls config update" - TLS_FILE=${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/server.crt + CHANNEL=$1 + INPUT_CONFIGFILE=$2 + OUTPUT=$3 + TLS_FILE=./organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/server.crt set -x + + #cleanup prior temp files + rm base_config_block.json org6consenter.json modified_config.json base_config.pb modified_config.pb updated_config.pb updated_config.json config_update_in_envelope.json + # filter requird data - jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" + jq .data.data[0].payload.data.config ${INPUT_CONFIGFILE} > base_config_block.json # edit orderer address - echo "{\"client_tls_cert\":\"$(cat $TLS_FILE | base64)\",\"host\":\"orderer6.example.com\",\"port\":7056,\"server_tls_cert\":\"$(cat $TLS_FILE | base64)\"}" > $PWD/org6consenter.json - jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" ${ORIGINAL} > ${MODIFIED} - - configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output config.pb - configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb - configtxlator compute_update --channel_id $CHANNEL --original config.pb --updated modified_config.pb --output config_update.pb - configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output 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 + echo "{\"client_tls_cert\":\"$(cat $TLS_FILE | base64)\",\"host\":\"orderer6.example.com\",\"port\":7056,\"server_tls_cert\":\"$(cat $TLS_FILE | base64)\"}" > org6consenter.json + + jq ".channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += [$(cat org6consenter.json)]" base_config_block.json > modified_config.json + + configtxlator proto_encode --input base_config_block.json --type common.Config --output base_config.pb + configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb + configtxlator compute_update --channel_id $CHANNEL --original base_config.pb --updated modified_config.pb --output updated_config.pb + configtxlator proto_decode --input updated_config.pb --type common.ConfigUpdate --output updated_config.json + echo '{"payload":{"header":{"channel_header":{"channel_id":"'${CHANNEL}'", "type":2}},"data":{"config_update":'$(cat updated_config.json)'}}}' | jq . > config_update_in_envelope.json configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output "${OUTPUT}" { set +x; } 2>/dev/null + infoln " $(timestamp) Completed creating config update " } createConfigUpdateEndpoint() { - infoln "$(timestamp) Creating config update" + infoln "$(timestamp) Creating orderer endpoint config update" + CHANNEL=$1 - ORIGINAL=$2 - MODIFIED=$3 - OUTPUT=$4 + INPUT_CONFIGFILE=$2 + OUTPUT=$3 set -x + + #cleanup prior temp files + rm base_config_block.json modified_config.json base_config.pb modified_config.pb updated_config.pb updated_config.json config_update_in_envelope.json + # filter requird data - jq .data.data[0].payload.data.config config_block.json > "${ORIGINAL}" + jq .data.data[0].payload.data.config ${INPUT_CONFIGFILE} > base_config_block.json # edit orderer address + jq ".channel_group.groups.Orderer.groups.OrdererOrg.values.Endpoints.value.addresses += [\"orderer6.example.com:7056\"]" base_config_block.json > modified_config.json - jq ".channel_group.groups.Orderer.groups.OrdererOrg.values.Endpoints.value.addresses += [\"orderer6.example.com:7056\"]" config.json > modified_config.json - configtxlator proto_encode --input "${ORIGINAL}" --type common.Config --output config.pb - configtxlator proto_encode --input "${MODIFIED}" --type common.Config --output modified_config.pb - configtxlator compute_update --channel_id $CHANNEL --original config.pb --updated modified_config.pb --output config_update.pb - configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output 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 base_config_block.json --type common.Config --output base_config.pb + configtxlator proto_encode --input modified_config.json --type common.Config --output modified_config.pb + configtxlator compute_update --channel_id $CHANNEL --original base_config.pb --updated modified_config.pb --output updated_config.pb + configtxlator proto_decode --input updated_config.pb --type common.ConfigUpdate --output updated_config.json + echo '{"payload":{"header":{"channel_header":{"channel_id":"'${CHANNEL}'", "type":2}},"data":{"config_update":'$(cat updated_config.json)'}}}' | jq . > config_update_in_envelope.json configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output "${OUTPUT}" { set +x; } 2>/dev/null - infoln " $(timestamp) Completed creating config update " -} - - - -# signConfigtxAsPeerOrg -# Set the peerOrg admin of an org and sign the config update -signConfigtxAsPeerOrg() { - infoln "Signing config update transaction" - - ORG=$1 - CONFIGTXFILE=$2 - setOrderer $ORG - set -x - - peer channel signconfigtx -f "${CONFIGTXFILE}" - { set +x; } 2>/dev/null - infoln " $(timestamp) Completed signing the config update process" + #cleanup prior temp files + rm base_config_block.json modified_config.json base_config.pb modified_config.pb updated_config.pb updated_config.json config_update_in_envelope.json + infoln " $(timestamp) Completed creating config update " } + # Submit the config update transaction submitConfigUpdateTransaction(){ @@ -165,101 +162,51 @@ submitConfigUpdateTransaction(){ infoln " $(timestamp) Submit config update process done" } - -fetchConfigBlock(){ - - infoln "Fetch latest block from channel ${2}" - ORG=$1 - CHANNEL=$2 - setOrderer $ORG - peer channel fetch config channel-artifacts/latest_config.block -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com -c ${CHANNEL} --tls --cafile $ORDERER - docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/latest_config.block ./channel-artifacts/latest_config.block - - -} - - - - # generate crypto for new orderer generateOrdererCrypto -# fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel' 'config_block.json' -# create config update for system channel -createConfigUpdateTLS 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# sign the config update -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' - - - -echo $CORE_PEER_MSPCONFIGPATH -echo $CORE_PEER_ADDRESS -echo $CORE_PEER_LOCALMSPID -echo $CORE_PEER_TLS_ROOTCERT_FILE -echo $ORDERER +# fetch latest config block from sysytem channel +fetchChannelConfig 1 'system-channel' 'config_block_iteration1.json' +# create config update for system channel +createConfigUpdateTLS 'system-channel' 'config_block_iteration1.json' 'neworderer_tls_config_update_in_envelope.pb' # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' - +submitConfigUpdateTransaction 1 'system-channel' 'neworderer_tls_config_update_in_envelope.pb' # fetch latest config and move the config block to channel artifacts -fetchConfigBlock 1 'system-channel' # fetch latest config block from sysytem channel -fetchChannelConfig 1 'system-channel' 'config_block.json' -# update endpoint info in sysytem channel -createConfigUpdateEndpoint 'system-channel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# sign the update -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +fetchChannelConfig 1 'system-channel' 'config_block_iteration2.json' +# update endpoint info in sysytem channel +createConfigUpdateEndpoint 'system-channel' 'config_block_iteration2.json' 'neworderer_endpoint_config_update_in_envelope.pb' -echo $CORE_PEER_MSPCONFIGPATH -echo $CORE_PEER_ADDRESS -echo $CORE_PEER_LOCALMSPID -echo $CORE_PEER_TLS_ROOTCERT_FILE -echo $ORDERER # submit update in system channel -submitConfigUpdateTransaction 1 'system-channel' 'config_update_in_envelope.pb' +submitConfigUpdateTransaction 1 'system-channel' 'neworderer_endpoint_config_update_in_envelope.pb' + # start new orderer container startNewOrderer -# Application channel updates - -fetchChannelConfig 1 'mychannel' 'config_block.json' -createConfigUpdateTLS 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' -echo $CORE_PEER_MSPCONFIGPATH -echo $CORE_PEER_ADDRESS -echo $CORE_PEER_LOCALMSPID -echo $CORE_PEER_TLS_ROOTCERT_FILE -echo $ORDERER -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' - - -fetchChannelConfig 1 'mychannel' 'config_block.json' -# createConfigUpdateEndpoint -createConfigUpdateEndpoint 'mychannel' 'config.json' 'modified_config.json' 'config_update_in_envelope.pb' -# signConfigtxAsPeerOrg 1 'config_update_in_envelope.pb' +# Application channel updates + fetchChannelConfig 1 'mychannel' 'mychannel_config_block_iteration1.json' + createConfigUpdateTLS 'mychannel' 'mychannel_config_block_iteration1.json' 'mychannel_neworderer_tls_config_update_in_envelope.pb' + submitConfigUpdateTransaction 1 'mychannel' 'mychannel_neworderer_tls_config_update_in_envelope.pb' -echo $CORE_PEER_MSPCONFIGPATH -echo $CORE_PEER_ADDRESS -echo $CORE_PEER_LOCALMSPID -echo $CORE_PEER_TLS_ROOTCERT_FILE -echo $ORDERER + fetchChannelConfig 1 'mychannel' 'mychannel_config_block_iteration2.json' + createConfigUpdateEndpoint 'mychannel' 'mychannel_config_block_iteration2.json' 'mychannel_neworderer_endpoint_config_update_in_envelope.pb' + submitConfigUpdateTransaction 1 'mychannel' 'mychannel_neworderer_endpoint_config_update_in_envelope.pb' -submitConfigUpdateTransaction 1 'mychannel' 'config_update_in_envelope.pb' #verify latest block -fetchChannelConfig 1 'mychannel' 'latest.json' +fetchChannelConfig 1 'mychannel ' 'latest.json' #verify system block -fetchChannelConfig 1 'system-channel' 'latestsys.json' +fetchChannelConfig 1 'system-channel ' 'latestsys.json' \ No newline at end of file From 03356342b4fd8b68f0a868b3ea1347bd2591c50a Mon Sep 17 00:00:00 2001 From: sapthasurendran Date: Fri, 10 Dec 2021 20:01:01 +0530 Subject: [PATCH 10/10] docker container cleanup and script changes Signed-off-by: sapthasurendran --- fabric-network/bin/.gitignore | 1 + .../docker/docker-compose-new-orderer.yaml | 3 ++- .../scripts/addNewOrderer.sh | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fabric-network/bin/.gitignore b/fabric-network/bin/.gitignore index 036b57c..58ce5da 100644 --- a/fabric-network/bin/.gitignore +++ b/fabric-network/bin/.gitignore @@ -8,3 +8,4 @@ idemixgen orderer osnadmin fabric-ca-server +ledgerutil \ No newline at end of file diff --git a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml index 07c73e0..6f9aa14 100644 --- a/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml +++ b/fabric-network/docker-based-syschannel/docker/docker-compose-new-orderer.yaml @@ -39,9 +39,10 @@ services: working_dir: /opt/gopath/src/github.com/hyperledger/fabric command: orderer volumes: - - ../system-genesis-block/genesis.block:/var/hyperledger/orderer/orderer.genesis.block + - ../channel-artifacts/latest_config.block:/var/hyperledger/orderer/orderer.genesis.block - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/msp:/var/hyperledger/orderer/msp - ../organizations/ordererOrganizations/example.com/orderers/orderer6.example.com/tls/:/var/hyperledger/orderer/tls + ports: - 7056:7056 - 17056:17056 diff --git a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh index a55f054..e28b5af 100755 --- a/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh +++ b/fabric-network/docker-based-syschannel/scripts/addNewOrderer.sh @@ -58,7 +58,7 @@ fetchChannelConfig() { setOrderer $ORG export FABRIC_CFG_PATH=$PWD/../config/ - echo '--------------------' $ORDERER + infoln "$(timestamp) Fetching the most recent configuration block for the channel ${CHANNEL}" set -x @@ -161,7 +161,17 @@ submitConfigUpdateTransaction(){ { set +x; } 2>/dev/null infoln " $(timestamp) Submit config update process done" } +fetchConfigBlock(){ + + infoln "Fetch latest block from channel ${2}" + ORG=$1 + CHANNEL=$2 + setOrderer $ORG + peer channel fetch config channel-artifacts/latest_config.block -o localhost:7050 --ordererTLSHostnameOverride orderer1.example.com -c ${CHANNEL} --tls --cafile $ORDERER + docker cp cli:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts/latest_config.block ./channel-artifacts/latest_config.block + +} # generate crypto for new orderer generateOrdererCrypto @@ -189,6 +199,10 @@ submitConfigUpdateTransaction 1 'system-channel' 'neworderer_endpoint_config_upd +# fetch latest block and move to channel artifacts +fetchConfigBlock 1 'system-channel' + + # start new orderer container startNewOrderer