Skip to content

Commit 22318f9

Browse files
committed
Refactor EntrypointParams into Entrypoint
1 parent 0c5ed7b commit 22318f9

File tree

5 files changed

+40
-61
lines changed

5 files changed

+40
-61
lines changed

Cargo.lock

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

fvm/src/call_manager/default.rs

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use fvm_shared::econ::TokenAmount;
1212
use fvm_shared::error::{ErrorNumber, ExitCode};
1313
use fvm_shared::event::StampedEvent;
1414
use fvm_shared::sys::BlockId;
15-
use fvm_shared::{ActorID, MethodNum, METHOD_SEND};
15+
use fvm_shared::{ActorID, METHOD_SEND};
1616
use num_traits::Zero;
1717

1818
use super::state_access_tracker::{ActorAccessState, StateAccessTracker};
@@ -688,8 +688,7 @@ where
688688

689689
// additional_params takes care of adding entrypoint specific params to the block
690690
// registry and passing them to wasmtime
691-
let mut additional_params = EntrypointParams::new(entrypoint);
692-
additional_params.maybe_put_registry(&mut block_registry)?;
691+
let additional_params = entrypoint.into_params(&mut block_registry)?;
693692

694693
// Increment invocation count
695694
self.invocation_count += 1;
@@ -746,7 +745,7 @@ where
746745
};
747746

748747
let mut params = vec![wasmtime::Val::I32(params_id as i32)];
749-
params.extend_from_slice(additional_params.params().as_slice());
748+
params.extend_from_slice(additional_params.as_slice());
750749

751750
// Set the available gas.
752751
update_gas_available(&mut store)?;
@@ -998,53 +997,3 @@ impl EventsAccumulator {
998997
})
999998
}
1000999
}
1001-
1002-
impl Entrypoint {
1003-
fn method_num(&self) -> MethodNum {
1004-
match self {
1005-
Entrypoint::Invoke(num) => *num,
1006-
Entrypoint::Upgrade(_) => fvm_shared::METHOD_UPGRADE,
1007-
}
1008-
}
1009-
1010-
fn func_name(&self) -> &'static str {
1011-
match self {
1012-
Entrypoint::Invoke(_) => "invoke",
1013-
Entrypoint::Upgrade(_) => "upgrade",
1014-
}
1015-
}
1016-
}
1017-
1018-
// EntrypointParams is a helper struct to init the registry with the entrypoint specific
1019-
// parameters and then forward them to wasmtime
1020-
struct EntrypointParams {
1021-
entrypoint: Entrypoint,
1022-
params: Vec<wasmtime::Val>,
1023-
}
1024-
1025-
impl EntrypointParams {
1026-
fn new(entrypoint: Entrypoint) -> Self {
1027-
Self {
1028-
entrypoint,
1029-
params: Vec::new(),
1030-
}
1031-
}
1032-
1033-
fn maybe_put_registry(&mut self, br: &mut BlockRegistry) -> Result<()> {
1034-
match self.entrypoint {
1035-
Entrypoint::Invoke(_) => Ok(()),
1036-
Entrypoint::Upgrade(ui) => {
1037-
let ui_params = to_vec(&ui).map_err(
1038-
|e| syscall_error!(IllegalArgument; "failed to serialize upgrade params: {}", e),
1039-
)?;
1040-
let block_id = br.put_reachable(Block::new(CBOR, ui_params, Vec::new()))?;
1041-
self.params.push(wasmtime::Val::I32(block_id as i32));
1042-
Ok(())
1043-
}
1044-
}
1045-
}
1046-
1047-
fn params(&self) -> &Vec<wasmtime::Val> {
1048-
&self.params
1049-
}
1050-
}

fvm/src/call_manager/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2021-2023 Protocol Labs
22
// SPDX-License-Identifier: Apache-2.0, MIT
33
use cid::Cid;
4+
use fvm_ipld_encoding::{to_vec, CBOR};
45
use fvm_shared::address::Address;
56
use fvm_shared::econ::TokenAmount;
67
use fvm_shared::error::ExitCode;
@@ -9,7 +10,7 @@ use fvm_shared::{ActorID, MethodNum};
910

1011
use crate::engine::Engine;
1112
use crate::gas::{Gas, GasCharge, GasTimer, GasTracker, PriceList};
12-
use crate::kernel::{self, Result};
13+
use crate::kernel::{self, BlockRegistry, Result};
1314
use crate::machine::{Machine, MachineContext};
1415
use crate::state_tree::ActorState;
1516
use crate::Kernel;
@@ -213,3 +214,32 @@ impl std::fmt::Display for Entrypoint {
213214
}
214215
}
215216
}
217+
218+
impl Entrypoint {
219+
fn method_num(&self) -> MethodNum {
220+
match self {
221+
Entrypoint::Invoke(num) => *num,
222+
Entrypoint::Upgrade(_) => fvm_shared::METHOD_UPGRADE,
223+
}
224+
}
225+
226+
fn func_name(&self) -> &'static str {
227+
match self {
228+
Entrypoint::Invoke(_) => "invoke",
229+
Entrypoint::Upgrade(_) => "upgrade",
230+
}
231+
}
232+
233+
fn into_params(self, br: &mut BlockRegistry) -> Result<Vec<wasmtime::Val>> {
234+
match self {
235+
Entrypoint::Invoke(_) => Ok(Vec::new()),
236+
Entrypoint::Upgrade(ui) => {
237+
let ui_params = to_vec(&ui).map_err(
238+
|e| crate::syscall_error!(IllegalArgument; "failed to serialize upgrade params: {}", e),
239+
)?;
240+
let block_id = br.put_reachable(kernel::Block::new(CBOR, ui_params, Vec::new()))?;
241+
Ok(vec![wasmtime::Val::I32(block_id as i32)])
242+
}
243+
}
244+
}
245+
}

testing/conformance/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ where
299299
self.0.lookup_delegated_address(actor_id)
300300
}
301301

302-
fn upgrade_actor(&mut self, new_code_cid: Cid, params_id: BlockId) -> Result<BlockId> {
303-
self.0.upgrade_actor(new_code_cid, params_id)
302+
fn upgrade_actor<KK>(&mut self, new_code_cid: Cid, params_id: BlockId) -> Result<BlockId> {
303+
self.0.upgrade_actor::<Self>(new_code_cid, params_id)
304304
}
305305
}
306306

testing/test_actors/actors/fil-upgrade-actor/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2021"
55
publish = false
66

77
[target.'cfg(target_arch = "wasm32")'.dependencies]
8-
fvm_sdk = { version = "4.0.0-alpha.3", path = "../../../../sdk" }
9-
fvm_shared = { version = "4.0.0-alpha.3", path = "../../../../shared" }
8+
fvm_sdk = { version = "4.0.0-alpha.4", path = "../../../../sdk" }
9+
fvm_shared = { version = "4.0.0-alpha.4", path = "../../../../shared" }
1010
fvm_ipld_encoding = { version = "0.4.0", path = "../../../../ipld/encoding" }
1111
cid = { workspace = true }
1212
serde = { version = "1.0.164", features = ["derive"] }

0 commit comments

Comments
 (0)