refactor: Wasm vm redesign - #7952
Conversation
chore: Fix clang version in devshell
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| } | ||
|
|
||
| /// A check's verdict. No cost, because nothing was executed. | ||
| struct CheckResult { |
There was a problem hiding this comment.
Do we need both a CheckResult and a RunResult? There seems to be a lot of overlap between the two of them.
| /// A negative return is a `HostError` code. | ||
| #[namespace = "xrpl"] | ||
| #[cxx_name = "getLedgerSqn"] | ||
| fn get_ledger_sqn(self: &HostContext, out: &mut [u8]) -> i32; |
There was a problem hiding this comment.
While I get that it might be idiomatic for snake case with rust, I think there is a broader question here about do we want to allow this difference within this repo. The CPP code is camel case (which in itself is not necessarily idiomatic cpp either).
There was a problem hiding this comment.
I am fine with having a split, I just wanted to point it out in case in really matter to someone.
| } | ||
|
|
||
| /// Every import must be one the linker defines. The first that is not ends the | ||
| /// check, so a module with several faults reports the earliest. |
There was a problem hiding this comment.
Curious if this is also how the original code operated? I think a question would be what a better developer experience would be vs how much overhead it would take to provide the full list of faults.
| // is generated from the same table. | ||
| for &op in HostFunctionSpec::ALL { | ||
| match op { | ||
| HostFunctionSpec::GetLedgerSqn => linker.func_wrap( |
There was a problem hiding this comment.
This match is going to be somewhat large. What are the options in Rust to handle this? Could we use a traits based approach in rust as well?
High Level Overview of Change
This PR replaces the wasmi C-API integration with a Rust wasmi wrapper reached over a cxx
bridge.
What's here
crates/— cargo workspace, built in via corrosion.xrpl-host-functions— the ABI's single declaration site.host_functions! { … }generates the
HostFunctionstrait and the spec enum (import name + gas per function).no_std, no allocator, zero runtime deps, builds forwasm32— so the guest SDK canimplement the same trait from the same declaration.
xrpl-wasm-vm— the engine:run, andcheck(compile / imports / entry point /declared memory, with no host, store or gas, because a transaction's
preflight()has noledger to serve a host call from).
xrpl-wasm-vm-ffi— the bridge. Three crossings:run_escrowin, host calls back out,check_escrowin.xrpl-wasm-testkit— test-onlycompile_wat, a separate crate so no assembler can reachthe shipped node.
C++ —
HostContext.{h,cpp}, an ABI-shapednoexceptview ofHostFunctions; andWasmVM.{h,cpp}withrunEscrowWasm/preflightEscrowWasmand both TER maps.Not in this PR
ldgr_index,home_le_field,sha512_half,trace,trace_num). The remainingHostFuncImpl*.cppare untouched and still compile.src/test/app/HostFuncImpl_test.cppis commented out: its assertions ran through thedeleted C lowering.
Base branches
The PR is based on 2 branches:
Context of Change
API Impact
libxrplchange (any change that may affectlibxrplor dependents oflibxrpl)