using go routine in the chaincode #fabric-questions #fabric-chaincode


elmira
 

 Hi,
Concurrency (using goroutine and go channel) can cause non-deterministic behavior in fabric.

I have not found any source or example on the use of Goroutines and go channels in fabric contracts; I need an example; Are there any links that I can read about it?.

I know that it is better not to use the following code, but I want to know how the race condition that is in the code causes inconsistency among peers.
I appritiate any help.

package main import (

"fmt"

"github.com/hyperledger/fabric/core/chaincode/shim"

"github.com/hyperledger/fabric/protos/peer"

)

type BadChainCode struct{

}

func (t *BadChainCode) Invoke(stub shim.ChaincodeStubInterface){


go writeToLedger(stub, “data1”)

go writeToLedger(stub, “data2”)

 

}
func writeToLedger(stub shim.ChaincodeStubInterface, data string){

stub.PutState(“key”,[]byte(data))

}

Join fabric@lists.hyperledger.org to automatically receive all group messages.