fabric createChannel创建通道

使用docker和docker-compose创建名为'mychannel'的通道。生成通道创世块并加入组织1和组织2的orderer节点。接着,组织1和组织2的peer节点加入通道。最后,设置两个组织的锚节点。
摘要由CSDN通过智能技术生成

在这里插入图片描述在这里插入图片描述

[root@iZ8vbjcbks7pzj9po96hleZ test-network]# ./network.sh createChannel
Using docker and docker-compose
Creating channel ‘mychannel’.
If network is not up, starting nodes with CLI timeout of ‘5’ tries and CLI delay of ‘3’ seconds and using database 'leveldb
Network Running Already
Using docker and docker-compose
Generating channel genesis block ‘mychannel.block’
/opt/fabric/scripts/fabric-samples/bin/configtxgen

  • configtxgen -profile TwoOrgsApplicationGenesis -outputBlock ./channel-artifacts/mychannel.block -channelID mychannel
    2022-06-08 14:48:23.792 CST 0001 INFO [common.tools.configtxgen] main -> Loading configuration
    2022-06-08 14:48:23.799 CST 0002 INFO [common.tools.configtxgen.localconfig] completeInitialization -> orderer type: etcdraft
    2022-06-08 14:48:23.799 CST 0003 INFO [common.tools.configtxgen.localconfig] completeInitialization -> Orderer.EtcdRaft.Options unset, setting to tick_interval:“500ms” election_tick:10 heartbeat_tick:1 max_inflight_blocks:5 snapshot_interval_size:16777216
    2022-06-08 14:48:23.799 CST 0004 INFO [common.tools.configtxgen.localconfig] Load -> Loaded configuration: /opt/fabric/scripts/fabric-samples/test-network/configtx/configtx.yaml
    2022-06-08 14:48:23.800 CST 0005 INFO [common.tools.configtxgen] doOutputBlock -> Generating genesis block
    2022-06-08 14:48:23.800 CST 0006 INFO [common.tools.configtxgen] doOutputBlock -> Creating application channel genesis block
    2022-06-08 14:48:23.800 CST 0007 INFO [common.tools.configtxgen] doOutputBlock -> Writing genesis block

  • res=0
    Creating channel mychannel
    Using organization 1

  • osnadmin channel join --channelID mychannel --config-block ./channel-artifacts/mychannel.block -o localhost:7053 --ca-file /opt/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem --client-cert /opt/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt --client-key /opt/fabric/scripts/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key

  • res=0
    Status: 201
    {
    “name”: “mychannel”,
    “url”: “/participation/v1/channels/mychannel”,
    “consensusRelation”: “consenter”,
    “status”: “active”,
    “height”: 1
    }

