When a call is made from Hyperledger Composer to Fabric runtime, is the transaction hash generated only after the commit in the entire network. If thats the case, should we wait synchronously and track the data from traditional system. Like in ethereum cant we get a transaction hash immediately and track the commit status later.What is the best way of handling this in Hyperledger Fabric.
Yes, just like in ethereum we can get transaction hash inside the smart-contract/chaincode in HL fabric too, it doesn't matter if later transaction is committed or not.
For every invocation request, a transaction ID is generated, it can be accessed by a method
getTxId()
(in java chaincode, similarly can be found in go/node cc) which returns a String transaction id for that request.
refer Java chaincode getTxId
Related
I am new to the latest Hyperledger fabric 2. Before deprecating fabric-composer (a very well thought and intuitive framework) if you wanted to add multiple assests you could call AssetRegistry.addAll() method to add not just one asset but an array of assets. Is there an equivalent in the new hlf version 2? If I have an array of assets/states that I want added in the world-state database and I call putState() multiple times for each state/asset is it not less efficient than calling a putStateList() method that would take as param an array of states? (BTW the old naming of asset from the times of hyperledger composer is much more intuitive than the new name of state ... composer vs de-composer :)))
There is no putStateList in Hyperledger Fabric.
As you mentioned, the only way is to call PutState the number of times you want.
In terms of performance, the data to be sent by the chaincode to the peer is the same length, but I understand that if Peer node could accept a list of states, it could be more efficient on the server-side.
If we look at the internals of Node.JS library, we can see that handlePutState connects to the peer and waits:
And then, it will send the message to the peer, writing the msg to the stream:
I am using the hyper-ledger fabric network with 2 organisation and chain-code also installed on the network its working. I came across submitTransaction and EvaluateTransaction in fabric node js. what is difference between them, what i observer is.
When i initiate contract.submittransaction the submitTransaction from the fabric-node even though if i call the query method from the chain-code its create the new block and chain-code query method don't have put-state
If i use contract.evaluateTransaction the evaluate transaction from the fabric-node to query method its does not create any transaction.
The difference between submitTransaction vs evaluateTransaction is that submitTransaction takes the proposal results returned from invoking the smart contract and submits them to the orderer and waits for the transaction to be committed. This means that the proposal results will be ordered and delivered to the peers for validation and committed to the blockchain.
It is irrespective of what the smart contract transaction does, however the general pattern is that submitTransaction is used for transactions that change the world state and evaluateTransaction is used for transactions that only query the world state (or query key history).
However it's perfectly reasonable for example to want to record querying of the world state onto the ledger and so you would use submitTransaction on a smart contract function that doesn't modify the world state in order to do this.
contract.submittransaction execute the transaction against the chain code that's why it creates the new block. while contract.evaluateTransaction only query the state database that's why don't create the new block.
I am new in this field and therefore I am still doing studies and researches, I would like to know if JSON files can be imported in Hyperldeger Fabric--if it is better Hyperledeger Fabric or Fabric Composer. more precisely I would like to understand if there is a way to populate the DLT of Hyperledger Fabric automatically.
for now, I have only tried Hyperledger Composer online playground
Fabric don't have any feature to automatically populate the ledger.
You have to develop a solution in order to upoload each Json file and put that on the ledger state.
Any type of data can be inserted on the ledged because it stores byte arrays so its up to you how to serialize.
in case you're asking to making your chaincode or smart contract like talking to the file system and read file or even call some API to collect JSON files,
it could be done but this will break your transaction flow specially during the endorsement process due to during the endorsement process it's expected from each peer to return the same value after executing the transaction against the chaincode to consider the transaction is a valid transaction,
so in case one of the endorsers failed to call the API or failed to read file from file system the transaction will considered to be invalid.
so it's not recommended to do any third party activity in your chaincode or smart contract even if it's possible to do so.
about populating the ledger it can be done it's eventually a database so you can dump it's data, However, if you're trying to backup to recover the ledger in case the whole network down it's impossible due to when you'll reinstall the network the whole config and certificates which were bounded to the transaction will be changed so it has no sense to do it.
I'm looking for a transaction rollback. This is necessary if a chaincode transaction modifies the state, but then fails with an error before it is able to return.
I saw this is done for a pull request but I can not understand how does it works
Added support for rolling back a tx if chaincode execution fails
Someone can give me an example how does it works?
EDIT
What I'm looking for is the concept of Transaction in database(unit of work) but in Hyperledger Fabric
Let's suppose that we are going to register a product for a list of clients, if there is a problem with the registration of the product in some customer then the operation is eliminated and the registration is not made to any client
The commit you linked is no longer relevant to current Hyperledger Fabric versions. This functionality was added before v1.0, which restructured the entire framework architecture.
As of v1.0+, transactions are first simulated by endorsers, which create a signed set of state changes resulting from the chaincode. If enough endorsers sign a transaction (according to an endorsement policy), the client can then send the transaction to the ordering service for inclusion in the ledger. A transaction that results in an error in the chaincode would never get to this point, because it would fail to gather the necessary endorsements due to the error. The client must modify the transaction or request a modification of the chaincode for it to work.
Check out the Hyperledger Fabric architecture paper for a more detailed explanation, including a sequence diagram.
I am reading about chaincode in hyperledger fabric for my project. I have a doubt on
How to invoke chaincode automatically based on events like time. If so, are any working examples available.
Thank you in advance.
You cannot invoke transactions automatically without a client. If you look at the transaction flow of Hyperledger Fabric, the client has a lot of responsibilities signing the transactions, like collecting the endorsement, optionally filtering out the proposal responses (bad ones) and sending it for ordering. So, you cannot replace all this logic in the chaincode layer which is essentially responsible for endorsement.
You have to do this invocation based on events like time with the help of the client whose rules you are supposed to define.
So, best way would be put some sort of authorization logic on the chaincode function you want to invoke at regular intervals of time and use a client and a user's certificate to call the functions on the chaincode using some cron mechanism.
Reference to Authorization in Chaincode:
Summary Video: https://www.youtube.com/watch?v=WTW9QVO28l0
Chaincode Reference: https://github.com/hyperledger/fabric-samples/tree/release-1.2/chaincode/abac/go
Documentation: https://docs.google.com/document/d/1GP5tcN0oK9Zewed9h5pLiM2BowWPhtgFUGXEDKjeGGo/edit