7.1 KiB
7.1 KiB
Start the configtxlator
First start a fabric network with docker-compose-2orgs-4peers.yaml, and make sure the network can work,
then we will use configtxlator
to start an http server listening on the designated port and process request.
$ docker exec -it fab-cli bash
$ configtxlator start
UTC [configtxlator] startServer -> INFO 001 Serving HTTP requests on 0.0.0.0:7059
This logs appears, indicating startup successful.
Function
translation
/protolator/decode/{msgName}
Any of the configuration related protos, including common.Block
, common.Envelope
, common.ConfigEnvelope
,
common.ConfigUpdateEnvelope
, common.Configuration
, and common.ConfigUpdate
are valid targets for these URLs.
this will produces human readable version of config, such as translate to json
Execute following command in new terminal,
$ docker exec -it fabric-cli bash
$ cd channel-artifacts
$ curl -X POST --data-binary @businesschannel_0.block http://127.0.0.1:7059/protolator/decode/common.Block > businesschannel_0.json
for channel.tx, use following msgType.
curl -X POST --data-binary @channel.tx http://127.0.0.1:7059/protolator/decode/common.Envelope > channel.json
/protolator/encode/{msgName}
And we can transform json to proto.
$ curl -X POST --data-binary @businesschannel_0.json http://127.0.0.1:7059/protolator/encode/common.Block > businesschannel_0.block
Re-Configuration example
- here we will introduce how to re-configuration config.block, first fetch the block and translate it to json.
$ ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
$ peer channel fetch config -o orderer.example.com:7050 -c businesschannel --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA|xargs mv true config_block.pb
$ peer channel fetch config config_block.pb -o orderer.example.com:7050 -c businesschannel # with no-tls
$ curl -X POST --data-binary @config_block.pb http://127.0.0.1:7059/protolator/decode/common.Block > config_block.json
- Extract the config section from the block:
$ apt-get install jq
$ jq .data.data[0].payload.data.config config_block.json > config.json
- edit the config.json, set the batch size to 11, and saving it as update_config.json
4. $ jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count = 11" config.json > updated_config.json
- Re-encode both the original config, and the updated config into proto:
$ curl -X POST --data-binary @config.json http://127.0.0.1:7059/protolator/encode/common.Config > config.pb
$ curl -X POST --data-binary @updated_config.json http://127.0.0.1:7059/protolator/encode/common.Config > updated_config.pb
- send them to the configtxlator service to compute the config update which transitions between the two.
$ curl -X POST -F original=@config.pb -F updated=@updated_config.pb http://127.0.0.1:7059/configtxlator/compute/update-from-configs -F channel=businesschannel > config_update.pb
- we decode the ConfigUpdate so that we may work with it as text:
$ curl -X POST --data-binary @config_update.pb http://127.0.0.1:7059/protolator/decode/common.ConfigUpdate > config_update.json
- Then, we wrap it in an envelope message:
$ echo '{"payload":{"header":{"channel_header":{"channel_id":"businesschannel", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' > config_update_as_envelope.json
- Next, convert it back into the proto form of a full fledged config transaction:
$ curl -X POST --data-binary @config_update_as_envelope.json http://127.0.0.1:7059/protolator/encode/common.Envelope > config_update_as_envelope.pb
- Finally, submit the config update transaction to ordering to perform a config update.
$ CORE_PEER_LOCALMSPID=OrdererMSP
$ CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
$ peer channel update -o orderer.example.com:7050 -c businesschannel -f config_update_as_envelope.pb --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA
$ peer channel update -f config_update_as_envelope.pb -o orderer.example.com:7050 -c businesschannel # with no-tls
[WIP]Add an organization
- Execute
configtxgen
to generatechannel.tx
$ ORDERER_GENERAL_GENESISPROFILE=SampleDevModSolo #Change this env before start ordering service.
$ docker exec -it fabric-cli bash
$ configtxgen -profile SampleDevModSolo -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID businesschannel
- create channel use channel.tx, then we will get block businesschannel.block
$ peer channel create -o orderer.example.com:7050 -c businesschannel -f ./channel-artifacts/channel.tx
- Start configtxlator
$ docker exec -it fabric-cli bash
$ configtxlator start
- In a new window, decoding current genesis block
$ curl -X POST --data-binary @businesschannel.block http://127.0.0.1:7059/protolator/decode/common.Block > businesschannel.json
- Extract current config
jq .data.data[0].payload.data.config businesschannel.json > config.json
- generating new config
jq '. * {"channel_group":{"groups":{"Application":{"groups":{"ExampleOrg": .channel_group.groups.Application.groups.SampleOrg}}}}}' config.json |
jq '.channel_group.groups.Application.groups.ExampleOrg.values.MSP.value.config.name = "ExampleOrg"' > update_config.json
- Translate config.json and update_config.json to proto
curl -X POST --data-binary @config.json http://127.0.0.1:7059/protolator/encode/common.Config > config.pb
curl -X POST --data-binary @update_config.json http://127.0.0.1:7059/protolator/encode/common.Config > update_config.pb
- Computing config update
curl -X POST -F original=@config.pb -F updated=@update_config.pb http://127.0.0.1:7059/configtxlator/compute/update-from-configs -F channel=businesschannel > config_update.pb
- Decoding config update
curl -X POST --data-binary @config_update.pb http://127.0.0.1:7059/protolator/decode/common.ConfigUpdate > config_update.json
- Generating config update envelope
echo '{"payload":{"header":{"channel_header":{"channel_id":"businesschannel", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' > config_update_in_envelope.json
- Next, convert it back into the proto form of a full fledged config transaction:
curl -X POST --data-binary @config_update_in_envelope.json http://127.0.0.1:7059/protolator/encode/common.Envelope > config_update_in_envelope.pb
- Sending config update to channel
$ CORE_PEER_LOCALMSPID=OrdererMSP
$ CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
$ peer channel update -o orderer.example.com:7050 -c businesschannel -f config_update_in_envelope.pb --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA
$ (optional)peer channel update -f config_update_as_envelope.pb -o orderer.example.com:7050 -c businesschannel # with no-tls