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

feat: build and run F3 sidecar in Forest process via FFI #4727

Merged
merged 17 commits into from
Sep 11, 2024

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Sep 4, 2024

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #4700

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 force-pushed the hm/f3-sidecar-ffi branch 3 times, most recently from 9f41432 to 0963e25 Compare September 4, 2024 06:41
@@ -0,0 +1,210 @@
package main
Copy link
Contributor Author

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

@hanabi1224 hanabi1224 force-pushed the hm/f3-sidecar-ffi branch 2 times, most recently from e91f8e9 to 2854a58 Compare September 4, 2024 07:06
@hanabi1224 hanabi1224 marked this pull request as ready for review September 5, 2024 10:05
@hanabi1224 hanabi1224 requested a review from a team as a code owner September 5, 2024 10:05
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and elmattic and removed request for a team September 5, 2024 10:05
@hanabi1224 hanabi1224 force-pushed the hm/f3-sidecar-ffi branch 2 times, most recently from a32b3c2 to 8569f43 Compare September 5, 2024 10:36
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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using

/// 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,
}
}
when checking for truthy env variables.

Copy link
Contributor Author

@hanabi1224 hanabi1224 Sep 6, 2024

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.

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}")),
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

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(),
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to returning SocketAddr

Copy link
Contributor Author

@hanabi1224 hanabi1224 Sep 6, 2024

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)

Copy link
Member

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.

Copy link
Contributor Author

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

Comment on lines 104 to 105
env:
FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT: 1
Copy link
Member

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?

Copy link
Contributor Author

@hanabi1224 hanabi1224 Sep 5, 2024

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

Copy link
Contributor Author

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

@hanabi1224 hanabi1224 force-pushed the hm/f3-sidecar-ffi branch 4 times, most recently from e7178ff to 1fbc03f Compare September 6, 2024 04:40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated.

Comment on lines +31 to +34
match std::env::var("FOREST_F3_SIDECAR_FFI_BUILD_OPT_OUT") {
Ok(value) => !matches!(value.to_lowercase().as_str(), "1" | "true"),
_ => true,
}
Copy link
Member

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?

Copy link
Contributor Author

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

@ruseinov
Copy link
Contributor

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.

@hanabi1224
Copy link
Contributor Author

hanabi1224 commented Sep 10, 2024

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in Forest name

Copy link
Contributor Author

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

@hanabi1224 hanabi1224 added this pull request to the merge queue Sep 11, 2024
Merged via the queue into main with commit 5257127 Sep 11, 2024
30 checks passed
@hanabi1224 hanabi1224 deleted the hm/f3-sidecar-ffi branch September 11, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integrate F3 sidecar into Forest with FFI
4 participants