如何解决Hyperledger Fabric v2.1:Fabcar,在网关连接选项中将asLocalhost设置为false
我正在尝试运行Hyperledger Fabric的多计算机网络。我遇到了一些错误。通过在fabric-samples/fabcar/javascript/query.js
中更改一行,我能够在Fabric v2.1的Fabcar example中的同一台计算机上重现相同的错误。我换了线
await gateway.connect(ccp,{ wallet,identity: 'appUser',discovery: { enabled: true,asLocalhost: true } });
一行
await gateway.connect(ccp,asLocalhost: false } });
因此,我将discovery.asLocalhost
设置为false
而不是true
。当我在node query.js
目录中运行fabric-samples/fabcar/javascript/
时。我收到以下错误。
Wallet path: /home/userName/my/code/fabric-samples/fabcar/javascript/wallet
2020-10-23T06:09:56.505Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050,url:grpcs://orderer.example.com:7050
2020-10-23T06:09:56.507Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server orderer.example.com:7050 url:grpcs://orderer.example.com:7050 timeout:3000
2020-10-23T06:09:56.508Z - error: [DiscoveryService]: _buildOrderer[mychannel] - Unable to connect to the discovered orderer orderer.example.com:7050 due to Error: Failed to connect before the deadline on Committer- name: orderer.example.com:7050,url:grpcs://orderer.example.com:7050
2020-10-23T06:09:59.522Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051,url:grpcs://peer0.org1.example.com:7051
2020-10-23T06:09:59.523Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org1.example.com:7051 url:grpcs://peer0.org1.example.com:7051 timeout:3000
2020-10-23T06:09:59.523Z - error: [DiscoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org1.example.com:7051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org1.example.com:7051,url:grpcs://peer0.org1.example.com:7051
2020-10-23T06:10:02.528Z - error: [ServiceEndpoint]: Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051,url:grpcs://peer0.org2.example.com:9051
2020-10-23T06:10:02.528Z - error: [ServiceEndpoint]: waitForReady - Failed to connect to remote gRPC server peer0.org2.example.com:9051 url:grpcs://peer0.org2.example.com:9051 timeout:3000
2020-10-23T06:10:02.529Z - error: [DiscoveryService]: _buildPeer[mychannel] - Unable to connect to the discovered peer peer0.org2.example.com:9051 due to Error: Failed to connect before the deadline on Endorser- name: peer0.org2.example.com:9051,url:grpcs://peer0.org2.example.com:9051
2020-10-23T06:10:02.564Z - error: [SingleQueryHandler]: evaluate: message=Query failed. Errors: [],stack=FabricError: Query failed. Errors: []
at SingleQueryHandler.evaluate (/home/sarva/my/code/viacomrepos/temp-fabric-samples/fabric-samples/fabcar/javascript/node_modules/fabric-network/lib/impl/query/singlequeryhandler.js:45:23)
at Transaction.evaluate (/home/sarva/my/code/viacomrepos/temp-fabric-samples/fabric-samples/fabcar/javascript/node_modules/fabric-network/lib/transaction.js:287:49)
at Contract.evaluateTransaction (/home/sarva/my/code/viacomrepos/temp-fabric-samples/fabric-samples/fabcar/javascript/node_modules/fabric-network/lib/contract.js:115:45)
at main (/home/sarva/my/code/viacomrepos/temp-fabric-samples/fabric-samples/fabcar/javascript/query.js:46:39)
at processTicksAndRejections (internal/process/task_queues.js:85:5),name=FabricError
Failed to evaluate transaction: FabricError: Query failed. Errors: []
我遵循了Fabcar tutorial中的说明。下面是重现该错误的步骤。
cd fabric-samples/fabcar
./startFabric.sh javascript
cd javascript
npm install
node enrollAdmin.js
node registerUser.js
[Change the line in query.js]
node query.js
如果我能弄清楚如何/在哪里指定grpcs URL,我认为我可以使多机网络正常工作。任何帮助表示赞赏。
可以按照this answer的建议设置export GRPC_TRACE=all
和export GRPC_VERBOSITY=DEBUG
来获取更详细的错误日志。
解决方法
在单机情况下,客户端应用程序在本地计算机上运行,但是节点(对等节点和订购者)在本地计算机上的Docker容器中运行,并且主机名类似peer0.org1.example.com
。
在Docker网络中,节点可以使用其主机名相互通信,例如peer0.org1.example.com
。您的客户端(在Docker网络外部)无法与peer0.org1.example.com
进行对话,因为该DNS名称不存在。相反,它需要通过Docker网络映射到Docker网络中特定主机/端口或从Docker网络映射到特定主机/端口的端口上的localhost。
您的客户端应用程序通过两种方式获取节点端点:
- 其本地连接配置文件中的条目。
- 服务发现返回的网络拓扑。
您可以在连接配置文件中设置适当的(本地主机)端点URL。但是,发现返回的端点URL将是Docker网络中公开的那些URL。 peer0.org1.example.com
。为了简化这种情况,SDK提供了discovery.asLocalhost
设置,该设置启用后会将发现返回的所有终结点地址映射到localhost的同一端口。一种替代方法是将条目添加到本地主机文件中,这些条目将节点名称映射到localhost。
如果您的节点可以使用其配置的主机名在实际网络上访问,则不应启用discovery.asLocalhost
设置。这些主机名在DNS中必须是可解析的(因此对于实际部署,您不能使用诸如example.com
之类的不可解析的地址),并且必须与您的Fabric网络配置(以及使用TLS的服务器证书详细信息)相匹配。
用于设置多机器网络。您必须进行的更改是在config.json和connection.yaml(基本上是连接配置文件)上。
await gateway.connect(ccp,{ wallet,identity: 'appUser',discovery: { enabled: true,asLocalhost: false } });
在设置多主机区块链网络时,应将localhost属性设置为“ false”。您可以创建一个覆盖网络以与其连接。
---
name: mychannel.firstnetwork.connectionprofile
x-type: "hlfv1"
description: "connection profile for 2.1 network"
version: "1.0"
channels:
mychannel:
orderers:
- orderer.example.com
peers:
peer0.org1.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
peer0.org2.example.com:
endorsingPeer: true
chaincodeQuery: true
ledgerQuery: true
eventSource: true
organizations:
Org1:
mspid: Org1MSP
peers:
- peer0.org1.example.com
certificateAuthorities:
- ca.org1.example.com
adminPrivateKey:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore/8717c2e82c3c4caff76fca964bb70_sk
signedCert:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts/cert.pem
Org2:
mspid: Org2MSP
peers:
- peer0.org2.example.com
certificateAuthorities:
- ca.org2.example.com
adminPrivateKey:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore/9592495c719c2e87fc4a8_sk
signedCert:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts/cert.pem
orderers:
orderer.example.com:
url: grpcs://orderer.example.com:7050
grpcOptions:
ssl-target-name-override: orderer.example.com
tlsCACerts:
path: ./caro-blockchain-commonfiles/config/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peers:
peer0.org1.example.com:
url: grpcs://peer0.org1.example.com:7051
grpcOptions:
ssl-target-name-override: peer0.org1.example.com
tlsCACerts:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp/cacerts/localhost-7054-ca-org1.pem
peer0.org2.example.com:
url: grpcs://peer0.org2.example.com:9051
grpcOptions:
ssl-target-name-override: peer0.org2.example.com
tlsCACerts:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/msp/cacerts/localhost-8054-ca-org2.pem
certificateAuthorities:
ca.org1.example.com:
url: https://ca.org1.example.com:7054
httpOptions:
verify: false
tlsCACerts:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org1.example.com/ca/ca.org1.example.com-cert.pem
registrar:
- enrollId: admin
enrollSecret: adminpw
caName: ca-org1
ca.org2.example.com:
url: https://ca.org2.example.com:8054
httpOptions:
verify: false
tlsCACerts:
path: ./caro-blockchain-commonfiles/config/crypto-config/peerOrganizations/org2.example.com/ca/ca.org2.example.com-cert.pem
registrar:
- enrollId: admin
enrollSecret: adminpw
caName: ca-org2
此处的grpcs://peer0.org1.example.com:7051
这样的URLs属性应从主机名更改为另一台计算机的IP,再更改为运行对等容器的VM(grpcs://XX.XX.XX.XX:7051
)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。