Configtxlator script changes (#552)

Signed-off-by: sapthasurendran <saptha.surendran@ibm.com>
This commit is contained in:
sapthasurendran 2021-12-09 17:07:38 +05:30 committed by GitHub
parent 06d67ecbfa
commit 9df7e9f86d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 14 deletions

View file

@ -34,19 +34,19 @@ function create_config_update() {
local modified=$2
local output=$3
configtxlator proto_encode --input "${original}" --type common.Config > original_config.pb
configtxlator proto_encode --input "${modified}" --type common.Config > modified_config.pb
configtxlator proto_encode --input "${original}" --type common.Config --output original_config.pb
configtxlator proto_encode --input "${modified}" --type common.Config --output modified_config.pb
# returns non-zero if no updates were detected between current and new config
configtxlator compute_update --channel_id "${CHANNEL_NAME}" --original original_config.pb --updated modified_config.pb > config_update.pb
configtxlator compute_update --channel_id "${CHANNEL_NAME}" --original original_config.pb --updated modified_config.pb --output config_update.pb
if [ $? -ne 0 ]; then
echo "Anchor peer has already been set to ${ANCHOR_PEER_HOST}:${ANCHOR_PEER_PORT} - no update required."
return 1
fi
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate > config_update.json
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
echo '{"payload":{"header":{"channel_header":{"channel_id":"'${CHANNEL_NAME}'", "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 config_update_in_envelope.json --type common.Envelope --output ${output}
return 0
}
@ -60,7 +60,7 @@ function create_anchor_peer_update() {
jq '.channel_group.groups.Application.groups.'${CORE_PEER_LOCALMSPID}'.values += {"AnchorPeers":{"mod_policy": "Admins","value":{"anchor_peers": [{"host": "'${ANCHOR_PEER_HOST}'","port": '${ANCHOR_PEER_PORT}'}]},"version": "0"}}' config.json > modified_config.json
{ set +x; } 2>/dev/null
# Compute a config update, based on the differences between
# Compute a config update, based on the differences between
# config.json and modified_config.json, write
# it as a transaction to anchors.tx
create_config_update config.json modified_config.json anchors.tx

View file

@ -10,7 +10,7 @@
# 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
# NOTE: this must be run in a CLI container since it requires configtxlator
fetchChannelConfig() {
ORG=$1
CHANNEL=$2
@ -25,14 +25,15 @@ 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
}
# 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
# NOTE: this must be run in a CLI container since it requires configtxlator
createConfigUpdate() {
CHANNEL=$1
ORIGINAL=$2
@ -40,12 +41,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
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}"
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output "${OUTPUT}"
{ set +x; } 2>/dev/null
}