[Ethereum] Does every node execute the contract code for each transaction

consensuscontract-invocationevmtransactions

This question was asked on Reddit a while ago:

When a node sends a transaction to the network and has the receiver as a contract, does every node execute the contract bytecode with the inputs to confirm the hash? Or does the first node receiving the transaction execute and create the transaction hash that's then distributed and is what's used for consensus. Basically, is the contract code executed once or many times for each transaction? I assume the it's the former if every node is running the EVM.
Reddit: Basic Questions About the Ethereum EVM and State Storage

Best Answer

Yes, the answer is quite logic. Every node has to verify the results of a transaction which invokes a smart contract. The result is that at least every full node will execute the code.

The hash of the transaction isn't relevant until it is being stuffed into a merkle tree. When running the execution, all we care about is the amount of gas, the data being passed in, and the code of the contract that's being called. When the execution completes, the storage tree of the contract may be updated, so we recompute the merkle root hash of that tree (and any other contract which may have been called by that one!)

Source.

Related Topic