简体   繁体   English

同一组织的Hyperledger Fabric 2对等节点导致Chaincode和Couchdb问题

[英]Hyperledger Fabric 2 peers of same organisation causing issue with chaincode and couchdb

I am facing a very strange issue with Hyperledger Fabric node.js sdk issue. 我面临Hyperledger Fabric node.js sdk问题的一个非常奇怪的问题。

Right now, my network consists of: 现在,我的网络包括:

a.) Single org b.) 2 peers of that org (peer0 and peer1). a。)单个组织b。)该组织的2个对等体(peer0和peer1)。 c.) 1 orderer d.) 1 ca c。)1个订购者d。)1个ca

When using node.js sdk, both peers joined the channel as you can see in the code snippet below: 使用node.js sdk时,两个对等方都加入了该频道,如下面的代码片段所示:

var fabric_client = new Fabric_Client();
var channel = fabric_client.newChannel(channelName);
var peer = fabric_client.newPeer('grpc://localhost:7051');
var peer2 = fabric_client.newPeer('grpc://localhost:8051');
channel.addPeer(peer);
channel.addPeer(peer2);
var order = fabric_client.newOrderer('grpc://localhost:7050')
channel.addOrderer(order);

I am calling a chaincode function written in golang that generates a unique id, create the hash of it (SHA256) and saves in couchdb and logs that hash to container like this: 我打电话写在chaincode功能golang生成一个唯一的ID,创建它(SHA256)散列,并保存在couchdb并记录散列这样的容器:

"password":"5ef32e670c38727ce5011dad62ff1a150362433789fdd878f2623a08bbdc990b"

The issue is, when node.js sdk is configured with single peer. 问题是,当node.js sdk配置有单个对等时。 It saves the same hash in couchdb that log shows. 它将与日志显示的相同的哈希保存在couchdb中。 But when configured with 2 peers as the above sdk code snippet shows. 但是,当配置了2个对等方时,如上面的sdk代码片段所示。 The logged hash and couchdb hash does not match. 记录的哈希值和ouchdb哈希值不匹配。

I think the hash changes because 2nd peer execute the same code again in which a random string is generated and hashed. 我认为哈希会发生变化,因为第二个对等方再次执行相同的代码,其中会生成随机字符串并进行哈希处理。

Any help/comment would be appreciated. 任何帮助/评论将不胜感激。 Thanks 谢谢

A few things: 一些东西:

1) Not sure what your endorsement policy is, but assuming it is the default then generally speaking you only need to request endorsement from a single peer in the organization 1)不确定您的背书政策是什么,但是假设它是默认政策,那么通常来说,您只需要向组织中的单个对等方请求背书

2) Most importantly you should not use non-deterministic functions within your chaincode. 2) 最重要的是,您不应在链码中使用非确定性函数。 If you actually had multiple organizations and the endorsement policy required signatures from multiple orgs, then your transaction would fail anyway (as peers from different orgs would generate different responses due to the non-deterministic unique id function you are using). 如果您实际上有多个组织,并且背书策略要求来自多个组织的签名,那么您的交易无论如何都会失败(因为来自不同组织的对等方会由于您使用的不确定性唯一ID函数而产生不同的响应)。 In this case, since you only require a single endorsement, the state would likely be updated but it would use the value of the first response. 在这种情况下,由于您只需要单签注,状态可能会被更新,但会使用第一个响应的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM