Skip to content

Add invoke hostcall#944

Merged
tomusdrw merged 4 commits into
mainfrom
maso-refine-invoke
Apr 19, 2026
Merged

Add invoke hostcall#944
tomusdrw merged 4 commits into
mainfrom
maso-refine-invoke

Conversation

@DrEverr

@DrEverr DrEverr commented Apr 13, 2026

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@DrEverr has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 57 minutes and 49 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 57 minutes and 49 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a8b1e104-5601-4549-afbf-1c3abff8aec7

📥 Commits

Reviewing files that changed from the base of the PR and between 81c0ded and 9917bc5.

📒 Files selected for processing (1)
  • packages/jam/in-core/externalities/refine.ts
📝 Walkthrough

Walkthrough

The PR implements machineInvoke in RefineExternalitiesImpl and adds tests. machineInvoke now locates an inner PVM by machine index, returns an error if missing, initializes the inner PVM with encoded registers and gas, runs the inner PVM, reads status, exit param, remaining gas, and encoded registers, maps PVM Status values into a MachineResult (including extracting host-call or fault details when applicable), and returns a Result.ok. Tests add a helper to allocate HostCallRegisters and cover missing-machine errors, status mapping, out-of-gas behavior, register pass-through, and remaining-gas reporting.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Add Machine HostCall #935: Related work that allocates and initializes inner PVM instances which machineInvoke executes against.

Suggested reviewers

  • tomusdrw
  • skoszuta
  • mateuszsikora

Poem

🐇 I copied registers, set the gas just right,
The inner PVM hummed through day and night,
Status emerged, the result took flight,
Tests hopped in to check each light,
A tiny rabbit cheers this code tonight.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether it relates to the changeset. Add a description explaining the purpose and context of the machineInvoke implementation and its role in the refine externalities.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add invoke hostcall' directly relates to the main change, which implements the machineInvoke functionality for PVM host calls.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch maso-refine-invoke

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.

@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

🧹 Nitpick comments (1)
packages/jam/in-core/externalities/refine.test.ts (1)

352-430: Add explicit HOST/FAULT payload mapping tests.

machineInvoke now has dedicated mapping for Status.HOST (hostCallIndex) and Status.FAULT (address), but this suite currently validates only PANIC/OOG shape. Please add direct assertions for both payload branches to prevent regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/jam/in-core/externalities/refine.test.ts` around lines 352 - 430,
Add two new test cases in the "machineInvoke" suite that invoke machineInvoke on
a machine whose inner PVM returns Status.HOST and Status.FAULT respectively, and
assert the mapped payload fields: for HOST assert result.isOk is true,
result.ok.result.status === Status.HOST and that
result.ok.result.payload.hostCallIndex equals the inner PVM's host call index;
for FAULT assert result.ok.result.status === Status.FAULT and that
result.ok.result.payload.address equals the inner PVM's fault address. Use the
existing helpers (createExt, machineInit, machineInvoke, BytesBlob.blobFrom,
MINIMAL_PROGRAM or a minimal program that triggers the desired inner status) and
check result.ok.registers/gas as appropriate; reference machineInvoke,
Status.HOST, Status.FAULT, hostCallIndex, and address when locating the
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/jam/in-core/externalities/refine.ts`:
- Around line 199-203: The branch handling Status.HOST and Status.FAULT
currently defaults exitParam to 0 when null; instead, in the function that sets
machineStatus (the block that checks status === Status.HOST / Status.FAULT and
calls tryAsU64), explicitly check the raw exitParam (from getExitParam() / the
local exitParam variable) for null and if null return a Result.error() (not
throw) describing the invariant violation; preserve use of tryAsU64 when
non-null and set machineStatus = { status, hostCallIndex: tryAsU64(exitParam) }
or { status, address: tryAsU64(exitParam) } respectively, and reference Status,
machineStatus, and tryAsU64 to locate the changes.

---

Nitpick comments:
In `@packages/jam/in-core/externalities/refine.test.ts`:
- Around line 352-430: Add two new test cases in the "machineInvoke" suite that
invoke machineInvoke on a machine whose inner PVM returns Status.HOST and
Status.FAULT respectively, and assert the mapped payload fields: for HOST assert
result.isOk is true, result.ok.result.status === Status.HOST and that
result.ok.result.payload.hostCallIndex equals the inner PVM's host call index;
for FAULT assert result.ok.result.status === Status.FAULT and that
result.ok.result.payload.address equals the inner PVM's fault address. Use the
existing helpers (createExt, machineInit, machineInvoke, BytesBlob.blobFrom,
MINIMAL_PROGRAM or a minimal program that triggers the desired inner status) and
check result.ok.registers/gas as appropriate; reference machineInvoke,
Status.HOST, Status.FAULT, hostCallIndex, and address when locating the
assertions.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 64e99834-2bd3-458f-9eff-a822ce82859e

📥 Commits

Reviewing files that changed from the base of the PR and between 6923c44 and 16b19a9.

