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(multichain): update token-info client #1208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lok52
Copy link
Contributor

@lok52 lok52 commented Jan 24, 2025

Summary by CodeRabbit

Release Notes

  • Dependencies

    • Added contracts-info-proto dependency across multiple packages
    • Updated dependency configurations in Cargo.toml files
  • Client Modifications

    • Improved token information client configuration
    • Added support for HTTP timeout settings
    • Streamlined token search request handling
  • Code Refactoring

    • Restructured token information client and search functionality
    • Updated type conversions and error handling
    • Simplified client initialization process

@lok52 lok52 requested a review from rimrakhimov January 24, 2025 09:00
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request introduces significant changes to the multichain-aggregator project by integrating the contracts-info-proto dependency across multiple components. The modifications span several files in the project, including Cargo.toml files for different packages and source code files. The primary focus is on restructuring how token information is handled, replacing custom token info client implementations with a new proto-based approach. This involves updating dependencies, modifying client instantiation methods, and refactoring how token information is searched and processed throughout the multichain-aggregator logic and server components.

Possibly related PRs

Poem

🐰 Hop, hop, through code so bright,
Dependencies aligned just right!
Proto clients dance with glee,
Tokens flowing, wild and free
Multichain magic takes its flight! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 2

🧹 Nitpick comments (6)
multichain-aggregator/multichain-aggregator-logic/src/clients/mod.rs (1)

2-7: Consider selective re-exports for maintainability.

Re-exporting the entire contents of contracts_info_proto may make it less obvious which items are actually used, potentially complicating future refactoring. Consider re-exporting specific structs or modules that are actively consumed to maintain a clearer API surface.

multichain-aggregator/multichain-aggregator-server/src/settings.rs (2)

60-67: Ensure default timeout is documented.

Including #[serde(default = "default_token_info_timeout")] helps avoid missing configuration, but ensure the documentation clarifies the default timeout's behavior.


112-114: Potentially adjust default timeout based on environment.

Five seconds may be insufficient or too generous in some deployments. Consider making it configurable at build time or environment-based.

multichain-aggregator/multichain-aggregator-logic/src/search.rs (1)

53-58: Validate the default pagination parameters.

Specifying page_size = Some(100) and setting chain_id = None expands the search across all chains. Confirm this aligns with intended usage and that 100 is the appropriate default page size. If needed, consider hooking into a configurable setting or having a safe upper limit.

multichain-aggregator/multichain-aggregator-server/src/services/multichain_aggregator.rs (1)

30-30: Validate client reuse.

Changing token_info_client to a specialized token_info::Client clarifies its purpose. Verify that reusing a single client instance does not introduce synchronization or performance issues if it’s used across multiple concurrent requests.

multichain-aggregator/multichain-aggregator-server/Cargo.toml (1)

30-33: Maintain clarity of feature flags.

Expanding feature lists for blockscout-service-launcher improves readability. Confirm that the newly listed features ("test-server", "test-database") are required for all environments or limit them to only development and testing where appropriate.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f36bc2 and 4500e83.

📒 Files selected for processing (10)
  • multichain-aggregator/Cargo.toml (1 hunks)
  • multichain-aggregator/multichain-aggregator-logic/Cargo.toml (1 hunks)
  • multichain-aggregator/multichain-aggregator-logic/src/clients/mod.rs (1 hunks)
  • multichain-aggregator/multichain-aggregator-logic/src/clients/token_info.rs (0 hunks)
  • multichain-aggregator/multichain-aggregator-logic/src/search.rs (3 hunks)
  • multichain-aggregator/multichain-aggregator-logic/src/types/token_info.rs (2 hunks)
  • multichain-aggregator/multichain-aggregator-server/Cargo.toml (1 hunks)
  • multichain-aggregator/multichain-aggregator-server/src/server.rs (1 hunks)
  • multichain-aggregator/multichain-aggregator-server/src/services/multichain_aggregator.rs (4 hunks)
  • multichain-aggregator/multichain-aggregator-server/src/settings.rs (4 hunks)
💤 Files with no reviewable changes (1)
  • multichain-aggregator/multichain-aggregator-logic/src/clients/token_info.rs
🧰 Additional context used
🪛 GitHub Actions: Test, lint and docker (multichain-aggregator)
multichain-aggregator/Cargo.toml

[error] Failed to load manifest for workspace member. Dependency 'contracts-info-proto' could not be found because its Cargo.toml file is missing at '/home/runner/work/blockscout-rs/blockscout-rs/contracts-info-proto/Cargo.toml'

🔇 Additional comments (13)
multichain-aggregator/multichain-aggregator-logic/src/types/token_info.rs (2)

13-16: Validate optional fields in unit tests.

The token_name and token_symbol fields are enforced via ok_or_else(...). Ensure there are test cases covering missing values to verify the error handling logic.


26-29: Confirm chain ID parsing for edge cases.

While the try_into() approach is correct, consider adding coverage for edge values (e.g., 0, negative numbers if relevant, etc.) to ensure that this error handling is robust.

multichain-aggregator/multichain-aggregator-server/src/server.rs (1)

