Hyperledger Fabric: Endorsement policy - hyperledger-fabric

It's possible in Hyperledger Fabric to specify that all peers in an organization must endorse the transactions?
I'll try to explain better what I am doing. Starting from the examples in the fabric-samples repository, I want to realize a scenario in which I have two separate nodes (on two different VM): on the first one I have my first peer (peer0.org1.example.com), the orderer and the fabric-ca; on the second one I have my second peer (peer1.org1.example.com).
For now, I am been able to do that: I install the chaincode on both peers and instantiate it on the channel, so I can (from both the peers on the two VMs) send transactions. But when I instantiate the chaincode, I can only say that only one of the two peer is needed to endorse the transactions (I am instantiating it with something like: docker exec cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mychaincode -l java -v 1.0 -c '{"Args":["init"]}' -P "OR('Org1MSP.member')" ).
Can I specify that both peer0.org1.example.com and peer1.org1.example.com must endorse all transactions? In my configuration they both belong to the Org1 organization, I wouldn't want to split them in two ones.

Of course you can. With the syntax OutOf(), you can set how many peers needs to sign.
For example:
OutOf(1, 'Org1.member', 'Org2.member')
OutOf(3, 'Org1.member')
OutOf(2, 'Org1.member', 'Org2.member', 'Org3.member')
You can check more of this sintax here.

Related

How to add an endorsing peer in hyperledger fabric?

What steps are required in order to add an endorsing peer to a blockchain network (in hyperledger-fabric)? What about promoting a committing peer in an endorsing one?
Should I just alter files crypto-config.yaml and configtx.yaml by adding the new peer?
I am using the fabcar example from the fabric-samples repo (https://github.com/hyperledger/fabric-samples), so should I change the docker-compose(-cli).yaml also? When starting the network with startFabric.sh script, should I just install chaincode on the new peers, or are other steps requires also?
I tried it with just installing a chaincode on the new peers, however I got an error stating that "... Consortium was not met when instantiating the chaincode ..."
Edit:
I was able to install the chaincode on all four peers and instantiate it on the channel. Initial non-query transaction is successful and another one after it. However, after the first two transactions I get:
Failed to submit transaction createInquiry: Error: Peer localhost:8051 has rejected transaction "e8a83c12bfbcae97c7a3f2baaad7735fe8b44195a0ce252a3533a7b4a2a8103b" with code "ENDORSEMENT_POLICY_FAILURE"
can you stop, remove and kill containers and try once again to instantiate.

Can a transaction in org1 peer1 be queried from org2 peer1?

I have a smart contract in ORG1.MSP peer1 and I'll like to query it from ORG2.MSP peer1. Is this possible?
If they're both on the same channel, they have access to the same ledger, which contains blocks, which contain transactions.
You have to install the ChainCode on each peer which should make use of its functions. If you want them to work on the same ledger, let the peers join the same channel, install the chaincode on them and then you are able to execute transactions via chaincode on the ledger(s).
So yes it is possible.

What install and instantiation chaincode really mean in hyperledger fabric? and what are the differences between them?

In the hyperledger fabric documentation, there are 2 terms used
1. Install the chaincode on peers and
2. Instantiate the chaincode on the channel
What are the major differences between these two?
In the documentation it said that a chaincode can be installed on multiple peers but can be instantiated once. I understood this point as a channel only needs the information about the channel.
I was following the balance-transfer example, so after channel creation, peers need to be joined to that channel.
There are 2 peers which joined the channel ["peer0.org1.example.com", "peer0.org1.example.com"], so when I am instantiating the chaincode it is creating 2 docker images of chaincode
dev-peer0.org1.example.com-chaincode-v0
dev-peer1.org1.example.com-chaincode-v0
What these 2 images really mean?
Isn't initializing the chaincode means for the channel?
Or channel initialize it on all the peers who joined it?
Where actually this initialization is happening?
Thanks!
Thanks to #PaulO'Mahony and #kajuken for the resources and explanation.
Following are the summary of my doubts:
A chaincode runs in a Docker container that is associated with any peer that needs to interact with it.
Chaincode is installed on a peer, then instantiated on a channel.
All members that want to submit transactions or read data by using a chaincode need to install the chaincode on their peer.
Instantiation will input the initial data used by the chaincode, and then start the chaincode containers on peers joined to the channel with the chaincode installed.
Note that only one network member needs to instantiate a chaincode. If a peer with a chaincode installed joins a channel where it has already been instantiated, the chaincode container will start automatically.
a chaincode is installed onto the file system of every peer that joins a channel, the chaincode must then be instantiated on the channel so that peers can interact with the ledger via the chaincode container. The instantiation performs any necessary initialization of the chaincode. This will often involve setting the key value pairs that comprise a chaincode's initial world state.
A peer can the install the chaincode once, and then use the same chaincode container on any channel where it has been instantiated.
References:
install and instantiate the chaincode
instantiate the chaincode
What these 2 images really mean?
Isn't initializing the chaincode means for the channel?
Yes and no. Every peer needs the same version of the chaincode installed on itself since everybody needs to be able to execute and verify incoming queries/invokes.
So there are 2 steps to do.
install the chaincode on every peer on the channel
instantiate the chaincode on the channel
Where actually this initialization is happening?
So the instantiating of chaincode is happening last after every peer has "knowledge" of the chaincode and it can be verified.

In Fabric how chaincode versioning happen internally?

Scenario:
I am creating hyperledger infrastructure with two organizations each having two peers and one orderer joining two channel.
Questions:
How are we define channels at the time of chain-code installation?
How the chain-code version maintains internally?
Thanks,
Murugesan
1) You can install chaincode on the peer(s) prior to creating / joining any channels. You then instantiate chaincode on specific channels. Those channels must have been created on the ordering service(s) and the peer(s) must join those channels. Once that has been done, you can then instantiate (active) chaincode on the channels you like. If a peer did not have the chaincode installed at the time it was instantiated on a channel, that's ok as well ... once the chaincode has been installed, it will be launched the first time you try to invoke the chaincode on that peer.
2) When you install chaincode, you specify a version. The same holds true for instantiating chaincode as well.

Can a single peer run 2 different chaincode

I am trying to chaincode something so just have a question that can a single peer run 2 different chaincodes?
So need your help here.
Yes, peer can have more than one chaincode installed and instantiated. Moreover for some case this is actually vital, for example if you would like to have a chaincode foo too call chaincode bar, you have install both these chaincodes on same peer. (Of course chaincodes have to be instantiated).

Resources