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.
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.
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) .
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.
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 ?
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 ?