Skip to content

Commit 012f721

Browse files
author
Jason Yellick
committed
[FAB-4821] Improve configtxlator reconfig examples
This improves the configtxlator README.md to use '.pb' as the suffix for files contain protobuf messages rather than '.proto' which confuses the 'make protos' target. It also improves the scripts for the existing examples, to use common functions and adds an interactive mode which pauses between each step, so that the user may inspect the file artifacts as they are generated. It additionally improves error checking on the output of the assorted commands, as the script would not reliably fail at the error points, but might continue several statements. Finally, it adds a new example for adding an organization to a channel. Change-Id: I5c60cefe364f41dfc0d15c1dc5dd8f9ddc85ea2b Signed-off-by: Jason Yellick <[email protected]>
1 parent 040a9b1 commit 012f721

File tree

7 files changed

+552
-130
lines changed

7 files changed

+552
-130
lines changed

examples/configtxupdate/README.md

+97-21
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ For extensibility, and because certain fields must be signed over, many proto fi
3131

3232
To convert a proto to its human readable JSON equivalent, simply post the binary proto to the rest target `http://$SERVER:$PORT/protolator/decode/<message.Name>` where `<message.Name>` is the fully qualified proto name of the message.
3333

34-
For instance, to decode a configuration block saved as `configuration_block.proto`, run the command:
34+
For instance, to decode a configuration block saved as `configuration_block.pb`, run the command:
3535

3636
```
37-
curl -X POST --data-binary @configuration_block.proto http://127.0.0.1:7059/protolator/decode/common.Block
37+
curl -X POST --data-binary @configuration_block.pb http://127.0.0.1:7059/protolator/decode/common.Block
3838
```
3939

4040
To convert the human readable JSON version of the proto message, simply post the JSON version to `http://$SERVER:$PORT/protolator/encode/<message.Name` where `<message.Name>` is again the fully qualified proto name of the message.
@@ -51,10 +51,10 @@ Any of the configuration related protos, including `common.Block`, `common.Envel
5151

5252
Given two different configurations, it is possible to compute the config update which transitions between them. Simply POST the two `common.Config` proto encoded configurations as `multipart/formdata`, with the original as field `original` and the updated as field `updated`, to `http://$SERVER:$PORT/configtxlator/compute/update-from-configs`.
5353

54-
For example, given the original config as the file `original_config.proto` and the updated config as the file `updated_config.proto` for the channel `desiredchannel`
54+
For example, given the original config as the file `original_config.pb` and the updated config as the file `updated_config.pb` for the channel `desiredchannel`:
5555

5656
```
57-
curl -X POST -F channel=desiredchannel -F original=@original_config.proto -F updated=@updated_config.proto http://127.0.0.1:7059/configtxlator/compute/update-from-configs
57+
curl -X POST -F channel=desiredchannel -F original=@original_config.pb -F updated=@updated_config.pb http://127.0.0.1:7059/configtxlator/compute/update-from-configs
5858
```
5959

