txpool: introduce MaxTxGasLimit feature to enforce per-transaction gas limits #626
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces a new
MaxTxGasLimit
feature that allows node operators (particularly the sequencer on single-sequencer rollups) to configure a maximum gas limit for individual transactions in the transaction pool. When configured via the--txpool.maxtxgas
flag, any transaction exceeding this limit will be rejected by the transaction pool with anErrTxGasLimitExceeded
error.Tests
Added comprehensive tests covering the new functionality:
Unit tests in
legacypool_test.go
:TestTxPoolMaxTxGasLimit
: Verifies that transactions exceeding the configured limit are rejected while transactions within the limit are acceptedTestTxPoolMaxTxGasLimitDisabled
: Ensures that when the feature is disabled (default), all transactions are accepted regardless of gas limitValidation tests in
validation_test.go
:TestValidateTransactionMaxTxGasLimit
: Tests the core validation logic with various scenarios including no limit, under limit, at limit, and over limit casesAdditional context
By default, transactions can use as much gas as is available to an entire block. This is reasonable on Ethereum mainnet where the block gas limit can be executed in a small fraction of the block time, but on high throughput rollups, it allows worst case transactions to push execution time beyond the block time—sometimes far beyond the block time. Flashblocks introduce an even smaller constraint of one-tenth of a block.
Both state growth and gas target increases change the equilibrium for worst case transactions that the latest opcode pricing was intended to achieve. In between opcode repricings, we need a way to mitigate this problem. A per-transaction gas maximum prevents a single large worst case transaction (e.g. XEN) from stalling the chain, and limits the excess execution time that a block full of worst case transactions can cause.
The limit can be set based on how underpriced we expect opcodes to become before we fork to reprice them. For instance, a 10x underpriced opcode can 10x execution time without a transaction gas maximum. With a transaction gas maximum of 1/10th of the block gas limit, a 10x underpriced opcode can only double the execution time. A 5x underpriced opcode would be able to 1.5x the execution time with the same limit, and a 20x underpriced opcode would 3x the execution time.
EIP 7825 aims to introduce a similar per-transaction gas limit at 30 million gas that would apply to both the txpool and block validation. High throughput rollups will typically want a lower limit chosen in relation to the block gas limit, and single-sequencer rollups can avoid block validation rules that require a hard fork to adjust as gas dynamics evolve.