Skip to content

[FVM] Unify metering-disabled behavior for ledger interaction - #8610

Merged
janezpodhostnik merged 5 commits into
masterfrom
janez/unify-metering-disabled-flag
Aug 3, 2026
Merged

[FVM] Unify metering-disabled behavior for ledger interaction#8610
janezpodhostnik merged 5 commits into
masterfrom
janez/unify-metering-disabled-flag

Conversation

@janezpodhostnik

@janezpodhostnik janezpodhostnik commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

RunWithMeteringDisabled now skips ledger-interaction metering the same way it already skips computation, memory, and events. Previously interaction bytes were still accumulated (only the limit was not enforced) while disabled. There was no specific reason to keep interaction separate, so this unifies the logic across all metered quantities.

This changes execution behavior and requires an HCU to deploy: transactions close to the interaction limit could now fail where they previously succeeded (or succeed where they previously failed), so all execution nodes must switch at the same height.

Summary by CodeRabbit

  • New Features
    • Added a scoped option to temporarily disable resource metering during state operations.
    • Operations performed while metering is disabled do not count toward configured usage limits or populate read caches.
  • Bug Fixes
    • Storage interactions now consistently enforce configured limits.
    • Metering resumes correctly after the disabled scope ends.
  • Documentation
    • Clarified that computation, memory, emitted events, and ledger interactions are excluded while metering is disabled.

@janezpodhostnik
janezpodhostnik requested a review from a team as a code owner July 13, 2026 16:17
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 51420a65-5e1a-4e71-832e-79a206e190ee

📥 Commits

Reviewing files that changed from the base of the PR and between 7a937e0 and 5138905.

📒 Files selected for processing (1)
  • fvm/meter/meter_test.go

📝 Walkthrough

Walkthrough

Storage read and write metering now enforce interaction limits without an enforcement flag. Execution state adds scoped metering suppression, with tests covering bypassed limits, resumed enforcement, cache behavior, and interaction thresholds.

Changes

Storage metering behavior

Layer / File(s) Summary
Unconditional storage interaction limits
fvm/meter/interaction_meter.go, fvm/meter/*_test.go
Storage read and write methods use simplified signatures and always check interaction limits. Metering tests retain coverage for reads, writes, combined operations, merged meters, and ledger-interaction limits.
Scoped metering suppression
fvm/storage/state/execution_state.go, fvm/storage/state/transaction_state.go
RunWithMeteringDisabled temporarily suppresses metering. Get and Set skip storage accounting while disabled and restore the previous state afterward.
Metering behavior validation
fvm/storage/state/execution_state_test.go, fvm/fvm_blockcontext_test.go
Tests cover disabled-scope accounting, resumed enforcement, read-cache behavior, and the 60-account interaction-limit threshold.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ExecutionState
  participant limitsController
  participant InteractionMeter

  ExecutionState->>limitsController: RunWithMeteringDisabled(callback)
  limitsController->>ExecutionState: Disable metering
  ExecutionState->>InteractionMeter: Skip storage read/write metering
  limitsController->>ExecutionState: Restore previous metering state
Loading

Suggested reviewers: zhangchiqing, kay-zee

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: making ledger-interaction metering behavior consistent when metering is disabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch janez/unify-metering-disabled-flag

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.

Comment thread fvm/storage/state/execution_state_test.go
Base automatically changed from janez/unify-limit-exceeded-errors to master July 31, 2026 17:43
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
fvm/meter/interaction_meter.go (1)

64-76: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Update the remaining MeterStorageRead call.

fvm/meter/meter_test.go Line 968 still passes true. MeterStorageRead now accepts two arguments. The fvm/meter test package will not compile until that argument is removed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fvm/meter/interaction_meter.go` around lines 64 - 76, Update the remaining
MeterStorageRead call in meter_test.go to pass only the storage key and value,
removing the obsolete true argument. Keep the call aligned with the current
InteractionMeter.MeterStorageRead signature so the fvm/meter tests compile.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@fvm/fvm_blockcontext_test.go`:
- Around line 1303-1309: Update the test using
CreateMultiAccountCreationTransaction to assert that output.Err contains
errors.LimitKindLedgerInteraction, in addition to the existing Cadence runtime
error check, so it verifies the specific ledger-interaction limit cause.

---

Outside diff comments:
In `@fvm/meter/interaction_meter.go`:
- Around line 64-76: Update the remaining MeterStorageRead call in meter_test.go
to pass only the storage key and value, removing the obsolete true argument.
Keep the call aligned with the current InteractionMeter.MeterStorageRead
signature so the fvm/meter tests compile.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b6d3f2a2-2281-47c5-8d04-e3fbf0b08228

📥 Commits

Reviewing files that changed from the base of the PR and between 9cd9685 and 7a937e0.

📒 Files selected for processing (7)
  • fvm/fvm_blockcontext_test.go
  • fvm/meter/interaction_meter.go
  • fvm/meter/interaction_meter_test.go
  • fvm/meter/meter_test.go
  • fvm/storage/state/execution_state.go
  • fvm/storage/state/execution_state_test.go
  • fvm/storage/state/transaction_state.go

Comment on lines +1303 to +1309
// The account count is sized so that the metered interaction
// exceeds MaxStateInteractionSize, triggering the interaction
// limit from within Cadence execution.
_, txBodyBuilder := testutil.CreateMultiAccountCreationTransaction(
t,
chain,
40)
60)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the ledger-interaction failure cause.

The test only checks for a Cadence runtime error. A computation, memory, or event limit failure would also pass. Assert that output.Err contains errors.LimitKindLedgerInteraction to verify the new threshold behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fvm/fvm_blockcontext_test.go` around lines 1303 - 1309, Update the test using
CreateMultiAccountCreationTransaction to assert that output.Err contains
errors.LimitKindLedgerInteraction, in addition to the existing Cadence runtime
error check, so it verifies the specific ledger-interaction limit cause.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@blacksmith-sh

This comment has been minimized.

@janezpodhostnik
janezpodhostnik added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 90062b5 Aug 3, 2026
62 of 63 checks passed
@janezpodhostnik
janezpodhostnik deleted the janez/unify-metering-disabled-flag branch August 3, 2026 15:12
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.

4 participants