4

We are currently making a plan for our hyperledger fabric network. We really need to know the answer to the following question: "Does a query to the blockchain/worldstate add another transaction to the blockchain"?

The docs tells us the following (that's where the confusion occured).

  • "Applications submit transactions which capture changes to the world state, and these transactions end up being committed to the ledger blockchain."
  • "The blockchain is structured as sequential log of interlinked blocks, where each block contains a sequence of transactions, each transaction representing a query or update to the world state."

So does only updates result in new transactions on the blockchain or also queries?

M Yil
  • 877
  • 1
  • 14
  • 35

2 Answers2

6

The answer is no, you will not insert another transaction in a block, but a transaction is generated to do the query.

Let me explain better:

When an application wants to insert data into the blockchain, it generates a transaction. The application will contact endorsing peers for making the transaction proposal, check the results, and only if they are equal and correct, the transaction is sent to the ordering service. The ordering service is the only one who is allowed to generate new blocks for the blockchain. The ordering service receive these transactions and insert them into blocks, and then send the blocks to the various peers in order to update their local copy of the ledger.

Instead, when you want to do a query, you generate a transaction to communicate with one or more peer, the peer will send you the answer but here the transaction ends. By ends, I mean that the transaction is not sent to the orderer, he is not contacted at any point when you do a query. This because you query the ledger contained in the peer, which is a local copy of the ledger, and you don't generate a new block.

So, transaction is used to communicate with the peer, but is not sent to the orderer in this case, it is not written inside a block and it is not used for that. Inside blocks you will find only transactions approved by the application after the proposal, which are next validated by the ordering service and can modify the world state.

Riki95
  • 706
  • 1
  • 7
  • 16
  • 1
    remember you can set this as an answer if it solved. – Riki95 Dec 16 '19 at 09:07
  • 1
    This means that what we find here (https://medium.com/@kctheservant/transactions-in-hyperledger-fabric-50e068dda8a9) in the section "Demo Flow" is wrong? They said that the function queryCar() -a query indeed- generates another block (so it must be a transaction). – giacom0c Dec 19 '19 at 09:28
  • 2
    that function calls a method INVOKE to do a query, this means a new block is generated. if you use the QUERY method instead, you just query the ledger without generating a new block – Riki95 Dec 24 '19 at 14:46
-1

It's denpends on your deamand. There are two function in fabirc 1.4 SDK(java). If you don't want to the query transaction submitred to ledger than use the evaluateTransaction funciton.

    /**
     * Evaluate a transaction function and return its results.
     * The transaction function {@code name}
     * will be evaluated on the endorsing peers but the responses will not be sent to
     * the ordering service and hence will not be committed to the ledger.
     * This is used for querying the world state.
     * This function is equivalent to calling {@code createTransaction(name).evaluate()}.
     *
     * @param name Transaction function name.
     * @param args Transaction function arguments.
     * @return Payload response from the transaction function.
     * @throws ContractException if no peers are reachable or an error response is returned.
     */
    byte[] evaluateTransaction(String name, String... args) throws ContractException;

    /**
     * Submit a transaction to the ledger. The transaction function {@code name}
     * will be evaluated on the endorsing peers and then submitted to the ordering service
     * for committing to the ledger.
     * This function is equivalent to calling {@code createTransaction(name).submit()}.
     *
     * @param name Transaction function name.
     * @param args Transaction function arguments.
     * @return Payload response from the transaction function.
     * @throws ContractException if the transaction is rejected.
     * @throws TimeoutException If the transaction was successfully submitted to the orderer but
     * timed out before a commit event was received from peers.
     * @throws InterruptedException if the current thread is interrupted while waiting.
     * @throws GatewayRuntimeException if an underlying infrastructure failure occurs.
     *
     * @see <a href="https://hyperledger-fabric.readthedocs.io/en/release-1.4/developapps/application.html#submit-transaction">Developing Fabric Applications - Submit transaction</a>
     */
    byte[] submitTransaction(String name, String... args) throws ContractException, TimeoutException, InterruptedException;

  • The above question is a conceptual question about query and invoke in fabric. Currently, your answer is mapped to the calling function name of sdk. – myeongkil kim Dec 15 '20 at 04:51
  • Of course, depending on the situation, when requesting query and invoke on the SDK, you use the code you wrote, but it seems that it can be used as an example here. – myeongkil kim Dec 15 '20 at 04:51
  • Couldn't it be further processed by attaching examples after conceptual explanations and answers take precedence? – myeongkil kim Dec 15 '20 at 04:51
  • In addition, it would be nice to use Markdown to increase readability. For code, use code blocks, and for phrases or keywords to be emphasized, use \`keyword\` -> `keyword`. Please refer to the link below [editor.md](https://pandao.github.io/editor.md/en.html) – myeongkil kim Dec 15 '20 at 04:51