4

Consider two transactions, A and B. A is valid given the state of the blockchain as of the last block. B is currently invalid, but becomes valid once A takes effect. A and B are from the same caller and their nonces are sequential - eg A has nonce 4 and B has nonce 5.

For examples of this, consider two smart contract calls where B depends on the effects of A to function.

My understanding is that if both transactions end up on the same block, this block will be valid, because when tx B is processed , tx A will already have happened.

My question is - in practice (ie with current miner implementations) - will both transactions be included on the same block? Assume the gas price is high on both.

I could see it both ways - a miner might not include transactions that are invalid as of the state of the last block. But I could also see them trying to include them all, and the nonces give a hint as to the ordering and validity.

2 Answers 2

3

There is no guarantee that both transactions will be executed in the same block, as miners do typically order them based on gas price, and you can have other transactions with higher prices than yours.

However, you have the guarantee that transaction B won't be executed before A due to the nonce, no matter if it is in the same block or in different ones.

If your question is: I want to execute B only if I have the certainty that A has been confirmed, then you may consider how many block confirmations you want to wait for A until launching transaction B. E.g.: when transferring funds, you want to be really sure that they have been effectively transferred if other actions depend on such transfer.

2
  • It's more that I want to minimize the time between A and B occurring, to reduce waiting time - so if they can be included in the same block (instead of waiting for another one or several blocks) then that's preferable. For example, if we assume the two txs have the highest gas price in the block, how does that change the answer?
    – Claudiu
    Commented Mar 12, 2021 at 16:41
  • 2
    If you could ensure that both transactions will fall in the same block, then you wouldn't need to wait for block confirmations between the two transactions, but you should pay a big amount of gas price and even in that case, you still wouldn't have 100% guarantee to have both transactions mined in the same block. Commented Mar 12, 2021 at 17:09
1

Yes, transaction B will be included in the same block as transaction A provided that their gas price is high enough. If they have the exact same gas price, transaction B will be included immediately after transaction A.

Generally, miner nodes will consider B valid because there is a sequence of valid transactions up to B. However, if you were to broadcast a transaction after skipping a nonce, this transaction would be considered invalid because the sequence of nonces would be broken.

An exception to the first paragraph would be if there is not enough gas in the block to process transaction B. For instance, if after processing transaction A there is 100000 gas left in the block and if transaction B requires 200000 gas, transaction B would be included in the next block and not the same block as A.

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.