2017-12-06 22:30:57 +08:00
|
|
|
#!/bin/bash
|
|
|
|
# Demo to use configtxlator to modify orderer config
|
|
|
|
# Usage: bash test_configtxlator solo|kafka
|
|
|
|
# Configtxlator APIs:
|
|
|
|
# Json -> ProtoBuf: http://$SERVER:$PORT/protolator/encode/<message.Name>
|
|
|
|
# ProtoBuf -> Json: http://$SERVER:$PORT/protolator/decode/<message.Name>
|
|
|
|
# Compute Update: http://$SERVER:$PORT/configtxlator/compute/update-from-configs
|
|
|
|
# <message.Name> could be: common.Block, common.Envelope, common.ConfigEnvelope, common.ConfigUpdateEnvelope, common.Config, common.ConfigUpdate
|
|
|
|
# More details about configtxlator, see http://hlf.readthedocs.io/en/latest/configtxlator.html
|
|
|
|
|
|
|
|
if [ -f ./func.sh ]; then
|
|
|
|
source ./func.sh
|
|
|
|
elif [ -f scripts/func.sh ]; then
|
|
|
|
source scripts/func.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
[ $# -ne 1 ] && echo_r "Usage: bash test_configtxlator solo|kafka" && exit 1
|
|
|
|
|
|
|
|
MODE=$1
|
|
|
|
|
|
|
|
pushd $MODE/${CHANNEL_ARTIFACTS}
|
|
|
|
|
|
|
|
# Must run `make gen_config` to generate config files first
|
|
|
|
|
2018-10-12 11:33:24 +08:00
|
|
|
|
2017-12-06 22:30:57 +08:00
|
|
|
echo_b "Clean potential existing container $CTL_CONTAINER"
|
|
|
|
[ "$(docker ps -a | grep $CTL_CONTAINER)" ] && docker rm -f $CTL_CONTAINER
|
|
|
|
|
|
|
|
echo_b "Start configtxlator service in background (listen on port 7059)"
|
|
|
|
docker run \
|
|
|
|
-d -it \
|
|
|
|
--name ${CTL_CONTAINER} \
|
|
|
|
-p 127.0.0.1:7059:7059 \
|
2018-10-12 11:33:24 +08:00
|
|
|
-v ${PWD}:/tmp \
|
|
|
|
-w /tmp \
|
2017-12-06 22:30:57 +08:00
|
|
|
${CTL_IMG} \
|
|
|
|
configtxlator start --port=7059
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
2018-09-29 17:44:36 +08:00
|
|
|
echo_b "Convert all block files into json"
|
2019-05-02 17:30:13 +08:00
|
|
|
for block_file in *.block; do
|
2020-01-04 02:02:03 +08:00
|
|
|
configtxlatorDecode "common.Block" ${block_file} ${block_file}.json
|
2017-12-29 21:52:46 +08:00
|
|
|
decode_result=$?
|
|
|
|
#echo_b "Parse payload..."
|
2019-05-02 17:30:13 +08:00
|
|
|
#[ ${decode_result} -eq 0 ] && jq "$PAYLOAD_PATH" ${block_file}.json > ${block_file}_payload.json
|
2017-12-06 22:30:57 +08:00
|
|
|
done
|
|
|
|
|
2017-12-19 14:40:39 +08:00
|
|
|
echo_b "Update the content of orderer genesis file"
|
2019-05-02 17:30:13 +08:00
|
|
|
if [ -f ${ORDERER0_GENESIS_BLOCK} ]; then
|
2017-12-06 22:30:57 +08:00
|
|
|
echo_b "Checking existing Orderer.BatchSize.max_message_count in the genesis json"
|
2019-05-28 10:39:20 +08:00
|
|
|
jq "$MAX_BATCH_SIZE_PATH" ${ORDERER0_GENESIS_BLOCK}.json
|
2017-12-06 22:30:57 +08:00
|
|
|
|
|
|
|
echo_b "Creating new genesis json with updated Orderer.BatchSize.max_message_count"
|
2019-06-17 16:02:26 +08:00
|
|
|
jq "$MAX_BATCH_SIZE_PATH=100" ${ORDERER0_GENESIS_BLOCK}.json > ${ORDERER0_GENESIS_BLOCK}_updated.json
|
2017-12-06 22:30:57 +08:00
|
|
|
|
2019-06-17 16:02:26 +08:00
|
|
|
echo_b "Re-Encoding the updated orderer genesis json to block"
|
|
|
|
configtxlatorEncode "common.Block" ${ORDERER0_GENESIS_BLOCK}_updated.json ${ORDERER0_GENESIS_BLOCK}_updated.block
|
2017-12-06 22:30:57 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo_b "Stop configtxlator service"
|
|
|
|
docker rm -f $CTL_CONTAINER
|
|
|
|
|
|
|
|
echo_g "Test configtxlator for $MODE Passed"
|