Skip to content

refactor(gas): rename InitialAndFloorGas.initial_total_gas to regular_gas#3589

Open
rakita wants to merge 1 commit intomainfrom
helper-init
Open

refactor(gas): rename InitialAndFloorGas.initial_total_gas to regular_gas#3589
rakita wants to merge 1 commit intomainfrom
helper-init

Conversation

@rakita
Copy link
Copy Markdown
Member

@rakita rakita commented Apr 21, 2026

Summary

Refactors InitialAndFloorGas to store the regular and state portions of the intrinsic gas as separate fields and derive the total on demand, rather than keeping a pre-merged total plus a state subset. Also adds small accumulator helpers so call sites don't have to touch the fields directly.

Field change

Before After Meaning
initial_total_gas: u64 regular_gas: u64 Regular (non-state) portion only
initial_state_gas: u64 state_gas: u64 EIP-8037 state-gas portion
floor_gas unchanged EIP-7623 floor
eip7702_reservoir_refund unchanged EIP-7702 state refund for existing auths

New methods

  • total_gas(&self) -> u64 — saturating regular_gas + state_gas
  • add_regular_gas(&mut self, gas: u64) — saturating += on the regular portion
  • add_state_gas(&mut self, gas: u64) — saturating += on the state portion
  • initial_regular_gas() retained as a transition alias for pre-rename call sites

Migration

Downstream code that read gas.initial_total_gas should switch to gas.total_gas(); direct writes (gas.initial_total_gas += x) become gas.add_regular_gas(x) (if the increment was regular) or gas.add_state_gas(x) (if it was state). gas.initial_state_gas becomes gas.state_gas.

Internal callers updated

  • GasParams::initial_tx_gas — uses add_regular_gas / add_state_gas; dropped the trailing initial_total_gas += initial_state_gas merge.
  • validation.rstotal_gas() for the intrinsic-vs-gas-limit check; gas.regular_gas for the EIP-8037 regular cap check.
  • post_execution.rs::build_result_gas — reads state_gas.
  • Doc comments in pre_execution.rs / gas_params.rs updated to the new field names.

Test plan

  • cargo check --workspace — clean.
  • cargo test --workspace --lib — all green, including test_initial_state_gas_for_create (updated to use state_gas + total_gas()) and the handler validation suite.
  • cargo clippy --workspace --all-targets — no new warnings.

…_gas

Replace `initial_total_gas` (which stored regular + state) with
`regular_gas` (regular portion only), and rename `initial_state_gas`
to `state_gas`. Total is now derived on demand via `total_gas()`.

Also adds helpers for accumulating into each portion:

- `total_gas(&self) -> u64`       — saturating `regular_gas + state_gas`
- `add_regular_gas(&mut self, u64)` — saturating `+=` on regular
- `add_state_gas(&mut self, u64)`   — saturating `+=` on state

The `initial_regular_gas()` method is retained as a transition alias.

Internal callers (`initial_tx_gas`, validation, post-execution) switch
to the new API; `initial_tx_gas` drops its trailing
`initial_total_gas += initial_state_gas` merge line since total is now
computed on read.
@rakita rakita changed the base branch from devnet3 to main April 21, 2026 15:07
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