Repository navigation
fix(contracts): send the fee estimate when deploy or write omit fees - #435
danieljrc888 wants to merge 1 commit into
Conversation
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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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 writewith no fee flags send a zeroed distribution and are rejected withFeeValueMustBeNonZero(1);--fees '{"distribution":{"leaderTimeunitsAllocation":"100","validatorTimeunitsAllocation":"200","rotations":["0"]}}'example is rejected withFeeValueMustBeNonZero(3), becauseexecutionBudgetPerRoundand the three price caps stay at 0.User-facing report: #421.
With this change, if a deploy or write gives no
feeValueand the chain's fee policy is enabled, the CLI submits the estimate thatgenlayer estimate-feeswould produce for that transaction. Values the user passes explicitly are still sent exactly as given.estimateTransactionFeesForWritefor the target call; deploy:estimateTransactionFees--feeswithoutfeeValueestimateTransactionFeeswith the user's fields: their values are kept and only missing fields are filled--feeswithfeeValue, or--fee-value--fee-profileOut 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:resolveTransactionFeeschecksgetCurrentFeePolicy()before estimating. It does this only on Studio chains or chains with afeeManagerContract, so networks without a fee policy never read one. For writes it then callsestimateTransactionFeesForWrite(falling back toestimateTransactionFeeson clients without it). It usestoTransactionFeesandparseFeeEstimateOptions, the same helpers asestimate-fees. When--feesis partial, the generic estimator is used even for writes, because the write estimator resizesexecutionBudgetPerRound/totalMessageFeesfrom the simulation and could override fields the user set.src/commands/contracts/write.ts: passes the target call to the resolver.--feeshelp 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.tsandtests/actions/write.test.ts. They cover: no flags with the policy enabled or disabled, a chain without a policy source, partial--feeskeeping the user's fields, explicitfeeValue/--fee-valuepassed 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: oknpx tsc --noEmit: only the existingtests/actions/stakingWizard.test.ts(83)error, which is also onv0.40-deveslint.config.jsmatches no.tsfiles. Prettier output for the new code matches the repo config.Live on studio-next (chain 61997), using an isolated
HOMEand a throwaway funded keystore, with astorage_v3.pycontract:FeeValueMustBeNonZero(1)0x29703c7779eedea8f21dca98e06d97fa20864d4a97210fb461f39c494031b097FINISHED_WITH_RETURN, contract0x6f21c86b32b854B711AED86E529629A02eB24F000x1a6c3f3e6cf06588dac311611130d2cf228e72ab38c61834922a8c5906cae374FeeValueMustBeNonZero(1)0x974ecfe45a77c3baee868f2cdb931ff61468e6550aef224bc4e8fc8ebc881e22FINISHED_WITH_RETURN,get_storagereturns the new value0x149c4fc01d0473f839644dc33ee3937524fdd5e2d1e61106f367813e6105cdb2--fees, this branch (user fields kept)0xc84eb5a4a51b84e266d05fce3df517f92f47db03a75ac21c114d13d820852eaf--fees "$(genlayer estimate-fees <addr> update_storage --args … --json)"0x5011938caad483f8aa4572f775318aacc824ef5e525d4935210c2c3f85c96c69--fees "$(genlayer estimate-fees --json)"0x8cdd93552264e35694ce3b54dcb0bdc074ea6f1049f2536cab29ac9282996945Risk: 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
--feeswith afeeValue. 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.