Skip to content

txpool: introduce MaxTxGasLimit feature to enforce per-transaction gas limits #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: optimism
Choose a base branch
from

Conversation

niran
Copy link

@niran niran commented Jun 5, 2025

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 an ErrTxGasLimitExceeded error.

Tests

Added comprehensive tests covering the new functionality:

  1. Unit tests in legacypool_test.go:

    • TestTxPoolMaxTxGasLimit: Verifies that transactions exceeding the configured limit are rejected while transactions within the limit are accepted
    • TestTxPoolMaxTxGasLimitDisabled: Ensures that when the feature is disabled (default), all transactions are accepted regardless of gas limit
  2. Validation tests in validation_test.go:

    • TestValidateTransactionMaxTxGasLimit: Tests the core validation logic with various scenarios including no limit, under limit, at limit, and over limit cases

Additional 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant