Skip to content

fix(fees): stop double-counting the observed execution fee - #242

Merged
danieljrc888 merged 1 commit into
v2-devfrom
fix/estimate-observed-execution-double-count
Nov 10, 2026
Merged

danieljrc888 merged 1 commit into
v2-devfrom
fix/estimate-observed-execution-double-count

Conversation

@danieljrc888

Copy link
Copy Markdown
Contributor

Fixes #241

What

  • The observed execution budget built from a simulation no longer adds execution_fee_consumed and feeReport.totalEstimatedFee. It now mirrors Studio v0.123.0-rc.11 recommended_fee_preset / _observed_chargeable_execution_fee (backend/protocol_rpc/fees.py):
    • observed = execution_fee_consumed if > 0, else feeReport.chargeableExecution.totalExecution if > 0, else feeReport.totalEstimatedFee
    • required = max(observed, feeReport.genvmBuckets.execution)
    • per round = max(policy floor, required + 20% headroom), or 0 when nothing was observed
  • Files: src/contracts/actions.ts (observedSimulationFeeUsage), src/types/transactions.ts.
  • chargeableExecution and genvmBuckets are read in camelCase, the only form Studio emits; absent means 0.
  • The observed block keeps executionFeeConsumed and executionFeeReportTotal for existing consumers (no longer summed) and adds observedExecutionFee, genvmExecutionRequired, observedExecutionBudget (on SimulationFeeUsage); StudioGenvmFeeBucketReport gains execution, receipt, layout.

Why

Both summed figures are the execution fee of the same simulated round, so executionBudgetPerRound came out about 2x: on a real rc.11 simulation on studio-next, 188707800000000 instead of 94623000000000. Estimates from simulation (and the estimateTransactionFeesForWrite fallback when Studio returns no preset) deposited twice what the round needs. estimateTransactionFeesForWrite already prefers Studio's recommendedPreset, so on rc.11 its distribution was right, but its observed block showed the inflated figure.

Testing done

  • rc.11 vector (consumed 78628500000000, totalEstimatedFee 78628000000000, genvmBuckets.execution 78852500000000) now yields 94623000000000, the same value Studio's own recommended_fee_preset computes from those inputs.
  • Fallback cases: consumed 0 with chargeableExecution > 0; both 0 falling back to totalEstimatedFee; genvmBuckets absent; all zero gives 0; floor dominates.
  • npm test (vitest --typecheck): 213 passed, no type errors. tsc --noEmit and eslint clean. New cases in tests/contracts-actions.test.ts.
  • Existing test "builds a trusted preset from a simulation" expected the doubled value: budget 602117 -> 400000 (floor), feeValue drops by exactly 4 x 202117.
  • Live, read-only: estimate for a write on studio-next (rc.11) with this branch gives observed recommendedExecutionBudgetPerRound 94623000000000, equal to the server preset's executionBudgetPerRound. (checked with genlayer-py; the logic is identical.)

Decisions made

  • Kept the SDK's existing floor (executionBudgetFloor). Studio's preset floor also takes genvmStartBudgetFloor and receipt headroom for message-emitting txs into account; on rc.11 defaults genvmBuckets.execution already exceeds it, so results match. Aligning the floor is a possible follow-up.
  • Malformed fee values still raise, as for the other fields (Studio treats them as 0).

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

The behavioral change is the single block in the observed-usage helper; the rest is tests and reporting fields.

User facing release notes

Fee estimates from simulation no longer double the execution budget per round, so deposits for writes and deploys estimated from a simulation are about half of what they were and match Studio's recommended preset.

Fee estimates built from a simulation sized executionBudgetPerRound from
execution_fee_consumed + feeReport.totalEstimatedFee. Both are the execution
fee consumed by the same simulated round, so the recommended budget came out
about twice what the round needs (rc.11 studio-next vector: 188,707,800,000,000
instead of 94,623,000,000,000).

observedSimulationFeeUsage now mirrors Studio v0.123.0-rc.11
(backend/protocol_rpc/fees.py: recommended_fee_preset and
_observed_chargeable_execution_fee):

  observed = execution_fee_consumed if > 0
             else feeReport.chargeableExecution.totalExecution if > 0
             else feeReport.totalEstimatedFee
  budget   = max(observed, feeReport.genvmBuckets.execution)
  per round = max(policy.executionBudgetFloor, budget + headroom), or 0
              when nothing was observed

executionFeeConsumed and executionFeeReportTotal stay on SimulationFeeUsage
for existing consumers but no longer feed a sum. New fields report the
figures actually used: observedExecutionFee, genvmExecutionRequired and
observedExecutionBudget. StudioGenvmFeeBucketReport gains the execution,
receipt and layout keys Studio already emits.

estimateTransactionFeesForWrite still returns Studio's recommendedPreset when
present; its observed block and its gen_call fallback use the corrected
logic through the same helper.

Validation: the rc.11 vector now yields 94,623,000,000,000 (1.2 x
78,852,500,000,000, matching Studio's preset). New tests cover the
chargeableExecution fallback, the totalEstimatedFee fallback, a missing
genvmBuckets, an all-zero report, the policy floor, and the gen_call
fallback of estimateTransactionFeesForWrite. npm test -- --run (213 passed,
no type errors), npm run lint, tsc --noEmit and npm run build all pass.

Fixes #241
@danieljrc888 danieljrc888 self-assigned this Nov 10, 2026
@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 53ef2896-aae6-4851-a91a-9d2e8e9c6caa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T06:44:06.134599Z 06b4cf9 PR opened
🔒 Security Review ✅ Completed 2026-11-10T06:46:22.361275Z 06b4cf9 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danieljrc888
danieljrc888 merged commit a9b97e7 into v2-dev Nov 10, 2026
8 of 9 checks passed
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