github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/examples/configtxupdate/reconfig_batchsize/script.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  CDIR=$(dirname $(basename "$0"))
     9  
    10  # Defaults
    11  : ${CHANNEL:="testchainid"}
    12  : ${OUTDIR:="example_output"}
    13  mkdir -p ${OUTDIR} || die "could not create output dir ${OUTDIR}"
    14  
    15  CONFIG_BLOCK_PB="${OUTDIR}/config_block.pb"
    16  CONFIG_BLOCK_JSON="${OUTDIR}/config_block.json"
    17  CONFIG_JSON="${OUTDIR}/config.json"
    18  CONFIG_PB="${OUTDIR}/config.pb"
    19  UPDATED_CONFIG_JSON="${OUTDIR}/updated_config.json"
    20  UPDATED_CONFIG_PB="${OUTDIR}/updated_config.pb"
    21  CONFIG_UPDATE_PB="${OUTDIR}/config_update.pb"
    22  CONFIG_UPDATE_JSON="${OUTDIR}/config_update.json"
    23  CONFIG_UPDATE_IN_ENVELOPE_PB="${OUTDIR}/config_update_in_envelope.pb"
    24  CONFIG_UPDATE_IN_ENVELOPE_JSON="${OUTDIR}/config_update_in_envelope.json"
    25  
    26  . ${CDIR}/../common_scripts/common.sh
    27  
    28  bigMsg "Beginning config update batchsize example"
    29  
    30  findPeer || die "could not find peer binary"
    31  
    32  bigMsg "Fetching current config block"
    33  
    34  fetchConfigBlock "${CHANNEL}" "${CONFIG_BLOCK_PB}"
    35  
    36  bigMsg "Decoding current config block"
    37  
    38  decode common.Block "${CONFIG_BLOCK_PB}" "${CONFIG_BLOCK_JSON}"
    39  
    40  bigMsg "Isolating current config"
    41  
    42  echo -e "Executing:\tjq .data.data[0].payload.data.config '${CONFIG_BLOCK_JSON}' > '${CONFIG_JSON}'"
    43  jq .data.data[0].payload.data.config "${CONFIG_BLOCK_JSON}" > "${CONFIG_JSON}" || die "Unable to extract config from config block"
    44  
    45  pauseIfInteractive
    46  
    47  bigMsg "Generating new config"
    48  
    49  OLD_BATCH_SIZE=$(jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count" "${CONFIG_JSON}")
    50  NEW_BATCH_SIZE=$(($OLD_BATCH_SIZE+1))
    51  
    52  echo -e "Executing:\tjq '.channel_group.groups.Orderer.values.BatchSize.value.max_message_count = $NEW_BATCH_SIZE' '${CONFIG_JSON}'  > '${UPDATED_CONFIG_JSON}'"
    53  jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count = $NEW_BATCH_SIZE" "${CONFIG_JSON}"  > "${UPDATED_CONFIG_JSON}" || die "Error updating batch size"
    54  
    55  pauseIfInteractive
    56  
    57  bigMsg "Translating original config to proto"
    58  
    59  encode common.Config "${CONFIG_JSON}" "${CONFIG_PB}"
    60  
    61  bigMsg "Translating updated config to proto"
    62  
    63  encode common.Config "${UPDATED_CONFIG_JSON}" "${UPDATED_CONFIG_PB}"
    64  
    65  bigMsg "Computing config update"
    66  
    67  computeUpdate "${CHANNEL}" "${CONFIG_PB}" "${UPDATED_CONFIG_PB}" "${CONFIG_UPDATE_PB}"
    68  
    69  bigMsg "Decoding config update"
    70  
    71  decode common.ConfigUpdate "${CONFIG_UPDATE_PB}" "${CONFIG_UPDATE_JSON}"
    72  
    73  bigMsg "Generating config update envelope"
    74  
    75  wrapConfigEnvelope "${CONFIG_UPDATE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_JSON}"
    76  
    77  bigMsg "Encoding config update envelope"
    78  
    79  encode common.Envelope "${CONFIG_UPDATE_IN_ENVELOPE_JSON}" "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    80  
    81  bigMsg "Sending config update to channel"
    82  
    83  updateConfig ${CHANNEL} "${CONFIG_UPDATE_IN_ENVELOPE_PB}"
    84  
    85  bigMsg "Config Update Successful!"