Suppose a contract has three call APIs that have side effects.

What's the behavior if I try to:

  1. Call all three APIs from one address (i.e. issue three transactions if from nodejs). Are all three mined simultaneously? In what order?
  2. Same question, but three APIs are called from three different addresses?

Transactions are executed purely sequentially, in an order set arbitrarily by the miner who wins each block. Higher gas priced transactions are more likely to make it into a block, so that contributes to order as well, at the discretion of the miner.

Note that each miner chooses separately, but only one miner wins a round. The winning miner determines the final accepted order, and other miners verify with that order.

Transactions from individual accounts are always executed in order of an auto-incrementing nonce.

  • If every miner makes its own mine I don't see how there can be consensus, because the output from the block could depend on the order the transactions are executed. So I don't see how this could be correct. All the miners would need to share the same ordering algorithm.
    – Paul S
    Feb 16 '16 at 5:16
  • 1
    Only one block makes it into the final consensus, that is the magic of blockchains. Whoever finds a valid block first sends it out to the network, and other miners then mine on top of that. The longest chain is considered the true chain. Feb 16 '16 at 5:34
  • I thought all miners had to run the transaction to verify the winning miner wasn't cheating? Sure they can verify proof of work by checking the hash but they actually have to run the turing machine to verify its output. Or does the winning miner specify the order and all other miners verify by running in that order?
    – Paul S
    Feb 16 '16 at 6:43
  • 1
    That is correct. The winning miner specifies the order, and all of the subsequent miners simply verify in that order. Feb 16 '16 at 6:48
  • please edit your answer to add "winning miner determines order, and other miners verify with that order".
    – Paul S
    Feb 16 '16 at 6:52

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.