0

I read in one of the answers as below -

So when does smart contract code run?

Lots of times, repeatedly and redundantly. By design.

Smart contracts are if then - so if this is run repeatedly and redundantly - wont then "then" condition in the contract execute multiple times ?

Also when a smart contract is published - what exactly miners do? Are they the ones responsible for validating the smart contract and pushing to block chain ?

Also I read that once the smart contract is added to the block, it is propagated to other nodes and they validate - what exactly the other nodes validate - do they check the mining ( similar to validating the nonce in bit coin ? )

Now that the smart contract resides in all the nodes - which node is responsible for execution of the same ? and who triggers the execution of smart contract ?

Thanks in advance.

2

Every node executes every transaction and they all do so identically. It's massively redundant, and that's on purpose.

Your questions "which node is responsible for execution" is the culprit in allowing you to understand what's going on. All nodes are equally responsible and run the code 100% independently of each other. They do this because they are competing to win the block reward.

Each node executes the smart contract correctly because they know that if they don't the other nodes will reject their result. After processing a group of transactions, the first node that finds the block hash publishes it across the network. The other nodes, being interested in verifying the transactions as quickly as possible, quickly do so and return to trying to win the next block.

So the premise of your question is wrong. There is no "one node responsible" to run the smart contract. Every node runs every transaction (which are either transfers of ether or smart contract executions).

Hope that clarifies a little bit.

  • Thanks Thomas, that helped a lot and i got a good understanding now. One last clarification - what is the process of pushing the smart contract to the block chain. Is it just a matter of writing the code and making sure it is pushed . My reading from all blog / tutorials explains that - write and push. Now that execution and mining part is clarified - please help on the first part . Thanks a ton again for your explanation, that really helped. – Harish Narayanan Jan 4 '18 at 6:25
  • “Pushing” (or deploying) a smart contract is identical to sending any other transaction on the network, with two caveats. (1) the “to” address is 0x0, and (2) the contents of the input data field are the compiled byte code of your smart contract. (Normally, the input data field either contains nothing in the case of regular transfer of ether, or function call data in the case of a smart contract invocation.) – Thomas Jay Rush Jan 4 '18 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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