2

When this is in the Solidity Contract ...

address.send(amount)

... what happens specifically on my node and blockchain? Step by step.

And, in this case is the throw state or the SuccessEvent() executed immediately?

if (!celler.send(dealAmount)){
    throw;
} else{
    SuccessEvent();
}

Thanks.

1
  • I edited your question a little to help you out. Commented Jan 26, 2017 at 9:14

2 Answers 2

3

It sounds like you're questioning timing and flow control and maybe thinking about mining delays and so on.

There's a delay to mine a transaction, but you don't need to consider that delay inside a transaction because transactions always execute or fail completely.

Your address.send() returns a true/false success/failure result to your contract. You can safely think about that as happening immediately. It will log an event if the send() succeeded, or nothing will happen if the send() failed, because (throw).

There's no time delay between the send() and the event because each new block presents an internally consistent picture of the accepted transactions and the results.

Step-by-step:

  1. Someone sends a transaction to a function
  2. Miners run the contract and discover if it succeeds or fails. If it succeeds, what changed? There was a value transfer and an event.
  3. If the transaction succeeded, it gets included in a block and the state changes are part of the blockchain.
  4. If it failed (throw), miners ignore the transaction and there will be no state changes.

Hope it helps.

2
  • As for SuccessEvent(), it’s invoked on your node when you receive a block containing the successful transaction. Commented Jan 26, 2017 at 12:16
  • Good point. That's when the node knows about it. Commented Jan 26, 2017 at 12:48
1

All EVM code is executed sequentially, like any other programming language where there is no implicit or explicit asynchronous clls.

Both throw and Event creation are executed immediately.

If the contract called in a transaction throws, then the whole transaction is rolled back with out of gas (invalid jump) error. Miners still get their gas.

If a contract is called from another contract and the function throws then the transaction is not rolled back, but this is handled as a boolean return value.

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.