Skip to content

Commit bb8e95a

Browse files
committed
chore: update FVM to 3.0.0-alpha.23
This updates the FVM and switches gas to u64.
1 parent b247164 commit bb8e95a

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

rust/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ serde_json = "1.0.46"
3434
memmap = "0.7"
3535
rust-gpu-tools = { version = "0.5", optional = true, default-features = false }
3636
fr32 = { version = "~5.0", default-features = false }
37-
fvm3 = { package = "fvm", version = "3.0.0-alpha.22", default-features = false }
38-
fvm3_shared = { package = "fvm_shared", version = "3.0.0-alpha.18" }
39-
fvm3_ipld_encoding = { package = "fvm_ipld_encoding", version = "0.3.2" }
37+
fvm3 = { package = "fvm", version = "3.0.0-alpha.23", default-features = false }
38+
fvm3_shared = { package = "fvm_shared", version = "3.0.0-alpha.20" }
39+
fvm3_ipld_encoding = { package = "fvm_ipld_encoding", version = "0.3.3" }
4040
fvm2 = { package = "fvm", version = "2.2.0", default-features = false }
4141
fvm2_shared = { package = "fvm_shared", version = "2.0.0" }
4242
fvm2_ipld_encoding = { package = "fvm_ipld_encoding", version = "0.2.3" }

rust/src/fvm/engine.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod v3 {
182182

183183
// fvm v2 implementation
184184
mod v2 {
185-
use anyhow::anyhow;
185+
use anyhow::{anyhow, Context};
186186
use cid::Cid;
187187
use num_traits::FromPrimitive;
188188
use std::sync::Mutex;
@@ -241,14 +241,14 @@ mod v2 {
241241
let res = fvm2::executor::Executor::execute_message(
242242
self,
243243
Message2 {
244-
version: msg.version,
244+
version: msg.version.try_into().context("invalid message version")?,
245245
from: Address2::from_bytes(&msg.from.to_bytes()).unwrap(),
246246
to: Address2::from_bytes(&msg.to.to_bytes()).unwrap(),
247247
sequence: msg.sequence,
248248
value: TokenAmount2::from_atto(msg.value.atto().clone()),
249249
method_num: msg.method_num,
250250
params: RawBytes2::new(msg.params.into()),
251-
gas_limit: msg.gas_limit,
251+
gas_limit: msg.gas_limit.try_into().context("invalid gas limit")?,
252252
gas_fee_cap: TokenAmount2::from_atto(msg.gas_fee_cap.atto().clone()),
253253
gas_premium: TokenAmount2::from_atto(msg.gas_premium.atto().clone()),
254254
},
@@ -263,7 +263,11 @@ mod v2 {
263263
msg_receipt: Receipt {
264264
exit_code: ExitCode::new(ret.msg_receipt.exit_code.value()),
265265
return_data: RawBytes::new(ret.msg_receipt.return_data.into()),
266-
gas_used: ret.msg_receipt.gas_used,
266+
gas_used: ret
267+
.msg_receipt
268+
.gas_used
269+
.try_into()
270+
.context("negative gas used")?,
267271
events_root: None,
268272
},
269273
penalty: TokenAmount::from_atto(ret.penalty.atto().clone()),
@@ -273,8 +277,8 @@ mod v2 {
273277
ret.over_estimation_burn.atto().clone(),
274278
),
275279
refund: TokenAmount::from_atto(ret.refund.atto().clone()),
276-
gas_refund: ret.gas_refund,
277-
gas_burned: ret.gas_burned,
280+
gas_refund: ret.gas_refund.try_into().context("negative gas refund")?,
281+
gas_burned: ret.gas_burned.try_into().context("negative gas burned")?,
278282
failure_info: ret.failure_info.map(|failure| match failure {
279283
ApplyFailure2::MessageBacktrace(bt) => {
280284
ApplyFailure::MessageBacktrace(Backtrace {
@@ -318,12 +322,26 @@ mod v2 {
318322
.into_iter()
319323
.filter_map(|tr| match tr {
320324
ExecutionEvent2::GasCharge(charge) => {
325+
// We set the gas for "negative" charges to 0. This isn't correct,
326+
// but it won't matter in practice (the sum of the gas charges in
327+
// the trace aren't guaranteed to equal the total gas charge
328+
// anyways).
321329
Some(ExecutionEvent::GasCharge(GasCharge {
322330
name: charge.name,
323331
compute_gas: Gas::from_milligas(
324-
charge.compute_gas.as_milligas(),
332+
charge
333+
.compute_gas
334+
.as_milligas()
335+
.try_into()
336+
.unwrap_or_default(),
337+
),
338+
other_gas: Gas::from_milligas(
339+
charge
340+
.storage_gas
341+
.as_milligas()
342+
.try_into()
343+
.unwrap_or_default(),
325344
),
326-
other_gas: Gas::from_milligas(charge.storage_gas.as_milligas()),
327345
elapsed: Default::default(), // no timing information for v2.
328346
}))
329347
}

rust/src/fvm/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,9 @@ destructor!(destroy_fvm_machine_flush_response, Result<c_slice::Box<u8>>);
315315
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]
316316
struct LotusGasCharge {
317317
pub name: Cow<'static, str>,
318-
pub total_gas: i64,
319-
pub compute_gas: i64,
320-
pub storage_gas: i64,
318+
pub total_gas: u64,
319+
pub compute_gas: u64,
320+
pub storage_gas: u64,
321321
}
322322

323323
#[derive(Clone, Debug, Serialize_tuple, Deserialize_tuple)]

rust/src/fvm/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ pub struct FvmMachineExecuteResponse {
3737
pub over_estimation_burn_lo: u64,
3838
pub refund_hi: u64,
3939
pub refund_lo: u64,
40-
pub gas_refund: i64,
41-
pub gas_burned: i64,
40+
pub gas_refund: u64,
41+
pub gas_burned: u64,
4242
pub exec_trace: Option<c_slice::Box<u8>>,
4343
pub failure_info: Option<str::Box>,
4444
pub events: Option<c_slice::Box<u8>>,

0 commit comments

Comments
 (0)