Skip to content

Commit 9a13081

Browse files
authored
feat: use Type from builtin-actors when building the bundle (#583)
This change upgrades to the v4 bundler that _does not_ depend on the FVM to map actor types to IDs. Instead, it relies on the Type enum defined in this repo. This means new actor types can be added here without having to make changes in multiple places.
1 parent 387e51c commit 9a13081

File tree

4 files changed

+50
-20
lines changed

4 files changed

+50
-20
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ fil_actor_system = { version = "9.0.0-alpha.1", path = "./actors/system", featur
2626
fil_actor_init = { version = "9.0.0-alpha.1", path = "./actors/init", features = ["fil-actor"] }
2727

2828
[build-dependencies]
29-
fil_actor_bundler = "3.0.4"
29+
fil_actor_bundler = "4.0.0"
3030
cid = { version = "0.8.3", default-features = false, features = ["serde-codec"] }
31+
fil_actors_runtime = { version = "9.0.0-alpha.1", path = "runtime" }
32+
num-traits = "0.2.15"
3133

3234
[dependencies]
33-
clap = { version = "3.1.8", features = ["derive"] }
35+
clap = { version = "3.2.3", features = ["derive"] }
3436

3537
[features]
3638
default = [] ## translates to mainnet

build.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use fil_actor_bundler::Bundler;
2+
use fil_actors_runtime::runtime::builtins::Type;
3+
use num_traits::cast::FromPrimitive;
24
use std::error::Error;
35
use std::io::{BufRead, BufReader};
46
use std::path::Path;
@@ -16,11 +18,11 @@ const ACTORS: &[(&Package, &ID)] = &[
1618
("init", "init"),
1719
("cron", "cron"),
1820
("account", "account"),
19-
("multisig", "multisig"),
2021
("power", "storagepower"),
2122
("miner", "storageminer"),
2223
("market", "storagemarket"),
2324
("paych", "paymentchannel"),
25+
("multisig", "multisig"),
2426
("reward", "reward"),
2527
("verifreg", "verifiedregistry"),
2628
];
@@ -158,7 +160,12 @@ fn main() -> Result<(), Box<dyn Error>> {
158160

159161
let dst = Path::new(&out_dir).join("bundle.car");
160162
let mut bundler = Bundler::new(&dst);
161-
for (pkg, id) in ACTORS {
163+
for (&(pkg, name), id) in ACTORS.iter().zip(1u32..) {
164+
assert_eq!(
165+
name,
166+
Type::from_u32(id).expect("type not defined").name(),
167+
"actor types don't match actors included in the bundle"
168+
);
162169
let bytecode_path = Path::new(&out_dir)
163170
.join("wasm32-unknown-unknown/wasm")
164171
.join(format!("fil_actor_{}.wasm", pkg));
@@ -167,10 +174,12 @@ fn main() -> Result<(), Box<dyn Error>> {
167174
// content-addressed CIDs.
168175
let forced_cid = None;
169176

170-
let cid = bundler.add_from_file(id, forced_cid, &bytecode_path).unwrap_or_else(|err| {
171-
panic!("failed to add file {:?} to bundle for actor {}: {}", bytecode_path, id, err)
172-
});
173-
println!("cargo:warning=added actor {} to bundle with CID {}", id, cid);
177+
let cid = bundler
178+
.add_from_file(id, name.to_owned(), forced_cid, &bytecode_path)
179+
.unwrap_or_else(|err| {
180+
panic!("failed to add file {:?} to bundle for actor {}: {}", bytecode_path, id, err)
181+
});
182+
println!("cargo:warning=added {} ({}) to bundle with CID {}", name, id, cid);
174183
}
175184
bundler.finish().expect("failed to finish bundle");
176185

runtime/src/runtime/builtins.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,21 @@ pub enum Type {
2020
Reward = 10,
2121
VerifiedRegistry = 11,
2222
}
23+
24+
impl Type {
25+
pub fn name(&self) -> &'static str {
26+
match *self {
27+
Type::System => "system",
28+
Type::Init => "init",
29+
Type::Cron => "cron",
30+
Type::Account => "account",
31+
Type::Power => "storagepower",
32+
Type::Miner => "storageminer",
33+
Type::Market => "storagemarket",
34+
Type::PaymentChannel => "paymentchannel",
35+
Type::Multisig => "multisig",
36+
Type::Reward => "reward",
37+
Type::VerifiedRegistry => "verifiedregistry",
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)