Skip to content

Conversation

jeandemeusy
Copy link
Contributor

@jeandemeusy jeandemeusy commented Apr 16, 2025

This pull request introduces several updates across the codebase, focusing on improving test execution, enhancing REST API responses, refining error handling, and updating dependencies. Below is a categorized summary of the most important changes:

Test Execution Updates:

  • Updated the Makefile to replace source .venv/bin/activate with uv run for running tests and local clusters, streamlining the test execution process. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L68-R72), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-76ed074a9305c04054cdebb9e9aad2d818052b07091de1f20cad0bbac34ffb52L100-R99))

REST API Enhancements:

  • Introduced a new FundChannelResponse struct to standardize the response for funding a channel. This replaces the plain string response with a structured JSON object. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-1df3f9bf9a8abe27e00d7f7721d0e8591f2e91f66c160bf2075d38895d759a63R464-R475), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-1df3f9bf9a8abe27e00d7f7721d0e8591f2e91f66c160bf2075d38895d759a63L487-R499), [[3]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-1df3f9bf9a8abe27e00d7f7721d0e8591f2e91f66c160bf2075d38895d759a63L512-R524))
  • Added a NodeGraphResponse struct for the channel graph API, improving the clarity and structure of the response. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-5bf6b6849c16ea33849b2bfa103b6a590f9a63d21d204b3b730a5c873c03e366R308-R326), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-5bf6b6849c16ea33849b2bfa103b6a590f9a63d21d204b3b730a5c873c03e366L329-R341))
  • Changed the node configuration API to return a HashMap<String, String> wrapped in JSON instead of a plain string. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-5bf6b6849c16ea33849b2bfa103b6a590f9a63d21d204b3b730a5c873c03e366L56-R56), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-5bf6b6849c16ea33849b2bfa103b6a590f9a63d21d204b3b730a5c873c03e366L66-R66))

Error Handling Improvements:

  • Enhanced error messages in the Python localcluster module by including more descriptive runtime errors when nodes fail to connect or return addresses. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-bf5445bb6294f658842ba0530a55f4f2768ccb7ec59cfc3c1b5b4122460413acL80-R88), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-bf5445bb6294f658842ba0530a55f4f2768ccb7ec59cfc3c1b5b4122460413acL104-R102))
  • Added a new exception handler for RuntimeError in the bringup function to log errors more effectively. ([sdk/python/localcluster/main_process.pyR93-R95](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-fd306027f1b9a2d4cd8aa6774752b44d64b9aabc2059bd9370fb4e0ac17b3dc2R93-R95))

Dependency and Configuration Updates:

  • Updated the pyproject.toml files for sdk-api and sdk-localcluster to increment the version and add new dependencies (click for sdk-localcluster). ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-9b29183277b4bc5d50a3aab7ac0ced8e5312f131a7bb35c9c47f812d7c318ceaL3-R3), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-b59227696d090d8af77ffda26d7a4e5df1c9e8aaa6a4d6b2246f455563e307e6L3-R5))
  • Removed the python39 dependency from the flake.nix file, likely reflecting a migration to newer Python versions. ([flake.nixL370](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-206b9ce276ab5971a2489d75eb1b12999d4bf3843b7988cbe8d687cfde61dea0L370))

