Skip to content

Conversation

jeandemeusy
Copy link
Contributor

Opening a channel requires an Address as peer_address.
When introducing the PeerOrAddress, the peer_address field was replaced by destination which allows both PeerId and Address to be used, but this is a breaking change.
To avoid breaking changes, both previous and new field where set to be accepted, but a typo has been done: instead of accepting an Address it was set to accept a PeerId.

Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request focus on the OpenChannelBodyRequest structure within the hoprd/rest-api/src/channels.rs file. The peer_id field has been replaced with peer_address, changing its type from Option<hopr_lib::PeerId> to Option<hopr_lib::Address>. The open_channel function has been updated to use this new field, ensuring that the logic for processing the request remains consistent while adapting to the new structure.

Changes

File Change Summary
hoprd/rest-api/src/channels.rs Updated OpenChannelBodyRequest structure: replaced peer_id with peer_address of type Option<hopr_lib::Address>. Modified open_channel function to utilize peer_address instead of peer_id.

Possibly related PRs

  • Fix backwards compatibility with the 2.1.x #6595: This PR modifies the hoprd/rest-api/src/channels.rs file, specifically in the open_channel function, which is directly related to the changes made in the main PR regarding the OpenChannelBodyRequest structure and the handling of the peer_id and destination fields.

Suggested labels

dependencies, crate:hoprd-api

Suggested reviewers

  • tolbrino

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.

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: 0

🧹 Outside diff range and nitpick comments (1)
hoprd/rest-api/src/channels.rs (1)

257-257: Update struct documentation to clarify field usage

The struct documentation should be updated to clarify:

  1. The relationship between destination and peer_address fields
  2. That peer_address is provided for API v2.2 compatibility

Add the following documentation above the struct:

 #[derive(Debug, Clone, Deserialize, utoipa::ToSchema)]
 #[serde(rename_all = "camelCase")]
 #[schema(example = json!({
         "amount": "10",
         "destination": "0xa8194d36e322592d4c707b70dbe96121f5c74c64"
     }))]
+/// Request body for opening a channel.
+///
+/// For compatibility with API v2.2, this struct accepts either:
+/// - `destination`: The preferred way to specify the counterparty using PeerOrAddress
+/// - `peer_address`: Legacy way to specify the counterparty using Address (API v2.2)
 pub(crate) struct OpenChannelBodyRequest {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bf696e4 and 99e1740.

📒 Files selected for processing (1)
  • hoprd/rest-api/src/channels.rs (2 hunks)
🔇 Additional comments (2)
hoprd/rest-api/src/channels.rs (2)

311-312: LGTM! Implementation correctly handles API v2.2 compatibility

The changes properly handle both the new destination field and the legacy peer_address field, maintaining backward compatibility with API v2.2 while supporting the new PeerOrAddress type.


Line range hint 257-312: Verify API documentation and test coverage

Since this change affects the API contract, we should verify:

  1. API documentation is updated
  2. Test coverage exists for both new and legacy field usage
✅ Verification successful

API contract changes are properly documented and handled

The verification shows that:

  1. The peer_address field is properly documented in the OpenAPI schema through utoipa annotations
  2. The code handles both destination and peer_address fields in a backward-compatible way
  3. The API documentation in the route handler correctly describes the request body and possible responses
  4. The changes are consistent across the codebase with no outdated references

The implementation maintains backward compatibility while introducing the new field, and all documentation is up-to-date.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for API documentation files
echo "Checking for API documentation files..."
fd -e md -e yaml -e json "api|swagger|openapi"

# Check for test files
echo "Checking for related test files..."
fd -e rs "test.*channel"

# Check for usage of peer_address in tests
echo "Checking for peer_address usage in tests..."
rg -l "peer_address.*test" -g "*.rs"

Length of output: 622


Script:

#!/bin/bash
# Let's search for test files and peer_address usage more broadly
echo "Searching for channel-related test files..."
rg "mod test" -A 5 -g "*channel*.rs"

echo "Searching for peer_address usage..."
rg "peer_address" -B 2 -A 2 -g "*.rs"

# Check for API documentation in the specific REST API module
echo "Checking REST API documentation..."
rg "#\[utoipa::path" -A 10 -g "*channels.rs"

# Look for OpenChannelBodyRequest usage
echo "Checking OpenChannelBodyRequest usage..."
rg "OpenChannelBodyRequest" -g "*.rs"

Length of output: 14160

@Teebor-Choka Teebor-Choka added this to the 2.2.0-rc.1 milestone Nov 18, 2024
@Teebor-Choka Teebor-Choka added the bug Something isn't working label Nov 18, 2024
@Teebor-Choka Teebor-Choka merged commit 773d846 into master Nov 18, 2024
30 checks passed
@Teebor-Choka Teebor-Choka deleted the jean/api-fix-compatibility branch November 18, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crate:hoprd-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Backwards incompatible changes in api/v3/messages and api/v3/channels route in 2.2.0
2 participants