72-76: Verify error handling for asynchronous client creation.

token_info::Client::new(config).await likely returns a Result; confirm that any potential errors (e.g., invalid URL, timeout) are handled or bubbled up. If needed, add a ? or handle it explicitly.

multichain-aggregator/multichain-aggregator-server/src/settings.rs (2)

7-8: Good use of serde_as for custom serialization.

This makes it straightforward to store duration fields in seconds while maintaining a std::time::Duration in code.


93-93: Highlight usage of a default timeout in the default settings.

The default function sets a fallback of 5 seconds. Confirm this is clear in any configuration docs to prevent confusion.

multichain-aggregator/multichain-aggregator-logic/src/search.rs (2)

4-4: Confirm compatibility with external references.

Importing Client and SearchTokenInfosRequest from the new proto-based module is a solid step. Ensure all call sites and references (e.g., testing code, integration points) are updated to use these new imports to avoid potential mismatches.


41-41: Ensure uniform interface updates.

Switching from &HttpApiClient to &Client requires consistent updates throughout the codebase (e.g., function calls, trait implementations). Double-check that no references to HttpApiClient remain where they should now be Client.

multichain-aggregator/multichain-aggregator-server/src/services/multichain_aggregator.rs (2)

13-13: Check the scoping of re-exports.

Re-exporting endpoints::SearchTokenInfos and proto::SearchTokenInfosRequest consolidates usage under token_info. Confirm that any existing aliases or references to removed modules (if any) are now correctly mapped here.


39-39: Maintain consistency in constructor parameters.

Passing token_info_client: token_info::Client consistently across constructors helps reduce confusion. Double-check that all services and tests requiring this struct are aligned with the new signature.

multichain-aggregator/multichain-aggregator-logic/Cargo.toml (1)

24-24: Confirm version alignment.

Adding contracts-info-proto = { workspace = true } indicates a new shared dependency. Verify that the workspace’s contracts-info-proto version is compatible with the logic requiring it, and ensure no version drift exists in related crates.

multichain-aggregator/multichain-aggregator-server/Cargo.toml (2)

22-22: Evaluate necessity of serde_with.

serde_with can simplify serialization and deserialization of certain patterns (e.g., flattening, specialized date/time formats). Confirm that it’s indeed needed and used. Otherwise, removing it can help keep dependencies minimal.


35-35: Confirm consistency in reqwest features.

Refactoring reqwest usage with features = ["json"] is clean. Verify no other feature sets (e.g., gzip) are required for production usage to avoid unexpected runtime failures.

multichain-aggregator/Cargo.toml (1)

34-34: Verify the http-client feature configuration.

Let's verify that the http-client feature is correctly defined in the contracts-info-proto crate.

🧰 Tools
🪛 GitHub Actions: Test, lint and docker (multichain-aggregator)

[error] Failed to load manifest for workspace member. Dependency 'contracts-info-proto' could not be found because its Cargo.toml file is missing at '/home/runner/work/blockscout-rs/blockscout-rs/contracts-info-proto/Cargo.toml'

Comment on lines +126 to +131
let token_info_search_endpoint = SearchTokenInfos::new(SearchTokenInfosRequest {
query: inner.q.to_string(),
chain_id,
page_size: inner.page_size,
page_token: inner.page_token,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implement thorough error handling & boundary checks.

Using SearchTokenInfos::new(...) with user-supplied parameters is good. Ensure validations are performed on inner.q, inner.page_size, etc., to avoid potential large or invalid requests. Consider falling back to default values or returning errors if the user input is out of range.

Comment on lines +33 to +34
# clients
contracts-info-proto = { path = "../contracts-info-proto", features = ["http-client"] }
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix the dependency path to resolve build failure.

The pipeline is failing because the contracts-info-proto dependency cannot be found at the specified path ../contracts-info-proto. This indicates that either:

  1. The repository structure is different from what's expected
  2. The dependency path needs to be adjusted

To resolve this, we need to verify the correct path to the dependency. Please run this script to check the repository structure:

#!/bin/bash
# Description: Check repository structure and find the contracts-info-proto directory

echo "Searching for contracts-info-proto directory..."
fd -t d "contracts-info-proto$"

echo -e "\nChecking if the directory exists at ../contracts-info-proto..."
if [ -d "../contracts-info-proto" ]; then
    echo "Directory exists at ../contracts-info-proto"
    if [ -f "../contracts-info-proto/Cargo.toml" ]; then
        echo "Cargo.toml exists in the directory"
    else
        echo "Cargo.toml is missing"
    fi
else
    echo "Directory does not exist at ../contracts-info-proto"
fi
🧰 Tools
🪛 GitHub Actions: Test, lint and docker (multichain-aggregator)

[error] Failed to load manifest for workspace member. Dependency 'contracts-info-proto' could not be found because its Cargo.toml file is missing at '/home/runner/work/blockscout-rs/blockscout-rs/contracts-info-proto/Cargo.toml'

@lok52 lok52 changed the title feat: update token-info client feat(multichain): update token-info client Jan 24, 2025
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