📒 Files selected for processing (2)
  • packages/jam/in-core/externalities/refine.test.ts
  • packages/jam/in-core/externalities/refine.ts

Comment thread packages/jam/in-core/externalities/refine.ts
@DrEverr DrEverr requested a review from tomusdrw April 14, 2026 05:28
Comment thread packages/jam/in-core/externalities/refine.ts Outdated
@github-actions

Copy link
Copy Markdown
View all
File Benchmark Ops
bytes/hex-from.ts[0] parse hex using Number with NaN checking 69893.38 ±0.58% 84.69% slower
bytes/hex-from.ts[1] parse hex from char codes 456429.02 ±1.03% fastest ✅
bytes/hex-from.ts[2] parse hex from string nibbles 265647.86 ±0.44% 41.8% slower
bytes/hex-to.ts[0] number toString + padding 90392.34 ±1.81% fastest ✅
bytes/hex-to.ts[1] manual 7344.12 ±2.84% 91.88% slower
codec/bigint.compare.ts[0] compare custom 93722390.69 ±4.29% fastest ✅
codec/bigint.compare.ts[1] compare bigint 89329070.36 ±5.64% 4.69% slower
codec/bigint.decode.ts[0] decode custom 72379081.03 ±2.89% 24.73% slower
codec/bigint.decode.ts[1] decode bigint 96156461.71 ±4.4% fastest ✅
codec/decoding.ts[0] manual decode 9865453 ±0.66% 85.92% slower
codec/decoding.ts[1] int32array decode 68017350.78 ±2.54% 2.95% slower
codec/decoding.ts[2] dataview decode 70086230.24 ±3.14% fastest ✅
codec/encoding.ts[0] manual encode 1080211.94 ±0.88% 14.42% slower
codec/encoding.ts[1] int32array encode 1262187.85 ±0.33% fastest ✅
codec/encoding.ts[2] dataview encode 1227660.09 ±0.44% 2.74% slower
collections/map-set.ts[0] 2 gets + conditional set 71664.12 ±0.08% fastest ✅
collections/map-set.ts[1] 1 get 1 set 47662.93 ±0.07% 33.49% slower
logger/index.ts[0] console.log with string concat 5106470.23 ±38.72% fastest ✅
logger/index.ts[1] console.log with args 1187820.54 ±89.02% 76.74% slower
math/add_one_overflow.ts[0] add and take modulus 102141784.67 ±4.78% fastest ✅
math/add_one_overflow.ts[1] condition before calculation 96646308.25 ±5.22% 5.38% slower
math/count-bits-u32.ts[0] standard method 36523839.86 ±1.63% 57.96% slower
math/count-bits-u32.ts[1] magic 86885478.21 ±4.31% fastest ✅
math/count-bits-u64.ts[0] standard method 4771130.05 ±2.43% 82.18% slower
math/count-bits-u64.ts[1] magic 26774026.07 ±1.14% fastest ✅
math/mul_overflow.ts[0] multiply and bring back to u32 101494512.54 ±3.94% fastest ✅
math/mul_overflow.ts[1] multiply and take modulus 95069321.06 ±5.51% 6.33% slower
math/switch.ts[0] switch 97405484.06 ±5.35% 1.26% slower
math/switch.ts[1] if 98648227.94 ±5.47% fastest ✅
hash/index.ts[0] hash with numeric representation 68.8 ±0.06% 31.44% slower
hash/index.ts[1] hash with string representation 43.49 ±0.49% 56.66% slower
hash/index.ts[2] hash with symbol representation 67.14 ±0.17% 33.09% slower
hash/index.ts[3] hash with uint8 representation 77.01 ±0.07% 23.26% slower
hash/index.ts[4] hash with packed representation 100.35 ±0.23% fastest ✅
hash/index.ts[5] hash with bigint representation 70.91 ±2.67% 29.34% slower
hash/index.ts[6] hash with uint32 representation 93.68 ±0.94% 6.65% slower
bytes/bytes-to-number.ts[0] Conversion with bitops 3699.98 ±5.41% fastest ✅
bytes/bytes-to-number.ts[1] Conversion without bitops 2953.59 ±4.52% 20.17% slower
bytes/compare.ts[0] Comparing Uint32 bytes 11285.12 ±0.14% fastest ✅
bytes/compare.ts[1] Comparing raw bytes 10474.89 ±2.23% 7.18% slower
codec/view_vs_collection.ts[0] Get first element from Decoded 14846.65 ±0.6% 54.73% slower
codec/view_vs_collection.ts[1] Get first element from View 32798.78 ±0.82% fastest ✅
codec/view_vs_collection.ts[2] Get 50th element from Decoded 14884.34 ±0.49% 54.62% slower
codec/view_vs_collection.ts[3] Get 50th element from View 17461.59 ±0.29% 46.76% slower
codec/view_vs_collection.ts[4] Get last element from Decoded 15009.33 ±0.12% 54.24% slower
codec/view_vs_collection.ts[5] Get last element from View 12126.36 ±0.32% 63.03% slower
codec/view_vs_object.ts[0] Get the first field from Decoded 204938.33 ±0.36% 1.16% slower
codec/view_vs_object.ts[1] Get the first field from View 34645.78 ±64.35% 83.29% slower
codec/view_vs_object.ts[2] Get the first field as view from View 50408.43 ±2.18% 75.69% slower
codec/view_vs_object.ts[3] Get two fields from Decoded 203257.65 ±0.56% 1.97% slower
codec/view_vs_object.ts[4] Get two fields from View 39405.94 ±2.04% 80.99% slower
codec/view_vs_object.ts[5] Get two fields from materialized from View 81191.66 ±0.51% 60.84% slower
codec/view_vs_object.ts[6] Get two fields as views from View 41262.74 ±0.33% 80.1% slower
codec/view_vs_object.ts[7] Get only third field from Decoded 207338.82 ±0.28% fastest ✅
codec/view_vs_object.ts[8] Get only third field from View 50995.83 ±0.31% 75.4% slower
codec/view_vs_object.ts[9] Get only third field as view from View 51339.4 ±0.31% 75.24% slower
collections/map_vs_sorted.ts[0] Map 109362.24 ±0.07% fastest ✅
collections/map_vs_sorted.ts[1] Map-array 47547.73 ±0.06% 56.52% slower
collections/map_vs_sorted.ts[2] Array 54668.81 ±0.87% 50.01% slower
collections/map_vs_sorted.ts[3] SortedArray 83679.31 ±0.29% 23.48% slower
collections/hash-dict-vs-blob-dict_delete.ts[0] StringHashDictionary 2600.48 ±0.38% 1.45% slower
collections/hash-dict-vs-blob-dict_delete.ts[1] BlobDictionary(1) 2594.22 ±0.46% 1.69% slower
collections/hash-dict-vs-blob-dict_delete.ts[2] BlobDictionary(2) 2624.11 ±0.35% 0.55% slower
collections/hash-dict-vs-blob-dict_delete.ts[3] BlobDictionary(3) 2616.71 ±0.3% 0.84% slower
collections/hash-dict-vs-blob-dict_delete.ts[4] BlobDictionary(4) 2623.69 ±0.32% 0.57% slower
collections/hash-dict-vs-blob-dict_delete.ts[5] BlobDictionary(5) 2638.75 ±0.32% fastest ✅
collections/hash-dict-vs-blob-dict_get.ts[0] StringHashDictionary 2924.84 ±0.61% 1.02% slower
collections/hash-dict-vs-blob-dict_get.ts[1] BlobDictionary(1) 2923.86 ±0.81% 1.05% slower
collections/hash-dict-vs-blob-dict_get.ts[2] BlobDictionary(2) 2954.86 ±0.43% fastest ✅
collections/hash-dict-vs-blob-dict_get.ts[3] BlobDictionary(3) 2908.77 ±0.49% 1.56% slower
collections/hash-dict-vs-blob-dict_get.ts[4] BlobDictionary(4) 2939.41 ±0.43% 0.52% slower
collections/hash-dict-vs-blob-dict_get.ts[5] BlobDictionary(5) 2924.85 ±0.53% 1.02% slower
collections/hash-dict-vs-blob-dict_set.ts[0] StringHashDictionary 2302.74 ±1.03% 0.24% slower
collections/hash-dict-vs-blob-dict_set.ts[1] BlobDictionary(1) 2308.28 ±0.39% fastest ✅
collections/hash-dict-vs-blob-dict_set.ts[2] BlobDictionary(2) 1584.83 ±61.08% 31.34% slower
collections/hash-dict-vs-blob-dict_set.ts[3] BlobDictionary(3) 1721.38 ±2.27% 25.43% slower
collections/hash-dict-vs-blob-dict_set.ts[4] BlobDictionary(4) 2288.53 ±0.38% 0.86% slower
collections/hash-dict-vs-blob-dict_set.ts[5] BlobDictionary(5) 2290.32 ±0.41% 0.78% slower
hash/blake2b.ts[0] our hasher 1.08 ±0.26% fastest ✅
hash/blake2b.ts[1] blake2b js 0.03 ±0.2% 97.22% slower
crypto/ed25519.ts[0] native crypto 5.76 ±0.9% fastest ✅
crypto/ed25519.ts[1] wasm lib 2.29 ±0.24% 60.24% slower
crypto/ed25519.ts[2] wasm lib batch 2.22 ±2.33% 61.46% slower

Benchmarks summary: 83/83 OK ✅

@tomusdrw tomusdrw added this pull request to the merge queue Apr 19, 2026
Merged via the queue into main with commit 7338c21 Apr 19, 2026
14 checks passed
@tomusdrw tomusdrw deleted the maso-refine-invoke branch April 19, 2026 20:23
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.

2 participants