Skip to content

engine: add targetGasLimit to PayloadAttributesV4#796

Merged
mkalinin merged 3 commits into
ethereum:mainfrom
nflaig:fcu-gas-limit
May 18, 2026
Merged

engine: add targetGasLimit to PayloadAttributesV4#796
mkalinin merged 3 commits into
ethereum:mainfrom
nflaig:fcu-gas-limit

Conversation

@nflaig

@nflaig nflaig commented May 11, 2026

Copy link
Copy Markdown
Member

Adds targetGasLimit to PayloadAttributesV4 so that the CL can pass the target gas limit to the EL on engine_forkchoiceUpdatedV4, instead of relying on a static flag on the EL side for local building.

This is useful for several reasons

  1. it unifies where users have to configure their target gas limit
  2. it allows to configure the gas limit per validator/pubkey, similar to the fee recipient
  3. allows us to use vanilla ELs as builders, see comment

Based on #608 (credit to @mcdee)

Comment thread src/engine/amsterdam.md Outdated
@nerolation

Copy link
Copy Markdown
Contributor

LGTM!

Just to note, this means the EL has to then determine the block.gas_limit based on the target_gas_limit, e.g.:

max_delta = parent_gas_limit // 1024

block.gas_limit = max(
    parent_gas_limit - max_delta,
    min(
        target_gas_limit,
        parent_gas_limit + max_delta,
    ),
)

@nflaig

nflaig commented May 12, 2026

Copy link
Copy Markdown
Member Author

Just to note, this means the EL has to then determine the block.gas_limit based on the target_gas_limit, e.g.:

should the engine spec have more details about this? from the EL side nothing should change, just the source from where they get the target gas limit changes

@mkalinin mkalinin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec change looks good to me 👍 Is there a consensus among CL and EL devs on the acceptance of this change?

@nflaig

nflaig commented May 12, 2026

Copy link
Copy Markdown
Member Author

Is there a consensus among CL and EL devs on the acceptance of this change?

we've discussed this on ACDT 79 yesterday, there was no opposition to this but we should probably get approvals before merging this change

@barnabasbusa

barnabasbusa commented May 12, 2026

Copy link
Copy Markdown
Member

I think this must be bundled together with the removal of gas limit target flags on the EL side. Otherwise the expected behaviour might be unknown. If we merge this in, it would be good for EL teams to start signalling that the EL side gas limit flag will be deprecated post glamsterdam, and probably following the fork the flag should just go away completely.

