Skip to content
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 20 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
542 changes: 445 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ members = [
"fendermint/testing",
"fendermint/testing/*-test",
"fendermint/vm/*",
"fendermint/actors",
"fendermint/actors/chainmetadata",
]

[workspace.package]
Expand Down Expand Up @@ -153,8 +155,12 @@ ipc_actors_abis = { path = "contracts/binding" }
# Vendored for cross-compilation, see https://github.com/cross-rs/cross/wiki/Recipes#openssl
openssl = { version = "0.10", features = ["vendored"] }

fvm = { version = "4.1.0", default-features = false } # no opencl feature or it fails on CI
fvm_shared = { version = "4.1.0", features = ["crypto"] }
# NOTE: When upgrading the FVM it may cause our fendermint/actors/build.rs to fail as it can
# pull in crates as transitive dependencies that do not support Wasm architector. If this
# happens, try removing "crypto" feature from fvm_shared dependency in contracts/binding/Cargo.toml
# and run `cargo build`. Then add the "crypto" feature back and run `cargo build` again.
fvm = { version = "4.1.0", default-features = false } # no opencl feature or it fails on CI
fvm_shared = { version = "4.1.0" }
fvm_sdk = { version = "4.1.0" }

fvm_ipld_blockstore = "0.2.0"
Expand All @@ -169,7 +175,7 @@ fvm_ipld_amt = "0.6.2"
# fvm_ipld_encoding = { path = "../ref-fvm/ipld/encoding" }
# fvm_ipld_car = { path = "../ref-fvm/ipld/car" }
# fvm_ipld_hamt = { path = "../ref-fvm/ipld/hamt" }
# fvm_shared = { path = "../ref-fvm/shared", features = ["crypto"] }
# fvm_shared = { path = "../ref-fvm/shared" }

# We are using the bundle for the builtin-actors dependency, and repeating DTO classes on our side,
# to cut down the time it takes to compile everything. However, some projects have a "shared" part,
Expand All @@ -186,9 +192,8 @@ cid = { version = "0.10.1", default-features = false, features = [
"std",
] }

# Depending on the release cycle, this dependency might want an earlier version of the FVM.
# We can work around it by hardcoding the method hashes; currently there is only one.
# frc42_dispatch = "3.2"
# We need a version of frc42_dispatch that has been updated to use FVM 4.1
frc42_dispatch = { git = "https://github.com/fridrik01/filecoin.git", branch = "update-fvm-4.1" }
Copy link
Contributor Author

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)


# Using the same tendermint-rs dependency as tower-abci. From both we are interested in v037 modules.
tower-abci = { version = "0.7" }
Expand All @@ -206,3 +211,13 @@ tendermint-proto = { version = "0.31" }
gcra = { git = "https://github.com/consensus-shipyard/gcra-rs.git", branch = "main" }
# Contains some API changes that the upstream has not merged.
merkle-tree-rs = { git = "https://github.com/consensus-shipyard/merkle-tree-rs.git", branch = "dev" }

[profile.wasm]
inherits = "release"
panic = "abort"
overflow-checks = false
lto = true
opt-level = "z"
strip = true
codegen-units = 1
incremental = false
1 change: 1 addition & 0 deletions docs/fendermint/demos/milestone-1/fendermint-demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ rm -rf ~/.fendermint/data
mkdir -p ~/.fendermint/data
cp -r ./fendermint/app/config ~/.fendermint/config
cp ./builtin-actors/output/bundle.car ~/.fendermint/bundle.car
cp ./actors/output/custom_actors_bundle.car ~/.fendermint/custom_actors_bundle.car

#17
fendermint run
Expand Down
1 change: 1 addition & 0 deletions docs/fendermint/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ configuration will look for it at `~/.fendermint/bundle.car`, so we might as wel
```shell
make actor-bundle
fridrik01 marked this conversation as resolved.
Show resolved Hide resolved
cp ./builtin-actors/output/bundle.car ~/.fendermint/bundle.car
cp ./actors/output/custom_actors_bundle.car ~/.fendermint/custom_actors_bundle.car
```