6060
## Bootstraping example
@@ -72,23 +72,35 @@ $ configtxlator start
7272
2017-05-31 12:57:22.499 EDT [configtxlator] main -> INFO 001 Serving HTTP requests on port: 7059
7373
```
7474

75-
Then, in another window, build and run the `configtxgen` tool to produce a genesis block for the ordering system channel.
75+
Then, in another window, build the `configtxgen` tool.
7676

7777
```
7878
$ make configtxgen
7979
build/bin/configtxgen
8080
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "nopkcs11" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-63e0dc80f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/common/configtx/tool/configtxgen
8181
Binary available as build/bin/configtxgen
8282
```
83+
84+
It is recommended to run the example by invoking the script `fabric/example/configtxupdate/bootstrap_batchsize/script.sh` as follows:
85+
86+
```
87+
INTERACTIVE=true ./script.sh
8388
```
84-
$ configtxgen -outputBlock genesis_block.proto
89+
90+
This will write out what is happening at each step, pause, and allow you to inspect the artifacts generated before proceeding. Alternatively, you may run the steps below manually.
91+
92+
----
93+
First produce a genesis block for the ordering system channel.
94+
95+
```
96+
$ configtxgen -outputBlock genesis_block.pb
8597
2017-05-31 14:15:16.634 EDT [common/configtx/tool] main -> INFO 001 Loading configuration
8698
2017-05-31 14:15:16.646 EDT [common/configtx/tool] doOutputBlock -> INFO 002 Generating genesis block
8799
2017-05-31 14:15:16.646 EDT [common/configtx/tool] doOutputBlock -> INFO 003 Writing genesis block
88100
```
89101
Decode the genesis block into a human editable form.
90102
```
91-
curl -X POST --data-binary @genesis_block.proto http://127.0.0.1:7059/protolator/decode/common.Block > genesis_block.json
103+
curl -X POST --data-binary @genesis_block.pb http://127.0.0.1:7059/protolator/decode/common.Block > genesis_block.json
92104
```
93105
Edit the `genesis_block.json` file in your favorite JSON editor, or manipulate it programatically, here, we use the JSON CLI tool `jq`. For simplicity, we are editing the batch size for the channel, because it is a single numeric field, but any edits, including policy and MSP edits may be made here.
94106
```
@@ -106,15 +118,12 @@ $ jq "$MAXBATCHSIZEPATH" updated_genesis_block.json
106118
```
107119
The genesis block is now ready to be re-encoded into the native proto form to be used for bootstrapping.
108120
```
109-
curl -X POST --data-binary @updated_genesis_block.json http://127.0.0.1:7059/protolator/encode/common.Block > updated_genesis_block.proto
121+
curl -X POST --data-binary @updated_genesis_block.json http://127.0.0.1:7059/protolator/encode/common.Block > updated_genesis_block.pb
110122
```
111-
The `updated_genesis_block.proto` file may now be used as the genesis block for bootstrapping an ordering system channel.
123+
The `updated_genesis_block.pb` file may now be used as the genesis block for bootstrapping an ordering system channel.
112124

113125
## Reconfiguration example
114126

115-
Reconfiguring a channel can be performed in a very similar way to modifying a genesis config.
116-
117-
118127
First build and start the `configtxlator`.
119128

120129
```
@@ -143,17 +152,28 @@ build/bin/orderer
143152
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-63e0dc80f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/orderer
144153
Binary available as build/bin/orderer
145154
```
146-
147155
Start the orderer using the default options, including the provisional bootstrapper which will create a `testchainid` ordering system channel.
148156

149157
```
150158
ORDERER_GENERAL_LOGLEVEL=debug orderer
151159
```
152160

161+
Reconfiguring a channel can be performed in a very similar way to modifying a genesis config.
162+
163+
The recommended path to proceed with this example is to run the script located at `fabric/example/configtxupdate/reconfigure_batchsize/script.sh` by invoking
164+
165+
```
166+
INTERACTIVE=true ./script.sh
167+
```
168+
169+
This will write out what is happening at each step, pause, and allow you to inspect the artifacts generated before proceeding. Alternatively, you may run the steps below manually.
170+
171+
----
172+
153173
At this point, executing `examples/reconfig/script.sh` in another window will increase the batch size of the ordering system channel by 1, or, you may follow the steps below to do the process interactively.
154174

155175
```
156-
$ peer channel fetch config config_block.proto -o 127.0.0.1:7050 -c testchainid
176+
$ peer channel fetch config config_block.pb -o 127.0.0.1:7050 -c testchainid
157177
2017-05-31 15:11:37.617 EDT [msp] getMspConfig -> INFO 001 intermediate certs folder not found at [/home/yellickj/go/src/github.com/hyperledger/fabric/sampleconfig/msp/intermediatecerts]. Skipping.: [stat /home/yellickj/go/src/github.com/hyperledger/fabric/sampleconfig/msp/intermediatecerts: no such file or directory]
158178
2017-05-31 15:11:37.617 EDT [msp] getMspConfig -> INFO 002 crls folder not found at [/home/yellickj/go/src/github.com/hyperledger/fabric/sampleconfig/msp/intermediatecerts]. Skipping.: [stat /home/yellickj/go/src/github.com/hyperledger/fabric/sampleconfig/msp/crls: no such file or directory]
159179
Received block: 1
@@ -164,7 +184,7 @@ Received block: 1
164184
Send the config block to the `configtxlator` service for decoding:
165185

166186
```
167-
curl -X POST --data-binary @config_block.proto http://127.0.0.1:7059/protolator/decode/common.Block > config_block.json
187+
curl -X POST --data-binary @config_block.pb http://127.0.0.1:7059/protolator/decode/common.Block > config_block.json
168188
```
169189

170190
Extract the config section from the block:
@@ -182,25 +202,25 @@ jq ".channel_group.groups.Orderer.values.BatchSize.value.max_message_count = 30"
182202
Re-encode both the original config, and the updated config into proto.
183203

184204
```
185-
curl -X POST --data-binary @config.json http://127.0.0.1:7059/protolator/encode/common.Config > config.proto
205+
curl -X POST --data-binary @config.json http://127.0.0.1:7059/protolator/encode/common.Config > config.pb
186206
```
187207

188208
```
189-
curl -X POST --data-binary @updated_config.json http://127.0.0.1:7059/protolator/encode/common.Config > updated_config.proto
209+
curl -X POST --data-binary @updated_config.json http://127.0.0.1:7059/protolator/encode/common.Config > updated_config.pb
190210
```
191211

192212
Now, with both configs properly encoded, send them to the `configtxlator` service to compute the config update which transitions between the two.
193213

194214
```
195-
curl -X POST -F original=@config.proto -F updated=@updated_config.proto http://127.0.0.1:7059/configtxlator/compute/update-from-configs -F channel=testchainid > config_update.proto
215+
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=testchainid > config_update.pb
196216
```
197217

198218
At this point, the computed config update is now prepared, and traditionally, an SDK would be used to sign and wrap this message, but in the interest of using only the peer cli, the `configtxlator` can also be used for this task.
199219

200220
First, we decode the ConfigUpdate so that we may work with it as text.
201221

202222
```
203-
$ curl -X POST --data-binary @config_update.proto http://127.0.0.1:7059/protolator/decode/common.ConfigUpdate > config_update.json
223+
$ curl -X POST --data-binary @config_update.pb http://127.0.0.1:7059/protolator/decode/common.ConfigUpdate > config_update.json
204224
```
205225

206226
Then, we wrap it in an envelope message.
@@ -212,11 +232,67 @@ echo '{"payload":{"header":{"channel_header":{"channel_id":"testchainid", "type"
212232
And finally, convert it back into the proto form of a full fledged config transaction.
213233

214234
```
215-
curl -X POST --data-binary @config_update_as_envelope.json http://127.0.0.1:7059/protolator/encode/common.Envelope > config_update_as_envelope.proto
235+
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
216236
```
217237

218238
Finally, submit the config update transaction to ordering to perform a config update.
219239

220240
```
221-
peer channel update -f config_update_as_envelope.proto -c testchainid -o 127.0.0.1:7050
241+
peer channel update -f config_update_as_envelope.pb -c testchainid -o 127.0.0.1:7050
242+
```
243+
244+
## Adding an organization
245+
246+
First build and start the `configtxlator`.
247+
248+
```
249+
$ make configtxlator
250+
build/bin/configtxlator
251+
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-42434e60f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/common/tools/configtxlator
252+
Binary available as build/bin/configtxlator
253+
```
254+
```
255+
$ configtxlator start
256+
2017-05-31 12:57:22.499 EDT [configtxlator] main -> INFO 001 Serving HTTP requests on port: 7059
257+
```
258+
259+
Then, in another window, build the `configtxgen` tool.
260+
261+
```
262+
$ make configtxgen
263+
build/bin/configtxgen
264+
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "nopkcs11" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-63e0dc80f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/common/configtx/tool/configtxgen
265+
Binary available as build/bin/configtxgen
222266
```
267+
268+
Then, build the orderer and peer.
269+
270+
```
271+
$ make peer
272+
Installing chaintool
273+
curl -L https://github.com/hyperledger/fabric-chaintool/releases/download/v0.10.3/chaintool > build/bin/chaintool
274+
...
275+
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-63e0dc80f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/peer
276+
Binary available as build/bin/peer
277+
278+
$ make orderer
279+
build/bin/orderer
280+
CGO_CFLAGS=" " GOBIN=/home/yellickj/go/src/github.com/hyperledger/fabric/build/bin go install -tags "" -ldflags "-X github.com/hyperledger/fabric/common/metadata.Version=1.0.0-alpha3-snapshot-63e0dc80f -X github.com/hyperledger/fabric/common/metadata.BaseVersion=0.3.1 -X github.com/hyperledger/fabric/common/metadata.BaseDockerLabel=org.hyperledger.fabric -X github.com/hyperledger/fabric/common/metadata.DockerNamespace=hyperledger -X github.com/hyperledger/fabric/common/metadata.BaseDockerNamespace=hyperledger" github.com/hyperledger/fabric/orderer
281+
Binary available as build/bin/orderer
282+
```
283+
284+
Start the orderer using the `SampleDevModSolo` profile option.
285+
286+
```
287+
ORDERER_GENERAL_LOGLEVEL=debug ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo orderer
288+
```
289+
290+
The process to add an organization then follows exactly like the batch size example, but, instead of setting the batch size, a new org is defined at the application level. Adding an organization is slightly more involved, because we must first create a channel, then modify its membership set.
291+
292+
To see this example run the script `fabric/examples/configtxupdate/reconfig_membership/script.sh` by:
293+
294+
```
295+
INTERACTIVE=true ./script.sh
296+
```
297+
298+
Running the script interactively (as above), you may inspect the artifacts produced as they appear in the `example_output` directory.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
CDIR=$(dirname $(basename "$0"))
4+
5+
: ${OUTDIR:="example_output"}
6+
mkdir -p ${OUTDIR} || die "could not create output dir ${OUTDIR}"
7+
8+
GENESIS_BLOCK_PB="${OUTDIR}/genesis_block.pb"
9+
GENESIS_BLOCK_JSON="${OUTDIR}/genesis_block.json"
10+
UPDATED_GENESIS_BLOCK_JSON="${OUTDIR}/updated_genesis_block.json"
11+
UPDATED_GENESIS_BLOCK_PB="${OUTDIR}/updated_genesis_block.pb"
12+
13+
. ${CDIR}/../common_scripts/common.sh
14+
15+
findConfigtxgen || die "no configtxgen present"
16+
17+
bigMsg "Creating bootstrap block"
18+
19+
echo -e "Executing:\n\tconfigtxgen -outputBlock '${GENESIS_BLOCK_PB}' -profile SampleSingleMSPSolo"
20+
$CONFIGTXGEN -outputBlock "${GENESIS_BLOCK_PB}" -profile SampleSingleMSPSolo 2>/dev/null || die "Error generating genesis block"
21+
22+
pauseIfInteractive
23+
24+
bigMsg "Decoding genesis block"
25+
decode common.Block "${GENESIS_BLOCK_PB}" "${GENESIS_BLOCK_JSON}"
26+
27+
bigMsg "Updating the genesis config"
28+
ORIGINAL_BATCHSIZE=$(jq ".data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count" genesis_block.json)
29+
NEW_BATCHSIZE=$(( ${ORIGINAL_BATCHSIZE} + 1 ))
30+
echo "Updating batch size from ${ORIGINAL_BATCHSIZE} to ${NEW_BATCHSIZE}."
31+
echo -e "Executing\n\tjq '.data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count = ${NEW_BATCHSIZE}' '${GENESIS_BLOCK_JSON}' > '${UPDATED_GENESIS_BLOCK_JSON}'"
32+
jq ".data.data[0].payload.data.config.channel_group.groups.Orderer.values.BatchSize.value.max_message_count = ${NEW_BATCHSIZE}" "${GENESIS_BLOCK_JSON}" > "${UPDATED_GENESIS_BLOCK_JSON}"
33+
34+
pauseIfInteractive
35+
36+
bigMsg "Re-encoding the updated genesis block"
37+
38+
encode common.Block "${UPDATED_GENESIS_BLOCK_JSON}" "${UPDATED_GENESIS_BLOCK_PB}"
39+
40+
bigMsg "Bootstrapping edit complete"

examples/configtxupdate/bootstrapping/script.sh

-38
This file was deleted.

0 commit comments

Comments
 (0)