-
Notifications
You must be signed in to change notification settings - Fork 152
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
feat: build and run F3 sidecar in Forest process via FFI #4727
Conversation
9f41432
to
0963e25
Compare
@@ -0,0 +1,210 @@ | |||
package main |
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.
Include this file so that the Go mod builds out of box without codegen from Rust build
e91f8e9
to
2854a58
Compare
2854a58
to
7b4642b
Compare
a32b3c2
to
8569f43
Compare
8569f43
to
2640a6f
Compare
src/f3/mod.rs
Outdated
// Opt-out building the F3 sidecar staticlib | ||
match std::env::var("FOREST_F3_SIDECAR_FFI_ENABLED") { | ||
Ok(value) => { | ||
let enabled = matches!(value.to_lowercase().as_str(), "1" | "true"); |
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.
I recommend using
Lines 15 to 21 in b7c004b
/// Check if the given environment variable is set to truthy value. | |
pub fn is_env_truthy(env: &str) -> bool { | |
match std::env::var(env) { | |
Ok(var) => matches!(var.to_lowercase().as_str(), "1" | "true"), | |
_ => false, | |
} | |
} |
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.
Didn't know that. Fixed.
src/daemon/mod.rs
Outdated
crate::rpc::f3::get_f3_rpc_endpoint().to_string(), | ||
finality, | ||
std::env::var("FOREST_F3_DB_PATH") | ||
.unwrap_or_else(|_| format!("/var/tmp/f3-db-{chain}")), |
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.
Why that location and not in the Forest data directory?
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.
Fixed.
src/daemon/mod.rs
Outdated
services.spawn_blocking(move || { | ||
crate::f3::run_f3_sidecar_if_enabled( | ||
format!("http://{rpc_address}/rpc/v1"), | ||
crate::rpc::f3::get_f3_rpc_endpoint().to_string(), |
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.
In general, it would be nice if get_f3_rpc_endpoint
would return a Url
and the strong typing would be used in other places.
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.
Changed to returning SocketAddr
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.
@LesnyRumcajs Hmm this is not a rust SocketAddr because it supports DNS like f3:23456
, nor is it an URL because protocol(http) is not included. Any suggestions on what type to use instead of String?
// Go code
listener, err := net.Listen("tcp", f3RpcSocketAddress)
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.
That's a weird one. We could make an enum, but if it's too much hassle and overengineering we could do with a type alias F3Endpoint
for the time being. It's not blocking.
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.
Thanks. I'd do more investigation and improve this in another PR. #4736
.github/workflows/forest.yml
Outdated
env: | ||
FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT: 1 |
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.
Should it be noted somewhere that the crates.io
releases do not contain this, as opposed to docker images?
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.
It's only excluded from docs.rs
build not crates.io
. cargo install filecoin-forest
still has sidecar FFI included
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.
Or maybe I should just install Go
for this job
e7178ff
to
1fbc03f
Compare
1fbc03f
to
8d798ca
Compare
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.
Should we mention that Go
is required in https://github.com/ChainSafe/forest?tab=readme-ov-file#dependencies?
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.
Good catch. Updated.
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") { | ||
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"), | ||
_ => true, | ||
} |
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.
Can we use the function mentioned elsewhere in the PR for that in the build script?
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.
The util is not available here in the build script context
Looks fine by me, though the conditions are a bit confusing. Curious if we shouldn't actually disable sidecar by default and make it feature-enabled. Perhaps then it's going to be less confusing with all the environment variables. |
@ruseinov F3 is not yet feature complete for being enabled by default (in Lotus as well). e.g. Loading power table at a fixed upgrade epoch that is 2000 epochs older than head does not work. For now we can only do joint testing with some manual setup. |
} | ||
else { | ||
if enabled { | ||
tracing::error!("Failed to enable F3 sidecar, the forerst binary is not compiled with f3-sidecar Go lib"); |
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.
typo in Forest name
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.
Good catch! Will fix this in the follow up PR #4732
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes #4700
Other information and links
Change checklist