Now, start the application.
Expand Down
12 changes: 10 additions & 2 deletions fendermint/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

BUILTIN_ACTORS_TAG ?= v12.0.0
BUILTIN_ACTORS_BUNDLE := $(PWD)/builtin-actors/output/bundle.car
CUSTOM_ACTORS_BUNDLE := $(PWD)/actors/output/custom_actors_bundle.car

IPC_ACTORS_DIR := $(PWD)/../contracts
IPC_ACTORS_OUT := $(IPC_ACTORS_DIR)/out
Expand Down Expand Up @@ -39,6 +40,7 @@ install: $(IPC_ACTORS_GEN)
# Using --release for testing because wasm can otherwise be slow.
test: $(BUILTIN_ACTORS_BUNDLE) $(IPC_ACTORS_GEN)
FM_BUILTIN_ACTORS_BUNDLE=$(BUILTIN_ACTORS_BUNDLE) \
FM_CUSTOM_ACTORS_BUNDLE=$(CUSTOM_ACTORS_BUNDLE) \
FM_CONTRACTS_DIR=$(IPC_ACTORS_OUT) \
cargo test --release $(PACKAGE)

Expand All @@ -50,6 +52,7 @@ e2e: docker-build | cargo-make
clean:
cargo clean
rm $(BUILTIN_ACTORS_BUNDLE)
rm $(CUSTOM_ACTORS_BUNDLE)

lint: \
check-fmt \
Expand All @@ -64,11 +67,12 @@ check-clippy: $(IPC_ACTORS_GEN)
@# We could have a separate top level job that does `fmt` and `clippy` check on the whole project.
cargo clippy $(PACKAGE) --no-deps --tests -- -D clippy::all

docker-deps: $(BUILTIN_ACTORS_BUNDLE) $(IPC_ACTORS_GEN)
docker-deps: $(BUILTIN_ACTORS_BUNDLE) $(CUSTOM_ACTORS_BUNDLE) $(IPC_ACTORS_GEN)
rm -rf docker/.artifacts
mkdir -p docker/.artifacts/contracts
cp -r $(IPC_ACTORS_OUT)/* docker/.artifacts/contracts
cp $(BUILTIN_ACTORS_BUNDLE) docker/.artifacts
cp $(CUSTOM_ACTORS_BUNDLE) docker/.artifacts

# To use `buildx` locally to produce multiplatform images, one needs to run `docker buildx create --use`.
# After that it looks like even the regular docker build needs the `--load` parameter, which hopefully
Expand All @@ -94,7 +98,7 @@ docker-build: docker-deps $(FENDERMINT_CODE)
# Build a bundle CAR; this is so we don't have to have a project reference,
# which means we are not tied to the release cycle of both FVM _and_ actors;
# so long as they work together.
actor-bundle: $(BUILTIN_ACTORS_BUNDLE)
actor-bundle: $(BUILTIN_ACTORS_BUNDLE) $(CUSTOM_ACTORS_BUNDLE)

compile-abi: $(IPC_ACTORS_GEN)

Expand All @@ -103,6 +107,10 @@ $(BUILTIN_ACTORS_BUNDLE):
mkdir -p $(dir $@)
curl -L -o $@ https://github.com/filecoin-project/builtin-actors/releases/download/$(BUILTIN_ACTORS_TAG)/builtin-actors-mainnet.car

# Build a bundle CAR for the custom actors in this repo.
$(CUSTOM_ACTORS_BUNDLE):
cargo build --release -p fendermint_actors

# Regenerate the ABI artifacts if we don't have them already, or they changed.
$(IPC_ACTORS_GEN): $(IPC_ACTORS_CODE)
cd $(IPC_ACTORS_DIR) && make compile-abi
Expand Down
1 change: 1 addition & 0 deletions fendermint/actors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
23 changes: 23 additions & 0 deletions fendermint/actors/Cargo.toml
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 }
118 changes: 118 additions & 0 deletions fendermint/actors/build.rs
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(())
}
30 changes: 30 additions & 0 deletions fendermint/actors/chainmetadata/Cargo.toml
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"]
Loading
Loading