Skip to content

fix(contracts): send the fee estimate when deploy or write omit fees - #435

Closed
danieljrc888 wants to merge 1 commit into
v0.40-devfrom
fix/default-fee-estimate
Closed

danieljrc888 wants to merge 1 commit into
v0.40-devfrom
fix/default-fee-estimate

Conversation

@danieljrc888

Copy link
Copy Markdown

Problem and outcome

Studio v0.123 (studio-next, and local genlayer up) applies Consensus v0.6 fee admission to every user deploy and write. Every one of the six fee fields has to be non-zero. Today the CLI only builds fees from --fee-profile, so:

  • genlayer deploy / genlayer write with no fee flags send a zeroed distribution and are rejected with FeeValueMustBeNonZero(1);
  • the README --fees '{"distribution":{"leaderTimeunitsAllocation":"100","validatorTimeunitsAllocation":"200","rotations":["0"]}}' example is rejected with FeeValueMustBeNonZero(3), because executionBudgetPerRound and the three price caps stay at 0.

User-facing report: #421.

With this change, if a deploy or write gives no feeValue and the chain's fee policy is enabled, the CLI submits the estimate that genlayer estimate-fees would produce for that transaction. Values the user passes explicitly are still sent exactly as given.

Flags Fee policy enabled Fee policy disabled / no policy on chain
none write: estimateTransactionFeesForWrite for the target call; deploy: estimateTransactionFees unchanged (no fees)
--fees without feeValue estimateTransactionFees with the user's fields: their values are kept and only missing fields are filled unchanged
--fees with feeValue, or --fee-value unchanged unchanged
--fee-profile unchanged unchanged

Out of scope: no genlayer-js change is needed or assumed (genlayer-js is being fixed separately). Compose and localnet files are not touched.

Implementation and validation

  • src/commands/contracts/fees.ts: resolveTransactionFees checks getCurrentFeePolicy() before estimating. It does this only on Studio chains or chains with a feeManagerContract, so networks without a fee policy never read one. For writes it then calls estimateTransactionFeesForWrite (falling back to estimateTransactionFees on clients without it). It uses toTransactionFees and parseFeeEstimateOptions, the same helpers as estimate-fees. When --fees is partial, the generic estimator is used even for writes, because the write estimator resizes executionBudgetPerRound/totalMessageFees from the simulation and could override fields the user set.
  • src/commands/contracts/write.ts: passes the target call to the resolver.
  • --fees help text and README: the fee examples now work on fee-enabled Studio, and the README documents the default estimate and --fees "$(genlayer estimate-fees --json)".

Tests: added 11 cases in tests/actions/deploy.test.ts and tests/actions/write.test.ts. They cover: no flags with the policy enabled or disabled, a chain without a policy source, partial --fees keeping the user's fields, explicit feeValue / --fee-value passed through unchanged, and the write-estimator fallback. With the new branch disabled, 6 of them fail.

  • npx vitest run: 77 files, 851 tests passed (840 before this change)
  • npm run build: ok
  • npx tsc --noEmit: only the existing tests/actions/stakingWizard.test.ts(83) error, which is also on v0.40-dev
  • The repo has no lint script, and eslint.config.js matches no .ts files. Prettier output for the new code matches the repo config.

Live on studio-next (chain 61997), using an isolated HOME and a throwaway funded keystore, with a storage_v3.py contract:

Run Result Tx
deploy, no fee flags, published 0.40.0-rc.5 reverted FeeValueMustBeNonZero(1) 0x29703c7779eedea8f21dca98e06d97fa20864d4a97210fb461f39c494031b097
deploy, no fee flags, this branch ACCEPTED, FINISHED_WITH_RETURN, contract 0x6f21c86b32b854B711AED86E529629A02eB24F00 0x1a6c3f3e6cf06588dac311611130d2cf228e72ab38c61834922a8c5906cae374
write, no fee flags, published 0.40.0-rc.5 reverted FeeValueMustBeNonZero(1) 0x974ecfe45a77c3baee868f2cdb931ff61468e6550aef224bc4e8fc8ebc881e22
write, no fee flags, this branch (target-write estimate, deposit 378492000010352 wei) ACCEPTED, FINISHED_WITH_RETURN, get_storage returns the new value 0x149c4fc01d0473f839644dc33ee3937524fdd5e2d1e61106f367813e6105cdb2
write, old README partial --fees, this branch (user fields kept) ACCEPTED 0xc84eb5a4a51b84e266d05fce3df517f92f47db03a75ac21c114d13d820852eaf
write, --fees "$(genlayer estimate-fees <addr> update_storage --args … --json)" ACCEPTED 0x5011938caad483f8aa4572f775318aacc824ef5e525d4935210c2c3f85c96c69
deploy, --fees "$(genlayer estimate-fees --json)" ACCEPTED 0x8cdd93552264e35694ce3b54dcb0bdc074ea6f1049f2536cab29ac9282996945

Risk: on a fee-enabled chain, a deploy or write without fee flags now makes one extra policy read. A write also runs an estimation simulation first, so a call that fails in simulation now fails before it is submitted. To bypass the estimate, pass --fees with a feeValue. If the policy cannot be read on a Studio chain, the command fails instead of falling back to sending no fees. Rollback: revert this commit.

Fee-enabled Studio (v0.123) rejects deploy and write transactions whose
fee distribution has zero fields, so `genlayer deploy` and `genlayer write`
without fee flags failed with FeeValueMustBeNonZero(1), and the README
`--fees` example (distribution without feeValue) failed with
FeeValueMustBeNonZero(3).

When no feeValue is given (neither in --fees nor via --fee-value) and the
chain's fee policy is enabled, the CLI now asks genlayer-js for the same
estimate `genlayer estimate-fees` produces and submits it:
- no fee flags: write uses estimateTransactionFeesForWrite for the target
  call, deploy uses estimateTransactionFees;
- --fees without feeValue: estimateTransactionFees keeps every field the
  user set and fills the rest (the write estimator is not used here because
  it resizes execution/message budgets from the simulation).

The policy is read only on Studio chains or chains with a FeeManager, so
networks without a fee policy, a disabled policy, explicit feeValue /
--fee-value and --fee-profile all behave as before.
@danieljrc888 danieljrc888 self-assigned this Nov 3, 2026
@coderabbitai

coderabbitai Bot commented Nov 3, 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: 3ca79c0a-afd5-4efc-b64f-d2cfb8558870

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

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

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T17:01:43.140467Z f695af1 PR opened
🔒 Security Review ✅ Completed 2026-11-03T17:03:59.403432Z f695af1 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.

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