bft-smart / fabric-orderingservice

Byzantine fault-tolerant ordering service for Hyperledger Fabric
Apache License 2.0
139 stars 56 forks source link

Using multiple endorsers in a chain code #12

Closed gogo9th closed 6 years ago

gogo9th commented 6 years ago

Hi,

I'm trying to have a setup such that there are 5 endorsing nodes involved in a particular channel (called ch1), where 5 endorsing nodes belong to 5 different physical machines, and whenever a client invokes a chain code action within this channel ch1, all 5 endorsing nodes should endorse it. But when a client invokes a chain code action, it seems that only a single endorser endorses it. My setup commands were as follows:

[Machine 1~5]: // start a replica in each of 5 machines $ ./startReplica.sh

[Machine 1]: // start the front-end in Machine 1 $ ./startFrontend.sh 1000 10 9999

[Machine 1]: // generate a genesis block in Machine 1 $ build/bin/configtxgen -profile SampleSingleMSPBFTsmart -channelID initialChannel -outputBlock genesisblock

[Machine 1]: // start an orderer in Machine 1 $ build/bin/orderer start

[Machine 1~5]: // start endorsing peers in all 5 machines $ ./build/bin/peer node start

[Machine 1]: // generate a configuration file for creating a new channel ch1 $ build/bin/configtxgen -channelID ch1 -outputCreateChannelTx ch1.tx -profile SampleSingleMSPChannel

[Machine 1]: // generate a configuration file for updating anchor peers $ ./build/bin/configtxgen -profile SampleSingleMSPChannel -outputAnchorPeersUpdate ch1-SampleOrg-anchor.tx -channelID ch1 -asOrg SampleOrg

[Machine 1]: // create channel ch1 $ ./build/bin/peer channel create -o ${Machine1_IP_Address}:7050 -c ch1 -f ch1.tx

[Machine1 manually sends ch1.block (channel ch1's genesis block) to Machine 2, 3, 4, 5]

[Machine 1~5]: // join channel ch1 $ ./build/bin/peer channel join -b ch1.block ;

[Machine 1~5]: // install the chain code in all 5 machines $ ./build/bin/peer chaincode install -n ch1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

[Machine 1]: // client in Machine 1 instantiates a new chain code cc1 in channel ch1 $ build/bin/peer chaincode instantiate -o ${Machine1_IP_Address}:7050 -C ch1 -n cc1 -v 1.0 -c '{"Args":["init","a","100","b","200"]}'

[Machine 1]: // client in Machine 1 invokes an action on chain code cc1 $ build/bin/peer chaincode invoke -C ch1 -n cc1 -v 1.0 -c '{"Args":["invoke","a","b","0"]}'

After I run the last command above (/build/bin/peer chaincode invoke -C ch1 -n cc1 ...), a new block gets created immediately, and this block contains only 1 endorsement signature. But I want this chaincode action to be endorsed by all 5 machines, and thereby to contain 5 endorsement signatures. How can I enforce this? (Possibly some of my commands above are wrong...)

Ronny

jcs47 commented 6 years ago

I noticed that you did not specified any endorsement policy when you instantiate the chaincode. Try specifying a policy when instantiating the chaincode as described here: https://hyperledger-fabric.readthedocs.io/en/release-1.1/endorsement-policies.html

gogo9th commented 6 years ago

Thanks for the great link teaching how to create endorsement policies.

But just one thing I am still unsure is how to identify each channel member's MSP ID & ROLE. For example, suppose that Machine 1 creates a new channel ch1 by running the following two commands:

$ ./build/bin/configtxgen -channelID ch1 -outputCreateChannelTx ch1.tx -profile SampleSingleMSPChannel

$ ./build/bin/peer channel create -o '${Machine 1's IP}':7050 -c ch1 -f ch1.tx

Now Machine 1 shares ch1.block with all other Machines. And suppose that a new member joins this channel by running the following three commands:

$ ./build/bin/configtxgen -profile SampleSingleMSPChannel -outputAnchorPeersUpdate SampleOrg-anchor.tx -channelID ch1 -asOrg SampleOrg

$ ./build/bin/peer channel join -b ch1.block $ ./build/bin/peer channel update -o ${Machine 1's IP}:7050 -c ch1 -f SampleOrg-anchor.tx

---- SampleOrg is defined in configtx.yaml as follows: ---- Organizations:

In this case, what is the newly joined member's MSP ID & ROLE? I think the MSP ID id 'DEFAULT'. But what is this member's ROLE? (there can be 3 possible roles: admin, peer, or client)

Also, if I want to get signatures from multiple members in the same organization (e.g., 3 members from DEFAULT organization), what should be the endorsement policy grammer?

jcs47 commented 6 years ago

The MSP ID is defined in the ID field, which is set to DEFAULT. As for the role of the peer and signatures from the same organization, I have to admit I am not sure how it is supposed to work either. The lion share of our work in Fabric was dedicated to implement this ordering service and evaluating it under heavy loads, so we never got to configure a real network with Fabric. I would advise you to take these questions to the official fabric's mailing list or to their chat.

gogo9th commented 6 years ago

It seems that if we set the endorsement policy to be AND(DEFAULT.member, DEFAULT.member, DEFAULT.member), this policy will require endorsements from 3 different principals from DEFAULT organization.

However, the following command wouldn't collect endorsement signatures from multiple endorsers: $ build/bin/peer chaincode invoke -C ch1 -n cc1 -v 1.0 -c '{"Args":["invoke","a","b","0"]}'

Instead, we need to use "--peerAddresses" flag to add all endorser addresses inside the above command. (Refer to: https://github.com/hyperledger/fabric/blob/ad8f4c4cb50b1a565924c7b2d51bc8cbe022aa46/examples/e2e_cli/scripts/script.sh#L220-L267)

However, "--peerAddresses" seems to be supported only in the development version (and hopefully as of Hyprledger Fabric v1.2).