Skip to content

Commit f46d4dc

Browse files
authored
Reverse import of fil_actors_runtime and vm_api (#1359)
* amend actor type to match fvm impl * reverse builtin <-> runtime dependency * hide testing utils behind feature flag
1 parent 584f88f commit f46d4dc

File tree

12 files changed

+161
-132
lines changed

12 files changed

+161
-132
lines changed

Cargo.lock

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

integration_tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fil_actor_evm = { workspace = true }
2929
fil_actor_eam = { workspace = true }
3030
fil_actor_ethaccount = { workspace = true }
3131
fil_actors_evm_shared = { workspace = true }
32-
vm_api = { workspace = true }
32+
vm_api = { workspace = true, features = ["testing"] }
3333

3434
anyhow = { workspace = true }
3535
bimap = { workspace = true }

integration_tests/src/tests/init_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use fil_actors_runtime::{
77
};
88
use fvm_shared::{address::Address, econ::TokenAmount, error::ExitCode, METHOD_SEND};
99
use num_traits::Zero;
10-
use vm_api::{actor, util::serialize_ok, VM};
10+
use vm_api::{new_actor, util::serialize_ok, VM};
1111

1212
use crate::{FIRST_TEST_USER_ADDR, TEST_FAUCET_ADDR};
1313

@@ -22,7 +22,7 @@ pub fn placeholder_deploy_test(v: &dyn VM) {
2222
// Create a "fake" eam.
2323
v.set_actor(
2424
&EAM_ACTOR_ADDR,
25-
actor(*EAM_ACTOR_CODE_ID, EMPTY_ARR_CID, 0, TokenAmount::zero(), None),
25+
new_actor(*EAM_ACTOR_CODE_ID, EMPTY_ARR_CID, 0, TokenAmount::zero(), None),
2626
);
2727

2828
// Create a placeholder.

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ serde = { workspace = true }
3333
serde_repr = { workspace = true }
3434
thiserror = { workspace = true }
3535
unsigned-varint = { workspace = true }
36+
vm_api = { workspace = true }
3637

3738
# A fake-proofs dependency but... we can't select on that feature here because we enable it from
3839
# build.rs.

runtime/src/runtime/builtins.rs

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1 @@
1-
use num_derive::FromPrimitive;
2-
3-
/// Identifies the builtin actor types for usage with the
4-
/// actor::resolve_builtin_actor_type syscall.
5-
/// Note that there is a mirror of this enum in the FVM SDK src/actors/builtins.rs.
6-
/// These must be kept in sync for the syscall to work correctly, without either side
7-
/// importing the other.
8-
#[derive(PartialEq, Eq, Clone, Copy, PartialOrd, Ord, FromPrimitive, Debug)]
9-
#[repr(i32)]
10-
pub enum Type {
11-
System = 1,
12-
Init = 2,
13-
Cron = 3,
14-
Account = 4,
15-
Power = 5,
16-
Miner = 6,
17-
Market = 7,
18-
PaymentChannel = 8,
19-
Multisig = 9,
20-
Reward = 10,
21-
VerifiedRegistry = 11,
22-
DataCap = 12,
23-
Placeholder = 13,
24-
EVM = 14,
25-
EAM = 15,
26-
EthAccount = 16,
27-
}
28-
29-
impl Type {
30-
pub fn name(&self) -> &'static str {
31-
match *self {
32-
Type::System => "system",
33-
Type::Init => "init",
34-
Type::Cron => "cron",
35-
Type::Account => "account",
36-
Type::Power => "storagepower",
37-
Type::Miner => "storageminer",
38-
Type::Market => "storagemarket",
39-
Type::PaymentChannel => "paymentchannel",
40-
Type::Multisig => "multisig",
41-
Type::Reward => "reward",
42-
Type::VerifiedRegistry => "verifiedregistry",
43-
Type::DataCap => "datacap",
44-
Type::Placeholder => "placeholder",
45-
Type::EVM => "evm",
46-
Type::EAM => "eam",
47-
Type::EthAccount => "ethaccount",
48-
}
49-
}
50-
}
1+
pub use vm_api::builtin::Type;

runtime/src/runtime/mod.rs

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ use fvm_ipld_encoding::CborStore;
77
use fvm_shared::address::Address;
88
use fvm_shared::clock::ChainEpoch;
99
use fvm_shared::consensus::ConsensusFault;
10-
use fvm_shared::crypto::hash::SupportedHashes;
11-
use fvm_shared::crypto::signature::{
12-
Signature, SECP_PUB_LEN, SECP_SIG_LEN, SECP_SIG_MESSAGE_HASH_SIZE,
13-
};
1410
use fvm_shared::econ::TokenAmount;
15-
use fvm_shared::piece::PieceInfo;
1611
use fvm_shared::randomness::RANDOMNESS_LENGTH;
1712
use fvm_shared::sector::{
18-
AggregateSealVerifyProofAndInfos, RegisteredSealProof, ReplicaUpdateInfo, SealVerifyInfo,
19-
WindowPoStVerifyInfo,
13+
AggregateSealVerifyProofAndInfos, ReplicaUpdateInfo, SealVerifyInfo, WindowPoStVerifyInfo,
2014
};
2115
use fvm_shared::version::NetworkVersion;
2216
use fvm_shared::{ActorID, MethodNum, Response};
@@ -49,6 +43,7 @@ use fvm_ipld_encoding::ipld_block::IpldBlock;
4943
use fvm_shared::chainid::ChainID;
5044
use fvm_shared::event::ActorEvent;
5145
use fvm_shared::sys::SendFlags;
46+
pub use vm_api::Primitives;
5247

5348
/// Runtime is the VM's internal runtime object.
5449
/// this is everything that is accessible to actors, beyond parameters.
@@ -280,39 +275,6 @@ pub trait MessageInfo {
280275
fn gas_premium(&self) -> TokenAmount;
281276
}
282277

283-
/// Pure functions implemented as primitives by the runtime.
284-
pub trait Primitives {
285-
/// Hashes input data using blake2b with 256 bit output.
286-
fn hash_blake2b(&self, data: &[u8]) -> [u8; 32];
287-
288-
/// Hashes input data using a supported hash function.
289-
fn hash(&self, hasher: SupportedHashes, data: &[u8]) -> Vec<u8>;
290-
291-
/// Hashes input into a 64 byte buffer
292-
fn hash_64(&self, hasher: SupportedHashes, data: &[u8]) -> ([u8; 64], usize);
293-
294-
/// Computes an unsealed sector CID (CommD) from its constituent piece CIDs (CommPs) and sizes.
295-
fn compute_unsealed_sector_cid(
296-
&self,
297-
proof_type: RegisteredSealProof,
298-
pieces: &[PieceInfo],
299-
) -> Result<Cid, anyhow::Error>;
300-
301-
/// Verifies that a signature is valid for an address and plaintext.
302-
fn verify_signature(
303-
&self,
304-
signature: &Signature,
305-
signer: &Address,
306-
plaintext: &[u8],
307-
) -> Result<(), anyhow::Error>;
308-
309-
fn recover_secp_public_key(
310-
&self,
311-
hash: &[u8; SECP_SIG_MESSAGE_HASH_SIZE],
312-
signature: &[u8; SECP_SIG_LEN],
313-
) -> Result<[u8; SECP_PUB_LEN], anyhow::Error>;
314-
}
315-
316278
/// filcrypto verification primitives provided by the runtime
317279
pub trait Verifier {
318280
/// Verifies a sector seal proof.

test_vm/src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use serde::ser;
3939
use std::cell::{RefCell, RefMut};
4040
use std::collections::{BTreeMap, HashMap};
4141
use vm_api::trace::InvocationTrace;
42-
use vm_api::{actor, ActorState, MessageResult, VMError, VM};
42+
use vm_api::{new_actor, ActorState, MessageResult, VMError, VM};
4343

4444
use vm_api::util::{get_state, serialize_ok};
4545

@@ -95,22 +95,25 @@ where
9595
let sys_st = SystemState::new(store).unwrap();
9696
let sys_head = v.put_store(&sys_st);
9797
let sys_value = faucet_total.clone(); // delegate faucet funds to system so we can construct faucet by sending to bls addr
98-
v.set_actor(&SYSTEM_ACTOR_ADDR, actor(*SYSTEM_ACTOR_CODE_ID, sys_head, 0, sys_value, None));
98+
v.set_actor(
99+
&SYSTEM_ACTOR_ADDR,
100+
new_actor(*SYSTEM_ACTOR_CODE_ID, sys_head, 0, sys_value, None),
101+
);
99102

100103
// init
101104
let init_st = InitState::new(store, "integration-test".to_string()).unwrap();
102105
let init_head = v.put_store(&init_st);
103106
v.set_actor(
104107
&INIT_ACTOR_ADDR,
105-
actor(*INIT_ACTOR_CODE_ID, init_head, 0, TokenAmount::zero(), None),
108+
new_actor(*INIT_ACTOR_CODE_ID, init_head, 0, TokenAmount::zero(), None),
106109
);
107110

108111
// reward
109112

110113
let reward_head = v.put_store(&RewardState::new(StoragePower::zero()));
111114
v.set_actor(
112115
&REWARD_ACTOR_ADDR,
113-
actor(*REWARD_ACTOR_CODE_ID, reward_head, 0, reward_total, None),
116+
new_actor(*REWARD_ACTOR_CODE_ID, reward_head, 0, reward_total, None),
114117
);
115118

116119
// cron
@@ -127,21 +130,21 @@ where
127130
let cron_head = v.put_store(&CronState { entries: builtin_entries });
128131
v.set_actor(
129132
&CRON_ACTOR_ADDR,
130-
actor(*CRON_ACTOR_CODE_ID, cron_head, 0, TokenAmount::zero(), None),
133+
new_actor(*CRON_ACTOR_CODE_ID, cron_head, 0, TokenAmount::zero(), None),
131134
);
132135

133136
// power
134137
let power_head = v.put_store(&PowerState::new(&v.store).unwrap());
135138
v.set_actor(
136139
&STORAGE_POWER_ACTOR_ADDR,
137-
actor(*POWER_ACTOR_CODE_ID, power_head, 0, TokenAmount::zero(), None),
140+
new_actor(*POWER_ACTOR_CODE_ID, power_head, 0, TokenAmount::zero(), None),
138141
);
139142

140143
// market
141144
let market_head = v.put_store(&MarketState::new(&v.store).unwrap());
142145
v.set_actor(
143146
&STORAGE_MARKET_ACTOR_ADDR,
144-
actor(*MARKET_ACTOR_CODE_ID, market_head, 0, TokenAmount::zero(), None),
147+
new_actor(*MARKET_ACTOR_CODE_ID, market_head, 0, TokenAmount::zero(), None),
145148
);
146149

147150
// verifreg
@@ -190,28 +193,28 @@ where
190193
let verifreg_head = v.put_store(&VerifRegState::new(&v.store, root_msig_addr).unwrap());
191194
v.set_actor(
192195
&VERIFIED_REGISTRY_ACTOR_ADDR,
193-
actor(*VERIFREG_ACTOR_CODE_ID, verifreg_head, 0, TokenAmount::zero(), None),
196+
new_actor(*VERIFREG_ACTOR_CODE_ID, verifreg_head, 0, TokenAmount::zero(), None),
194197
);
195198

196199
// Ethereum Address Manager
197200
v.set_actor(
198201
&EAM_ACTOR_ADDR,
199-
actor(*EAM_ACTOR_CODE_ID, EMPTY_ARR_CID, 0, TokenAmount::zero(), None),
202+
new_actor(*EAM_ACTOR_CODE_ID, EMPTY_ARR_CID, 0, TokenAmount::zero(), None),
200203
);
201204

202205
// datacap
203206
let datacap_head =
204207
v.put_store(&DataCapState::new(&v.store, VERIFIED_REGISTRY_ACTOR_ADDR).unwrap());
205208
v.set_actor(
206209
&DATACAP_TOKEN_ACTOR_ADDR,
207-
actor(*DATACAP_TOKEN_ACTOR_CODE_ID, datacap_head, 0, TokenAmount::zero(), None),
210+
new_actor(*DATACAP_TOKEN_ACTOR_CODE_ID, datacap_head, 0, TokenAmount::zero(), None),
208211
);
209212

210213
// burnt funds
211214
let burnt_funds_head = v.put_store(&AccountState { address: BURNT_FUNDS_ACTOR_ADDR });
212215
v.set_actor(
213216
&BURNT_FUNDS_ACTOR_ADDR,
214-
actor(*ACCOUNT_ACTOR_CODE_ID, burnt_funds_head, 0, TokenAmount::zero(), None),
217+
new_actor(*ACCOUNT_ACTOR_CODE_ID, burnt_funds_head, 0, TokenAmount::zero(), None),
215218
);
216219

217220
// create a faucet with 1 billion FIL for setting up test accounts
@@ -294,8 +297,8 @@ where
294297
) -> Result<MessageResult, VMError> {
295298
let from_id = &self.resolve_id_address(from).unwrap();
296299
let mut a = self.actor(from_id).unwrap();
297-
let call_seq = a.call_seq;
298-
a.call_seq = call_seq + 1;
300+
let call_seq = a.sequence;
301+
a.sequence = call_seq + 1;
299302
// EthAccount abstractions turns Placeholders into EthAccounts
300303
if a.code == *PLACEHOLDER_ACTOR_CODE_ID {
301304
a.code = *ETHACCOUNT_ACTOR_CODE_ID;

test_vm/src/messaging.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ use serde::Serialize;
6161
use std::cell::{RefCell, RefMut};
6262
use vm_api::trace::InvocationTrace;
6363
use vm_api::util::get_state;
64-
use vm_api::{actor, ActorState, VM};
64+
use vm_api::{new_actor, ActorState, VM};
6565

6666
use std::ops::Add;
6767

@@ -334,7 +334,7 @@ where
334334
act.code = code_id;
335335
act
336336
}
337-
None => actor(code_id, EMPTY_ARR_CID, 0, TokenAmount::zero(), predictable_address),
337+
None => new_actor(code_id, EMPTY_ARR_CID, 0, TokenAmount::zero(), predictable_address),
338338
_ => {
339339
return Err(actor_error!(forbidden;
340340
"attempt to create new actor at existing address {}", addr));
@@ -489,7 +489,7 @@ where
489489
}
490490

491491
fn lookup_delegated_address(&self, id: ActorID) -> Option<Address> {
492-
self.v.actor(&Address::new_id(id)).and_then(|act| act.predictable_address)
492+
self.v.actor(&Address::new_id(id)).and_then(|act| act.delegated_address)
493493
}
494494

495495
fn send(

test_vm/tests/test_vm_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use fvm_shared::METHOD_SEND;
1212
use num_traits::Zero;
1313
use test_vm::{TestVM, FIRST_TEST_USER_ADDR, TEST_FAUCET_ADDR};
1414
use vm_api::util::{get_state, pk_addrs_from};
15-
use vm_api::{actor, VM};
15+
use vm_api::{new_actor, VM};
1616

1717
#[test]
1818
fn state_control() {
@@ -22,7 +22,7 @@ fn state_control() {
2222
let addr2 = Address::new_id(2222);
2323

2424
// set actor
25-
let a1 = actor(
25+
let a1 = new_actor(
2626
*ACCOUNT_ACTOR_CODE_ID,
2727
make_identity_cid(b"a1-head"),
2828
42,
@@ -34,7 +34,7 @@ fn state_control() {
3434
assert_eq!(out, a1);
3535
let check = v.checkpoint();
3636

37-
let a2 = actor(
37+
let a2 = new_actor(
3838
*PAYCH_ACTOR_CODE_ID,
3939
make_identity_cid(b"a2-head"),
4040
88,
@@ -64,7 +64,7 @@ fn assert_account_actor<BS: Blockstore>(
6464
) {
6565
let act = v.actor(&addr).unwrap();
6666
let st: AccountState = get_state(v, &addr).unwrap();
67-
assert_eq!(exp_call_seq, act.call_seq);
67+
assert_eq!(exp_call_seq, act.sequence);
6868
assert_eq!(*ACCOUNT_ACTOR_CODE_ID, act.code);
6969
assert_eq!(exp_bal, act.balance);
7070
assert_eq!(exp_pk_addr, st.address);

vm_api/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ publish = false
1111
[lib]
1212

1313
[dependencies]
14-
fil_actors_runtime = { workspace = true, features = [ "test_utils" ] }
15-
1614
anyhow = { workspace = true }
1715
cid = { workspace = true }
1816
fvm_ipld_blockstore = { workspace = true }
1917
fvm_ipld_encoding = { workspace = true }
2018
fvm_ipld_hamt = { workspace = true }
2119
fvm_shared = { workspace = true }
20+
num-derive = { workspace = true }
21+
num-traits = { workspace = true }
2222
rand = { workspace = true }
2323
rand_chacha = { workspace = true }
2424
serde = { workspace = true }
2525

26+
[features]
27+
testing = []
28+

0 commit comments

Comments
 (0)