Search code examples
hyperledger-fabrichyperledgerhyperledger-chaincodehyperledger-fabric-ca

Shared infrastructure in Hyperledger Fabric


I was checking a use-case if it is possible to share the peers, invoke chaincode functions & perform transactions with different MSPs. This is a use-case where a shared environment will be required for some organizations that are not willing to spend on infrastructure but may want to use the blockchain network running by the network operator.

For example, a network operator with MSP org1 creates a Hyperledger Fabric network. org4 wants to join the network but without any peers. The CA container will be there for this org4. Is it possible for org4 identity to invoke transactions on org1 peers? I tried this actually. Check the logs of the rest client below:

[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=[]

The above logs show that rest-client tries to match the MSP id with peers

The logs without service discovery:

[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=[]

In general, these organizations will join the shared infrastructure and when they are ready to use their own infrastructure, they will be migrated to it. In the meantime, they will be invoking chaincode functions through their identities


Solution

  • The fabric-sdk was trying to match the invoker's MSP ID with the available endorser's MSP ID which was failing the whole transaction because there's no peer that matches with the invoker's MSP ID. I had to disable the service discovery, add specific peers into the target peer list to make this working.

    Some code:

    const endorsingPeers = channel.getEndorsers('org1');
    
    if (endorsingPeers.length > 0) transaction = transaction.setEndorsingPeers(endorsingPeers);
        
    const response_payloads = await  transaction.evaluate(JSON.stringify(args))