Any terrible thing will happen if change Chaincode state in invokeChaincode?

294 views Asked by At

Let's say I have two chaincode in Hyperledger Fabric, ChaincodeA and ChaincodeB.

Some events in ChaincodeA will have to change state in ChaincodeB, for example, change its balance. If invokeChaincode() used in ChaincodeA to invoke some logic in ChaincodeB, which calls putState() to change ChaincodeB's state, any race condition could happen when getting consensus? What's the best practices on handling this?

2

There are 2 answers

0
Artem Barger On BEST ANSWER

While invoking a chaincode you do not change the state you only simulate transaction execution based on the current state. Only once transaction placed into the block by ordering service and reaches the peer where it has to pass VSCC and MVCC checks it gonna be eventually committed. MVCC will take care of possible race condition. Transaction execution works as following:

  1. Client sends transaction proposal to the peer
  2. Peer simulates transaction sign the results and put them into signed transaction proposal
  3. Client has to repeat step #2 based on expected endorsement policies
  4. Once client collected enough endorsements he send them to the ordering service
  5. Ordering service cuts the block and order all transaction
  6. Block delivered to the peers
  7. Peer validates and eventually commits the block
0
Anup On

As I understated two chaincode deployed on two different channels. chaincodeA want to call method of chaincodeB. As per specification its possible but only for read operation. https://godoc.org/github.com/hyperledger/fabric/core/chaincode/shim#ChaincodeStub.InvokeChaincode

can you please share code how you are calling another chaincodeB from chaincodeA?