fabric1.4动态添加组织

2019-12-27  本文已影响0人  liurenhao

动态添加组织

准备liuhao2-crypto.yaml配置文件

PeerOrgs:
  - Name: liuhao2
    Domain: liuhao2.yinhai.com
    EnableNodeOUs: true
    Template:
      Count: 2
    Users:
      Count: 1

生成证书文件

$ cryptogen generate --config=./liuhao2-crypto.yaml

准备configtx.yaml文件

Organizations:
    - &liuhao2
        Name: liuhao2MSP

        # ID to load the MSP definition as
        ID: liuhao2MSP

        MSPDir: crypto-config/peerOrganizations/liuhao2.yinhai.com/msp

        Policies:
            Readers:
                Type: Signature
                Rule: "OR('liuhao2MSP.admin', 'liuhao2MSP.peer', 'liuhao2MSP.client')"
            Writers:
                Type: Signature
                Rule: "OR('liuhao2MSP.admin', 'liuhao2MSP.client')"
            Admins:
                Type: Signature
                Rule: "OR('liuhao2MSP.admin')"

        AnchorPeers:
            - Host: peer0.liuhao2.yinhai.com
              Port: 11051

生成通道配置交易

configtxgen -printOrg liuhao2MSP > ../channel-artifacts/liuhao2.json

获取通道最新配置区块

进入cli

$ docker exec -it cli

获取liuhaochannel通道最新配置块

$ peer channel fetch config config_block_liuhao.pb -o orderer.yinhai.com:7050 -c liuhaochannel --tls --cafile $ORDER_CA

对配置块进行json format

$ configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > config_liuhaochannel.json

liuhao2.json加入到配置中

$ jq -s '.[0] * {"channel_group":{"groups":{"Application":{"groups": {"liuhao2MSP":.[1]}}}}}' config_liuhaochannel.json ./channel-artifacts/liuhao2.json > modified_config_liuhaochannel.json

对比modified_config_liuhaochannel.jsonconfig_liuhaochannel.json,生成更改配置

$ configtxlator proto_encode --input config_liuhaochannel.json --type common.Config --output config_liuhaochannel.pb
$ configtxlator proto_encode --input modified_config_liuhaochannel.json --type common.Config --output modified_config_liuhaochannel.pb
$ configtxlator compute_update --channel_id liuhaochannel --original config_liuhaochannel.pb --updated modified_config_liuhaochannel.pb --output liuhao2_update.pb
$ configtxlator proto_decode --input liuhao2_update.pb --type common.ConfigUpdate | jq . > liuhao2_update.json

包装信息

$ echo '{"payload":{"header":{"channel_header":{"channel_id":"liuhaochannel", "type":2}},"data":{"config_update":'$(cat liuhao2_update.json)'}}}' | jq . > liuhao2_update_in_envelope.json
$ configtxlator proto_encode --input liuhao2_update_in_envelope.json --type common.Envelope --output liuhao2_update_in_envelope.pb

签名并提交配置信息

$ peer channel signconfigtx -f liuhao2_update_in_envelope.pb

注:默认策略需要通道内大多数组织签名,需要大多数组织都执行以上操作

切换到另一个组织,执行提交(会自动签名)

$ peer channel update -f liuhao2_update_in_envelope.pb -c liuhaochannel -o orderer.yinhai.com:7050 --tls --cafile $ORDER_CA
上一篇下一篇

猜你喜欢

热点阅读