问题描述
我正在检查一个用例是否可以共享对等点、调用链代码函数并与不同的 MSP 执行交易。这是一个用例,对于一些不愿意在基础设施上花钱但可能希望使用由网络运营商运行的区块链网络的组织,将需要一个共享环境。
例如,拥有 MSP org1
的网络运营商创建了一个 Hyperledger Fabric 网络。 org4
想加入网络但没有任何对等点。 CA 容器将用于此 org4
。 org4
身份是否可以调用 org1
对等点上的交易?
我实际上试过这个。检查下面其余客户端的日志:
[Service discovery Turned On]
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - start - org4
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer0.org1.com:7051 - org1
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer1.org1.com:7051 - org1
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer1.networkoperator.com:7051 - networkoperator
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer0.networkoperator.com:7051 - networkoperator
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer0.org2.com:7051 - org2
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer1.org2.com:7051 - org2
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer0.org3.com:7051 - org3
2021-04-02T04:19:27.643Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer1.org3.com:7051 - org3
2021-04-02T04:19:27.643Z - debug: [RoundRobinQueryHandler]: constructor: peers=[]
上面的日志显示,rest-client 尝试将 MSP id 与 peers 匹配
没有服务发现的日志:
[Service discovery Turned Off]
2021-04-02T04:39:11.091Z - debug: [Channel]: _getServiceEndpoints - start - org4
2021-04-02T04:39:11.091Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer0.org1.com - org1
2021-04-02T04:39:11.091Z - debug: [Channel]: _getServiceEndpoints - Endorser mspid not matched,not added peer1.org1.com - org1
2021-04-02T04:39:11.091Z - debug: [RoundRobinQueryHandler]: constructor: peers=[]
一般来说,这些组织会加入共享基础架构,当他们准备好使用自己的基础架构时,就会迁移到共享基础架构中。同时,他们将通过他们的身份调用链码函数
解决方法
fabric-sdk 试图将调用者的 MSP ID 与可用的背书者的 MSP ID 匹配,这导致整个交易失败,因为没有与调用者的 MSP ID 匹配的对等点。我必须禁用服务发现,将特定对等点添加到目标对等点列表中才能使其正常工作。
一些代码:
const endorsingPeers = channel.getEndorsers('org1');
if (endorsingPeers.length > 0) transaction = transaction.setEndorsingPeers(endorsingPeers);
const response_payloads = await transaction.evaluate(JSON.stringify(args))
,
在这种情况下,org4 将仅使用网络运营商提供给它的加密材料来连接到网络并调用链码。以下对我来说没有意义。
org4 身份是否可以调用 org1 节点上的事务?
据我所知,只要你有 cyrpto 材料连接到 HLF,并且你有正确的连接配置文件,org4 运行的 HLF 客户端最终会向所有对等点发布交易,检查模拟结果HLF 客户端,然后将交易发送给 orderer 以将其提交给对等方。
因此,在您的情况下,我们将为 org4 创建一个新用户以供使用,然后 org4 将使用该加密材料来调用链码。任何组织提交的交易最终都会被所有参与组织的基础设施执行,所以有人不想贡献基础设施,他们只会使用加密材料连接到 HLF 网络,而不是添加和重用现有的链码。