Channel ‘mychannel’ created
Joining org1 peer to the channel…
Using organization 1

  • peer channel join -b ./channel-artifacts/mychannel.block
  • res=0
    2022-06-08 14:48:29.863 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 14:48:29.881 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
    Joining org2 peer to the channel…
    Using organization 2
  • peer channel join -b ./channel-artifacts/mychannel.block
  • res=0
    2022-06-08 14:48:32.920 CST 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 14:48:32.937 CST 0002 INFO [channelCmd] executeJoin -> Successfully submitted proposal to join channel
    Setting anchor peer for org1…
    Using organization 1
    Fetching channel config for channel mychannel
    Using organization 1
    Fetching the most recent configuration block for the channel
  • peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
    2022-06-08 06:48:33.046 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 06:48:33.048 UTC 0002 INFO [cli.common] readBlock -> Received block: 0
    2022-06-08 06:48:33.048 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 0
    2022-06-08 06:48:33.049 UTC 0004 INFO [cli.common] readBlock -> Received block: 0
    Decoding config block to JSON and isolating config to Org1MSPconfig.json
  • configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
  • jq ‘.data.data[0].payload.data.config’ config_block.json
    Generating anchor peer update transaction for Org1 on channel mychannel
  • jq ‘.channel_group.groups.Application.groups.Org1MSP.values += {“AnchorPeers”:{“mod_policy”: “Admins”,“value”:{“anchor_peers”: [{“host”: “peer0.org1.example.com”,“port”: 7051}]},“version”: “0”}}’ Org1MSPconfig.json
  • configtxlator proto_encode --input Org1MSPconfig.json --type common.Config --output original_config.pb
  • configtxlator proto_encode --input Org1MSPmodified_config.json --type common.Config --output modified_config.pb
  • configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
  • configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
  • jq .
    ++ cat config_update.json
  • echo ‘{“payload”:{“header”:{“channel_header”:{“channel_id”:“mychannel”, “type”:2}},“data”:{“config_update”:{’ ‘“channel_id”:’ ‘“mychannel”,’ ‘“isolated_data”:’ ‘{},’ ‘“read_set”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Application”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Org1MSP”:’ ‘{’ ‘“groups”:’ ‘{},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{’ ‘“Admins”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Endorsement”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Readers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Writers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“values”:’ ‘{’ ‘“MSP”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“value”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘},’ ‘“write_set”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Application”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Org1MSP”:’ ‘{’ ‘“groups”:’ ‘{},’ ‘“mod_policy”:’ ‘“Admins”,’ ‘“policies”:’ ‘{’ ‘“Admins”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Endorsement”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Readers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Writers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“values”:’ ‘{’ ‘“AnchorPeers”:’ ‘{’ ‘“mod_policy”:’ ‘“Admins”,’ ‘“value”:’ ‘{’ ‘“anchor_peers”:’ ‘[’ ‘{’ ‘“host”:’ ‘“peer0.org1.example.com”,’ ‘“port”:’ 7051 ‘}’ ‘]’ ‘},’ ‘“version”:’ ‘“0”’ ‘},’ ‘“MSP”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“value”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“version”:’ ‘“1”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘}}}}’
  • configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org1MSPanchors.tx
    2022-06-08 06:48:33.210 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 06:48:33.218 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
    Anchor peer set for org ‘Org1MSP’ on channel ‘mychannel’
    Setting anchor peer for org2…
    Using organization 2
    Fetching channel config for channel mychannel
    Using organization 2
    Fetching the most recent configuration block for the channel
  • peer channel fetch config config_block.pb -o orderer.example.com:7050 --ordererTLSHostnameOverride orderer.example.com -c mychannel --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem
    2022-06-08 06:48:33.328 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 06:48:33.330 UTC 0002 INFO [cli.common] readBlock -> Received block: 1
    2022-06-08 06:48:33.330 UTC 0003 INFO [channelCmd] fetch -> Retrieving last config block: 1
    2022-06-08 06:48:33.331 UTC 0004 INFO [cli.common] readBlock -> Received block: 1
  • configtxlator proto_decode --input config_block.pb --type common.Block --output config_block.json
    Decoding config block to JSON and isolating config to Org2MSPconfig.json
  • jq ‘.data.data[0].payload.data.config’ config_block.json
    Generating anchor peer update transaction for Org2 on channel mychannel
  • jq ‘.channel_group.groups.Application.groups.Org2MSP.values += {“AnchorPeers”:{“mod_policy”: “Admins”,“value”:{“anchor_peers”: [{“host”: “peer0.org2.example.com”,“port”: 9051}]},“version”: “0”}}’ Org2MSPconfig.json
  • configtxlator proto_encode --input Org2MSPconfig.json --type common.Config --output original_config.pb
  • configtxlator proto_encode --input Org2MSPmodified_config.json --type common.Config --output modified_config.pb
  • configtxlator compute_update --channel_id mychannel --original original_config.pb --updated modified_config.pb --output config_update.pb
  • configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate --output config_update.json
  • jq .
    ++ cat config_update.json
  • echo ‘{“payload”:{“header”:{“channel_header”:{“channel_id”:“mychannel”, “type”:2}},“data”:{“config_update”:{’ ‘“channel_id”:’ ‘“mychannel”,’ ‘“isolated_data”:’ ‘{},’ ‘“read_set”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Application”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Org2MSP”:’ ‘{’ ‘“groups”:’ ‘{},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{’ ‘“Admins”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Endorsement”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Readers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Writers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“values”:’ ‘{’ ‘“MSP”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“value”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘},’ ‘“write_set”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Application”:’ ‘{’ ‘“groups”:’ ‘{’ ‘“Org2MSP”:’ ‘{’ ‘“groups”:’ ‘{},’ ‘“mod_policy”:’ ‘“Admins”,’ ‘“policies”:’ ‘{’ ‘“Admins”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Endorsement”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Readers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘},’ ‘“Writers”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“policy”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“values”:’ ‘{’ ‘“AnchorPeers”:’ ‘{’ ‘“mod_policy”:’ ‘“Admins”,’ ‘“value”:’ ‘{’ ‘“anchor_peers”:’ ‘[’ ‘{’ ‘“host”:’ ‘“peer0.org2.example.com”,’ ‘“port”:’ 9051 ‘}’ ‘]’ ‘},’ ‘“version”:’ ‘“0”’ ‘},’ ‘“MSP”:’ ‘{’ ‘“mod_policy”:’ ‘“”,’ ‘“value”:’ null, ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“version”:’ ‘“1”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘},’ ‘“mod_policy”:’ ‘“”,’ ‘“policies”:’ ‘{},’ ‘“values”:’ ‘{},’ ‘“version”:’ ‘“0”’ ‘}’ ‘}}}}’
  • configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope --output Org2MSPanchors.tx
    2022-06-08 06:48:33.505 UTC 0001 INFO [channelCmd] InitCmdFactory -> Endorser and orderer connections initialized
    2022-06-08 06:48:33.513 UTC 0002 INFO [channelCmd] update -> Successfully submitted channel update
    Anchor peer set for org ‘Org2MSP’ on channel ‘mychannel’
    Channel ‘mychannel’ joined
    [root@iZ8vbjcbks7pzj9po96hleZ test-network]#
    [root@iZ8vbjcbks7pzj9po96hleZ test-network]#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值