Is there anyway that i can limit the calling of apply method to just 1 in the Transaction Processor? By default it is called twice.
Asked
Active
Viewed 85 times
0
-
Welcome to SO. Please see https://stackoverflow.com/help/how-to-ask for information on how to ask questions. Your question in it's current state is hard to answer. Please add more information. Provide the code you have tried so far. – Korashen Nov 15 '19 at 19:49
1 Answers
1
I guess your question is based on the log traces you see.
Short answer: apply
method also the core business logic in your transaction family is executed once for a input transaction. There is a different reason for you to see the logs appear twice. Well, in reality transaction execution happens and state transitions are defined with respect to the context. Read the long answer for detailed understanding.
Long answer: If you're observing logs, then you may need to go a little deeper into the way Hyperledger Sawtooth works. Let's get started.
Flow of events (at very high level):
- Client sends the transaction embed in a batches.
- Validator adds all the transactions in the pending queue.
- Based on the consensus engine's request, the validator will start creating the block.
- For the block creation, a current state context information is passed along with the transaction request to the Transaction Processor. Eventually send to the right Transaction Family's apply method.
- The apply method's result either success or failure is recorded. The transaction is removed from the pending queue if is invalid or it is added to the block.
- If the response of the apply method is internal error then that is resubmitted.
- If a transaction is added to the block. Depending on the consensus algorithm, the created block is broadcasted to all the nodes.
- Every node executes the transactions in the arriving block. The node that created the block will also execute. This probably is what you're talking about.

Arun
- 592
- 3
- 13
-
Thanks a lot for reaching out to my concern, Actually my problem is that i have database insertion associated with apply method. so when the transaction happens, it adds dual records at the same time. After searching on internet i found this in FAQ of Sawtooth https://sawtooth.hyperledger.org/faq/transaction-processing/#why-is-the-apply-method-in-the-tp-handler-called-twice – Mohsin Anees Nov 16 '19 at 17:24
-
In that case, the external DB queries shall not be done through the TP. Raise an event and let the event listener add that data into the DB. Event is generated only when a block is committed. Note that this may not be good if you're using forking style of consensus engine. – Arun Nov 17 '19 at 12:48