using go routine in the chaincode #fabric-chaincode #fabric-questions
Matthew Sykes
It's less about a race and more about consistency. (A race can cause an inconsistency.) Imagine that when you run the contract on peer one, the sequence observed by the ledger is ["data1", "data2"]; on peer two the sequence can be ["data2", "data1"] because there's nothing that ensures one write occurs before another.
On Fri, Apr 16, 2021 at 1:56 PM elmira <elmira.ebrahimi@...> wrote: Hi, --
Matthew Sykes matthew.sykes@...
|
|
elmira <elmira.ebrahimi@...>
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. package main import ( "fmt" "github.com/hyperledger/fabric/core/chaincode/shim" "github.com/hyperledger/fabric/protos/peer" ) } go writeToLedger(stub, “data1”) go writeToLedger(stub, “data2”)
} stub.PutState(“key”,[]byte(data)) }
|
|