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(sdk): get node status #2139

Merged
merged 28 commits into from
Sep 27, 2024
Merged

feat(sdk): get node status #2139

merged 28 commits into from
Sep 27, 2024

Conversation

pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented Sep 18, 2024

Issue being fixed or feature implemented

We want to be able to display status of individual nodes in TUI.

What was done?

  1. In PR feat(platform): get current quorum info  #2168 , we introduced early version of FromUnproved and FetchUnproved traits to handle requests and responses that don't provide proofs.This PR improves these traits, following syntax already implemented by FromProof and Fetch traits.
  2. In PR feat: platform status endpoint #2088, we introduced new GetStatus DAPI request. This PR implements it into Sdk. Note special handling of this request, as we want to deliver it to a specific node (represented by EvoNode struct)
  3. Added Sdk::address_list() and impl IntoIterator for AddressList to expose current address list to the users.

How Has This Been Tested?

Added unit tests.

Integrated into TUI in dashpay/platform-tui#85

Breaking Changes

Changed FromUnproved and FetchUnproved traits (not yet released, so we don't consider it a breaking change).

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced AddressList with cloning and iteration capabilities.
    • Introduced a new method to retrieve the address list from the DapiClient.
    • Implemented gRPC functionality for handling getStatus requests.
    • New modules for node and status added to enhance modularity.
    • Added functionality to convert GetStatusRequest into EvonodeStatus.
    • Introduced EvoNode struct for querying the status of a network node.
    • Added a new module for evonode to organize related functionalities.
    • Enhanced FetchUnproved trait for improved querying and metadata handling.
    • Added support for EvonodeStatus in the Fetch trait.
    • New test cases for validating EvoNode status fetching.
  • Bug Fixes

    • Corrected documentation paths and terminology in the README.
  • Documentation

    • Updated the README for clarity on implementing fetch functionalities and corrected typographical errors.
  • Chores

    • Added mock response implementation for EvonodeStatus in mock requests.

@pauldelucia pauldelucia marked this pull request as ready for review September 18, 2024 13:33
packages/rs-dapi-client/src/address_list.rs Outdated Show resolved Hide resolved
packages/rs-dapi-client/src/dapi_client.rs Outdated Show resolved Hide resolved
@thephez thephez added this to the v1.3.0 milestone Sep 18, 2024
@lklimek lklimek modified the milestones: v1.3.0, v1.4.0 Sep 20, 2024
lklimek
lklimek previously approved these changes Sep 20, 2024
@shumkov shumkov changed the base branch from v1.3-dev to v1.4-dev September 20, 2024 16:18
@shumkov shumkov dismissed lklimek’s stale review September 20, 2024 16:18

The base branch was changed.

Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes involve multiple updates across several files in the rs-dapi-client and rs-dpp packages. Key modifications include the introduction of new methods for accessing address lists and status information, the addition of new modules for better organization, and the implementation of traits for handling status requests. New structures and enums are defined to encapsulate node status information, along with mock response implementations and test cases to ensure functionality.

Changes

File Path Change Summary
packages/rs-dapi-client/src/address_list.rs Added Clone trait to AddressList, introduced addresses method for accessing internal addresses.
packages/rs-dapi-client/src/dapi_client.rs Added address_list method to DapiClient to provide access to the address list.
packages/rs-dapi-client/src/transport/grpc.rs Implemented gRPC handling for getStatus requests.
packages/rs-dpp/src/lib.rs Introduced new public module node.
packages/rs-dpp/src/node/mod.rs Added new public module status.
packages/rs-dpp/src/node/status/mod.rs Defined EvonodeStatus enum and associated methods for status access.
packages/rs-dpp/src/node/status/v0/mod.rs Created EvonodeStatusV0 struct and EvonodeStatusV0Getters trait with relevant methods.
packages/rs-drive-proof-verifier/src/lib.rs Added new module evonode_status and re-exported public items.
packages/rs-drive-proof-verifier/src/types/evonode_status.rs Introduced EvoNodeStatus struct with nested structures for detailed status representation.
packages/rs-drive-proof-verifier/src/unproved.rs Implemented FromUnproved trait for EvoNodeStatus, adding metadata handling.
packages/rs-sdk/src/mock/requests.rs Added mock response implementation for EvoNodeStatus and CurrentQuorumsInfo.
packages/rs-sdk/src/platform/fetch_unproved.rs Updated FetchUnproved trait for flexible querying and metadata handling; implemented for EvoNodeStatus.
packages/rs-sdk/src/platform/types/evonode.rs Created EvoNode struct for querying node status, implementing TransportRequest trait.
packages/rs-sdk/src/sdk.rs Added address_list method to Sdk for retrieving address lists.
packages/rs-sdk/tests/fetch/evonode.rs Added tests for fetching status of Evo nodes, including valid and invalid URI cases.

Possibly related PRs

  • feat(platform): get current quorum info  #2168: The changes in this PR involve the addition of a new RPC method related to quorum information, which may interact with the AddressList struct in terms of data retrieval and representation, although it does not directly modify the same functions or classes.

Poem

🐰 In the meadow, changes bloom,
New paths for status, dispel the gloom.
Address lists now easily found,
With traits and modules, joy abounds!
Hops of progress, swift and bright,
Code rabbits dance in pure delight! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 821af1f and 7f9c668.

📒 Files selected for processing (2)
  • packages/rs-drive-proof-verifier/src/types/evonode_status.rs (1 hunks)
  • packages/rs-sdk/src/platform/types/evonode.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/rs-drive-proof-verifier/src/types/evonode_status.rs
  • packages/rs-sdk/src/platform/types/evonode.rs

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (10)
packages/rs-dpp/src/node/mod.rs (1)

1-1: LGTM! Consider adding a brief module-level documentation comment.

The addition of the status module aligns well with the PR objectives and follows good Rust practices for code organization. This will provide a clear location for the new EvonodeStatus structure and related functionality.

Consider adding a brief module-level documentation comment to provide context about the purpose of this module. For example:

/// Module for managing node status information.
pub mod status;

This would enhance code readability and make it easier for other developers to understand the purpose of this module at a glance.

packages/rs-dpp/src/node/status/v0/mod.rs (2)

4-11: LGTM: Well-structured and documented EvonodeStatusV0 struct.

The EvonodeStatusV0 struct is well-defined with appropriate derive macros and clear field names. The documentation provides a good overview of its purpose.

Consider adding #[serde(rename_all = "camelCase")] attribute to the struct for consistent JSON serialization if this struct is used in API responses. This would ensure that the field names in JSON match common JavaScript naming conventions.

 /// Information about the status of an Evonode
 #[derive(Clone, Debug, PartialEq, Encode, Decode, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
 pub struct EvonodeStatusV0 {
     // ... existing fields ...
 }

13-20: LGTM: Well-defined EvonodeStatusV0Getters trait.

The EvonodeStatusV0Getters trait is correctly defined with appropriate method signatures corresponding to the struct fields. The documentation provides a clear explanation of its purpose.

Consider using associated types or generics in the trait to make it more flexible. This would allow for different implementations to return different types, which could be useful if you need to support different versions or representations of the data in the future.

Here's an example of how you could refactor the trait:

pub trait EvonodeStatusV0Getters {
    type ProTxHash: AsRef<str>;
    type BlockHeight: Into<u64>;

    /// Returns the Evonode proTxHash
    fn pro_tx_hash(&self) -> Self::ProTxHash;

    /// Returns the Evonode's latest stored block height
    fn latest_block_height(&self) -> Self::BlockHeight;
}

This change would allow implementors to use types that can be converted to the required String and u64, providing more flexibility while maintaining type safety.

packages/rs-dpp/src/node/status/mod.rs (2)

9-23: LGTM: EvonodeStatus enum is well-defined with appropriate derive macros.

The EvonodeStatus enum is correctly defined with a single variant V0, suggesting good design for future extensibility. The derive macros cover all necessary traits for serialization, deserialization, and common operations.

Consider expanding the documentation comment to include a brief explanation of why the enum is used (e.g., for versioning) and what EvonodeStatusV0 represents. This would enhance the clarity for future developers working with this code.

- /// Information about the status of an Evonode
+ /// Information about the status of an Evonode.
+ /// 
+ /// This enum is used for versioning the Evonode status structure.
+ /// Currently, it only contains V0, which represents the initial version
+ /// of the Evonode status information.

25-39: LGTM: EvonodeStatusV0Getters trait implementation is correct.

The implementation of EvonodeStatusV0Getters for EvonodeStatus is well-structured and correctly handles the single variant case. The methods pro_tx_hash and latest_block_height provide access to the underlying EvonodeStatusV0 data.

Consider the following suggestions for improvement:

  1. Performance optimization: The pro_tx_hash method currently clones the string. If this method is called frequently, it might be worth considering returning a reference instead:
- fn pro_tx_hash(&self) -> String {
-     match self {
-         EvonodeStatus::V0(v0) => v0.pro_tx_hash.clone(),
-     }
- }
+ fn pro_tx_hash(&self) -> &str {
+     match self {
+         EvonodeStatus::V0(v0) => &v0.pro_tx_hash,
+     }
+ }
  1. Documentation: Enhance the method documentation to include more details about the return values:
- /// Returns the Evonode Identifier
+ /// Returns the Evonode Identifier (ProTxHash)
+ ///
+ /// This identifier uniquely identifies the Evonode in the network.

- /// Returns the Evonode's latest stored block height
+ /// Returns the Evonode's latest stored block height
+ ///
+ /// This represents the height of the most recent block that the Evonode has processed and stored.

These changes would improve performance for frequent calls and provide more context for developers using these methods.

packages/rs-sdk/README.md (1)

Line range hint 100-126: LGTM! Minor suggestion for improved clarity.

The changes in this section look good and align with the PR objectives. The updates to terminology (FetchAny → FetchMany) and the protobuf messages path are consistent and appear to be correct.

Consider adding a brief explanation of the difference between Fetch and FetchMany for developers who might be new to the SDK. This could be added after line 102, for example:

- `Fetch`: Used for retrieving a single object.
- `FetchMany`: Used for retrieving multiple objects in a single request.

This addition would provide more context and clarity for developers implementing these traits.

packages/rs-sdk/src/platform/fetch.rs (1)

285-288: LGTM: Fetch implementation for EvonodeStatus

The implementation of Fetch for EvonodeStatus is correct and consistent with other implementations in the file. It properly associates EvonodeStatus with GetStatusRequest, aligning with the PR objective.

Consider adding a brief doc comment above this implementation to explain its purpose, similar to other implementations in this file. For example:

/// Implements `Fetch` for `EvonodeStatus` to allow fetching node status information.
impl Fetch for EvonodeStatus {
    type Request = platform_proto::GetStatusRequest;
}
packages/rs-dapi-client/src/transport/grpc.rs (1)

415-423: LGTM! Consider adding a brief comment for clarity.

The implementation of GetStatusRequest is correct and consistent with other gRPC request implementations in this file. It properly utilizes the platform_proto module and the PlatformGrpcClient, aligning with the PR objective of implementing the new getStatus dapi-grpc call.

Consider adding a brief comment above the implementation to describe the purpose of the getStatus call, similar to comments present for some other implementations in this file. This would enhance code readability and maintainability.

+// Retrieves the status of the node
 impl_transport_request_grpc!(
     platform_proto::GetStatusRequest,
     platform_proto::GetStatusResponse,
     PlatformGrpcClient,
     RequestSettings::default(),
     get_status
 );
packages/rs-sdk/src/platform/query.rs (1)

650-660: LGTM: New Query implementation for GetStatusRequest added.

The new implementation of Query<GetStatusRequest> for the unit type () is consistent with other implementations in the file and correctly creates a new GetStatusRequest with the appropriate version.

However, consider handling the prove parameter consistently with other implementations in this file. Most other implementations check if prove is true and throw an "unimplemented" error if it's false. You might want to add this check for consistency, or document why this implementation differs.

Consider adding the following check at the beginning of the query method:

 impl Query<GetStatusRequest> for () {
     fn query(self, _prove: bool) -> Result<GetStatusRequest, Error> {
-        // ignore proof
+        if !_prove {
+            unimplemented!("queries without proofs are not supported yet");
+        }
 
         let request: GetStatusRequest = GetStatusRequest {
             version: Some(get_status_request::Version::V0(GetStatusRequestV0 {})),
         };
 
         Ok(request)
     }
 }
packages/rs-drive-proof-verifier/src/proof.rs (1)

1761-1762: Use a specific error variant for missing response version

When handling the absence of a version in the response, the code returns a ProtocolError::Generic error:

return Err(ProtocolError::Generic("No version in the response".to_string()).into())

For clearer error handling and better maintainability, consider defining and using a more specific error variant, such as Error::EmptyVersion, instead of ProtocolError::Generic. This will make it easier to identify and handle this specific error case in the future.

Apply this diff to introduce a new error variant and use it:

+// Define a new error variant
+#[derive(Debug)]
+pub enum Error {
+    EmptyVersion,
+    // ... existing variants
+}

 // In the match statement
 match response.version {
     Some(version) => version,
     None => {
-        return Err(ProtocolError::Generic("No version in the response".to_string()).into())
+        return Err(Error::EmptyVersion)
     }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 210be8e and e4e26c4.

📒 Files selected for processing (13)
  • packages/rs-dapi-client/src/address_list.rs (2 hunks)
  • packages/rs-dapi-client/src/dapi_client.rs (1 hunks)
  • packages/rs-dapi-client/src/transport/grpc.rs (1 hunks)
  • packages/rs-dpp/src/lib.rs (1 hunks)
  • packages/rs-dpp/src/node/mod.rs (1 hunks)
  • packages/rs-dpp/src/node/status/mod.rs (1 hunks)
  • packages/rs-dpp/src/node/status/v0/mod.rs (1 hunks)
  • packages/rs-drive-proof-verifier/src/proof.rs (3 hunks)
  • packages/rs-sdk/README.md (3 hunks)
  • packages/rs-sdk/src/mock/requests.rs (2 hunks)
  • packages/rs-sdk/src/platform/fetch.rs (2 hunks)
  • packages/rs-sdk/src/platform/query.rs (3 hunks)
  • packages/rs-sdk/src/sdk.rs (1 hunks)
🧰 Additional context used
LanguageTool
packages/rs-sdk/README.md

[uncategorized] ~126-~126: Possible missing article found.
Context: ...g RetrievedObjects that will store collection of returned objects, indexed by some k...

(AI_HYDRA_LEO_MISSING_A)

🔇 Additional comments not posted (14)
packages/rs-dpp/src/node/status/v0/mod.rs (2)

1-2: LGTM: Imports are appropriate and necessary.

The imports from bincode and serde are correctly used for the struct's derive macros, enabling serialization and deserialization capabilities.


1-20: Overall: Well-implemented new module for Evonode status.

This new module successfully introduces the EvonodeStatusV0 struct and EvonodeStatusV0Getters trait, aligning with the PR objectives. The code is well-structured, properly documented, and follows Rust best practices. The use of bincode and serde for serialization is appropriate for the intended use case.

A few minor suggestions were made to potentially improve the code:

  1. Consider adding #[serde(rename_all = "camelCase")] to the struct for consistent JSON serialization.
  2. The trait could be made more flexible by using associated types or generics.

These suggestions are optional and do not detract from the overall quality and correctness of the implementation.

packages/rs-dpp/src/node/status/mod.rs (2)

1-7: LGTM: Module declaration and imports look appropriate.

The module declaration and imports are well-organized and include all necessary components for the implementation of EvonodeStatus. The use of custom serialization traits (PlatformSerialize, PlatformDeserialize) is noted and appears to be in line with the project's serialization requirements.


1-39: Overall implementation is well-structured and aligns with PR objectives.

The introduction of the EvonodeStatus enum and its associated functionality in this file is well-implemented and aligns with the PR objectives. Key points:

  1. The code structure allows for future versioning of the Evonode status.
  2. Appropriate use of traits and derive macros for serialization and common operations.
  3. The implementation of EvonodeStatusV0Getters provides a clean interface for accessing Evonode status information.

The code follows Rust best practices and is well-organized. With the minor suggestions provided in previous comments, this implementation provides a solid foundation for handling Evonode status information in the SDK.

packages/rs-dapi-client/src/address_list.rs (1)

88-89: Consider the implications of deriving Clone for AddressList

While deriving Clone for AddressList provides flexibility in usage, it's important to consider the potential performance implications, especially if large instances are frequently cloned.

As per a previous comment from shumkov, it might be preferable to return references instead of encouraging cloning. This approach could be more efficient, especially for large address lists.

To assess the impact, let's check if there are any places in the codebase where AddressList is being cloned:

Consider documenting the rationale for adding Clone and any guidelines for its usage to prevent potential misuse.

packages/rs-sdk/src/mock/requests.rs (3)

9-9: LGTM: New import for EvonodeStatus added.

The import statement for EvonodeStatus from the dpp::node::status module is correctly placed and necessary for the new implementation of MockResponse for EvonodeStatus.


Line range hint 1-247: Summary: Changes enhance mock response capabilities.

The changes in this file successfully add support for EvonodeStatus in mock responses. The new import and implementation are consistent with existing patterns in the file and align with the PR objectives. These changes will allow for better testing and mocking of the new getStatus functionality in the SDK.


247-247: LGTM: MockResponse implementation added for EvonodeStatus.

The implementation of MockResponse for EvonodeStatus using the impl_mock_response! macro is consistent with other implementations in the file and allows EvonodeStatus to be used in mock expectation responses. This change aligns with the PR objectives of utilizing the new getStatus dapi-grpc call within the rs-sdk.

To ensure the new EvonodeStatus mock is being utilized correctly, let's verify its usage in the codebase:

✅ Verification successful

Let's update the verification scripts to ensure we capture all instances of EvonodeStatus usage in the codebase.


Verified: MockResponse implementation for EvonodeStatus is correctly added and utilized.

The impl_mock_response!(EvonodeStatus); in packages/rs-sdk/src/mock/requests.rs appropriately integrates EvonodeStatus into mock expectation responses. No additional usages or TODOs related to EvonodeStatus mocking were found, ensuring the implementation is correctly scoped and aligns with the PR objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of EvonodeStatus in mock responses

# Test 1: Check for imports of EvonodeStatus in test files
echo "Checking for imports of EvonodeStatus in test files:"
rg --type rust 'use .*EvonodeStatus' -g 'tests/**/*.rs'

# Test 2: Look for usage of EvonodeStatus in mock setup
echo "Checking for usage of EvonodeStatus in mock setup:"
rg --type rust 'mock.*EvonodeStatus' -g 'tests/**/*.rs'

# Test 3: Verify if there are any TODO comments related to EvonodeStatus mocking
echo "Checking for TODO comments related to EvonodeStatus mocking:"
rg --type rust 'TODO.*EvonodeStatus.*mock' -g 'tests/**/*.rs'

Length of output: 983


Script:

#!/bin/bash
# Description: Verify the usage of EvonodeStatus in mock responses without restrictive path filters

# Test 1: Check for imports of EvonodeStatus in all Rust files
echo "Checking for imports of EvonodeStatus in Rust files:"
rg --type rust 'use .*EvonodeStatus'

# Test 2: Look for usage of EvonodeStatus in mock setup across all Rust files
echo "Checking for usage of EvonodeStatus in mock setup:"
rg --type rust 'mock.*EvonodeStatus'

# Test 3: Verify if there are any TODO comments related to EvonodeStatus mocking in all Rust files
echo "Checking for TODO comments related to EvonodeStatus mocking:"
rg --type rust 'TODO.*EvonodeStatus.*mock'

Length of output: 816

packages/rs-dapi-client/src/dapi_client.rs (1)

115-119: LGTM! The new method aligns with best practices and previous feedback.

The address_list method provides a clean way to access the address_list without unnecessary cloning. This implementation addresses the previous review comment about avoiding cloning on every call. It's a good practice to return a reference, allowing the user to decide whether they need to clone or not.

packages/rs-sdk/src/platform/fetch.rs (2)

16-17: LGTM: Import modification for EvonodeStatus

The addition of node::status::EvonodeStatus to the imports from the dpp crate is consistent with the PR objective. It's correctly placed within the existing import group and doesn't conflict with other imports.


16-17: Summary: Successful integration of EvonodeStatus

The changes in this file successfully integrate the new EvonodeStatus type into the existing Fetch framework. The modifications are minimal, focused, and follow established patterns, which reduces the risk of introducing bugs. These changes effectively support the PR objective of utilizing the new getStatus dapi-grpc call within the rs-sdk.

Key points:

  1. Appropriate import of EvonodeStatus from the dpp crate.
  2. Correct implementation of Fetch for EvonodeStatus.

The changes look good and are ready for merging, pending any minor documentation improvements suggested earlier.

Also applies to: 285-288

packages/rs-dapi-client/src/transport/grpc.rs (1)

Line range hint 1-423: Overall, the changes enhance DAPI client capabilities without introducing breaking changes.

The addition of the GetStatusRequest implementation successfully integrates the new getStatus dapi-grpc call into the rs-sdk. This change:

  1. Follows established patterns in the file.
  2. Doesn't modify any existing code.
  3. Enhances the DAPI client's functionality.

The implementation aligns well with the PR objectives and maintains the code's consistency and structure.

packages/rs-sdk/src/platform/query.rs (1)

12-12: LGTM: New import added correctly.

The new import for GetStatusRequestV0 is correctly placed and consistent with other imports from the same module. This import is necessary for the new implementation of Query for GetStatusRequest.

packages/rs-drive-proof-verifier/src/proof.rs (1)

1767-1769: Handle missing pro_tx_hash more explicitly

In the extraction of pro_tx_hash from the response:

let pro_tx_hash = match v0.node {
    Some(node) => node.pro_tx_hash,
    None => None,
};

If v0.node or node.pro_tx_hash is None, the code proceeds without the pro_tx_hash. Verify whether this is the desired behavior. If the pro_tx_hash is essential for constructing the EvonodeStatus, consider returning an error or providing a default value with appropriate documentation.

packages/rs-dpp/src/lib.rs Outdated Show resolved Hide resolved
packages/rs-dapi-client/src/address_list.rs Outdated Show resolved Hide resolved
packages/rs-sdk/src/sdk.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/proof.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/proof.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/proof.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/proof.rs Outdated Show resolved Hide resolved
packages/rs-dpp/src/node/mod.rs Outdated Show resolved Hide resolved
packages/rs-dpp/src/node/status/mod.rs Outdated Show resolved Hide resolved
@lklimek lklimek self-assigned this Sep 26, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Outside diff range and nitpick comments (5)
packages/rs-sdk/src/platform/types.rs (1)

3-3: LGTM! Consider adding a brief comment for the new module.

The addition of the evonode module is consistent with the existing structure and naming conventions. It's correctly declared as public and placed in alphabetical order among other module declarations.

To maintain consistency with the file-level documentation, consider adding a brief inline comment explaining the purpose of the evonode module, similar to:

/// Type-specific implementation for Evonode-related functionality
pub mod evonode;
packages/rs-sdk/src/platform.rs (1)

35-35: Consider adding documentation for the new FetchUnproved functionality.

While the addition of FetchUnproved is consistent with the existing structure, it would be beneficial to include documentation explaining its purpose and usage.

Consider adding a brief comment or documentation string above the fetch_unproved module declaration to explain its functionality and how it differs from the existing Fetch and FetchMany operations.

packages/rs-sdk/src/platform/types/evonode.rs (2)

84-85: Remove unnecessary drop calls for client and pool.

In Rust, variables are automatically dropped when they go out of scope. Explicitly calling drop(client); and drop(pool); is unnecessary unless you need to release resources immediately before the end of the scope. Since there is no specific reason to drop them early in this context, you can remove these calls for cleaner code.

Apply this diff to remove the explicit drop statements:

84
-                drop(client);
85
-                drop(pool);

31-32: Consider deriving Serialize and Deserialize unconditionally if needed.

Currently, Serialize and Deserialize are derived only when the "mocks" feature is enabled. If serialization and deserialization might be useful outside of mocks—for example, for caching or logging—you might consider deriving them unconditionally.

31
-#[cfg_attr(feature = "mocks", derive(Serialize, Deserialize))]
+#[derive(Serialize, Deserialize)]
packages/rs-drive-proof-verifier/src/unproved.rs (1)

278-278: Unnecessary use of #[async_trait] attribute

The #[async_trait] attribute is applied, but maybe_from_unproved_with_metadata is a synchronous function. Since there are no asynchronous functions in this implementation, the attribute can be removed to keep the code clean.

Apply this diff to remove the unnecessary attribute:

-#[async_trait]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5537a05 and e409956.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (13)
  • packages/rs-dapi-client/src/lib.rs (1 hunks)
  • packages/rs-drive-proof-verifier/src/proof.rs (4 hunks)
  • packages/rs-drive-proof-verifier/src/types.rs (3 hunks)
  • packages/rs-drive-proof-verifier/src/unproved.rs (2 hunks)
  • packages/rs-sdk/Cargo.toml (3 hunks)
  • packages/rs-sdk/src/lib.rs (1 hunks)
  • packages/rs-sdk/src/mock.rs (1 hunks)
  • packages/rs-sdk/src/mock/requests.rs (2 hunks)
  • packages/rs-sdk/src/platform.rs (1 hunks)
  • packages/rs-sdk/src/platform/fetch_unproved.rs (3 hunks)
  • packages/rs-sdk/src/platform/query.rs (3 hunks)
  • packages/rs-sdk/src/platform/types.rs (1 hunks)
  • packages/rs-sdk/src/platform/types/evonode.rs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/rs-sdk/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/rs-drive-proof-verifier/src/proof.rs
  • packages/rs-sdk/src/platform/query.rs
🔇 Additional comments (21)
packages/rs-sdk/src/platform.rs (2)

Line range hint 3-7: Acknowledge the TODO comment and its importance.

The TODO comment provides valuable context for the current implementation and future plans for the SDK. It's crucial to keep this comment updated as the SDK evolves.

As the SDK development progresses, please ensure that this comment remains accurate and reflects the current state and plans for the platform DAPI requests.


35-35: New export FetchUnproved looks good.

The addition of FetchUnproved is consistent with the existing pattern of exports in this file. It appears to introduce a new functionality for fetching data without proof.

To ensure the completeness of this change, please verify the implementation of the fetch_unproved module:

✅ Verification successful

FetchUnproved Export Verified Successfully.

The fetch_unproved module and the FetchUnproved trait are present as expected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the fetch_unproved module

# Test: Check if the fetch_unproved module exists and contains the FetchUnproved struct or trait
rg --type rust -e "mod fetch_unproved" -e "struct FetchUnproved" -e "trait FetchUnproved" packages/rs-sdk/src

Length of output: 234

packages/rs-sdk/src/mock.rs (3)

41-43: Summary: Enhancements to mocking support look good.

The changes in this file appropriately extend the mocking capabilities of the Dash SDK:

  1. The crate-level export of BINCODE_CONFIG allows for consistent serialization configuration within the crate when mocks are enabled.
  2. The public export of MockDashPlatformSdk provides users with access to the mock SDK implementation when the "mocks" feature is enabled.

Both additions are conditionally compiled, ensuring they don't affect the crate's behavior when mocks are disabled. This approach maintains backwards compatibility while enhancing the mocking functionality.

These changes align well with the module's purpose and seem to be a positive addition to the mocking support.


42-43: LGTM. Verify MockDashPlatformSdk implementation and usage.

The public export of MockDashPlatformSdk is appropriate for the mocking functionality. It makes the mock SDK publicly accessible when the "mocks" feature is enabled, which is consistent with the module's purpose.

To ensure this addition is properly implemented and utilized, let's verify its implementation and usage:

#!/bin/bash
# Description: Verify the implementation and usage of MockDashPlatformSdk

# Test 1: Check the implementation of MockDashPlatformSdk
ast-grep --lang rust --pattern $'struct MockDashPlatformSdk {
  $$$
}' packages/rs-sdk/src/sdk.rs

# Test 2: Search for MockDashPlatformSdk usage in tests
rg --type rust 'MockDashPlatformSdk' packages/rs-sdk/tests

41-41: LGTM. Verify usage of BINCODE_CONFIG.

The addition of this crate-level export for BINCODE_CONFIG looks good. It enhances the mock functionality by making the configuration available within the crate when mocks are enabled.

To ensure this addition is properly utilized, let's verify its usage:

packages/rs-dapi-client/src/lib.rs (1)

17-17: LGTM. Consider verifying documentation for ConnectionPool.

The addition of ConnectionPool to the public exports aligns with the PR objective and is consistent with the module's structure. This change enhances the module's interface by making ConnectionPool available for external use.

To ensure comprehensive documentation, please run the following script:

If the ConnectionPool or its public methods lack documentation, consider adding it to improve the crate's usability.

✅ Verification successful

Documentation for ConnectionPool is adequately provided.

The ConnectionPool struct and its public methods (new, get) are properly documented, enhancing the crate's usability.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for documentation of ConnectionPool

# Test: Search for ConnectionPool documentation
rg --type rust -A 5 'pub struct ConnectionPool' packages/rs-dapi-client/src/connection_pool.rs

# Test: Verify if there are any public methods or associated functions
rg --type rust 'impl ConnectionPool' -A 10 packages/rs-dapi-client/src/connection_pool.rs

Length of output: 1135

packages/rs-sdk/Cargo.toml (1)

8-8: New dependency added: bincode

The addition of the bincode dependency looks good. It's correctly specified with a version, feature, and marked as optional. However, there are a couple of points to consider:

  1. The version "2.0.0-rc.3" is a release candidate. While it's fine to use for development, consider if a stable version would be more appropriate for production use.
  2. The serde feature is enabled, which aligns well with the serialization needs often associated with bincode usage.

To ensure this dependency is used in the codebase, let's run a quick check:

✅ Verification successful

'bincode' dependency is correctly utilized in the codebase

The bincode dependency is actively used across multiple modules, validating its addition to the Cargo.toml. However, since version "2.0.0-rc.3" is a release candidate, consider using a stable release for better reliability in production environments.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for bincode usage in Rust files
rg --type rust 'use.*bincode' || echo "No direct usage of bincode found in Rust files."

Length of output: 37398

packages/rs-sdk/src/mock/requests.rs (4)

18-21: LGTM: New imports align with PR objectives.

The addition of CurrentQuorumsInfo and EvonodeStatus to the imports is consistent with the PR's goal of implementing support for the new getStatus dapi-grpc call. These imports are necessary for the mock response implementations added later in the file.


247-248: LGTM: New mock response implementations added.

The addition of mock response implementations for EvonodeStatus and CurrentQuorumsInfo is consistent with the PR objectives. The use of the impl_mock_response! macro ensures these new implementations follow the same pattern as existing ones, maintaining consistency in the codebase.


Line range hint 1-248: Overall, the changes look good and align with the PR objectives.

The modifications to this file are well-structured and consistent with the existing codebase. The new imports, visibility change, and mock response implementations all contribute to supporting the new getStatus dapi-grpc call as intended. The use of existing patterns (like the impl_mock_response! macro) for new implementations is commendable.

A minor point to verify is the necessity of the BINCODE_CONFIG visibility change, but otherwise, the changes appear to be complete and correct.


25-25: Visibility change looks good, but please verify necessity.

The change of BINCODE_CONFIG visibility to pub(crate) is appropriate as it maintains encapsulation while allowing access within the crate. However, it's important to ensure this change is necessary.

Could you please confirm that this visibility change is required by other modules within the crate? If so, could you provide a brief explanation of where it's used?

✅ Verification successful

Visibility change approved.

The BINCODE_CONFIG visibility change to pub(crate) is appropriate as all usages are confined within the rs-sdk crate. External crates are not affected by this change.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usages of BINCODE_CONFIG outside this file
rg --type rust -g '!**/mock/requests.rs' 'BINCODE_CONFIG'

Length of output: 1392

packages/rs-sdk/src/platform/fetch_unproved.rs (7)

2-5: Necessary imports added correctly

The additional imports of MockResponse, ResponseMetadata, and EvonodeStatus are necessary for the updated functionality and are correctly specified.


10-10: Importing Query for flexible querying

The import of Query enables the use of the generic query parameter in the methods, enhancing query flexibility.


15-15: Added MockResponse to trait bounds

Including MockResponse in the trait bounds ensures that implementing types can provide mock responses, which is beneficial for testing and development purposes.


30-43: Updated fetch_unproved method for flexible querying

The method signature of fetch_unproved has been updated to accept a generic parameter Q implementing Query, along with a query parameter. This change allows for more flexible and reusable querying capabilities. The method correctly delegates to fetch_unproved_with_settings with default settings and properly handles the return value.


57-79: Enhanced fetch_unproved_with_settings method

The fetch_unproved_with_settings method now accepts a query parameter and returns a tuple containing the optional object and ResponseMetadata. This provides additional information about the response, which can be valuable for clients. The default implementation correctly constructs the request from the query, executes it, and parses the response along with metadata.


83-85: Implemented FetchUnproved for CurrentQuorumsInfo

The implementation correctly specifies GetCurrentQuorumsInfoRequest as the associated request type for CurrentQuorumsInfo, aligning with the structure of the trait.


87-89: Implemented FetchUnproved for EvonodeStatus

The implementation appropriately defines GetStatusRequest as the associated request type for EvonodeStatus, supporting the new getStatus dapi-grpc call as per the PR objectives.

packages/rs-sdk/src/platform/types/evonode.rs (1)

74-76: Ensure timeout settings are correctly applied.

The condition if !settings.timeout.is_zero() checks if the timeout is set. Make sure that grpc_request.set_timeout(settings.timeout); correctly applies the timeout to the gRPC request. Verify that the set_timeout method behaves as expected with the provided timeout value.

To confirm that the timeout is applied, you may run the following script:

packages/rs-drive-proof-verifier/src/types.rs (2)

8-8: Importing GetStatusResponse is appropriate

The import of GetStatusResponse is necessary for the implementation of TryFrom<GetStatusResponse> for EvonodeStatus.


29-29: Importing hex::ToHex for hexadecimal encoding

Importing hex::ToHex is appropriate for encoding the pro_tx_hash to a hexadecimal string.

packages/rs-sdk/Cargo.toml Outdated Show resolved Hide resolved
packages/rs-sdk/src/platform/types/evonode.rs Outdated Show resolved Hide resolved
packages/rs-sdk/src/platform/types/evonode.rs Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/unproved.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/types.rs Outdated Show resolved Hide resolved
packages/rs-drive-proof-verifier/src/types.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (1)
packages/rs-sdk/tests/fetch/mod.rs (1)

Line range hint 1-1: Consider creating an issue for the TODO comment.

There's a TODO comment at the beginning of the file suggesting to rename the test package. While this is unrelated to the current changes, it might be beneficial to create an issue to track this task for future improvements.

Would you like me to create a GitHub issue to track the task of renaming the test package?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e409956 and fa4bb87.

📒 Files selected for processing (3)
  • packages/rs-sdk/src/platform/types/evonode.rs (1 hunks)
  • packages/rs-sdk/tests/fetch/evonode.rs (1 hunks)
  • packages/rs-sdk/tests/fetch/mod.rs (1 hunks)
🔇 Additional comments (7)
packages/rs-sdk/tests/fetch/mod.rs (2)

20-20: LGTM: New evonode module added successfully.

The addition of the evonode module aligns with the PR objectives to implement functionality related to the new getStatus dapi-grpc call within the rs-sdk. The module is correctly placed alongside other related modules.


Line range hint 2-7: Verify the necessity of compile-time feature checks.

The file includes compile-time feature checks for mocks, network-testing, and offline-testing. While these are unrelated to the current changes, it might be worth verifying if these checks are still necessary and up-to-date.

✅ Verification successful

Compile-time feature checks are necessary and up-to-date.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the feature flags mentioned in the compile-time checks are still used in the project.

# Test 1: Check for the usage of 'mocks' feature
echo "Checking usage of 'mocks' feature:"
rg --type rust 'feature\s*=\s*"mocks"' -C 3

# Test 2: Check for the usage of 'network-testing' feature
echo "Checking usage of 'network-testing' feature:"
rg --type rust 'feature\s*=\s*"network-testing"' -C 3

# Test 3: Check for the usage of 'offline-testing' feature
echo "Checking usage of 'offline-testing' feature:"
rg --type rust 'feature\s*=\s*"offline-testing"' -C 3

# Expected results: The features should be used in other parts of the project. 
# If any of these searches return no results, it might indicate that the feature is no longer used and the check could potentially be removed.

Length of output: 71859

packages/rs-sdk/tests/fetch/evonode.rs (2)

1-7: LGTM: Imports and file-level comment are appropriate.

The file-level comment clearly describes the purpose of the tests, and the imports are relevant to the functionality being tested. Good job on keeping the imports concise and focused.


1-46: Overall, well-structured tests with room for enhancement.

The evonode.rs file contains two well-designed test functions that cover both positive and negative scenarios for Evo node status functionality. This approach to testing is commendable.

The suggested improvements for both test_evonode_status and test_evonode_status_refused functions will significantly enhance the robustness, reliability, and informativeness of these tests. Implementing these changes will:

  1. Improve error handling and prevent premature test termination.
  2. Add more specific assertions to validate the correctness of fetched data.
  3. Introduce timeouts to prevent tests from hanging indefinitely.
  4. Provide more detailed error checking for negative test cases.

These enhancements will lead to more dependable and maintainable tests, which are crucial for ensuring the reliability of the Evo node status functionality in the SDK.

packages/rs-sdk/src/platform/types/evonode.rs (3)

1-32: LGTM: Imports and documentation are well-structured.

The imports are appropriate for the functionality being implemented. The module-level documentation clearly explains the purpose of EvoNode, and the provided example demonstrates its usage effectively.


33-42: LGTM: EvoNode struct and implementation are well-defined.

The EvoNode struct is appropriately defined as a tuple struct containing an Address. The derive macros for Debug and Clone, along with the conditional derive for Serialize and Deserialize, are suitable for the struct's purpose. The new method provides a clear way to create an EvoNode instance, addressing the issue raised in the past review comment.


44-53: LGTM: Mockable implementation for EvoNode is correct.

The Mockable implementation, conditional on the "mocks" feature, correctly implements the mock_deserialize method using bincode. The error handling is appropriate, returning None if deserialization fails.

packages/rs-sdk/tests/fetch/evonode.rs Outdated Show resolved Hide resolved
packages/rs-sdk/tests/fetch/evonode.rs Outdated Show resolved Hide resolved
packages/rs-sdk/src/platform/types/evonode.rs Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fa4bb87 and bad801c.

📒 Files selected for processing (2)
  • packages/rs-drive-proof-verifier/src/types.rs (3 hunks)
  • packages/rs-sdk/tests/fetch/evonode.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rs-sdk/tests/fetch/evonode.rs
🔇 Additional comments (2)
packages/rs-drive-proof-verifier/src/types.rs (2)

620-632: LGTM: Well-defined EvonodeStatus struct

The EvonodeStatus struct is well-defined with appropriate fields, derives, and documentation. The use of [u8; ProTxHash::LEN] for pro_tx_hash ensures type safety and efficiency.


634-668: LGTM: Robust TryFrom<GetStatusResponse> implementation

The implementation is thorough, with good error handling and data extraction. The validation of pro_tx_hash length is a nice security touch.

packages/rs-drive-proof-verifier/src/types.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/rs-sdk/src/platform/fetch_unproved.rs (1)

17-17: LGTM: FetchUnproved trait enhancements look good.

The changes to the FetchUnproved trait improve its flexibility and functionality:

  1. Adding the MockResponse requirement facilitates testing.
  2. The new generic parameter Q: Query<<Self as FetchUnproved>::Request> allows for more flexible querying.
  3. Including ResponseMetadata in the return type of fetch_unproved_with_settings provides more context about the response.

Consider updating the method documentation for fetch_unproved and fetch_unproved_with_settings to reflect the changes in the return type and the addition of the query parameter.

Also applies to: 33-46, 61-84

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e58541d and ddbda44.

📒 Files selected for processing (2)
  • packages/rs-sdk/src/platform/fetch_unproved.rs (2 hunks)
  • packages/rs-sdk/src/platform/types/evonode.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/rs-sdk/src/platform/types/evonode.rs
🔇 Additional comments (4)
packages/rs-sdk/src/platform/fetch_unproved.rs (4)

1-1: LGTM: Import statements are correctly updated.

The new imports are consistent with the changes made in the trait and implementations. All imported items are used in the updated code.

Also applies to: 3-3, 5-7, 9-9


89-89: LGTM: FetchUnproved implementation for CurrentQuorumsInfo.

The implementation correctly specifies the Request associated type for CurrentQuorumsInfo.


91-93: LGTM: FetchUnproved implementation for EvonodeStatus.

The implementation correctly specifies the Request associated type for EvonodeStatus as EvoNode.


95-116: Implementation looks good, but please clarify type inconsistency.

The FromUnproved implementation for EvonodeStatus looks correct overall. It provides a flexible implementation by using Into traits for Request and Response.

However, there's an apparent inconsistency that needs clarification:

  • The Request associated type is defined as EvoNode
  • The delegation call uses <Self as FromUnproved<GetStatusRequest>>

Could you please clarify why GetStatusRequest is used in the delegation instead of EvoNode? Is this intentional, or should it be adjusted to match the Request type?

To help verify this, let's check the FromUnproved implementations for EvonodeStatus:

@lklimek lklimek changed the title feat: get node statuses in sdk feat(sdk): get node status Sep 27, 2024
@lklimek
Copy link
Contributor

lklimek commented Sep 27, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 27, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

/// Status of a network node.
///
/// Some fields may be `None` if the information is not available, eg. when the node is not fully functional.
pub struct EvonodeStatus {
Copy link
Member

Choose a reason for hiding this comment

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

Let's have it nested as proto otherwise it's too messy

Copy link
Contributor

Choose a reason for hiding this comment

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

done

// We need to delegate FromUnproved for the impl FetchUnproved for EvonodeStatus.
#[async_trait::async_trait]
impl FromUnproved<EvoNode> for EvonodeStatus {
type Request = EvoNode;
Copy link
Member

Choose a reason for hiding this comment

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

EvoNodeStatus?

Copy link
Contributor

Choose a reason for hiding this comment

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

done

"get_status"
}

fn execute_transport<'c>(
Copy link
Member

Choose a reason for hiding this comment

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

We create client every request?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

This query (getStatus) goes to exactly the node that is specified by EvoNode.0.

It means that:

  • this node doesn't have to be configured as one of Sdk endpoints,
  • this request will most likely go to each target only once, so caching clients will not add much value.

To ensure this is not an issue, I created 1 million clients in a loop like:

let start = time::Instant::now();
        for i in 0..1_000_000 {
            Self::Client::with_uri_and_settings(uri.clone(), settings, &pool);
        }
        let elapsed = start.elapsed();
        tracing::info!("1 mln client creations took: {:?}", elapsed);

Result:

INFO dash_sdk::platform::types::evonode: 1 mln client creations took: 1.718250235s

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
packages/rs-sdk/src/platform/fetch_unproved.rs (3)

17-17: LGTM: Improved flexibility in the FetchUnproved trait.

The changes to the FetchUnproved trait enhance its flexibility by introducing a generic query parameter and providing a default implementation. The use of Option<Self> in the return type is a good practice for handling cases where no object is found.

Consider adding a brief comment explaining the purpose of the Q: Query generic parameter for better documentation.

Also applies to: 33-46


61-84: LGTM: Improved fetch_unproved_with_settings method.

The updates to the fetch_unproved_with_settings method are well-implemented and consistent with the changes to the fetch_unproved method. The default implementation is clear and concise, providing a good template for specific implementations.

Consider adding error handling for the case where maybe_from_unproved_with_metadata returns None. This could involve mapping the None case to an appropriate error type.


95-117: LGTM: Well-implemented FromUnproved for EvoNodeStatus.

The new implementation of FromUnproved<EvoNode> for EvoNodeStatus is well-structured and uses an effective delegation pattern. This approach promotes code reuse and maintains consistency with existing implementations.

Consider adding a brief comment explaining why EvoNode is used as the Request type here, as it might not be immediately obvious to readers unfamiliar with the codebase.

packages/rs-drive-proof-verifier/src/types/evonode_status.rs (2)

174-174: Improve clarity of documentation comment

Consider rephrasing the comment for better readability:

-/// Identifier of chain the node is member of.
+/// Identifier of the chain the node is a member of.

207-304: Consider adding unit tests for the TryFrom<GetStatusResponse> implementation

To ensure the correctness of the conversion from GetStatusResponse to EvoNodeStatus, consider adding unit tests that cover various scenarios, including cases with missing or None fields and malformed data. This will help validate the robustness of the parsing logic.

Would you like me to help generate unit tests for this implementation or open a GitHub issue to track this task?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c66c815 and 821af1f.

📒 Files selected for processing (8)
  • packages/rs-drive-proof-verifier/src/types.rs (4 hunks)
  • packages/rs-drive-proof-verifier/src/types/evonode_status.rs (1 hunks)
  • packages/rs-drive-proof-verifier/src/unproved.rs (2 hunks)
  • packages/rs-sdk/src/mock/requests.rs (2 hunks)
  • packages/rs-sdk/src/platform/fetch_unproved.rs (2 hunks)
  • packages/rs-sdk/src/platform/types/evonode.rs (1 hunks)
  • packages/rs-sdk/src/sdk.rs (1 hunks)
  • packages/rs-sdk/tests/fetch/evonode.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/rs-drive-proof-verifier/src/types.rs
  • packages/rs-drive-proof-verifier/src/unproved.rs
  • packages/rs-sdk/src/mock/requests.rs
  • packages/rs-sdk/src/platform/types/evonode.rs
  • packages/rs-sdk/src/sdk.rs
  • packages/rs-sdk/tests/fetch/evonode.rs
🔇 Additional comments (3)
packages/rs-sdk/src/platform/fetch_unproved.rs (2)

1-1: LGTM: New imports are consistent with the changes.

The added imports support the new functionality in the FetchUnproved trait and its implementations. They are correctly placed and organized.

Also applies to: 3-3, 5-9


87-93: LGTM: New implementations for FetchUnproved trait.

The new implementations for CurrentQuorumsInfo and EvoNodeStatus are correctly defined, specifying the required Request associated type. These minimal implementations leverage the default methods provided by the trait.

packages/rs-drive-proof-verifier/src/types/evonode_status.rs (1)

236-242: Verify that default values are appropriate when v0.node is missing

In the TryFrom implementation, if v0.node is None, the Node struct defaults to its Default implementation using unwrap_or_default(). Please verify whether defaulting to empty Node information is acceptable, or if it should result in an error to prevent unintended behavior. This consideration also applies to other fields like chain, network, state_sync, and time.

To confirm whether using default values is appropriate, check how EvoNodeStatus and its fields are utilized elsewhere in the codebase:

This script will help identify whether the code assumes the presence of certain data in these fields.

Copy link
Member

@shumkov shumkov left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants