-
Notifications
You must be signed in to change notification settings - Fork 1
/
configtxlator.txt
71 lines (51 loc) · 3.88 KB
/
configtxlator.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Q1. Use configtxlator to update the channel configuration. How does it work,
how can you join Org3 to existing channel?
Example for artxchg2 project
----------------------------
The network is initially configured with Org1, Org2, Org3, ArtMarket and OrgOrderer organizations. There are two channels defined,
org1 = {Org1, ArtMarket} and org2 = {Org2, ArtMarket}. So initially Org3 exists outside any channels and will be added to channel
org2 during this example. Using configtxlator tool allows to decode/encode internal network data from protobuf binarny format to
json and in the opposite way.
Run configtxlator:
export PATH=/home/adam/hlf/FabricBinaries/bin:$PATH
configtxlator start &
Setup the network without Org3 in channel org2:
cp configtx-withoutOrg3inChannel.yaml configtx.yaml
./setup.sh
Start network and create channels:
docker-compose -f docker-compose-artxchg2.yaml up
docker exec cli.ArtMarket bash -c 'peer channel create -c org1 -f ./channels/Org1.tx -o orderer0.artxchg2.com:7050 --timeout 30'
docker exec cli.ArtMarket bash -c 'peer channel create -c org2 -f ./channels/Org2.tx -o orderer0.artxchg2.com:7050 --timeout 30'
Fetch current setup:
docker exec cli.ArtMarket bash -c 'peer channel fetch config ./channels/config_block-withoutOrg3inChannel.pb -c org2 -o orderer0.artxchg2.com:7050'
mv channels/config_block-withoutOrg3inChannel.pb ./config_block-withoutOrg3inChannel.pb
Translate it from PB to JSON:
curl -X POST --data-binary @config_block-withoutOrg3inChannel.pb http://127.0.0.1:7059/protolator/decode/common.Block > config_block-withoutOrg3inChannel.json
Strip headers:
jq .data.data[0].payload.data.config config_block-withoutOrg3inChannel.json > config-withoutOrg3inChannel.json
Create updated setup:
cp config-withoutOrg3inChannel.json config-withOrg3inChannel.json
# add Org3 to the channel by updating the config-withOrg3inChannel.json
# NOTE: for this example config-withOrg3inChannel.json was actually created by fetching channel configuration with Org3 in channel
vim config-withOrg3inChannel.json
Encode original config to PB:
curl -X POST --data-binary @config-withoutOrg3inChannel.json http://127.0.0.1:7059/protolator/encode/common.Config > config-withoutOrg3inChannel.pb
Encode updated config to PB:
curl -X POST --data-binary @config-withOrg3inChannel.json http://127.0.0.1:7059/protolator/encode/common.Config > config-withOrg3inChannel.pb
Create delta update:
curl -X POST -F [email protected] -F [email protected] http://127.0.0.1:7059/configtxlator/compute/update-from-configs -F channel=org2 > config_update-Org3inChannel.pb
Translate delta update from PB to JSON:
curl -X POST --data-binary @config_update-Org3inChannel.pb http://127.0.0.1:7059/protolator/decode/common.ConfigUpdate > config_update-Org3inChannel.json
Wrap it into headers envelope:
echo '{"payload":{"header":{"channel_header":{"channel_id":"org2", "type":2}},"data":{"config_update":'$(cat config_update-Org3inChannel.json)'}}}' > config_update-Org3inChannel-asEnvelope.json
Translate it back to PB:
curl -X POST --data-binary @config_update-Org3inChannel-asEnvelope.json http://127.0.0.1:7059/protolator/encode/common.Envelope > config_update-Org3inChannel-asEnvelope.pb
Sign it by ArtMarket:
mv config_update-Org3inChannel-asEnvelope.pb channels/config_update-Org3inChannel-asEnvelope.pb
docker exec cli.ArtMarket bash -c 'peer channel signconfigtx -f ./channels/config_update-Org3inChannel-asEnvelope.pb -o orderer0.artxchg2.com:7050'
Sign it by Org2:
docker exec cli0.Org2 bash -c 'peer channel signconfigtx -f ./channels/config_update-Org3inChannel-asEnvelope.pb -o orderer0.artxchg2.com:7050'
Update channel configuration:
docker exec cli.ArtMarket bash -c 'peer channel update -f ./channels/config_update-Org3inChannel-asEnvelope.pb -o orderer0.artxchg2.com:7050 -c org2'
Verify it works:
docker exec cli0.Org3 bash -c 'peer channel join -b org2.block'