导入业务网络卡片失败,咨询connection.json格式适配方案
Composer卡片导入失败的问题排查与修复方案
问题描述
你执行composer card import -f PeerAdmin@byfn-network-org1-only.card时遇到了导入失败,报错信息如下:
Failed to import the business network card keyword: required dataPath: schemaPath: #/required params: missingProperty: x-type message: should have required property 'x-type' keyword: required dataPath: schemaPath: #/required params: missingProperty: client message: should have required property 'client' keyword: required dataPath: schemaPath: #/required params: missingProperty: certificateAuthorities message: should have required property 'certificateAuthorities' keyword: required dataPath: schemaPath: #/required params: missingProperty: channels message: should have required property 'channels' keyword: type dataPath: .orderers schemaPath: #/type params: type: object message: should be object keyword: type dataPath: .peers schemaPath: #/type params: type: object message: should be object Error: Errors found in the connection profile in the card Command failed
你的环境配置为:
- FABRIC_VERSION=hlfv11
- Composer版本v0.19.5
当前使用的connection.json内容如下:
{ "name": "byfn-network-org1-only", "type": "hlfv11", "mspID": "Org1MSP", "peers": [ { "requestURL": "grpcs://localhost:7051", "eventURL": "grpcs://localhost:7053", "cert": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt", "hostnameOverride": "peer0.org1.example.com" }, { "requestURL": "grpcs://localhost:8051", "eventURL": "grpcs://localhost:8053", "cert": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt", "hostnameOverride": "peer1.org1.example.com" } ], "ca": { "url": "https://localhost:7054", "name": "ca-org1", "cert": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt", "hostnameOverride": "ca.org1.example.com" }, "orderers": [ { "url" : "grpcs://localhost:7050", "cert": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt", "hostnameOverride": "orderer.example.com" } ], "channel": "mychannel", "timeout": 300 }
问题原因
从报错信息能直接看出,你的connection.json不符合Composer v0.19.x对应hlfv11连接配置的JSON Schema要求:
- 缺少必填的顶级字段:
x-type、client、certificateAuthorities、channels orderers和peers字段要求是对象类型(key为节点名称,值为节点配置),但你当前用的是数组类型
修复方案
你完全可以保留核心配置逻辑,只调整结构使其符合要求即可,不需要改用旧格式。以下是修改后的完整配置:
{ "name": "byfn-network-org1-only", "type": "hlfv11", "x-type": "hlfv1", "mspID": "Org1MSP", "client": { "organization": "Org1", "connection": { "timeout": { "peer": { "endorser": "300" } } } }, "peers": { "peer0.org1.example.com": { "url": "grpcs://localhost:7051", "eventUrl": "grpcs://localhost:7053", "tlsCACerts": { "path": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" }, "grpcOptions": { "ssl-target-name-override": "peer0.org1.example.com" } }, "peer1.org1.example.com": { "url": "grpcs://localhost:8051", "eventUrl": "grpcs://localhost:8053", "tlsCACerts": { "path": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" }, "grpcOptions": { "ssl-target-name-override": "peer1.org1.example.com" } } }, "certificateAuthorities": { "ca-org1": { "url": "https://localhost:7054", "caName": "ca-org1", "tlsCACerts": { "path": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" }, "httpOptions": { "verify": false } } }, "orderers": { "orderer.example.com": { "url": "grpcs://localhost:7050", "tlsCACerts": { "path": "/home/koosh/fabric-tools/fabric-samples/first-network/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt" }, "grpcOptions": { "ssl-target-name-override": "orderer.example.com" } } }, "channels": { "mychannel": { "peers": { "peer0.org1.example.com": { "endorsingPeer": true, "chaincodeQuery": true, "ledgerQuery": true, "eventSource": true }, "peer1.org1.example.com": { "endorsingPeer": true, "chaincodeQuery": true, "ledgerQuery": true, "eventSource": true } }, "orderers": [ "orderer.example.com" ] } } }
关键修改点说明:
- 添加
x-type: hlfv1:这是Composer识别hlfv11类型连接配置的必填标识 - 将
peers和orderers从数组改为对象,每个节点的key为节点hostname(比如peer0.org1.example.com),同时调整了字段命名(requestURL改为url,hostnameOverride移到grpcOptions下的ssl-target-name-override,cert改为tlsCACerts.path) - 添加
client字段:指定所属组织和连接超时配置 - 添加
certificateAuthorities字段:将原来的ca配置迁移到这里,调整了字段名(name改为caName) - 添加
channels字段:明确指定通道mychannel关联的节点和排序节点
修改完成后,你需要重新生成业务网络卡片(如果是自行打包的话),或者替换现有卡片内的connection.json文件,再执行composer card import命令就能成功导入了。
内容的提问来源于stack exchange,提问作者user3584409
相关产品推荐
相关产品推荐

