Search code examples
hyperledger-fabrichyperledger-fabric-ca

Hyperledger/fabric Endorsement policy for one organisation with 5 peers


I have developed the network for one organisation with 5 peers using nodejs application but i am bit confused with endorsement policy. I want atleast 3 peers to endorse the the transaction. how should i define if atleast 3 peers have to endorse the transaction.

This is how i am trying to do but its failing. while invoke. can someone please help me with it,

'endorsement-policy': {
    identities: [
       { role: { name: 'peer', mspId: 'Org1MSP' } },
    ],
    policy: {
        '1-of': [ 
            { 'signed-by': 0 }
        ]
   }
}

But the above approach doesnt really work for me. can someone please suggest over this.


Solution

  • Unless you want to write your own endorsement plugin, the lowest granularity you can use for endorsement policies in Hyperledger Fabric is organisation. So, for your example to work, each peer would need to be in a separate organisation. Using the peer command CLI syntax, the policy would then be something like:

    OutOf(3, 'Org1.peer', 'Org2.peer', 'Org3.peer', 'Org4.peer', 'Org5.peer')
    

    or, in JSON:

    'endorsement-policy': {
      identities: [
        { role: { name: 'peer', mspId: ORGS['Org1'].mspid }},
        { role: { name: 'peer', mspId: ORGS['Org2'].mspid }},
        { role: { name: 'peer', mspId: ORGS['Org3'].mspid }},
        { role: { name: 'peer', mspId: ORGS['Org4'].mspid }},
        { role: { name: 'peer', mspId: ORGS['Org5'].mspid }}
      ],
      policy: {
        '3-of': [
          { 'signed-by': 0 }, 
          { 'signed-by': 1 }, 
          { 'signed-by': 2 }, 
          { 'signed-by': 3 }, 
          { 'signed-by': 4 }
        ]
      }
    }