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

refactor: remove GasOps from the Kernel #1951

Merged
merged 1 commit into from
Dec 19, 2023
Merged

Conversation

Stebalien
Copy link
Member

It's not really a proper "ops" trait, it's more "basic functionality".

Additionally, the concept of a global price list is going to go away as we make the kernel more pluggable.

  1. Move GasOps::gas_available/GasOps::charge_gas to the main Kernel trait as all kernels require them.
  2. Remove GasOps::gas_used, it's only used for testing.
  3. Remove GasOps::price_list. We're still exposing it on the CallManager, but one step at a time).

@codecov-commenter
Copy link

codecov-commenter commented Dec 14, 2023

Codecov Report

Merging #1951 (a627137) into master (a8f9be1) will decrease coverage by 21.27%.
The diff coverage is 15.78%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1951       +/-   ##
===========================================
- Coverage   75.79%   54.52%   -21.27%     
===========================================
  Files         157      157               
  Lines       15441    15445        +4     
===========================================
- Hits        11703     8422     -3281     
- Misses       3738     7023     +3285     
Files Coverage Δ
fvm/src/kernel/default.rs 18.73% <100.00%> (-63.45%) ⬇️
fvm/src/kernel/mod.rs 0.00% <ø> (-90.00%) ⬇️
fvm/src/syscalls/linker.rs 0.00% <ø> (-92.46%) ⬇️
fvm/src/engine/mod.rs 43.18% <0.00%> (-40.88%) ⬇️
fvm/src/syscalls/gas.rs 0.00% <0.00%> (-18.75%) ⬇️
fvm/src/kernel/filecoin.rs 0.00% <0.00%> (-22.66%) ⬇️
fvm/src/gas/price_list.rs 34.49% <0.00%> (-43.82%) ⬇️
fvm/src/syscalls/mod.rs 0.00% <0.00%> (-97.40%) ⬇️

... and 57 files with indirect coverage changes

It's not really a proper "ops" trait, it's more "basic functionality".

Additionally, the concept of a global price list is going to go away as
we make the kernel more pluggable.

1. Move `GasOps::gas_available`/`GasOps::charge_gas` to the main
`Kernel` trait as all kernels require them.
2. Remove `GasOps::gas_used`, it's only used for testing.
3. Remove `GasOps::price_list`. We're still exposing it on the
CallManager, but one step at a time).
fvm/src/engine/mod.rs Show resolved Hide resolved
@@ -286,6 +284,8 @@ lazy_static! {
// Charge 0.4gas/byte for copying/fill.
memory_copy_per_byte_cost: Gas::from_milligas(400),
memory_fill_per_byte_cost: Gas::from_milligas(400),

host_call_cost: Gas::new(14000),
Copy link
Member Author

Choose a reason for hiding this comment

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

So, the "wasm" prices are generally just the prices used for wasm instrumentation. But the host call cost is so tightly bound to the wasm runtime that it kind of makes sense to just put it in this structure (and means that the syscall binding logic doesn't need to know about the global price list.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that make sense! qq, do we need to adjust these if we upgrade the runtime version?

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean the VM (wasmtime)? We should, but we haven't bothered re-measuring them for a while.

But I should expand on this a bit more: The rest of the prices here are actually baked into the compiled wasm modules when we instrument the code with gas accounting. That means they get cached in the engine (along with the compiled wasm modules) between epochs (across multiple FVM instances).

The host-call cost doesn't quite belong here because we charge for that on the outside so it doesn't become a part of the compiled wasm modules. Although, TBH, we should charge for it inside wasm as we generally avoid "after the fact" charges like this.

fvm/src/gas/price_list.rs Show resolved Hide resolved
fvm/src/gas/price_list.rs Show resolved Hide resolved
@@ -4,10 +4,11 @@ use std::str;

use super::Context;
use crate::gas::Gas;
use crate::kernel::{ClassifyResult, GasOps, Result};
use crate::kernel::{ClassifyResult, Result};
use crate::Kernel;

pub fn charge_gas(
Copy link
Member Author

Choose a reason for hiding this comment

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

This syscall will go away once we get rid of the original prove-commit method: filecoin-project/FIPs#820.

@@ -21,6 +22,6 @@ pub fn charge_gas(
.map(|_| ())
}

pub fn available(context: Context<'_, impl GasOps>) -> Result<u64> {
pub fn available(context: Context<'_, impl Kernel>) -> Result<u64> {
Copy link
Member Author

Choose a reason for hiding this comment

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

This syscall will hopefully go away and turn into a read of a global variable. See filecoin-project/FIPs#845

fvm/src/syscalls/linker.rs Show resolved Hide resolved
fvm/src/syscalls/linker.rs Show resolved Hide resolved
testing/conformance/src/vm.rs Show resolved Hide resolved
@@ -286,6 +284,8 @@ lazy_static! {
// Charge 0.4gas/byte for copying/fill.
memory_copy_per_byte_cost: Gas::from_milligas(400),
memory_fill_per_byte_cost: Gas::from_milligas(400),

host_call_cost: Gas::new(14000),
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that make sense! qq, do we need to adjust these if we upgrade the runtime version?

fvm/src/engine/mod.rs Show resolved Hide resolved
@@ -32,7 +32,7 @@ pub struct CallResult {
///
/// Actors may call into the kernel via the syscalls defined in the [`syscalls`][crate::syscalls]
/// module.
pub trait Kernel: GasOps + SyscallHandler<Self> + 'static {
pub trait Kernel: SyscallHandler<Self> + 'static {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

testing/conformance/src/vm.rs Show resolved Hide resolved
Copy link
Contributor

@fridrik01 fridrik01 left a comment

Choose a reason for hiding this comment

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

LGTM

@Stebalien Stebalien merged commit 0b4a34f into master Dec 19, 2023
12 checks passed
@Stebalien Stebalien deleted the steb/cleanup-gas-ops branch December 19, 2023 17:14
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.

3 participants