I have been trying to understand smart contract execution in ethereum for some time. Post reading multiple documentation and hands on ganache, I wanted to verify if my overall understanding of its execution is correct.

Can someone validate this understanding of mine please. Please correct me if I have gone wrong somewhere (specially about who gets paid and who doesn't).

I understand there is much more complexity when it comes to error handling and events, but wanted to summarise the steps in a happy path scenario.

  1. To create a new smart contract, a transaction is created with a special address and submitted to a full node, which validates the authenticity of the transaction (by validating the signature) and passes on to all its peer nodes, which in turn also validates the transaction. This keeps happening till this transaction request reaches one or more mining nodes.

  2. Once a mining node decides to pick this transaction from its pool ( based on its choice by looking at the gas provided for this transaction by sender ), it adds this transaction to its list it has selected to make a block and tries to solve the “proof of work”. Once it's done it publishes this block to all full nodes (including itself). All the gas is awarded to this miner node if its block is selected to be added in the blockchain. ( Some gas might go to other miners who might have created ommer blocks for this transaction) .

  3. All the full nodes which receive this block, executes the transaction contained in the block and hence have a copy of this smart contract. They don't get paid anything for this work.

  4. When a state change method is called on this smart contract, it creates a transaction again and steps mentioned above 1 to 3 are followed. Again all full nodes execute this transaction upon receiving it in the block from the miner or peer node and the state variable is updated within their nodes ( assuming no error while executing the code ). Again no payment for any full node to execute a smart contract.

     Question: Does the validation like assert or require is validated by the first full ( local ) node encountered or is it validated only while executing the whole transaction post insertion of it in the block ?
  5. If a view/pure (call) request is made on smart contract method, the first full node would execute this and return the result. No transaction is created. If running a local full node or using something like infura this would not cost any gas, but if we invoke another full node from network gas will be charged for this read.

Question about full node :

If a new full node is coming up for the first time, it would download the whole blockchain from its peers. And it would also execute every transaction of every block to validate the authenticity of the block ( basically validate the merkel root of the block ) and create the latest value for state variables of a given smart contract.

Is this understanding correct ?

1 Answer 1

  1. The first node that accepts a transaction validates the transaction is well formed, its signature. It doesn't need to execute the contract.

  2. Any function executed off-chain doesn't pay any gas, because there's no transaction involved. If a pure/view function is executed inside a transaction it costs gas to the sender.

A full node could download the existing block and execute the transactions and it will recreate the same Ethereum World State that running nodes already have.

An Ethereum client isn't required to execute all the transactions in the blockchain. Some clients like geth, openethereum have a mode where the initial synchronization download a snapshot of the Ethereum state.

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.