@mkalinin mkalinin merged commit a22fbd4 into ethereum:main May 18, 2026
5 checks passed
barnabasbusa added a commit to barnabasbusa/execution-apis that referenced this pull request May 18, 2026
Aligns the SSZ schema with PR ethereum#796 (a22fbd4), which added
targetGasLimit to PayloadAttributesV4 in the JSON spec but
left this SSZ doc behind. Without it, CLs sending the alpha-8
field over SSZ get rejected by EL SSZ decoders that still use
the old 6-field layout (off-by-8 withdrawals offset -> malformed
SSZ body).
pull Bot pushed a commit to All-Blockchains/prysm that referenced this pull request May 19, 2026
- Add `target_gas_limit` field to `PayloadAttributesV4` to align
`engine_forkchoiceUpdatedV4`.
- Thread `val.GasLimit` from `TrackedValidator` through every
`PayloadAttributesV4` construction site (proposer RPC, blockchain FCU,
late-payload FCU, payload_attributes SSE event)
- Implements
[consensus-specs#5235](ethereum/consensus-specs#5235)
and
[execution-apis#796](ethereum/execution-apis#796).
VanshSahay pushed a commit to VanshSahay/erigon that referenced this pull request May 25, 2026
jihoonsong added a commit to jihoonsong/execution-apis that referenced this pull request May 26, 2026
benaadams added a commit to NethermindEth/nethermind that referenced this pull request Jun 3, 2026
commit 96ff773
Merge: 8a82ef5 1bb7582
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Tue Jun 2 13:33:56 2026 +0200

    Merge branch 'master' into feat/engine-payload-attrs-target-gas-limit

commit 8a82ef5
Author: Barnabas Busa <barnabas.busa@ethereum.org>
Date:   Mon May 18 15:47:00 2026 +0200

    feat(engine/ssz): add target_gas_limit to PayloadAttributesV4 wire (#11647)

    Plumbs the new TargetGasLimit field added in this PR through the
    SSZ-REST wire schema for engine_forkchoiceUpdatedV4 (PR #764).

    Without this, CLs that include target_gas_limit in the SSZ body get
    rejected as "Malformed SSZ body" because the 8 extra trailing bytes
    shift the inner withdrawals offset.

    The wire field is a required fixed-size uint64 (per execution-apis
    ssz-encoding.md), so a missing value fails SSZ decode directly — the
    V4 null-guard in PayloadAttributes.GetInvalidPayloadAttributesMessage
    remains as defense-in-depth for the JSON path.

    Changes:
    - PayloadAttributesWire gains target_gas_limit at the end of the
      container (matches execution-apis ssz-encoding.md PayloadAttributesV4).
    - SszCodec.PayloadAttributesFromWire forwards the wire ulong as long
      to PayloadAttributes.TargetGasLimit.
    - DecodeFcuV4Request roundtrip test now also asserts target_gas_limit
      survives encode/decode, using a diverse-byte value (0x0123456789ABCDEF).

commit e60c92c
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Fri May 15 08:05:21 2026 +0200

    refactor(aura): reuse inner calculator for IsGasLimitValid bound check

    `AuRaContractGasLimitOverride.IsGasLimitValid` now round-trips the
    candidate gas limit through `_innerCalculator` (a
    `TargetAdjustedGasLimitCalculator` in production): if the calculator
    returns the candidate unchanged it's within the standard parent ±
    delta range, otherwise it's been clamped. Drops the duplicated delta
    math and the `ISpecProvider` dependency added in the previous commit.

    Also strip the verbose XML doc comments added on `TargetGasLimit`,
    `PayloadAttributes.GetGasLimit`, `IGasLimitCalculator.GetGasLimit`,
    and the explanatory test comments.

commit fcd8b67
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Fri May 15 07:11:04 2026 +0200

    fix(aura): relax IsGasLimitValid for CL-supplied targetGasLimit

    `AuRaContractGasLimitOverride.GetGasLimit` prefers the CL-supplied
    `targetGasLimit` (PayloadAttributesV4) over the on-chain contract
    value, but `IsGasLimitValid` — called from `AuRaBlockProcessor` —
    still strictly required the block to match the contract. On an AuRa
    chain with an active gas-limit contract that ever activates
    EIP-7843, a producer using the override path would emit a block its
    own validator rejects.

    Accept any block gas limit within parent ± delta when it differs
    from the contract value (HeaderValidator independently enforces the
    full consensus rule). Inject `ISpecProvider` so the bound divisor is
    read from the active release spec instead of being hardcoded.

commit 6abd4a3
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Thu May 14 21:44:01 2026 +0200

    refactor(consensus): rename targetGasLimitOverride to targetGasLimit

    Align with the spec field name (`PayloadAttributesV4.targetGasLimit`).
    The "override" suffix was redundant — a non-null value already means
    override behavior. Inside `TargetAdjustedGasLimitCalculator`, reuse the
    parameter via `??=` instead of an extra local.

    Also drop the unused `using Nethermind.Xdc.Spec` in XdcGasLimitCalculator
    (left over from the previous expression-body collapse) — was failing the
    `IDE0005` lint check.

commit 74e2729
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Thu May 14 21:32:17 2026 +0200

    style(xdc): collapse XdcGasLimitCalculator.GetGasLimit to expression body

commit c3ae2b4
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Thu May 14 17:57:42 2026 +0200

    refactor(engine): simplify targetGasLimit wiring; AuRa override wins

    - Type `TargetGasLimit` as `long?` directly (was `ulong?`), dropping the
      narrowing cast and the upper-bound `> long.MaxValue` validation. Gas
      limits in Nethermind are already stored as `long`.
    - Consolidate the parameterless `PayloadAttributes.GetGasLimit()` and
      the duplicated `payloadAttributes?` access at the call site into a
      single `GetGasLimit(BlockHeader parent, IGasLimitCalculator calc)`.
      Base implementation routes `TargetGasLimit` through the calculator;
      Boost/Optimism/Taiko override to return their unadjusted value.
    - AuRa: drop the conflict warning and flip precedence — the CL's
      per-FCU `targetGasLimit` now takes priority over the on-chain
      contract value, with the contract acting as fallback when no
      override is supplied.
    - Dedup `TargetAdjustedGasLimitCalculatorTests` and the new AuRa
      override tests around small construction helpers.

commit e217c72
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Thu May 14 17:29:29 2026 +0200

    fix(engine): address review on targetGasLimit handling

    - Collapse `IGasLimitCalculator.GetGasLimit` to a single method with
      `long? targetGasLimitOverride = null` default; update all
      implementations (TargetAdjusted, AuRa, FollowOtherMiners, Optimism,
      Xdc, ManualGasLimitCalculator).
    - Reject `TargetGasLimit > long.MaxValue` in `PayloadAttributes.Validate`
      to prevent silent wrap of the `ulong? -> long?` narrowing. Cast sites
      in BlockProducerBase / TestingRpcModule now use a `checked` cast for
      defense-in-depth on paths that bypass validation.
    - AuRa contract override: when the contract returns a limit and the CL
      also supplies a `targetGasLimit`, log a warning so operators know the
      contract takes precedence; otherwise forward the override to the
      inner calculator.
    - Add focused unit tests for AuRa: contract wins (override ignored) and
      no-contract (override forwarded). Add a V4 validation case for
      `TargetGasLimit > Int64.MaxValue`.

commit 9524007
Author: lukasz.rozmej <lukasz.rozmej@gmail.com>
Date:   Thu May 14 16:54:06 2026 +0200

    feat(engine): support targetGasLimit in PayloadAttributesV4

    Implements ethereum/execution-apis#796, which adds a required
    `targetGasLimit` field to `PayloadAttributesV4` so the CL can supply
    the per-FCU gas-limit target instead of relying on the EL's static
    configuration.

    - `PayloadAttributes.TargetGasLimit` is included in `ToString`, the
      payload-id hash input, version inference, and required-field
      validation for V4 attributes.
    - `IGasLimitCalculator` gains an overload accepting an optional
      target override; `TargetAdjustedGasLimitCalculator` honors it,
      taking precedence over `BlocksConfig.TargetBlockGasLimit`.
      `AuRaContractGasLimitOverride` forwards the override to its inner
      calculator.
    - `BlockProducerBase` and `TestingRpcModule` pass the per-call target
      into the calculator so the standard gas-limit adjustment applies.
jihoonsong added a commit to jihoonsong/execution-apis that referenced this pull request Jun 9, 2026
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.

9 participants