Skip to content

Commit be69f54

Browse files
authored
feat: add an embryo actor (#667)
The embryo actor: - Has no constructor (the system is expected to simply "set" the embryo code CID, not construct it). - Immediately aborts when called with a non-zero method. We could, alternatively, use some well-known "id" address. But it's nice to make this actual valid wasm.
1 parent 0a4dfe1 commit be69f54

File tree

9 files changed

+52
-1
lines changed

9 files changed

+52
-1
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ fil_actor_miner = { version = "10.0.0-alpha.1", path = "./actors/miner", feature
2424
fil_actor_reward = { version = "10.0.0-alpha.1", path = "./actors/reward", features = ["fil-actor"] }
2525
fil_actor_system = { version = "10.0.0-alpha.1", path = "./actors/system", features = ["fil-actor"] }
2626
fil_actor_init = { version = "10.0.0-alpha.1", path = "./actors/init", features = ["fil-actor"] }
27+
fil_actor_embryo = { version = "10.0.0-alpha.1", path = "./actors/embryo", features = ["fil-actor"] }
2728
fil_actor_evm = { version = "10.0.0-alpha.1", path = "./actors/evm", features = ["fil-actor"] }
2829

2930
[build-dependencies]

actors/embryo/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "fil_actor_embryo"
3+
description = "Builtin embryo actor for Filecoin"
4+
version = "10.0.0-alpha.1"
5+
license = "MIT OR Apache-2.0"
6+
authors = ["Protocol Labs", "Filecoin Core Devs"]
7+
edition = "2021"
8+
keywords = ["filecoin", "web3", "wasm"]
9+
10+
[lib]
11+
## lib is necessary for integration tests
12+
## cdylib is necessary for Wasm build
13+
crate-type = ["cdylib", "lib"]
14+
15+
[dependencies]
16+
fvm_sdk = { version = "3.0.0-alpha.2", optional = true }
17+
fvm_shared = { version = "3.0.0-alpha.1", optional = true }
18+
19+
[features]
20+
fil-actor = ["fvm_sdk", "fvm_shared"]

actors/embryo/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[cfg(feature = "fil-actor")]
2+
#[no_mangle]
3+
pub extern "C" fn invoke(_: u32) -> u32 {
4+
fvm_sdk::vm::abort(
5+
fvm_shared::error::ExitCode::USR_UNHANDLED_MESSAGE.value(),
6+
Some("embryo actors may only receive messages on method 0"),
7+
)
8+
}

build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ACTORS: &[(&Package, &ID)] = &[
2525
("multisig", "multisig"),
2626
("reward", "reward"),
2727
("verifreg", "verifiedregistry"),
28+
("embryo", "embryo"),
2829
("evm", "evm"),
2930
];
3031

runtime/src/runtime/builtins.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub enum Type {
1919
Multisig = 9,
2020
Reward = 10,
2121
VerifiedRegistry = 11,
22-
EVM = 12,
22+
Embryo = 12,
23+
EVM = 13,
2324
}
2425

2526
impl Type {
@@ -36,6 +37,7 @@ impl Type {
3637
Type::Multisig => "multisig",
3738
Type::Reward => "reward",
3839
Type::VerifiedRegistry => "verifiedregistry",
40+
Type::Embryo => "embryo",
3941
Type::EVM => "evm",
4042
}
4143
}

runtime/src/test_utils.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ lazy_static::lazy_static! {
5757
pub static ref MULTISIG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/test/multisig");
5858
pub static ref REWARD_ACTOR_CODE_ID: Cid = make_builtin(b"fil/test/reward");
5959
pub static ref VERIFREG_ACTOR_CODE_ID: Cid = make_builtin(b"fil/test/verifiedregistry");
60+
pub static ref EMBRYO_ACTOR_CODE_ID: Cid = make_builtin(b"fil/test/embryo");
6061
pub static ref EVM_ACTOR_CODE_ID: Cid = make_builtin(b"fil/test/evm");
6162
pub static ref ACTOR_TYPES: BTreeMap<Cid, Type> = {
6263
let mut map = BTreeMap::new();
@@ -71,6 +72,7 @@ lazy_static::lazy_static! {
7172
map.insert(*MULTISIG_ACTOR_CODE_ID, Type::Multisig);
7273
map.insert(*REWARD_ACTOR_CODE_ID, Type::Reward);
7374
map.insert(*VERIFREG_ACTOR_CODE_ID, Type::VerifiedRegistry);
75+
map.insert(*EMBRYO_ACTOR_CODE_ID, Type::EVM);
7476
map.insert(*EVM_ACTOR_CODE_ID, Type::EVM);
7577
map
7678
};
@@ -86,6 +88,8 @@ lazy_static::lazy_static! {
8688
(Type::Multisig, *MULTISIG_ACTOR_CODE_ID),
8789
(Type::Reward, *REWARD_ACTOR_CODE_ID),
8890
(Type::VerifiedRegistry, *VERIFREG_ACTOR_CODE_ID),
91+
(Type::Embryo, *EMBRYO_ACTOR_CODE_ID),
92+
(Type::EVM, *EVM_ACTOR_CODE_ID),
8993
]
9094
.into_iter()
9195
.collect();
@@ -95,6 +99,8 @@ lazy_static::lazy_static! {
9599
map.insert(*PAYCH_ACTOR_CODE_ID, ());
96100
map.insert(*MULTISIG_ACTOR_CODE_ID, ());
97101
map.insert(*MINER_ACTOR_CODE_ID, ());
102+
map.insert(*EMBRYO_ACTOR_CODE_ID, ());
103+
map.insert(*EVM_ACTOR_CODE_ID, ());
98104
map
99105
};
100106
}

state/src/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub fn check_state_invariants<'a, BS: Blockstore + Debug>(
204204
acc.with_prefix("verifreg: ").add_all(&msgs);
205205
verifreg_summary = Some(summary);
206206
}
207+
Some(Type::Embryo) => {}
207208
Some(Type::EVM) => {}
208209
None => {
209210
bail!("unexpected actor code CID {} for address {}", actor.code, key);

test_vm/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ impl<'invocation, 'bs> InvocationCtx<'invocation, 'bs> {
661661
Type::Power => PowerActor::invoke_method(self, self.msg.method, &params),
662662
Type::PaymentChannel => PaychActor::invoke_method(self, self.msg.method, &params),
663663
Type::VerifiedRegistry => VerifregActor::invoke_method(self, self.msg.method, &params),
664+
Type::Embryo => {
665+
Err(ActorError::unhandled_message("embryo actors only handle method 0".into()))
666+
}
664667
Type::EVM => EvmContractActor::invoke_method(self, self.msg.method, &params),
665668
};
666669
if res.is_err() {

0 commit comments

Comments
 (0)