0

Let's imagine that I've two pretty same transactions - the only difference is their to field. The first transaction - A, has 0x1111.... and the second one - B, has 0x22222.... in the to field.

If I'm sending them at the same time - what will happen? I see two different ways:

  1. The "world" will be split in two parts: those nodes, who have received A at first and those, who have received B. So, depending on where "our" miner are - A or B will be mined, 50 / 50.

  2. Ethereum nodes allows replacing transactions if they are not comfirmed. So, if a transaction is not mined yet, and node receives a new one - it replaces.

And the second question. Let's set the gasPrice for the B twice bigger than in the A.

  1. I'm sending A
  2. Waiting for e.g. 2 seconds
  3. sending B

Does B have any chances to win this race? I mean, are there such rule like: "If there is a transaction from some address in tx pool, but there is another transaction from the same address and it's more expensive - first transaction should be replaced with the second one"

Thanks in advance!

1

If I'm sending them at the same time - what will happen?

A node will not replace transactions with the same nonce unless the gas price of the new transaction is higher than a certain value (Default: 10%, Min: 1%). As a result, A or B will be mined depends on which transaction the miner received first. Note that the non-mined transaction will be removed when a node receives the mined block.

Does B have any chances to win this race?

Yes. Account Nonce is used in Ethereum for replacing a transaction that is not being mined. Sending a transaction with the same nonce and a higher gas price will replace the old one. For a normal use case, nonce should be increased by 1 every time you send a transaction, so an account can send multiple transactions at the same time.

1

It's neither of those things.

The sent transactions end up in the pending transactions queue. Yes, the network nodes discover the pending transactions in their own time, certainly not simultaneously, but it doesn't matter.

The mining process establishes a definite order for the transactions that are accepted into the chain. It may be A, then B, or B then A. In any case, the transactions will be processed by all nodes in the same order.

A block is an ordered set of transactions. A blockchain is an ordered set of blocks. By extention, a blockchain is an ordered set of transactions. Everyone will actually process the transactions in same sequence, sooner or later.

Hope it helps.

  • 1
    It'll never be A then B or B then A, since the only difference between A and B is to and gasPrice. It'll always be A or B since they have the same nonce. – flygoing May 16 '18 at 12:33
  • I suppose that's what you meant by "the only difference". Firing off two transactions with the same nonce is highly unusual and not the way I interpreted your question. The world does not split into two parts. At most, a chain reorganization. Ultimately, one of your transactions is in and the other is out. – Rob Hitchens - B9lab May 16 '18 at 16:29
  • (Note: I wasn't the one that asked the question) I was just pointing out that OP implied that the nonce was the same, aka tx replacement. It's not that weird if you're trying to increase the gas price. Happens all the time, Metamask even has an option for it. – flygoing May 16 '18 at 16:39

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.