Skip to content

feat: --fee-profile reporter — measure per-method fees for developer suggestions - #94

Merged
MuncleUscles merged 1 commit into
v0.30-devfrom
feat/fee-profile-reporter
Jun 11, 2026
Merged

MuncleUscles merged 1 commit into
v0.30-devfrom
feat/fee-profile-reporter

Conversation

@MuncleUscles

Copy link
Copy Markdown
Member

What

Opt-in fee-profile reporter for gltest: --fee-profile=PATH (+ --fee-profile-headroom, default 1.25). Every deploy and write executed through gltest records the consumed fee data from its receipt; at session end PATH is written as a JSON fee profile sized at max observed × headroom, all values as decimal strings.

The file is designed to be shipped to the frontend verbatim and passed as suggestions to createTransactionKit (@genlayer/transaction-kit core, suggestions API as of 747165a):

createTransactionKit({ chain, provider, account, suggestions })
// suggestions: { version?, network?, measuredAt?, deploy?: SuggestedFees, methods?: Record<string, SuggestedFees> }
// SuggestedFees: { leaderTimeunitsAllocation?, validatorTimeunitsAllocation?, executionBudgetPerRound?, totalMessageFees? }

When a suggestion matches a call, the kit's PolicyQuote.source becomes 'developer' and the panel renders "Sized from the developer's measured fee profile".

Output schema

{
  "version": 1,
  "network": "studionet",
  "measuredAt": "2026-06-10T12:00:00Z",
  "deploy": {
    "executionBudgetPerRound": "625000",
    "totalMessageFees": "0"
  },
  "methods": {
    "create_bet": {
      "executionBudgetPerRound": "312500",
      "totalMessageFees": "12500"
    }
  }
}

What is measured

Studio/localnet receipts carry a canonical fees object; the reporter reads fees.consumed:

  • executionBudgetPerRound ← consumed.executionConsumed (Studio's chargeable per-round sum: receipt + nondet output + storage)
  • totalMessageFees ← consumed.messageFeesConsumed (a measured 0 is recorded — it is a real measurement)
  • leaderTimeunitsAllocation / validatorTimeunitsAllocation are never emitted: the backend reports consumed fee amounts, not time-unit usage. Missing keys fall back to preset/network defaults in the kit.

Testnet receipts (decoded from the consensus contracts) expose no consumed-fee data yet, and direct/sim mode is gasless — sessions there produce an empty profile with a session-end warning instead of fake numbers.

Implementation

  • gltest/fees/ — FeeProfileCollector (max-tracking, Decimal-based headroom with ceil, JSON writer), singleton + maybe_record_fee_observation no-op guard.
  • Recording hooks: Contract.transact and ContractFactory.deploy_contract_tx after wait_for_transaction_receipt — one-line, never raises.
  • Config plumbing: PluginConfig.fee_profile_path/.fee_profile_headroom, GeneralConfig accessors, pytest_sessionstart reset, pytest_sessionfinish write (reporter errors never fail the run).
  • Tests: collector unit tests (big-int exactness at 1e20, headroom ceil, malformed/missing fees ignored, shape/key omissions), transact/deploy integration with mocked client, plugin option + headroom validation tests (with singleton cleanup so the outer session doesn't write a stray profile).
  • README "Fee Profiling" section.
  • uv.lock caught up with the genlayer-py<0.20.0 pin relax from feat(gltest): fee-aware transactions and backend-agnostic success assertions #91.

Verification

  • uv run gltest tests/gltest/ tests/gltest_cli/ → 101 passed
  • uv run gltest tests/glsim/ → 71 passed; tests/gltest_direct/test_sdk_loader.py → 12 passed

…suggestions

Opt-in pytest options --fee-profile=PATH and --fee-profile-headroom (default
1.25). Every deploy/write executed through gltest records the consumed fee
data from Studio receipts (fees.consumed.executionConsumed /
messageFeesConsumed); at session end PATH is written as a JSON fee profile
(max observed x headroom, decimal strings) that frontends pass verbatim as
'suggestions' to createTransactionKit from @genlayer/transaction-kit.

Time-unit allocations are omitted: the backend reports consumed fee amounts
only, not time-unit usage. Testnet receipts expose no consumed-fee data yet,
so profiles measured there come out empty (warned at session end).

Also catches uv.lock up with the genlayer-py<0.20.0 pin relax from #91.
@coderabbitai

coderabbitai Bot commented Jun 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

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb14bcb8-3741-4784-b77c-164d9515a045

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
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fee-profile-reporter

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@MuncleUscles

Copy link
Copy Markdown
Member Author

First real end-to-end measurement completed (studio stack with GenVM built from main — see genlayer-studio#1674 validation comments). Two findings to fold into this PR:

  1. fees.consumed is only populated at FINALIZED — profiling with gltest's default ACCEPTED wait records zeros. The reporter should either force wait_until=FINALIZED for profiled transactions or emit a session warning when consumed values are all zero at ACCEPTED. Gasless txs carry no fees object at all (already warned).
  2. genlayer-py>=0.18 floor is too low — the reporter needs the fee-capable v0.19-dev line (fees=/wait_until).

First measured profile for reference (Storage contract, 1.25 headroom over consumed ~314.5k):

{ "deploy": { "executionBudgetPerRound": "393170", "totalMessageFees": "0" },
  "methods": { "update_storage": { "executionBudgetPerRound": "393143", "totalMessageFees": "0" } } }

@MuncleUscles
MuncleUscles merged commit 9da7c61 into v0.30-dev Jun 11, 2026
7 of 8 checks passed
@MuncleUscles
MuncleUscles deleted the feat/fee-profile-reporter branch June 11, 2026 21:45
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