Reputation: 51
While going over v1.0 examples, I ran into a confusion.
As far as I understand, query does not change the ledger as it is executed locally (e.g. no ordering, committing, endorsing involved).
But that is from the caller's point of view. Within chaincode, it just executes whatever the client calls given all of CAs and info are valid.
So for example, if I call
peer chaincode query -C mychannel -n chaincode -c '{"Args":["query", "a"]}'
this would be ok. It just queries a.
But if I call
peer chaincode query -C mychannel -n chaincode -c '{"Args":["**invoke**", "a"]}'
What would be the behavior given that invoke involves writing on the ledger?
Also on the other hand, if I call invoke on query method
(e.g. peer chaincode invoke ~~~ {"Args":["query", "a"]})
What would be the behavior?
As far as I understand, actual chaincode cannot distinguish whether it is query or invoke. It just executes the chaincode method.
Am I far off?
Upvotes: 1
Views: 374
Reputation: 41222
Indeed this is a bit confusing, especially taking into account the thing not very obvious when you using the cli
tool. Here is the thing, when you are using peer cli command with invoke the flow works as following:
- You send transaction proposal to the endorsing peer
- Endorsing peers executes transaction simulations and signs the results
- Client receives the results and send them out to the ordering service
- Ordering service cut the block
- Block delivered to the peers
- Peers validates transactions
- Eventually block appended to the blockchain
Now here is the difference, when you running peer cli with query
parameters key it will do only:
- You send transaction proposal to the endorsing peer
- Endorsing peers executes transaction simulations and signs the results
Therefore, since results is not sent to ordering service there is no effect on the final peer state, since even if you chaincode has made any changes it won't be committed.
Upvotes: 1