-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement get_tipset_cid #568
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7e18528
Add chain metadata actor
fridrik01 4706bb0
Add actor manifest
fridrik01 b85337f
Add actor_bundle option and load manifest at genesis
fridrik01 6321d05
Load actors_bundle at genesis
fridrik01 65261ac
Create chainmetadata actor at genesis
fridrik01 a00a836
Integrate chainmetadata actor in begin callback + use amt
fridrik01 84397e8
Fix CI + improve error handling in actor
fridrik01 353fa2a
Implement the get_tipset_cid
fridrik01 c6bda6a
Store raw blockhash digest in state
fridrik01 f633d38
Rename actors_bundle to custom_actors_bundle
fridrik01 8b115b4
Refactor duplicate code
fridrik01 1c9d5c6
Do not compile chainmetadata actor unless fil-actor feature is set
fridrik01 c49b867
Address review comments
fridrik01 28d32bb
Refactor the parsing of bundle for the manifest
fridrik01 1b60227
Update chainmetadata actor not convert blockhash into cid
fridrik01 63cde01
sol commit, please undo
fridrik01 ee3e823
wrap blockhash
fridrik01 2386c7d
fix rebase
fridrik01 02461cf
Fix wasm build errors after rebase due to transitive dependencies
fridrik01 1851ac5
Comment why we wrap the blockhash in get_tipset_cid
fridrik01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[package] | ||
name = "fendermint_actors" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
fendermint_actor_chainmetadata = { path = "chainmetadata", features = [ | ||
"fil-actor", | ||
] } | ||
|
||
[dependencies] | ||
cid = { workspace = true } | ||
anyhow = { workspace = true } | ||
fvm_ipld_blockstore = { workspace = true } | ||
fvm_ipld_encoding = { workspace = true } | ||
fendermint_actor_chainmetadata = { path = "chainmetadata" } | ||
|
||
[build-dependencies] | ||
fil_actors_runtime = { workspace = true, features = ["test_utils"] } | ||
fil_actor_bundler = "6.1.0" | ||
num-traits = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2022-2024 Protocol Labs | ||
// SPDX-License-Identifier: Apache-2.0, MIT | ||
|
||
use fil_actor_bundler::Bundler; | ||
use std::error::Error; | ||
use std::io::{BufRead, BufReader}; | ||
use std::path::Path; | ||
use std::process::{Command, Stdio}; | ||
use std::thread; | ||
|
||
const ACTORS: &[&str] = &["chainmetadata"]; | ||
|
||
const FILES_TO_WATCH: &[&str] = &["Cargo.toml", "src", "actors"]; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
// Cargo executable location. | ||
let cargo = std::env::var_os("CARGO").expect("no CARGO env var"); | ||
|
||
let out_dir = std::env::var_os("OUT_DIR") | ||
.as_ref() | ||
.map(Path::new) | ||
.map(|p| p.join("bundle")) | ||
.expect("no OUT_DIR env var"); | ||
println!("cargo:warning=out_dir: {:?}", &out_dir); | ||
|
||
let manifest_path = | ||
Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR unset")) | ||
.join("Cargo.toml"); | ||
|
||
for file in FILES_TO_WATCH { | ||
println!("cargo:rerun-if-changed={}", file); | ||
} | ||
|
||
// Cargo build command for all test_actors at once. | ||
let mut cmd = Command::new(cargo); | ||
cmd.arg("build") | ||
.args( | ||
ACTORS | ||
.iter() | ||
.map(|pkg| "-p=fendermint_actor_".to_owned() + pkg), | ||
) | ||
.arg("--target=wasm32-unknown-unknown") | ||
.arg("--profile=wasm") | ||
.arg("--features=fil-actor") | ||
.arg(format!("--manifest-path={}", manifest_path.display())) | ||
.stdout(Stdio::piped()) | ||
.stderr(Stdio::piped()) | ||
// We are supposed to only generate artifacts under OUT_DIR, | ||
// so set OUT_DIR as the target directory for this build. | ||
.env("CARGO_TARGET_DIR", &out_dir) | ||
// As we are being called inside a build-script, this env variable is set. However, we set | ||
// our own `RUSTFLAGS` and thus, we need to remove this. Otherwise cargo favors this | ||
// env variable. | ||
.env_remove("CARGO_ENCODED_RUSTFLAGS"); | ||
|
||
// Print out the command line we're about to run. | ||
println!("cargo:warning=cmd={:?}", &cmd); | ||
|
||
// Launch the command. | ||
let mut child = cmd.spawn().expect("failed to launch cargo build"); | ||
|
||
// Pipe the output as cargo warnings. Unfortunately this is the only way to | ||
// get cargo build to print the output. | ||
let stdout = child.stdout.take().expect("no stdout"); | ||
let stderr = child.stderr.take().expect("no stderr"); | ||
let j1 = thread::spawn(move || { | ||
for line in BufReader::new(stderr).lines() { | ||
println!("cargo:warning={:?}", line.unwrap()); | ||
} | ||
}); | ||
let j2 = thread::spawn(move || { | ||
for line in BufReader::new(stdout).lines() { | ||
println!("cargo:warning={:?}", line.unwrap()); | ||
} | ||
}); | ||
|
||
j1.join().unwrap(); | ||
j2.join().unwrap(); | ||
|
||
let result = child.wait().expect("failed to wait for build to finish"); | ||
if !result.success() { | ||
return Err("actor build failed".into()); | ||
} | ||
|
||
// make sure the output dir exists | ||
std::fs::create_dir_all("output") | ||
.expect("failed to create output dir for the custom_actors_bundle.car file"); | ||
|
||
let dst = Path::new("output/custom_actors_bundle.car"); | ||
let mut bundler = Bundler::new(dst); | ||
for (&pkg, id) in ACTORS.iter().zip(1u32..) { | ||
let bytecode_path = Path::new(&out_dir) | ||
.join("wasm32-unknown-unknown/wasm") | ||
.join(format!("fendermint_actor_{}.wasm", pkg)); | ||
|
||
// This actor version doesn't force synthetic CIDs; it uses genuine | ||
// content-addressed CIDs. | ||
let forced_cid = None; | ||
|
||
let cid = bundler | ||
.add_from_file(id, pkg.to_owned(), forced_cid, &bytecode_path) | ||
.unwrap_or_else(|err| { | ||
panic!( | ||
"failed to add file {:?} to bundle for actor {}: {}", | ||
bytecode_path, id, err | ||
) | ||
}); | ||
println!( | ||
"cargo:warning=added {} ({}) to bundle with CID {}", | ||
pkg, id, cid | ||
); | ||
} | ||
bundler.finish().expect("failed to finish bundle"); | ||
|
||
println!("cargo:warning=bundle={}", dst.display()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "fendermint_actor_chainmetadata" | ||
description = "Actor for storing chain metadata" | ||
license.workspace = true | ||
edition.workspace = true | ||
authors.workspace = true | ||
version = "0.1.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib", "lib"] | ||
|
||
[dependencies] | ||
cid = { workspace = true, default-features = false } | ||
fil_actors_runtime = { workspace = true, optional = true, features = [ | ||
"fil-actor", | ||
] } | ||
fvm_shared = { workspace = true } | ||
fvm_ipld_encoding = { workspace = true } | ||
fvm_ipld_blockstore = { workspace = true } | ||
fvm_ipld_amt = { workspace = true } | ||
num-derive = { workspace = true } | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_tuple = { workspace = true } | ||
num-traits = { workspace = true } | ||
frc42_dispatch = { workspace = true } | ||
anyhow = { workspace = true } | ||
|
||
[features] | ||
default = [] | ||
fil-actor = ["fil_actors_runtime"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, that I needed to fork this repo to update it to FVM 4.1. I have a PR for merging this into the official repo (filecoin-project/actors-utils#231)