Skip to content

fix(browser): resume bounded translated gas slices - #73

Merged
replghost merged 5 commits into
mainfrom
fix/resume-translated-out-of-gas
Oct 8, 2026
Merged

replghost merged 5 commits into
mainfrom
fix/resume-translated-out-of-gas

Conversation

@replghost

Copy link
Copy Markdown
Collaborator

Problem

The translated (browser compiler) backend executes an update in loop-bounded
gas slices (MAX_TRANSLATED_LOOPS_PER_UPDATE, 50M) but treated the end of the
first slice as fatal out-of-gas, even though the ABI call budget is
MAX_GAS_PER_UPDATE (10G). Heavy guests had to split their work artificially:
OpenHV world loading needed one startup operation per frame and took
2,560 s to become playable in Chromium.

Change

  • TranslatedPolkaVmRuntime takes a maxGasSlices count. When a slice ends
    with STATUS_OUT_OF_GAS and slices remain, it records a pending
    continuation instead of failing; the next tick resumes the same call with
    pvm_resume, preserving PC, registers, memory and remaining budget.
  • The worker core reschedules immediately (scheduleTick(0)) while a
    continuation is pending, so the scheduler, input and cancellation still run
    between slices.
  • Exhausting all slices (the full call budget) still fails the execution.
    Calls with a reduced budget get no extra slices.
  • ABI v1 document: a Host MAY run a call budget as smaller internal quanta;
    only exhausting the complete call budget is gas exhaustion.

Verification

  • npm test in js/packages/polkavm-browser-runtime: 310/310, including the
    new "translated execution resumes after exhausting a gas slice" test
    (resume preserves state; a single-slice runtime still fails).
  • OpenHV skirmish in Chromium through dotli: playable world in 61.86 s
    (was 2,560.16 s), move, production, placement and play through tick 420
    without runtime failure.

@replghost
replghost force-pushed the fix/resume-translated-out-of-gas branch from 1323718 to 144b77e Compare October 5, 2026 02:11
@replghost
replghost merged commit d6f27e5 into main Oct 8, 2026
7 checks passed
@replghost
replghost deleted the fix/resume-translated-out-of-gas branch October 8, 2026 05:30
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