Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Blockchain by (4.1k points)

Consider the Organization-Peer setup in a Hyperledger Fabric network as shown in the image.

enter image description here

Org 1 has two peers, Org 2 has one peer - all of which exist inside the same channel - X. Org 3 has one peer which exist outside in a different channel.

The peers have distinct chaincodes(c1, c2, c3 & c4) installed in each of them with the functions as explained.

write() - put a key-value pair into the ledger 
update() - update a value for an existing key 
read() - query an existing key-value pair 

 

Now on to few questions.

Can c3 invoke c2 to update a key's value (as c3 do not have update()function)?
Can c4 invoke c2 to update a key's value (as c4 do not have update()function)?
Can c3.read() query the data created by c1.write() ?
This link on chaincode tutorial says "State created by a chaincode is scoped exclusively to that chaincode and can’t be accessed directly by another chaincode". Does this apply for peers in the same channel too? As per my understanding blockchain ledger data is accessible to all participating peers.
Can c4.read() query the data created by c1.write() ?
Can c2.update() update the data created by c1.write() ?

1 Answer

0 votes
by (14.4k points)
edited by

You have to focus on the point nodes or peers can only execute the chain codes that they have installed and had local access. Although users can have multiple chain codes for a given peer, other peers can’t execute chain codes that are not related to them. 

The above statements are verified from the ChaincodeStub.invokeChaincode(chaincodeName, args, channel) documentation which is available at https://fabric-shim.github.io/ChaincodeStub.html#invokeChaincode__anchor

The document states, ‘Locally calls the specified chaincode invoke() using the same transaction context; that is, chaincode calling chaincode doesn't create a new transaction message.’

For handling access control, you should install every chain code for individual peers and use the ChaincodeStub.invokechainChaincode method along with ClientIdentity class.

Give yourself time to explore the Blockchain field properly. Enroll in Blockchain Online Training now.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...