dr_devbc
dr_devbc

Reputation: 303

Is there a best practice to invoke cross channel transaction?

For example, there are 2 channels as below.

CHANNEL_A:
  chaincode name -> chaincode_a
  ledger data -> amount=150

CHANNEL_B:
  chaincode name -> chaincode_b
  ledger data -> amount=0

I want to withdraw 100 from CHANNEL_A's ledger data and deposit 100 to CHANNEL_B's ledger data.
According to the Fabric documentation, if the called chaincode is on a different channel, only the response is returned to the calling chaincode; any PutState calls from the called chaincode will not have any effect on the ledger.

So, if I call chaincode_b and it calls chaincode_a, I can update the amount on chaincode_B, but I can't update on chaincode_A.
So, I have to invoke 2 transactions for both channels on the application side. I have to consider error handling and so on for data consistency.

Is there a best practice to handle such a transaction on the application side?

Upvotes: 1

Views: 409

Answers (1)

yacovm
yacovm

Reputation: 5140

To update something in channel A and also in channel B - you need to do 2 transactions and make them commit or not commit in an atomic manner.

A way to do this is to implement something equivalent to a 2-phase commit in the application layer.

However this isn't trivial to do, as you may always get MVCC conflicts that will get in the way.

Upvotes: 2

Related Questions