Logging Refinements:

  • Improved logging messages for better clarity, such as changing "Stop all local anvil servers running" to "Stopping all local anvil servers running" and using logging.warning instead of logging.info for missing snapshot files. ([[1]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-cd8a3595eb1086da0b25341ce323deb7b3c1548af6e1d119a4daa92658bc5c44L68-R68), [[2]](https://github.com/hoprnet/hoprnet/pull/7072/files#diff-eebeffea190caf0c5a0607cd56485da81d9d809ab8552f9c8a450dd3ccf80924L84-R84))

@jeandemeusy jeandemeusy self-assigned this Apr 16, 2025
Copy link
Contributor

coderabbitai bot commented Apr 16, 2025

📝 Walkthrough

Walkthrough

The changes introduce structured response types for several REST API endpoints, update OpenAPI documentation to reflect these types, and refine Python SDK methods to extract specific fields from API responses. Build and test scripts are updated to use uv run for Python execution, and project metadata is revised with new versions and dependencies. Logging and error handling are also adjusted in the local cluster management scripts.

Changes

File(s) Change Summary
Makefile Updated test and local cluster targets to use uv run -m for Python module execution, replacing direct virtual environment activation and python3 calls.
flake.nix Removed python39 from the Docker image build contents.
hoprd/rest-api/src/channels.rs Introduced FundChannelResponse struct and updated the fund_channel endpoint to return this structured response instead of a raw string; updated API documentation accordingly.
hoprd/rest-api/src/node.rs Introduced NodeGraphResponse struct; changed /node/configuration to return a JSON object; changed /node/graph to return a structured response; updated OpenAPI docs.
hoprd/rest-api/src/lib.rs Added new response types (FundChannelResponse, NodeGraphResponse) to the OpenAPI schema components list.
sdk/python/api/hopr.py Modified config and metrics methods to extract and return specific nested fields from API responses, improving data precision.
sdk/python/api/pyproject.toml Bumped version from 1.0.0 to 1.0.1.
sdk/python/localcluster/anvil.py Minor logging message adjustments for clarity; no logic changes.
sdk/python/localcluster/cluster.py Removed explicit logging before raising RuntimeError in the shared_bringup method.
sdk/python/localcluster/main_process.py Added error handling for RuntimeError in the bringup async function, logging the error and returning early.
sdk/python/localcluster/pyproject.toml Bumped version to 1.0.1; added click dependency (>=8.1.8).
sdk/python/localcluster/snapshot.py Changed log level from info to warning when expected snapshot files are missing.

Sequence Diagram(s)

REST API: Funding a Channel (Updated Response)

sequenceDiagram
    participant Client
    participant REST-API
    participant ChannelLogic

    Client->>REST-API: POST /channels/fund
    REST-API->>ChannelLogic: fund_channel()
    ChannelLogic-->>REST-API: Hash (transaction hash)
    REST-API-->>Client: JSON { "hash": "<transaction_hash>" }
Loading

REST API: Node Graph Retrieval (Updated Response)

sequenceDiagram
    participant Client
    participant REST-API
    participant NodeLogic

    Client->>REST-API: GET /node/graph
    REST-API->>NodeLogic: get_graph()
    NodeLogic-->>REST-API: String (graph data)
    REST-API-->>Client: JSON { "graph": "<graph_data>" }
Loading

Python SDK: Configuration and Metrics Retrieval

sequenceDiagram
    participant SDK
    participant API
    participant Server

    SDK->>API: GET /config
    API->>Server: Request config
    Server-->>API: { "config": {...} }
    API-->>SDK: Configuration object from "config" field

    SDK->>API: GET /metrics
    API->>Server: Request metrics
    Server-->>API: { "metrics": {...} }
    API-->>SDK: "metrics" field if successful, else None
Loading

Possibly related PRs

  • Extend usage of uv #6997: Changes Makefile targets to replace direct Python virtual environment activation and python3 -m pytest calls with uv run -m pytest invocations, closely related to the current updates in test command execution.

Suggested labels

component:api, testing

Suggested reviewers

  • Teebor-Choka

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 978d9b0 and 4e0d3aa.

📒 Files selected for processing (1)
  • sdk/python/api/hopr.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/python/api/hopr.py
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: hoprd / docker
  • GitHub Check: tests-unit-nightly
  • GitHub Check: Cargo Audit
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@github-actions github-actions bot added dependencies Pull requests that update a dependency file toolchain Developer and product happiness crate:hoprd-api labels Apr 16, 2025
@jeandemeusy jeandemeusy linked an issue Apr 16, 2025 that may be closed by this pull request
@Teebor-Choka
Copy link
Contributor

I don't see such a problem with having types like Hash the single output from the query.

@jeandemeusy
Copy link
Contributor Author

I don't see such a problem with having types like Hash the single output from the query.

Michal complains about having plain-text responses and objects. If everything is an object it's simpler to decode once the response is received.
A Hash type as single output will be sent as plain-text, thus bothering Michal.

@tolbrino tolbrino added this to the 3.0.0 milestone Apr 29, 2025
@jeandemeusy jeandemeusy requested a review from Teebor-Choka May 7, 2025 09:24
@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label May 12, 2025
@jeandemeusy jeandemeusy enabled auto-merge May 13, 2025 11:29
@jeandemeusy jeandemeusy added this pull request to the merge queue May 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 13, 2025
@jeandemeusy jeandemeusy added this pull request to the merge queue May 13, 2025
Merged via the queue into master with commit cdfa19b May 13, 2025
27 of 30 checks passed
@jeandemeusy jeandemeusy deleted the jean/api-return-objects-only branch May 13, 2025 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate:hoprd-api toolchain Developer and product happiness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

All API returns should be objects
4 participants