Let's imagine we have a 30kk gas limit block in ETH. 25kk of gas are already taken, and it's time for my transaction, which consumes 10kk gas. Will it be pushed to this block, with kind of "Out of gas" exception and 5kk consumed gas, or it gonna be pushed to the first block where it could consume full 10kk of gas?
1 Answer
It will stay in the mempool for possible inclusion in a future block.
Generally, miners are incentivized to pack as much gas as possible into blocks, at the highest offered gasPrice. It's like trying to pack a container with the highest possible mass - constrained by space but aiming for the highest possible weight.
So, a viable algorithm would be:
- Order mempool transactions by gasPrice, highest to lowest, regardless of size (gas)
- Insert txns in descending gasPrice order, skipping any that don't fit in the available space (gas consumption).
- Stop when gasLimit is reached or no mempool transactions that will fit in the remaining free space exist.
Hope it helps.
-
Yeah, that helps! But what will happen in case, if my transaction with gasLimit 30kk (and possible size of 30kk) is surrounded with try...catch block, so that it can anyway fit all the 5kk of remaining block space without being reverted? Miners will anyway try to maximise their profits and wait for a full 30kk transaction to be included?– Andy DJul 6, 2022 at 20:18
-
It's deterministic. Gas consumption is known when it's considered at a certain position in the block, as are all other conditional branches. Jul 7, 2022 at 2:58