fabric动态增加组织(二)组织加入通道

新增组织加入通道可以查看这篇博文,https://blog.csdn.net/btqszl/article/details/79071453我按照步骤走了之后发现组织可以添加到新增通道但是执行链码有问题,新增组织加入原有的通道会失败,因为无法获得原有组织对新加组织的签名,所以会一直报错,关于对组织签名用到的peer channel signconfigtx在下篇博文使用,https://blog.csdn.net/qq_26288303/article/details/82500190可以做成一个完整的例子。
描述的还很到位,但是需要注意几点:
1、新加组织的节点配置文件需要指定与原有组织处于同一网络,需要把我上篇博文中提到的配置文件做如下修改:
新增组织节点的配置需要指定网络networks,如每个新加节点都需要指定网络fgh

version: '2'
networks:
  fgh: 

services:

  peer0.org3.example.com:
    container_name: peer0.org3.example.com
    extends:
      file:  base/docker-compose-base-org3.yaml
      service: peer0.org3.example.com
    networks:
      - fgh    

同时初始的配置文件也需要增加以上配置

networks:
  fgh: 
services:
  orderer.example.com:
    extends:
      file:   base/docker-compose-base.yaml
      service: orderer.example.com
    container_name: orderer.example.com
    networks:
      - fgh 

2、配置文件启动需要在同一目录下,一般docker容器中存在网络命名规则为:
目录名_网络名,例如,在base目录下启动新增组织的配置文件,指定网络名为fgh则容器中网络名为:base_fgh
3、docker命令
使用 docker network ls 查看docker容器中网络
这里写图片描述
docker inspect peer0 查看peer0所处网络
这里写图片描述
可以看到networks指定为:e2ecli_fgh
4、组织加入通道
当执行完如下步骤时表示已经通知orderer更新,将增量包中的org3/org4组织信息加入到通道

export CORE_PEER_LOCALMSPID="OrdererMSP"
eport CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
export 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 update -o orderer.example.com:7050 -c testchainid -f ./channel-artifacts/config_update_envelope.tx --tls --cafile $ORDERER_CA

可以根据之前的通道信息新建通道

export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp

peer channel create -o orderer.example.com:7050 -c mychannel2 -f ./channel-artifacts/channel2.tx --tls true --cafile $ORDERER_CA

之后可以切换环境变量,将节点加入现有的通道中。例如:

export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
export CORE_PEER_ADDRESS=peer0.org3.example.com:7051 
peer channel join -b mychannel2.block

这是将org3加入通道,还可以切换到org1或者org2然后执行peer channel join命令
5、关于通道信息文件的创建

Profiles:
    TwoOrgsOrdererGenesis:
        Orderer:
            <<: *OrdererDefaults
            Organizations:
                - *OrdererOrg
        Consortiums:
            SampleConsortium:
                Organizations:
                    - *Org1
                    - *Org2
#                    - *Org3
    TwoOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1
                - *Org2
#                - *Org3
    NewOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org3
                - *Org1
                - *Org2
    OneOrgsChannel:
        Consortium: SampleConsortium
        Application:
            <<: *ApplicationDefaults
            Organizations:
                - *Org1

在profiles节点新加入OneOrgsChannel和NewOrgsChannel,以及它们包含的组织信息,代表着新建通道文件中初始存在的组织信息。
这里写图片描述
在organizations节点中新增org3组织信息。

../../release/linux-amd64/bin/configtxgen -profile NewOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel2.tx -channelID mychannel2

创建一个名为channnel2.tx的通道文件信息存放在channel-artifacts目录下,用于第四点中的创建通道。
6、关于链码的配置
在前面指定orderer和peer的网络必须指定chaincode的网络,否则在链码实例化时会出现timeout,无法连接到orderer,在peer_base找到CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE这项配置,从注释就可以看出这是配置链码容器的网络,需要与之前配置的网络名一样

version: '2'
services:
  peer-base:
    image: hyperledger/fabric-peer
    environment:
      - CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
      # the following setting starts chaincode containers on the same
      # bridge network as the peers
      # https://docs.docker.com/compose/networking/
      - CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE=e2ecli_fgh
      #- CORE_LOGGING_LEVEL=ERROR
      - CORE_LOGGING_LEVEL=DEBUG
      - CORE_PEER_TLS_ENABLED=true
      - CORE_PEER_GOSSIP_USELEADERELECTION=true
      - CORE_PEER_GOSSIP_ORGLEADER=false
      - CORE_PEER_PROFILE_ENABLED=true
      - CORE_PEER_TLS_CERT_FILE=/etc/hyperledger/fabric/tls/server.crt
      - CORE_PEER_TLS_KEY_FILE=/etc/hyperledger/fabric/tls/server.key
      - CORE_PEER_TLS_ROOTCERT_FILE=/etc/hyperledger/fabric/tls/ca.crt
    working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
    command: peer node start
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值