0

Assume I have a smart contract to wire 0.01 Eth to a predefined address when it is triggered. The smart contact is executed when the transaction gets included in a block by miner and the 0.01 Eth shall be sended out. I understand that the smart contract will be executed whenever the transaction is being validated by other nodes. My question is that the wiring by smart contract will happen for each validation. It would be a big problem if it does. Many thanks.

3

If you send a single transaction to the network, it will only be executed a single time.

It is possible that multiple nodes mine the same transaction, causing them to have divergent blocks, but the network is built to handle these situations by sharing with peers the chain with the highest block number, and other nodes validating and accepting that chain as the one valid blockchain.

So even if your transaction did get mined multiple times, on each of those nodes, it would only cause one execution of your function, and in the end, there will only be one such chain with one such execution.

You can think of it the same way as making a transfer between two Ethereum accounts. What you would expect to happens will happen, even though there may be thousands of nodes all trying to process your transaction.

I hope this is clear enough.

2

It may be helpful to specify what is meant by each node running the transaction independently.

These nodes are verifying and computing the contract code and the transaction so they can reach consensus about the outcome. This is quite different than many thousands of computers creating unique transactions.

  • Suppose Alice starts with 10 and Bob starts with 20.
  • Suppose Alice signs a transaction to send 5 to Bob.

Each node has the initial state. They know the balances of both accounts at a given block height. All nodes "see" the transaction at the same block height. This is true even if a node is behind - eventually it will sync up and see the same transactions in the same order as everyone else.

Each node will independently run the contract function, which (presumably) checks that Alice enough, Alice did indeed sign the transaction, and then both accounts should be adjusted. When this is over.

  • Alice has 5
  • Bob has 25

Every node independently executes the contract to determine, for itself, what the new state looks like after the transaction. The consensus is not necessarily universal or instant but it eventually converges on one interpretation that is widely accepted as truth. The most common divergence is slightly different transaction order (not duplication) and this is ironed out for you at the protocol level.

Hope it helps.

0

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.