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 client #777

Closed
wants to merge 2 commits into from
Closed

Tonic client #777

wants to merge 2 commits into from

Conversation

renancloudwalk
Copy link
Contributor

No description provided.

@renancloudwalk renancloudwalk requested a review from a team as a code owner May 5, 2024 02:31
Copy link

github-actions bot commented May 5, 2024

PR Review

⏱️ Estimated effort to review [1-5]

3, because the PR involves changes across multiple files with modifications in configuration and consensus logic which requires a good understanding of the system architecture and the specific functionalities being modified.

🧪 Relevant tests

No

🔍 Possible issues

Possible Bug: The comment in src/bin/run_with_importer.rs suggests that the consensus strategy should be shared between InMemory-Temporary and RocksDB-Permanent, but the implementation only shows changes related to the rocks feature. This might lead to inconsistencies or unhandled cases when the rocks feature is not enabled.

🔒 Security concerns

No

Code feedback:
relevant filesrc/bin/run_with_importer.rs
suggestion      

Consider implementing the shared consensus strategy for both InMemory-Temporary and RocksDB-Permanent as indicated by the comment. This could involve conditional compilation or a runtime check to handle both storage types appropriately. [important]

relevant linelet consensus_task = tokio::spawn(stratus::eth::storage::consensus::server::run_server());

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

Remove the commented-out code related to gather_clients if it is no longer needed, to keep the codebase clean and maintainable. If this logic is to be moved, ensure it is correctly implemented in the new location. [medium]

relevant line-pub async fn gather_clients() -> Result<()> {

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

Add error handling for network failures or incorrect responses within the ManagementClient methods. This could involve retry logic or more comprehensive error messages to aid in debugging and resilience. [important]

relevant linelet client = ClusterManagementClient::connect(addr).await?;

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

Consider implementing actual logic for add_learner and change_membership instead of mocked responses to ensure the system functions correctly in production environments. [important]

relevant lineOk(Response::new(ResultResponse {


✨ 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 5, 2024

PR Code Suggestions

CategorySuggestions                                                                                                                                                       
Enhancement
Rename the feature flag to better reflect its shared usage across storage strategies.

Consider using a more specific feature flag or renaming the existing one to reflect the
shared strategy between different storage types. The current feature flag "rocks" suggests
it is specific to RocksDB, which might be misleading if the strategy is shared.

src/bin/run_with_importer.rs [24-25]

-#[cfg(feature = "rocks")] // this should be a shared strategy between InMemory-Temporary and RocksDB-Permanent
+#[cfg(feature = "shared_storage_strategy")]
 let consensus_task = tokio::spawn(stratus::eth::storage::consensus::server::run_server());
 
Improve error handling in connection and initialization methods.

Add error handling for the connect and init_cluster methods to handle potential connection
and initialization failures more gracefully.

src/eth/storage/consensus/client.rs [16-24]

 pub async fn connect(addr: String) -> Result<Self, tonic::transport::Error> {
-    let client = ClusterManagementClient::connect(addr).await?;
+    let client = ClusterManagementClient::connect(addr).await
+        .map_err(|e| eprintln!("Failed to connect: {}", e))?;
     Ok(ManagementClient { client })
 }
 pub async fn init_cluster(&mut self, id: u64, address: String) -> Result<String, tonic::Status> {
     let request = Node { id, address };
-    let response = self.client.init_cluster(tonic::Request::new(request)).await?;
+    let response = self.client.init_cluster(tonic::Request::new(request)).await
+        .map_err(|e| eprintln!("Failed to initialize cluster: {}", e))?;
     Ok(response.into_inner().message)
 
Add logging to the change_membership method for better monitoring.

Refactor the change_membership method to include logging for better traceability and
debugging of membership changes.

src/eth/storage/consensus/server.rs [38-41]

 async fn change_membership(&self, _request: Request<ChangeMembershipRequest>) -> Result<Response<ResultResponse>, Status> {
+    println!("Changing membership");
     Ok(Response::new(ResultResponse {
         success: true,
         message: "Membership changed (mocked).".to_string(),
     }))
 
Add validation for grpc_address to ensure it is in the correct format.

Validate the format of grpc_address during startup to ensure it meets expected standards
and prevent runtime errors.

src/config.rs [395-396]

-#[arg(short = 'g', long = "grpc", env = "GRPC_ADDRESS", default_value = "0.0.0.0:50000")]
+#[arg(short = 'g', long = "grpc", env = "GRPC_ADDRESS", default_value = "0.0.0.0:50000", validator = validate_socket_address)]
 pub grpc_address: SocketAddr,
 
Add logging to the learner addition and membership change methods.

Implement logging for the add_learner and change_membership methods to provide insights
into the operations and facilitate troubleshooting.

src/eth/storage/consensus/client.rs [27-33]

 pub async fn add_learner(&mut self, id: u64, address: String) -> Result<String, tonic::Status> {
+    println!("Adding learner with ID: {}, Address: {}", id, address);
     let request = AddLearnerRequest {
         node: Some(Node { id, address }),
     };
     let response = self.client.add_learner(tonic::Request::new(request)).await?;
     Ok(response.into_inner().message)
 

✨ 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.

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