Skip to content

Modularise the wasm module#6441

Open
a1q123456 wants to merge 1 commit intoripple/wasmi-host-functionsfrom
a1q123456/modularise-wasm
Open

Modularise the wasm module#6441
a1q123456 wants to merge 1 commit intoripple/wasmi-host-functionsfrom
a1q123456/modularise-wasm

Conversation

@a1q123456
Copy link
Collaborator

High Level Overview of Change

This PR modularises the WASM module to make it possible to call wasm from transactors after transactor modularisation.

Context of Change

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (non-breaking change that only restructures code)
  • Performance (increase or change in throughput and/or latency)
  • Tests (you added tests for code that already exists, or your new feature included in this PR)
  • Documentation update
  • Chore (no impact to binary, e.g. .gitignore, formatting, dropping support for older tooling)
  • Release

API Impact

  • Public API: New feature (new methods and/or new fields)
  • Public API: Breaking change (in general, breaking changes should only impact the next api_version)
  • libxrpl change (any change that may affect libxrpl or dependents of libxrpl)
  • Peer protocol change (must be backward compatible or bump the peer protocol version)

Signed-off-by: JCW <a1q123456@users.noreply.github.com>
@a1q123456 a1q123456 requested a review from mvadari February 26, 2026 18:09
@a1q123456 a1q123456 changed the base branch from develop to ripple/wasmi-host-functions February 26, 2026 18:09
#pragma once

#include <xrpld/app/wasm/HostFunc.h>
#include <xrpl/tx/transactors/smart_escrow/HostFunc.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Smart Escrow is just one feature, wheras the WASM VM will power multiple "Smart Features." Because of that, I think may <xrpl/tx/transactors/wasm/HostFunc.h> is the better location?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want it to be in the transactors module or a separate module entirely?

Copy link
Collaborator Author

@a1q123456 a1q123456 Feb 26, 2026

Choose a reason for hiding this comment

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

My idea was, once we want to use wasm for something else, we take the smart_escrow/wasm folder and make it a top level module like xrpl.wasm and then we implement other things for that feature specifically.

HostFunc is something tightly coupled with smart escrow and I don't think we'll reuse it.

Copy link
Collaborator

@sappenin sappenin Feb 26, 2026

Choose a reason for hiding this comment

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

HostFunc is something tightly coupled with smart escrow and I don't think we'll reuse it.

Actually, HostFunctions are coupled to the broader category of Smart Features (with more coming soon), not just Smart Escrow.

Smart Escrow serves as a proving ground for generalized WASM functionality in xrpld. Future WASM-based features—like Smart Features, Smart Contracts, potentially even Native Transactors—will reuse this layer.

Ultimately, WASM should be viewed as a cross-cutting architectural feature that may even extend beyond transactor processing.

```
┌─────────────────────────────────────────────────────────────┐
WasmEngine (WasmVM.h)
EscrowWasm.h
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is incorrect. The WasmEngine is not specific to Escrow (it's used by Escrow, but will be used by more in the future).

@mvadari mvadari requested review from mvadari, oleks-rip and pwang200 and removed request for mvadari February 26, 2026 18:20

namespace xrpl {

// Generic WASM constants
Copy link
Collaborator

@oleks-rip oleks-rip Feb 26, 2026

Choose a reason for hiding this comment

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

This comment explain / clarify nothing, I don't think we need to add obvious comments.

uint32_t const MAX_PAGES = 128; // 8MB = 64KB*128

class WasmiEngine;
class WasmiRuntime;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know choosing naming is tough process, so it need to be done in separate PR with proper discussion. For example "Runtime" is more suitable for javascript engine, wasm is more docker like.

Renaming it here just complicate reviewing modularization.

class WasmiRuntime;

/**
* WasmEngine - Singleton facade for WASM runtime execution.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about renaming.

class WasmEngine
{
std::unique_ptr<WasmiEngine> const impl;
std::unique_ptr<WasmiRuntime> const impl;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about renaming.

* @return Shared pointer to the import vector
*/
std::shared_ptr<ImportVec>
createWasmImport(HostFunctions& hfs);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't belong to "Escrow", it is more general.

@@ -0,0 +1,65 @@
#pragma once
Copy link
Collaborator

Choose a reason for hiding this comment

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

Name EscrowWasm.h is more like some ledger object / transaction style. EscrowWasmHelpers.h more suitable


// std::cout << "runEscrowWasm, mod size: " << wasmCode.size()
// << ", gasLimit: " << gasLimit << ", funcName: " << funcName;
#ifdef DEBUG_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use another definition, as it not always needed during debugging.

WasmiEngine::allocate(int32_t sz)
WasmiRuntime::allocate(int32_t sz)
{
if (sz <= 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? You shouldn't remove security checks.

wasm_byte_vec_delete(&msg);

return trap;
wasm_message_t message;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, why you remove security checks?

gas = std::numeric_limits<decltype(gas)>::max();
WasmResult<int32_t> const ret{res.r.vec_.data[0].of.i32, gas - moduleWrap_->getGas()};

// #ifdef DEBUG_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

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

Coudl you please just put it into additional #ifdef section and not removing it.

@mvadari
Copy link
Collaborator

mvadari commented Feb 27, 2026

@a1q123456 can we focus on just the modularization in this PR, and not make any other changes? If you have other concerns/changes you want to make, we can discuss those separately, in PR review for #6075

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