问题
Consider the Organization-Peer setup in a Hyperledger Fabric network as shown in the image.
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 byc1.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 byc1.write()
? - Can
c2.update()
update the data created byc1.write()
?
回答1:
Peers can only execute chaincode that they have installed and have access to (local). You can have multiple chaincode for a given peer, but you can't have peers executing chaincode of other peers.
From ChaincodeStub.invokeChaincode(chaincodeName, args, channel)
documentation at https://fabric-shim.github.io/ChaincodeStub.html#invokeChaincode__anchor:
Locally calls the specified chaincode invoke() using the same transaction context; that is, chaincode calling chaincode doesn't create a new transaction message.
You should be able to install each chaincode for all peers and use the ChaincodeStub.invokeChaincode
method along with the ClientIdentity
class (https://fabric-shim.github.io/ClientIdentity.html) to handle with access control.
来源:https://stackoverflow.com/questions/51657142/chaincode-smart-contract-interactions-within-and-across-channels-in-hyperledge