Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 查询链码仅在使用nodejs的约3/5个案例中成功_Node.js_Hyperledger Fabric - Fatal编程技术网

Node.js 查询链码仅在使用nodejs的约3/5个案例中成功

Node.js 查询链码仅在使用nodejs的约3/5个案例中成功,node.js,hyperledger-fabric,Node.js,Hyperledger Fabric,我成功地在我的链上安装并实例化了链代码。我可以注册管理员并通过nodejs注册用户。如果我查询链码,它只返回大约5次中的3次正确响应。其余部分抛出链码找不到的错误 安装的链码是结构示例中的基本示例。 用于查询链码的My js文件(基于fabcar示例): 对于有错误的成功查询,在这些执行之间没有任何更改,并且在它们之间大约5秒钟的时间内调用了它们 root@devserver ~/fabric-samples/bla/first-network # node index.js Transact

我成功地在我的链上安装并实例化了链代码。我可以注册管理员并通过nodejs注册用户。如果我查询链码,它只返回大约5次中的3次正确响应。其余部分抛出链码找不到的错误

安装的链码是结构示例中的基本示例。 用于查询链码的My js文件(基于fabcar示例):

对于有错误的成功查询,在这些执行之间没有任何更改,并且在它们之间大约5秒钟的时间内调用了它们

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
2019-09-09T18:53:24.646Z - warn: [Query]: evaluate: Query ID "[object Object]" of peer "peer1.PharmaProducer.bigpharma.com:8051" failed: message=cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory, stack=Error: cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory
  at self._endorserClient.processProposal (/root/fabric-samples/bla/first-network/node_modules/fabric-network/node_modules/fabric-client/lib/Peer.js:140:36)
  at Object.onReceiveStatus (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:1207:9)
  at InterceptingListener._callNext (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:568:42)
  at InterceptingListener.onReceiveStatus (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:618:8)
  at callback (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:845:24), status=500, , url=grpcs://localhost:8051, name=peer1.PharmaProducer.bigpharma.com:8051, grpc.max_receive_message_length=-1, grpc.max_send_message_length=-1, grpc.keepalive_time_ms=120000, grpc.http2.min_time_between_pings_ms=120000, grpc.keepalive_timeout_ms=20000, grpc.http2.max_pings_without_data=0, grpc.keepalive_permit_without_calls=1, name=peer1.PharmaProducer.bigpharma.com:8051, grpc.ssl_target_name_override=peer1.PharmaProducer.bigpharma.com, grpc.default_authority=peer1.PharmaProducer.bigpharma.com, isProposalResponse=true
Failed to evaluate transaction: Error: cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory
我希望代码每次都能成功返回正确的结果,而不是随机显示代码不存在的错误


任何关于这一情况如何发生的见解都是值得赞赏的。

查看日志,我能理解为什么有时你会变得更为古怪,有时你会变得更为古怪,这是因为发现结果和处理结果导致不可能以任何特定顺序获得对等方列表,因此在您的组织中有2个对等方,而且这不是一个长时间运行的应用程序,而是一个短时间运行的调用,有时对等方列表中的第一个是peer0,有时是peer1。因为您只在peer0上安装了链码,peer1无法接受求值请求并返回错误

node sdk应该检测到这一点,然后尝试peer0,但是您使用的node sdk的旧版本肯定存在问题,没有尝试其他对等版本,或者node sdk认为这是(错误地,但可能无法区分)链码响应,并将其传递回调用方。
避免错误的解决方案是在所有对等方上安装链码。

您的组织中有多少对等方?我猜你有超过1个,但只在其中1个上安装了chaincode包?@david_k我每个组织有2个对等点,并在每个组织的peer0上安装了它。是的,您的猜测是正确的。您使用的是什么版本的NodeSDK?因为除非peer0没有响应,否则评估应该检测到peer1不能返回结果,然后尝试peer0。您可以通过设置env var
export HFC_LOGGING='{“debug”:“console”}'
来获取节点sdk。它也很奇怪,为什么它看起来像是先尝试peer1,而其他时候它是先尝试peer0。但是日志会提供更多细节。在查询事务中,我相信它会从通道内的连接配置文件的客户端部分随机选择一个对等点,因此如果您不这样做;t在两个对等机上都没有安装链码,这可能是问题的原因。找到您正在使用的版本的方法是转到node_modules/fabric network目录,查看package.json文件,它将有一个版本字段,其中包含实际安装的版本。在每个对等机上安装它可以解决问题,我更希望有一个自动检查链码是否安装,如果没有,查询下一个对等,但这是一个简单的修复。非常感谢您的帮助。@user3399276您是如何在所有对等计算机上安装它的?如果我使用
docker exec-it cli peer chaincode install…
简单地安装链码,则无法实例化链码,因为不符合联合体的要求。是的,这是正确的答案!我已经通过在我的所有同龄人上安装chaincode来验证它。然后问题就不再出现了。非常感谢。
root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
Transaction has been evaluated, resultb is: 210

root@devserver ~/fabric-samples/bla/first-network # node index.js 
2019-09-09T18:53:24.646Z - warn: [Query]: evaluate: Query ID "[object Object]" of peer "peer1.PharmaProducer.bigpharma.com:8051" failed: message=cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory, stack=Error: cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory
  at self._endorserClient.processProposal (/root/fabric-samples/bla/first-network/node_modules/fabric-network/node_modules/fabric-client/lib/Peer.js:140:36)
  at Object.onReceiveStatus (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:1207:9)
  at InterceptingListener._callNext (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:568:42)
  at InterceptingListener.onReceiveStatus (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:618:8)
  at callback (/root/fabric-samples/bla/first-network/node_modules/grpc/src/client_interceptors.js:845:24), status=500, , url=grpcs://localhost:8051, name=peer1.PharmaProducer.bigpharma.com:8051, grpc.max_receive_message_length=-1, grpc.max_send_message_length=-1, grpc.keepalive_time_ms=120000, grpc.http2.min_time_between_pings_ms=120000, grpc.keepalive_timeout_ms=20000, grpc.http2.max_pings_without_data=0, grpc.keepalive_permit_without_calls=1, name=peer1.PharmaProducer.bigpharma.com:8051, grpc.ssl_target_name_override=peer1.PharmaProducer.bigpharma.com, grpc.default_authority=peer1.PharmaProducer.bigpharma.com, isProposalResponse=true
Failed to evaluate transaction: Error: cannot retrieve package for chaincode mycc/1.0, error open /var/hyperledger/production/chaincodes/mycc.1.0: no such file or directory