In Hyperledger Fabric, if a transaction modify several assets, and then launch an exception, the assets keep modified or their state get reverted to be as before the transaction?
Asked
Active
Viewed 57 times
1 Answers
2
It depends on the stage the transaction gets rejected.
If chaincode fails at validation time, it will not be recorded in the ledger, since the transaction has not been sent to the ordering service. Exceptions on the chaincode are the most common exception, you execute your smart contract, and then it fails on some peers due to non-deterministic reasons or due to a bug.
After inspecting the responses of all the endorsing peers, if everything is OK, it can be sent to the ordering service. The ordering service doesn't accept the transaction sent, the transaction is still be written in the ledger but as invalid.
If you want to understand it deeply, transaction flow is explained in detail in hyperledger fabric docs.

David Viejo
- 751
- 1
- 6
- 6
-
One thing I don't see clear in documentation is if an Exception makes the transaction invalid. Supposing that don't, what if all contracts have the same behaviour, and the contract is for example: `...stub.updateState("a",something1); throw new Exception(); ...`. What happens here? – Eduardo Pascual Aseff Jun 13 '20 at 22:48
-
1Keep in mind that if an exception is thrown at validation time, no contact with the Orderer is made. If the execution of the chaincode fails, the application(your SDK) will receive an error and it won't keep going with the transaction. I found no documentation about the exact flow of the transaction from the client-side, but we can easily what's going on in the SDK by looking at the source code, for example, https://github.com/hyperledger/fabric-sdk-node/blob/master/fabric-network/src/transaction.ts#L216. – David Viejo Jun 14 '20 at 09:47