Skip to content

Commit

Permalink
chore: update FVM (#363)
Browse files Browse the repository at this point in the history
1. Updates to the latest gas fees.
2. Adapts to the changes in gas tracing (half way). We still need to
propagate this information to lotus, but that's a future patch.
  • Loading branch information
Stebalien authored Feb 10, 2023
1 parent 32df7d1 commit c35e816
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ serde_json = "1.0.46"
memmap = "0.7"
rust-gpu-tools = { version = "0.5", optional = true, default-features = false }
fr32 = { version = "~5.0", default-features = false }
fvm3 = { package = "fvm", version = "3.0.0-alpha.23", default-features = false }
fvm3 = { package = "fvm", version = "3.0.0-alpha.24", default-features = false }
fvm3_shared = { package = "fvm_shared", version = "3.0.0-alpha.20" }
fvm3_ipld_encoding = { package = "fvm_ipld_encoding", version = "0.3.3" }
fvm2 = { package = "fvm", version = "2.2.0", default-features = false }
Expand Down
20 changes: 13 additions & 7 deletions rust/src/fvm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ mod v3 {
mod v2 {
use anyhow::{anyhow, Context};
use cid::Cid;
use fvm3_ipld_encoding::ipld_block::IpldBlock;
use num_traits::FromPrimitive;
use std::sync::Mutex;

Expand Down Expand Up @@ -211,7 +212,7 @@ mod v2 {
use fvm3::kernel::SyscallError;

use fvm3::trace::ExecutionEvent;
use fvm3_ipld_encoding::RawBytes;
use fvm3_ipld_encoding::{RawBytes, DAG_CBOR};
use fvm3_shared::{
address::Address, econ::TokenAmount, error::ErrorNumber, error::ExitCode, message::Message,
receipt::Receipt,
Expand Down Expand Up @@ -355,17 +356,22 @@ mod v2 {
from,
to: Address::from_bytes(&to.to_bytes()).unwrap(),
method,
params: RawBytes::new(params.into()),
params: params.is_empty().then(|| IpldBlock {
codec: DAG_CBOR,
data: params.into(),
}),
value: TokenAmount::from_atto(value.atto().clone()),
}),
ExecutionEvent2::CallReturn(ret) => Some(ExecutionEvent::CallReturn(
ExitCode::OK,
RawBytes::new(ret.into()),
)),
ExecutionEvent2::CallAbort(ec) => Some(ExecutionEvent::CallReturn(
ExitCode::new(ec.value()),
RawBytes::default(),
ret.is_empty().then(|| IpldBlock {
codec: DAG_CBOR,
data: ret.into(),
}),
)),
ExecutionEvent2::CallAbort(ec) => {
Some(ExecutionEvent::CallReturn(ExitCode::new(ec.value()), None))
}
ExecutionEvent2::CallError(err) => {
Some(ExecutionEvent::CallError(SyscallError(
err.0,
Expand Down
23 changes: 11 additions & 12 deletions rust/src/fvm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ fn fvm_machine_execute_message(
let exec_trace = if !apply_ret.exec_trace.is_empty() {
let mut trace_iter = apply_ret.exec_trace.into_iter();
build_lotus_trace(
&(&mut trace_iter)
(&mut trace_iter)
// Skip gas charges before the first call, if any. Lotus can't handle them.
.find(|item| !matches!(item, &ExecutionEvent::GasCharge(_)))
.expect("already checked trace for emptiness"),
Expand Down Expand Up @@ -337,7 +337,7 @@ pub struct LotusReceipt {
}

fn build_lotus_trace(
new_call: &ExecutionEvent,
new_call: ExecutionEvent,
trace_iter: &mut impl Iterator<Item = ExecutionEvent>,
) -> anyhow::Result<LotusTrace> {
let mut new_trace = LotusTrace {
Expand All @@ -350,12 +350,12 @@ fn build_lotus_trace(
value,
} => Message {
version: 0,
from: Address::new_id(*from),
to: *to,
from: Address::new_id(from),
to,
value,
sequence: 0,
value: value.clone(),
method_num: *method,
params: params.clone(),
method_num: method,
params: params.map(|b| b.data).unwrap_or_default().into(),
gas_limit: 0,
gas_fee_cap: TokenAmount::default(),
gas_premium: TokenAmount::default(),
Expand All @@ -379,12 +379,12 @@ fn build_lotus_trace(
ExecutionEvent::Call { .. } => {
new_trace
.subcalls
.push(build_lotus_trace(&trace, trace_iter)?);
.push(build_lotus_trace(trace, trace_iter)?);
}
ExecutionEvent::CallReturn(exit_code, return_data) => {
new_trace.msg_receipt = LotusReceipt {
exit_code,
return_data,
return_data: return_data.map(|b| b.data).unwrap_or_default().into(),
gas_used: 0,
};
return Ok(new_trace);
Expand Down Expand Up @@ -431,7 +431,6 @@ mod test {
use crate::fvm::machine::build_lotus_trace;
use fvm3::kernel::SyscallError;
use fvm3::trace::ExecutionEvent;
use fvm3_ipld_encoding::RawBytes;
use fvm3_shared::address::Address;
use fvm3_shared::econ::TokenAmount;
use fvm3_shared::error::ErrorNumber::IllegalArgument;
Expand All @@ -442,7 +441,7 @@ mod test {
let call_event = ExecutionEvent::Call {
from: ActorID::default(),
method: 0,
params: RawBytes::default(),
params: None,
to: Address::new_id(0),
value: TokenAmount::default(),
};
Expand All @@ -461,7 +460,7 @@ mod test {

let mut trace_iter = trace.into_iter();

let lotus_trace = build_lotus_trace(&trace_iter.next().unwrap(), &mut trace_iter).unwrap();
let lotus_trace = build_lotus_trace(trace_iter.next().unwrap(), &mut trace_iter).unwrap();

assert!(trace_iter.next().is_none());

Expand Down

0 comments on commit c35e816

Please sign in to comment.