-1

I have a Data61BPMNtoChaincode Project on a ubuntu vm. (https://github.com/leoaction/Data61BPMNtoChaincode/tree/master)

For starting a client, NodeJS is used as a server which sends multiple requests like installChaincode and Deploying chaincode to the network.

When everything is running one can issue a request by sending a transaction to the server which performs either query or invoke -orderer requests to the running peers which runs isolated in a docker container.

In BPMN there is this possibility to build a process with a parallel Block, so 2 or more Activities will be "performed" in parallel.

Looks like this: BPMN parallel Block

So, it could be that the requests are pretty fast and so there is a read on a state which i guess is the old State and so there comes the error: MVCC Read conflict on the peer which is running on a docker container. So Peer A updated a variable with value 1, but the next request which is somehow concurrently trying to read the data just reads the old value 0.

If i introduce a sleep on client side for 3 seconds than it works. But i do not want to have sleeps in production thats why i want to catch this error and send the request again.

Now my question is how can i catch this error in the chaincode in order to propagate it back to the nodeJS Server so that i can send the request again. I think this must be done in the chaincode?

Running peers: running peers

Log of peer: log of peer

Thanks for any help.

sebi
  • 21
  • 8

2 Answers2

0

You cannot catch this condition in your smart contract. The error occurs later in the transaction flow during validation, after the transaction has been recorded in a block on the blockchain.

This workshop material might help clarify the transaction flow as it relates to the client application:

https://github.com/hyperledger/fabric-samples/blob/main/full-stack-asset-transfer-guide/docs/ApplicationDev/01-FabricGateway.md

Your Node server (which in this case is interacting with the Fabric network as a client application), identifies the failure when it obtains the transaction commit status and receives an MVCC_READ_CONFLICT validation code. The failed transaction is recorded on the blockchain and any subsequent transaction using the same transaction ID will fail due to a duplicate transaction ID. Your client application needs to attempt the entire transaction submit process again with the same arguments and a new transaction ID.

This documentation from the same workshop material linked above (and the accompanying sample client application code) provide a simple example of identifying the failure reason and retrying the transaction submit:

https://github.com/hyperledger/fabric-samples/blob/main/full-stack-asset-transfer-guide/docs/ApplicationDev/03-ApplicationOverview.md#retry-of-transaction-submit

bestbeforetoday
  • 1,302
  • 1
  • 8
  • 12
  • This idea is great, i was hoping that something like this is possilbe. But i cannot handle it properly on my project. I have a MSIT-SE Studio Project (Data61) Project where bpmn processes gets executed by endorsing transaction from running activity. So i dont know how to restrucure my project and do not even know where to put get code of getNetwork or gRPCconnnection, I have this nodesJS server which deployes the chaincode. Now i am sending a request to the nodeJS which sends an invoke request to the running peer, result is status 200 / 500 basend on chaincode shim.Error / .Success – sebi Jun 22 '23 at 12:31
  • This is the request to invoke: obj = shell.exec("docker exec -t " + peer + "_" + unique_id + "_cli peer chaincode invoke -o orderer." + orgDomain + ":7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/" + orgDomain + "/orderers/orderer."+ orgDomain + "/msp/tlscacerts/tlsca." + orgDomain + "-cert.pem -C " + channelName + " -n " + sessionId + " -c '{\"Args\":[\"" + actionName + "\"" + paramString + "]}'", {silent:use_silent}); – sebi Jun 22 '23 at 12:32
  • Project: https://github.com/leoaction/Data61BPMNtoChaincode Do you know how can implement this on this project? – sebi Jun 22 '23 at 12:43
0

I have solved the issue by adding --waitForEvent flag to the invoke orderer request. This seems to wait until the first transaction has been committed on so on the second the value is updated.

Solution: cli peer chaincode invoke --waitForEvent -o orderer ...

Thanks for helping.

sebi
  • 21
  • 8