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

Tonic #775

Merged
merged 7 commits into from
May 5, 2024
Merged

Tonic #775

merged 7 commits into from
May 5, 2024

Conversation

renancloudwalk
Copy link
Contributor

No description provided.

@renancloudwalk renancloudwalk requested a review from a team as a code owner May 4, 2024 18:37
@renancloudwalk renancloudwalk enabled auto-merge (squash) May 4, 2024 18:38
Copy link

github-actions bot commented May 4, 2024

PR Review

⏱️ Estimated effort to review [1-5]

4, due to the significant changes across multiple files including Rust source files, configuration files, and proto definitions. The PR introduces new dependencies and alters the architecture significantly, requiring a thorough review to ensure compatibility and correctness.

🧪 Relevant tests

No

🔍 Possible issues

Possible Bug: The use of unwrap() in tonic_build::compile_protos("proto/management.proto").unwrap(); could cause the program to panic if there are any issues compiling the proto files. It's generally safer to handle this error gracefully.

Thread Safety Concern: The new asynchronous tasks spawned in src/bin/run_with_importer.rs might not be safely sharing resources, especially if they access shared state without proper synchronization.

🔒 Security concerns

No

Code feedback:
relevant filebuild.rs
suggestion      

Consider handling errors from tonic_build::compile_protos gracefully instead of using unwrap(). This could prevent the build script from panicking and allow for more graceful error handling and logging. [important]

relevant linetonic_build::compile_protos("proto/management.proto").unwrap();

relevant filesrc/bin/run_with_importer.rs
suggestion      

Ensure that the resources shared between the tasks rpc_task, importer_task, and consensus_task are thread-safe and properly synchronized. Consider using thread-safe types like Arc<Mutex<T>> if necessary. [important]

relevant linelet rpc_task = tokio::spawn(serve_rpc(Arc::clone(&executor), Arc::clone(&storage), stratus_config));

relevant filesrc/eth/storage/rocks/consensus.rs
suggestion      

Since the gather_clients function now contains unused code (_pods_list), consider removing or refactoring this part to avoid confusion and maintain clean code. [medium]

relevant linelet _pods_list = [

relevant fileCargo.toml
suggestion      

Verify that the new dependencies tonic, prost, and openraft are compatible with the existing project setup and do not introduce any version conflicts with other dependencies. [medium]

relevant linetonic = "=0.11.0"


✨ Review tool usage guide:

Overview:
The review tool scans the PR code changes, and generates a PR review which includes several types of feedbacks, such as possible PR issues, security threats and relevant test in the PR. More feedbacks can be added by configuring the tool.

The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on any PR.

  • When commenting, to edit configurations related to the review tool (pr_reviewer section), use the following template:
/review --pr_reviewer.some_config1=... --pr_reviewer.some_config2=...
[pr_reviewer]
some_config1=...
some_config2=...

See the review usage page for a comprehensive guide on using this tool.

Copy link

github-actions bot commented May 4, 2024

PR Code Suggestions

CategorySuggestions                                                                                                                                                       
Best practice
Replace unwrap() with error handling to prevent potential panics.

It's a good practice to handle errors gracefully rather than unwrapping them directly,
which can cause the program to panic if an error occurs. Consider using a match statement
or the ? operator to handle potential errors from compile_protos.

build.rs [17]

-tonic_build::compile_protos("proto/management.proto").unwrap();
+tonic_build::compile_protos("proto/management.proto")?;
 
Use more flexible version constraints for dependencies to ease maintenance.

The version pinning using = for dependencies like tonic, prost, and openraft can lead to
difficulties in maintaining the project due to potential conflicts with other libraries or
missed updates for security patches. Consider using more flexible version constraints
unless there is a specific reason for strict pinning.

Cargo.toml [87]

-tonic = "=0.11.0"
+tonic = "0.11"
 
Possible issue
Ensure all asynchronous tasks are properly awaited.

The try_join! macro is used to await multiple tasks concurrently. It's important to ensure
that all tasks are properly awaited to handle their results or potential errors. In the
current implementation, the consensus_task is only awaited conditionally when the "rocks"
feature is enabled. This could lead to unhandled futures if the feature is not enabled.
Consider restructuring the code to ensure all tasks are always awaited regardless of
feature flags.

src/bin/run_with_importer.rs [30]

-let join_result = try_join!(rpc_task, importer_task, consensus_task)?;
+let join_result = if cfg!(feature = "rocks") {
+    try_join!(rpc_task, importer_task, consensus_task)
+} else {
+    try_join!(rpc_task, importer_task)
+}?;
 
Enhancement
Make the server address configurable to support different deployment environments.

The server address is hardcoded to listen only on IPv6 loopback address which might not be
suitable for all deployment environments. Consider making the server address configurable
through environment variables or configuration files to enhance flexibility and deployment
options.

src/eth/storage/rocks/consensus.rs [61]

-let addr = "[::1]:50051".parse()?;
+let addr = std::env::var("SERVER_ADDRESS").unwrap_or_else(|_| "[::1]:50051".to_string()).parse()?;
 
Maintainability
Implement or conditionally compile the mocked service methods.

The ClusterManagementService methods currently return mocked responses. For a production
environment, it's crucial to implement actual logic for these methods or to ensure that
the mocking is only used during testing. Consider adding real implementations or feature
gating the mocked responses.

src/eth/storage/rocks/consensus.rs [36-40]

-Ok(Response::new(ResultResponse {
-    success: true,
-    message: "Cluster initialized (mocked).".to_string(),
-}))
+if cfg!(test) {
+    Ok(Response::new(ResultResponse {
+        success: true,
+        message: "Cluster initialized (mocked).".to_string(),
+    }))
+} else {
+    // Implement actual logic here
+}
 

✨ Improve tool usage guide:

Overview:
The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.

  • When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:
/improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
[pr_code_suggestions]
some_config1=...
some_config2=...

See the improve usage page for a comprehensive guide on using this tool.

@renancloudwalk renancloudwalk merged commit 4c3510d into main May 5, 2024
25 checks passed
@renancloudwalk renancloudwalk deleted the tonic branch May 5, 2024 02:24
renancloudwalk added a commit that referenced this pull request May 5, 2024
This reverts commit 4c3510d.
renancloudwalk added a commit that referenced this pull request May 5, 2024
renancloudwalk added a commit that referenced this pull request May 5, 2024
* Tonic (#775)

* chore: add tonic as a consensus server

* add tonic into run with importer

* lint

* lint

* chore: use a Tonic client for election

* lint

* lint
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.

1 participant