InTerestedOWL
InTerestedOWL

Reputation: 51

Hyperledger Fabric: Endorsement policy two peers out of 3. Error

I am reaching out to you, because of an exception with hyperledger fabric endorsement policy belonging lifecycle.

What I have done:

Packaged, Installed, approved, and committed my chaincode on Three Peers out of 9, all in the same Organisational MSP.

Since I have the test case, that I should enforce an endorsement policy that looks like this:

OutOf(2, Org1MSP.member) which is in my eyes similar to: AND(Org1MSP.member, Org1MSP.member). Am I wrong?

Never the less, when I issue my chaincode I am getting back a message:

server returned: failed constructing descriptor for chaincodesname:"mycc": no peer combination can satisfy the endorsement policy

Confusing enough, when I using the Policy: AND(Org1MSP.member) everything is crystal clear and my chaincode is invoked. And using the discovery command in this case returns every single peer on a server, great. But it is not the case I want to achieve! I want to enforce an endorsement by 2 of 3 Endorsers.

I appreciate your help!

Here is my connection profile. Only containing the three endorsement-peers:

---
certificateAuthorities:
  Org1CA:
    caName: ca
    url: http://<IP is correct links to the right server>:7054
client:
  connection:
    timeout:
      orderer: '300'
      peer:
        endorser: '300'
  organization: Org1MSP
name: example.com
organizations:
  Org1MSP:
    certificateAuthorities:
      - Org1CA
    mspid: Org1MSP
    peers:
      - peer0.org1.example.com
      - peer1.org1.example.com
      - peer9.org1.example.com
peers:
  peer0.org1.example.com:
    url: grpc://peer0.org1.example.com:7051
  peer9.org1.example.com:
    url: grpc://peer9.org1.example.com16051
  peer1.org1.example.com:
    url: grpc://peer1.org1.example.com:8051
version: 1.0.0

Every peer is on a different machine. Here is an sample on how I am doing the Transaction invoke:

Gateway.Builder builder = Gateway.createBuilder();
Wallet wallet = Wallets.newInMemoryWallet();
X509Identity ident;

try {
    ident = Identities.newX509Identity("Org1MSP",
            Identities.readX509Certificate("removed key due to security porpuse"),
            Identities.readPrivateKey("removed key due to security porpuse"));
    String userName = "admin";
    Contract contract = null;

    InputStream input = classLoader.getResourceAsStream("connection-org1.yaml");
    wallet.put("admin", ident);
    builder.identity(wallet, userName).networkConfig(input).discovery(true);
    Gateway gateway = builder.connect();
    Network network = gateway.getNetwork("crm-field-1");
    contract = network.getContract(contractName);

    byte[] response = null;
    Transaction trans = contract.createTransaction("createCrmContact");
    Map<String, byte[]> data = new HashMap<String, byte[]>();
    data.put("value", value.getBytes());
    data.putAll(initialize());
    trans = trans.setTransient(data);
    response = trans.submit(pk, fieldName);
    // response = contract.submitTransaction("createCrmContact", pk, fieldName,
    // value);
    LOGGER.error("Logging: Response - " + response);
    if (response == null)
        return null;
    return decode(response);
} catch (Exception e) {
    LOGGER.error("Logging: Error" + e.getMessage());
    e.printStackTrace();
}

Upvotes: 2

Views: 1364

Answers (1)

InTerestedOWL
InTerestedOWL

Reputation: 51

So, I figured out by my self:

If the network does not have any Anchor peers set, the discovery fails, because there is no endpoint, where he gets the information about every one in the network. So added them to the network solved my issue.

Thanks for all advice

Upvotes: 1

Related Questions