Skip to content

Conversation

@niran
Copy link
Contributor

@niran niran commented Jan 20, 2026

Summary

  • Add execution time and state root time metering for transactions
  • Introduce ResourceMeteringMode enum with three modes: off, dry-run, enforce
  • Integrate with metering data from base_meterBundle RPC via TxDataStore
  • Add metrics to monitor metering accuracy before enforcement

Changes

New CLI Flag

--builder.resource-metering-mode=off|dry-run|enforce
  • off (default): Resource metering disabled
  • dry-run: Log and collect metrics without enforcing limits (for validation)
  • enforce: Reject transactions exceeding time limits

Resource Limits

  • Per-transaction execution time limit
  • Per-flashblock execution time budget (use it or lose it)
  • Per-transaction state root time limit
  • Per-block state root time budget (cumulative)

Metrics

  • Rejection counters by limit type
  • metering_known_transaction / metering_unknown_transaction counters
  • Time exceeded counters: tx_execution_time_exceeded, flashblock_execution_time_exceeded, tx_state_root_time_exceeded, block_state_root_time_exceeded

Test Plan

  • Unit tests for resource limit checking logic
  • Integration tested with local devnet in dry-run and enforce modes

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Jan 20, 2026

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@niran niran changed the title WIP: feat(builder): resource metering for transaction time limits feat(builder): resource metering for transaction time limits Jan 30, 2026
@niran niran marked this pull request as ready for review January 30, 2026 23:04
niran added 7 commits February 3, 2026 14:07
Refactor is_tx_over_limits to use structured ResourceLimits and TxResources
parameters, and add execution time tracking and enforcement:

- Add ResourceLimits struct to encapsulate all limit parameters
- Add TxResources struct for transaction resource consumption values
- Add cumulative_execution_time_us field to ExecutionInfo
- Add TransactionExecutionTimeExceeded and BlockExecutionTimeExceeded
  error variants to TxnExecutionResult
- Use metering data from TxDataStore in execute_best_transactions
- Track actual execution time post-simulation when metering unavailable
- Add execution time per-batch tracking for flashblocks
- Add CLI flags for execution time limits:
  - --builder.max-execution-time-per-tx-us
  - --builder.block-execution-time-budget-us

The metering data (MeterBundleResponse.total_execution_time_us) is now
used to predict transaction execution time before simulation. This
enables rejection of expensive transactions that would exceed configured
time budgets, helping ensure blocks complete within their allotted time.
Resource metering now tracks both execution time and state root time:

- Execution time: "use it or lose it" per flashblock - budgets reset at
  the start of each flashblock and don't carry over
- State root time: cumulative across the block - since state root is
  calculated once at the end, this resource accumulates like gas/DA

New CLI flags:
- --builder.max-state-root-time-per-tx-us: per-tx state root time limit
- --builder.block-state-root-time-budget-us: block-level cumulative limit

The metering data from MeterBundleResponse includes both
total_execution_time_us and state_root_time_us fields which are now
used for pre-simulation resource prediction.
Add 22 unit tests covering:
- Basic limit checks (gas, DA limits)
- Transaction and flashblock execution time limits
- Transaction and block state root time limits
- Reset behavior (execution time resets per flashblock, state root
  time persists across flashblocks)
- Edge cases (zero limits, overflow prevention, missing metering data)
- Combined resource limit scenarios
Combine enable_resource_metering and resource_metering_observe_only flags
into a single ResourceMeteringMode enum with three modes:
- off: disabled (default)
- observe: collect metrics without enforcing time limits
- enforce: collect metrics and reject transactions exceeding limits

Add observation metrics for monitoring metering accuracy:
- Rejection counters for each limit type
- Execution time prediction error (predicted vs actual)
- State root time / gas ratio for anomaly detection
- Distribution histograms for predicted and actual times
Replace "observe" terminology with "dry-run" throughout resource metering
to use more standard industry terminology for non-enforcement mode.
Separate resource metering limits (execution time, state root time) from
protocol-enforced limits (gas, DA) at the type level. This makes the
distinction explicit and simplifies the dry-run mode handling in the
payload builder context.

The new enum wraps all time-based limit violations, making pattern
matching cleaner and eliminating the need for matches! with a long list
of variants.
Remove redundant inline comments and improve field documentation:
- Simplify "Total gas left" to "Cumulative gas target"
- Remove "use it or lose it" descriptions (behavior is documented in
  ResourceLimits)
- Add TODO for backrun bundle metering data consideration
@niran niran force-pushed the feature/resource-metering-builder branch from cde0759 to fbd169d Compare February 3, 2026 06:30
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.

3 participants