I am working on a small project to get myself familiar with the Hyperledger Fabric.
Currently, I have a small network, consisting of single peer, orderer and ca nodes (plus cli, chaincode and explorer), defined in docker-compose.yml
I have installed sample chaincode, chaincode_example02 to be more specific The initial state of a ledger is A:100, B:200, defined by
peer chaincode instantiate -n mycc -v 0 -c '{"Args":["init","a","100","b","200"]}' -C myc
When I execute the transfer everything works as expected
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
That is 10 units gets transfered from A to B
BUT when I run let's say 3 transactions,
for i in {1..3}
do
peer chaincode invoke -n mycc -c '{"Args":["invoke","a","b","10"]}' -C myc
done
as a result I have three transactions in one block, but each of them identical, and as a result of those three transactions I have only 10 units transferred, whereas I would expect 30.
Do my question is: do I need to resort to the high throughoutput solution to have deterministic transactions? Or there is another way to achieve it (using events for example)?
Having this three transactions in the same block would mean that only one is successful, since all three of them writing into same key. The transaction to succeed is the first one, while two remaining will be considered as concurrent and hence invalidated.
The result of chaincode simulation/invocation is the Read-Write set, where it contains keys, values and modification version. Transactions trying to modify key with same or outdated version fails the MVCC (Multi Value Concurrency Control) check during block commit.