Assume we have a smart contract that has a state variable as follows:

uint data=32;

The contract is stored in the blockchain.

We have two transactions tx1, and tx2 sent to the contract one after the other. tx1 sums the variable with 40:

 data +=40, 

and tx2 multiplies "the new state" by 50:

data *=50

Question: Do the nodes who verify tx2, have to re-run tx1 as well to calculate state before tx2 (i.e. data +=40) again?

1 Answer 1


When tx1 and tx2 are broadcast to the network they will be picked up by miners and included in blocks.

  1. If both tx1 and tx2 originate from the same "owned" account, then they will be included in the blockchain in order (due to the transaction nonce).

  2. If you wait until tx1 has been mined before sending tx2, then they will again be included in order.

  3. Otherwise, there is no guarantee of the order in which the miner or miners will see, or choose to insert, tx1 and tx2 into the blockchain. In this case you could end up with either (32 + 40) * 50 as the result, or 32 * 50 + 40, unless you have some other ordering check within your contract.

Do the nodes who verify tx2, have to re-run tx1 as well to calculate state before tx2 (i.e. data +=40) again?

The role of the nodes is to validate the transactions in the order they appear in the blockchain and confirm that they get the same result. I.e. (full) nodes run every transaction in the same order as the miners included them. But they only run each transaction once.

Does this clarify and answer your question?

  • thanks for the answer. Well, it answers my question partially. I should have clarified in my question: assume Tx2 has issued long after when Tx1 is issued and Tx1 is already in the blockchain. The question is that how the nodes validating Tx2 know that the contract state has changed to data+=40, without redoing Tx1?
    – user153465
    Commented Aug 11, 2017 at 15:31
  • Sure, all nodes know the current state of the blockchain, including its storage - that's why they are always syncing. Every time a block is mined the nodes update their state accordingly. No transaction from a past block needs to be re-executed as new txs are added. Commented Aug 11, 2017 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.