Skip to content

Commit

Permalink
More review addressing
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Apr 28, 2022
1 parent 20d3ed1 commit c5b660b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
18 changes: 12 additions & 6 deletions fvm/src/call_manager/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,23 @@ where

// From this point on, there are no more syscall errors, only aborts.
let result: std::result::Result<RawBytes, Abort> = (|| {
let initial_milligas = store.data_mut().kernel.borrow_milligas().map_err(|e| match e {
ExecutionError::OutOfGas => Abort::OutOfGas,
ExecutionError::Fatal(m) => Abort::Fatal(m),
_ => Abort::Fatal(anyhow::Error::msg("setting avaialable gas")),
})?;
let initial_milligas =
store
.data_mut()
.kernel
.borrow_milligas()
.map_err(|e| match e {
ExecutionError::OutOfGas => Abort::OutOfGas,
ExecutionError::Fatal(m) => Abort::Fatal(m),
_ => Abort::Fatal(anyhow::Error::msg("setting avaialable gas")),
})?;

store
.data()
.avail_gas_global
.clone()
.set(&mut store, Val::I64(initial_milligas)).map_err(Abort::Fatal)?;
.set(&mut store, Val::I64(initial_milligas))
.map_err(Abort::Fatal)?;

// Lookup the invoke method.
let invoke: wasmtime::TypedFunc<(u32,), u32> = instance
Expand Down
9 changes: 7 additions & 2 deletions fvm/src/gas/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ impl GasTracker {
/// enough gas remaining for charge.
fn charge_milligas(&mut self, name: &str, to_use: i64) -> Result<()> {
if !self.own_limit {
panic!("charge_gas called when gas_limit owned by execution")
return Err(ExecutionError::Fatal(anyhow::Error::msg(
"charge_gas called when gas_limit owned by execution",
)));
}

match self.milligas_used.checked_add(to_use) {
Expand Down Expand Up @@ -78,7 +80,10 @@ impl GasTracker {
/// sets new available gas, creating a new gas charge if needed
pub fn return_milligas(&mut self, name: &str, new_avail_mgas: i64) -> Result<()> {
if self.own_limit {
panic!("gastracker already owns gas_limit, charge: {}", name)
return Err(ExecutionError::Fatal(anyhow::Error::msg(format!(
"gastracker already owns gas_limit, charge: {}",
name
))));
}
self.own_limit = true;

Expand Down
3 changes: 1 addition & 2 deletions fvm/src/gas/price_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use lazy_static::lazy_static;
use num_traits::Zero;

use super::GasCharge;
use crate::gas;

lazy_static! {
static ref OH_SNAP_PRICES: PriceList = PriceList {
Expand Down Expand Up @@ -260,7 +259,7 @@ lazy_static! {
// TODO: PARAM_FINISH
block_stat: 1,

exec_instruction_cost_milli: (gas::MILLIGAS_PRECISION / 2) as u64,
exec_instruction_cost_milli: 5000 as u64,
// TODO: PARAM_FINISH
};
}
Expand Down
6 changes: 0 additions & 6 deletions fvm/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,6 @@ pub trait CircSupplyOps {
}

/// Operations for explicit gas charging.
///
/// TODO this is unsafe; most gas charges should occur as part of syscalls, but
/// some built-in actors currently charge gas explicitly for concrete actions.
/// In the future (Phase 1), this should disappear and be replaced by gas instrumentation
/// at the WASM level.
/// TODO remove the todo above
pub trait GasOps {
/// GasUsed return the gas used by the transaction so far.
fn gas_used(&self) -> i64;
Expand Down

0 comments on commit c5b660b

Please sign in to comment.