diff --git a/Cargo.lock b/Cargo.lock index 11e9e5ad93..8ea80b3460 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1935,8 +1935,8 @@ version = "0.1.0" dependencies = [ "cid 0.10.1", "fvm_ipld_encoding 0.4.0", - "fvm_sdk 4.0.0-alpha.3", - "fvm_shared 4.0.0-alpha.3", + "fvm_sdk 4.0.0-alpha.4", + "fvm_shared 4.0.0-alpha.4", "serde", "serde_tuple", ] diff --git a/fvm/src/call_manager/default.rs b/fvm/src/call_manager/default.rs index 97eac440c4..bcdb15153a 100644 --- a/fvm/src/call_manager/default.rs +++ b/fvm/src/call_manager/default.rs @@ -12,7 +12,7 @@ use fvm_shared::econ::TokenAmount; use fvm_shared::error::{ErrorNumber, ExitCode}; use fvm_shared::event::StampedEvent; use fvm_shared::sys::BlockId; -use fvm_shared::{ActorID, MethodNum, METHOD_SEND}; +use fvm_shared::{ActorID, METHOD_SEND}; use num_traits::Zero; use super::state_access_tracker::{ActorAccessState, StateAccessTracker}; @@ -688,8 +688,7 @@ where // additional_params takes care of adding entrypoint specific params to the block // registry and passing them to wasmtime - let mut additional_params = EntrypointParams::new(entrypoint); - additional_params.maybe_put_registry(&mut block_registry)?; + let additional_params = entrypoint.into_params(&mut block_registry)?; // Increment invocation count self.invocation_count += 1; @@ -746,7 +745,7 @@ where }; let mut params = vec![wasmtime::Val::I32(params_id as i32)]; - params.extend_from_slice(additional_params.params().as_slice()); + params.extend_from_slice(additional_params.as_slice()); // Set the available gas. update_gas_available(&mut store)?; @@ -998,53 +997,3 @@ impl EventsAccumulator { }) } } - -impl Entrypoint { - fn method_num(&self) -> MethodNum { - match self { - Entrypoint::Invoke(num) => *num, - Entrypoint::Upgrade(_) => fvm_shared::METHOD_UPGRADE, - } - } - - fn func_name(&self) -> &'static str { - match self { - Entrypoint::Invoke(_) => "invoke", - Entrypoint::Upgrade(_) => "upgrade", - } - } -} - -// EntrypointParams is a helper struct to init the registry with the entrypoint specific -// parameters and then forward them to wasmtime -struct EntrypointParams { - entrypoint: Entrypoint, - params: Vec, -} - -impl EntrypointParams { - fn new(entrypoint: Entrypoint) -> Self { - Self { - entrypoint, - params: Vec::new(), - } - } - - fn maybe_put_registry(&mut self, br: &mut BlockRegistry) -> Result<()> { - match self.entrypoint { - Entrypoint::Invoke(_) => Ok(()), - Entrypoint::Upgrade(ui) => { - let ui_params = to_vec(&ui).map_err( - |e| syscall_error!(IllegalArgument; "failed to serialize upgrade params: {}", e), - )?; - let block_id = br.put_reachable(Block::new(CBOR, ui_params, Vec::new()))?; - self.params.push(wasmtime::Val::I32(block_id as i32)); - Ok(()) - } - } - } - - fn params(&self) -> &Vec { - &self.params - } -} diff --git a/fvm/src/call_manager/mod.rs b/fvm/src/call_manager/mod.rs index eede498598..db65b55ad6 100644 --- a/fvm/src/call_manager/mod.rs +++ b/fvm/src/call_manager/mod.rs @@ -1,6 +1,7 @@ // Copyright 2021-2023 Protocol Labs // SPDX-License-Identifier: Apache-2.0, MIT use cid::Cid; +use fvm_ipld_encoding::{to_vec, CBOR}; use fvm_shared::address::Address; use fvm_shared::econ::TokenAmount; use fvm_shared::error::ExitCode; @@ -9,7 +10,7 @@ use fvm_shared::{ActorID, MethodNum}; use crate::engine::Engine; use crate::gas::{Gas, GasCharge, GasTimer, GasTracker, PriceList}; -use crate::kernel::{self, Result}; +use crate::kernel::{self, BlockRegistry, Result}; use crate::machine::{Machine, MachineContext}; use crate::state_tree::ActorState; use crate::Kernel; @@ -213,3 +214,34 @@ impl std::fmt::Display for Entrypoint { } } } + +impl Entrypoint { + fn method_num(&self) -> MethodNum { + match self { + Entrypoint::Invoke(num) => *num, + Entrypoint::Upgrade(_) => fvm_shared::METHOD_UPGRADE, + } + } + + fn func_name(&self) -> &'static str { + match self { + Entrypoint::Invoke(_) => "invoke", + Entrypoint::Upgrade(_) => "upgrade", + } + } + + fn into_params(self, br: &mut BlockRegistry) -> Result> { + match self { + Entrypoint::Invoke(_) => Ok(Vec::new()), + Entrypoint::Upgrade(ui) => { + let ui_params = to_vec(&ui).map_err( + |e| crate::syscall_error!(IllegalArgument; "failed to serialize upgrade params: {}", e), + )?; + let block_id = br.put_reachable(kernel::Block::new(CBOR, ui_params, Vec::new()))?; + let mut params = Vec::new(); + params.push(wasmtime::Val::I32(block_id as i32)); + Ok(params) + } + } + } +}