Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

Fix the missing challenge in the send message response for backwards compatibility.

Note

Fixes #6674

@Teebor-Choka Teebor-Choka added the bug Something isn't working label Jan 7, 2025
@Teebor-Choka Teebor-Choka added this to the 2.2.0-rc.1 milestone Jan 7, 2025
@Teebor-Choka Teebor-Choka requested a review from a team January 7, 2025 13:41
@Teebor-Choka Teebor-Choka self-assigned this Jan 7, 2025
Copy link
Contributor

coderabbitai bot commented Jan 7, 2025

Caution

Review failed

The head commit changed during the review from cdb5e9d to 7f98ee3.

📝 Walkthrough

Walkthrough

The changes modify the SendMessageResponse struct in the REST API messages module to include a new challenge field of type Hash. This addition enhances the message sending response by introducing a cryptographic challenge alongside the existing timestamp. The implementation ensures backward compatibility by serializing the new field as a string and maintaining the previous response structure. Additionally, the version of the tower dependency in the Cargo.toml file has been updated.

Changes

File Change Summary
hoprd/rest-api/src/messages.rs - Added new challenge: Hash field to SendMessageResponse struct
- Updated send_message function to include challenge in response
hoprd/rest-api/Cargo.toml - Updated tower dependency version from 0.5.1 to 0.5.2

Assessment against linked issues

Objective Addressed Explanation
Backwards incompatible response for POST /api/v3/messages [#6674]

The changes align with the requirement for modifying the message sending API response by introducing a new challenge field while maintaining compatibility with existing implementations.

Finishing Touches

  • 📝 Generate Docstrings

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.

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.

@Teebor-Choka Teebor-Choka marked this pull request as ready for review January 7, 2025 13:41
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 comments (1)
hoprd/rest-api/src/messages.rs (1)

Add tests for SendMessageResponse and its challenge field

The codebase analysis confirms that while there are tests for request serialization, there are no tests covering the SendMessageResponse struct and its challenge field. Consider adding tests to verify:

  • JSON serialization/deserialization of SendMessageResponse
  • Proper handling of the challenge field
  • Response format validation
🔗 Analysis chain

Line range hint 1-1: Add tests for the challenge field.

The changes lack test coverage for the new challenge field in SendMessageResponse. Consider adding tests to verify:

  1. Challenge serialization/deserialization
  2. Challenge presence in the response
  3. Challenge format validation
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for existing tests related to SendMessageResponse
rg -l "SendMessageResponse" --type rust --glob "*test*.rs"

Length of output: 58


Script:

#!/bin/bash
# Find SendMessageResponse struct definition
ast-grep --pattern 'struct SendMessageResponse'

# Find test modules or files in the same directory
fd messages_test.rs
fd "messages.rs$" --exec dirname {} \; | xargs -I {} fd -t f "test" {}

Length of output: 188


Script:

#!/bin/bash
# Find SendMessageResponse struct definition
rg "struct SendMessageResponse" --type rust

# Look for test modules in rest-api
fd -t f . hoprd/rest-api/src -E vendor | grep -E "(test|spec).*\.rs$"

# Find test-related content in messages.rs
rg "#\[test\]|#\[cfg\(test\)\]" hoprd/rest-api/src/messages.rs

Length of output: 290


Script:

#!/bin/bash
# Get the test module content from messages.rs
rg -A 20 "#\[cfg\(test\)\]" hoprd/rest-api/src/messages.rs

Length of output: 628


Script:

#!/bin/bash
# Get complete test module content
rg -A 50 "#\[cfg\(test\)\]" hoprd/rest-api/src/messages.rs

Length of output: 1495

🧹 Nitpick comments (1)
hoprd/rest-api/src/messages.rs (1)

95-97: Update schema example to include the challenge field.

The schema example above the struct (line 82) should be updated to include the new challenge field for accurate API documentation.

 #[schema(example = json!({
-        "timestamp": 2147483647
+        "timestamp": 2147483647,
+        "challenge": "0x1234567890abcdef" // Replace with appropriate example hash
     }))]
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07935a2 and c6aa33f.

📒 Files selected for processing (1)
  • hoprd/rest-api/src/messages.rs (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: hoprd / docker
  • GitHub Check: hopli / docker
  • GitHub Check: Docs / Rust docs
  • GitHub Check: tests-smoke-websocket
  • GitHub Check: tests-smart-contracts
  • GitHub Check: tests-unit-nightly
  • GitHub Check: tests-unit
  • GitHub Check: Linter
🔇 Additional comments (2)
hoprd/rest-api/src/messages.rs (2)

12-12: LGTM!

The import of Hash type is correctly added and necessary for the new challenge field.


Line range hint 1-1: Verify websocket compatibility with the challenge field.

The websocket implementation might need to be updated to handle the challenge field consistently with the REST API changes.

Copy link
Contributor

@NumberFour8 NumberFour8 left a comment

Choose a reason for hiding this comment

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

Bump crate version

@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label Jan 7, 2025
@Teebor-Choka Teebor-Choka force-pushed the kauki/bug/challenge-missing-from-send-message-response branch from 7c24265 to 80a7272 Compare January 8, 2025 14:03
@Teebor-Choka Teebor-Choka force-pushed the kauki/bug/challenge-missing-from-send-message-response branch from 80a7272 to cdb5e9d Compare January 9, 2025 12:56
@Teebor-Choka Teebor-Choka merged commit 3f37387 into master Jan 9, 2025
29 checks passed
@Teebor-Choka Teebor-Choka deleted the kauki/bug/challenge-missing-from-send-message-response branch January 9, 2025 14:21
@coderabbitai coderabbitai bot mentioned this pull request Jan 17, 2025
2 tasks
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 dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[2.2] POST /api/v3/messages - backwards incompatible response
3 participants