Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ensure that a chaincode is invoked by another chaincode

Lets say that we have two different chaincodes: cc1 and cc2.

If cc1 invokes cc2 is there a way for cc2 to check if the invocation is coming from cc1.

like image 239
Ilia Vatahov Avatar asked Oct 26 '18 15:10

Ilia Vatahov


People also ask

What are the important ledger operations that can be done via invoking chaincode functions?

A chaincode can be invoked to update or query the ledger in a proposal transaction. Given the appropriate permission, a chaincode may invoke another chaincode, either in the same channel or in different channels, to access its state.

What are the four stages of a chaincode life cycle?

We provide four commands to manage a chaincode's lifecycle: package , install , instantiate , and upgrade .

How are chaincode functions initiated?

Chaincode runs in a seperate process from the peer and initializes and manages the ledger state through transactions submitted by applications. A chaincode typically handles business logic agreed to by members of the network, so it similar to a “smart contract”.

How endorsement policies are implemented in Chaincodes?

By default, endorsement policies are specified in the chaincode definition, which is agreed to by channel members and then committed to a channel (that is, one endorsement policy covers all of the state associated with a chaincode).


1 Answers

I think there is no current official support for that. But it seems possible to get first called chaincode from SignedProposal (More on this here)

Another possible generic solution can be something like temporary token verification, it goes like this: - chaincode1(cc1) gets called, and it wants to call chaincode2 (cc2) - cc1 random generates token and appends it to message with its name. - cc1 invokes cc2 - cc2 takes token and with help of given name invoked cc1 with same token in msg. - cc1 verifies that token is correct. - cc2 continues to do its thing. There is overhead in communication but it is, within my knowledge, only way to know for sure if your code is called from another specific chaincode.
edit: this way is not working

like image 165
draganrakita Avatar answered Oct 20 '22 15:10

draganrakita