Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to wasmi native fuel metering #815

Merged
merged 4 commits into from
Jun 3, 2023
Merged

Conversation

jayz22
Copy link
Contributor

@jayz22 jayz22 commented May 19, 2023

What

Pinned to my local wasmi branch: https://github.com/jayz22/wasmi/tree/soroban-fuel-metering

This PR adapts to wasmi upstream changes between v0.16 and v0.30. In particular the fuel metering features (resolves #683).

Changes include:

  • Conversion for Wasmi values (wasmi::core::FromValue no longer exist), added a new trait WasmiMarshal.
  • Turns off floating point and added a test
  • Implement the conversion and transferring between (host) budget and (wasmi) fuel, at the host<->Vm boundaries
    • When calling invoke_function on the VM
    • When Vm invokes host functions in dispatch

Why

[TODO: Why this change is being made. Include any context required to understand the why.]

Known limitations

We did not successfully get rid of the fork because of Wasmi does not have:

  • several accessors, e.g. in Fuel, and FuelCosts
  • Custom Sections
  • Memory metering. This was the biggest issue. Memory metering is not planned to be supported but wasmi will add a ResourceLimiter which will allow host limiting and charging the maximum amount of memory upfront. We will switch to it when the feature is ready (Add ResourceLimiter to wasmi::Store wasmi-labs/wasmi#728).

Still need to recalibrate the fuel costs.

@jayz22
Copy link
Contributor Author

jayz22 commented May 26, 2023

All tests passing against my wasmi branch.

@jayz22 jayz22 marked this pull request as ready for review June 2, 2023 00:16
@jayz22 jayz22 requested review from graydon, sisuresh and a team as code owners June 2, 2023 00:16
Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

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

Fairly good progress! A bit of refactoring in VM would be nice, and removal of asserts, but I think it's going in the right direction.

The division-losing-fuel problem is the bit that kinda seems bad to me. I'm not sure it's bad, but it seems like it might be. Perhaps we can discuss tomorrow?

soroban-test-wasms/src/lib.rs Outdated Show resolved Hide resolved
soroban-env-host/src/host.rs Outdated Show resolved Hide resolved
soroban-env-host/src/budget.rs Show resolved Hide resolved
soroban-env-host/src/test/basic.rs Show resolved Hide resolved
soroban-env-host/src/vm.rs Outdated Show resolved Hide resolved
soroban-env-host/src/vm.rs Outdated Show resolved Hide resolved
soroban-env-host/src/vm.rs Outdated Show resolved Hide resolved
soroban-env-host/src/vm.rs Outdated Show resolved Hide resolved
soroban-env-host/src/budget.rs Show resolved Hide resolved
Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

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

Fairly good progress! A bit of refactoring in VM would be nice, and removal of asserts, but I think it's going in the right direction.

The division-losing-fuel problem is the bit that kinda seems bad to me. I'm not sure it's bad, but it seems like it might be. Perhaps we can discuss tomorrow?

@jayz22 jayz22 changed the title [WIP] Switch to wasmi native fuel metering Switch to wasmi native fuel metering Jun 3, 2023
Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

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

Great, thanks!

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.

Evaluate viability of using wasmi's out-of-box fuel metering
3 participants