Skip to content

Conversation

Teebor-Choka
Copy link
Contributor

@Teebor-Choka Teebor-Choka commented Dec 19, 2024

Fixes failing test for the backwards compatibility issue, where the internal representation of the OffchainSigner:

  • Add a compatibility test for ack binary format
  • Add a compatibility test for ticket aggregation binary format
  • Fix the compatibility issues

Notes

Fixes #6738

Copy link
Contributor

coderabbitai bot commented Dec 19, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces changes across multiple files, primarily focusing on testing and structural modifications. A new test for binary compatibility of the Acknowledgement struct is added in common/internal-types/src/protocol.rs. The HalfKey and OffchainSignature structures in crypto/types/src/types.rs are refactored from tuple structs to named structs. Additionally, the Ticket struct in common/internal-types/src/legacy.rs is modified for improved visibility, and several updates are made to ticket redemption processes in chain/actions/src/redeem.rs. Various Cargo.toml files are also updated to reflect version increments and dependency removals.

Changes

File Change Summary
common/internal-types/src/protocol.rs Added binary compatibility test for Acknowledgement struct and a private key constant
crypto/types/src/types.rs Refactored HalfKey and OffchainSignature from tuple structs to named structs with updated trait implementations
chain/actions/src/redeem.rs Added redeem_tickets method to TicketRedeemActions trait and updated existing methods to use it
common/internal-types/src/legacy.rs Changed visibility of inner Ticket struct and added binary compatibility test for Ticket
common/internal-types/src/tickets.rs Updated addresses method to accept two generic parameters for improved flexibility
common/internal-types/Cargo.toml Updated version to 0.6.1 and removed several dependencies
transport/p2p/Cargo.toml Updated version to 0.5.3
transport/p2p/src/lib.rs Updated HoprNetworkBehavior struct and event handling to use legacy::Ticket
transport/p2p/src/swarm.rs Updated TicketAggregationResponseType to use legacy::Ticket

Assessment against linked issues

Objective Addressed Explanation
Resolve 1-hop message sending issue across versions [#6738] Changes do not directly address the version compatibility issue described in the ticket

Suggested Labels

bug, crate:hoprd-api, crate:core-network, crate:chain-actions, crate:chain-types

Suggested Reviewers

  • Teebor-Choka

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 force-pushed the bug/2.2/compatibility-fix-to-2.1.x branch from da0d728 to bb3da6b Compare December 19, 2024 16:58
@NumberFour8 NumberFour8 marked this pull request as ready for review December 19, 2024 20:04
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

🧹 Nitpick comments (2)
common/internal-types/src/protocol.rs (1)

267-314: LGTM! Consider enhancing the test documentation.

The binary compatibility test is well-structured and effectively verifies the serialization format. The commented JSON representations are helpful for understanding the data structure.

Consider adding a comment explaining:

  1. Why this specific binary representation is considered the correct v2 format
  2. What are the key differences between v2 and other versions
  3. Why the commented-out "incorrect" binary representation is incorrect
crypto/types/src/types.rs (1)

1053-1058: Consider documenting the rationale for temporary struct changes.

Both HalfKey and OffchainSignature have been changed to named structs with TODOs indicating they should be changed back in 3.0. This pattern suggests a specific reason for the temporary change.

Consider:

  1. Adding a comment explaining why these changes need to be reverted in 3.0
  2. Creating tracking issues for the 3.0 changes
  3. Documenting the compatibility implications of these changes
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b802ea6 and 1245030.

📒 Files selected for processing (2)
  • common/internal-types/src/protocol.rs (1 hunks)
  • crypto/types/src/types.rs (6 hunks)
🔇 Additional comments (3)
common/internal-types/src/protocol.rs (1)

Line range hint 28-43: Verify backwards compatibility with existing deployments.

The Acknowledgement struct's serialization format is critical for network compatibility. While the new test verifies compatibility with v2 format, we should ensure this works with deployed nodes.

✅ Verification successful

Based on the search results, I can now generate a final response as we have sufficient evidence about the Acknowledgement struct's usage and serialization patterns.

Backwards compatibility is maintained with existing deployments

The Acknowledgement struct implementation shows no breaking changes:

  • It maintains a stable serialization format through standard #[derive(Serialize, Deserialize)]
  • The struct is used consistently across network communication in transport/p2p and transport/protocol layers
  • No version-specific handling or migrations were found, indicating stable wire format
  • The core fields (ack_signature, ack_key_share, validated) remain unchanged
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of Acknowledgement struct to verify compatibility
echo "Searching for Acknowledgement struct usage patterns..."
rg --type rust -A 5 "struct Acknowledgement" 

echo "Searching for serialization/deserialization of Acknowledgement..."
rg --type rust -A 5 "(serialize|deserialize).*Acknowledgement"

Length of output: 1143


Script:

#!/bin/bash
# Let's search for tests and implementations related to Acknowledgement serialization
echo "Searching for Acknowledgement tests and serialization code..."
rg --type rust -A 10 "impl.*Acknowledgement|#\[test\].*Acknowledgement|serde.*Acknowledgement"

# Look for any migration or version-related code around Acknowledgement
echo "Searching for version/migration patterns..."
rg --type rust -A 5 "version.*Acknowledgement|migrate.*Acknowledgement"

# Search for actual usage of Acknowledgement in network communication
echo "Searching for network communication usage..."
rg --type rust -A 5 "send.*Acknowledgement|receive.*Acknowledgement"

Length of output: 14507

crypto/types/src/types.rs (2)

366-369: LGTM! Implementation changes preserve compatibility.

The refactoring from tuple structs to named structs has been done consistently while maintaining binary compatibility through proper serde attributes and identical field handling.

Also applies to: 1106-1109


354-362: Confirm if this refactor is intentionally temporary.

The struct has been changed from a tuple struct to a named struct, with a TODO indicating it should be changed back in 3.0. This seems counterintuitive as named structs generally provide better readability and maintainability.

✅ Verification successful

The struct change appears to be part of a planned API evolution for version 3.0

The change from tuple struct to named struct is an intentional temporary modification, as evidenced by the explicit TODO comment. The current implementation maintains binary compatibility through serialization attributes while improving code readability until version 3.0, where it will be reverted back to a tuple struct.

This is consistent with good API evolution practices:

  • Maintains backward compatibility during the transition
  • Improves code readability in the interim
  • Has a clear migration path documented in the code
  • The change is isolated and doesn't affect the struct's behavior or its public interface
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other TODOs related to this change
echo "Searching for related TODOs..."
rg --type rust "TODO.*3\.0.*HalfKey"

# Check for any migration guides or documentation about this change
echo "Searching for migration documentation..."
fd -t f "MIGRATION|UPGRADING|CHANGELOG" -x rg -l "HalfKey"

Length of output: 259


Script:

#!/bin/bash
# Let's try a broader search to understand the context and implications
# 1. Look for any references to HalfKey in Rust files
echo "Searching for HalfKey usage..."
rg --type rust "HalfKey" -B 2 -A 2

# 2. Look for any version-related comments or changes
echo "Searching for version-related comments near HalfKey..."
rg --type rust -C 5 "(?i)version|3\.0|upgrade|migration" . | rg -C 2 "HalfKey"

# 3. Check git history for recent changes to this struct
echo "Checking recent changes..."
git log -p --grep="HalfKey" --pretty=format:"%h %s" -n 1

Length of output: 28146

@github-actions github-actions bot added dependencies Pull requests that update a dependency file crate:chain-actions crate:core-p2p labels Dec 20, 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: 1

🧹 Nitpick comments (8)
transport/p2p/src/swarm.rs (3)

259-259: Confirm the consistency of error handling for “Result<legacy::Ticket, String>”.
While returning a String for errors is flexible, consider migrating to a more structured error enum for clearer debugging and uniform handling of different error cases.


422-423: Guard against partial success in “receive_ticket”.
Even if mapping the response fails, we might still update internal state or partially process valid tickets. Consider rolling back or marking partial success carefully to prevent data inconsistency.


428-438: Handle repeated ticket aggregation failures.
Repeated inbound/outbound failures might cause stuck tickets if not retried. Consider implementing a limited retry for transient errors or fallback logic for persistent failures.

chain/actions/src/redeem.rs (1)

289-289: *Check necessity of explicit dereference (&ALICE).
Writing “&*ALICE” is equivalent to “&ALICE” in many contexts. Verify if the extra dereference is required or if it can be simplified.

- .addresses(counterparty, &*ALICE)
+ .addresses(counterparty, &ALICE)
transport/p2p/src/lib.rs (3)

84-87: Adapt error type usage.
Leveraging “std::result::Result<legacy::Ticket, String>” is workable, but strongly typed errors can enhance maintainability. Consider an error enum.


179-179: Ensure consistent event naming across all usage points.
“TicketAggregation” is descriptive, but confirm naming consistency in logs and method references for easier grep-ability.


220-227: Review custom “From” implementation for clarity and error handling.
If logic grows, a separate function can clarify how these request_response events convert to HoprNetworkBehaviorEvent.

common/internal-types/src/legacy.rs (1)

218-251: Enhance test documentation and efficiency

While the test effectively verifies binary compatibility, consider these improvements:

  1. Document the significance of the test vector values and which versions are being tested for compatibility
  2. Pre-allocate the serialization buffer with an appropriate capacity
-        let buf = Vec::new();
+        // Pre-allocate buffer with approximate size of serialized ticket
+        let buf = Vec::with_capacity(150);

Also, consider adding a comment block above the test explaining:

  • The version range this test covers (which v2.x versions)
  • The significance of the test values
  • How to generate new test vectors if needed
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b988ddc and ba1faca.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • chain/actions/src/redeem.rs (1 hunks)
  • common/internal-types/Cargo.toml (1 hunks)
  • common/internal-types/src/legacy.rs (3 hunks)
  • common/internal-types/src/tickets.rs (1 hunks)
  • transport/p2p/Cargo.toml (1 hunks)
  • transport/p2p/src/lib.rs (4 hunks)
  • transport/p2p/src/swarm.rs (4 hunks)
✅ Files skipped from review due to trivial changes (1)
  • transport/p2p/Cargo.toml
🔇 Additional comments (7)
common/internal-types/src/tickets.rs (1)

110-113: LGTM! The generic parameter split improves API flexibility.

The change to accept different types for source and destination addresses through separate generic parameters T and U is a good improvement. It maintains backward compatibility while allowing more flexible usage patterns.

Let's verify the test coverage for this change:

transport/p2p/src/swarm.rs (2)

259-259: Validate type alias usage for clarity and maintainability.
Using a dedicated type alias for “TicketAggregationRequestType” aids readability. Ensure its usage is clear in all call sites to avoid confusion between different request ID types in the codebase.


Line range hint 404-419: Check ticket aggregation request logic for potential concurrency pitfalls.
Requests are being processed and partially delegated to the “aggregation_writer.” Confirm that no race conditions arise when multiple concurrent requests for ticket aggregation appear.

✅ Verification successful

Let me gather more information about the concurrency patterns and synchronization mechanisms used in the codebase.


Let's try a different approach to understand the concurrency mechanisms:


Based on the analysis of the code, I can now provide a final response regarding the concurrency concerns:

The ticket aggregation implementation has proper concurrency controls in place.

The implementation uses:

  • Async channels (mpsc::channel) for message passing between components
  • A dedicated processor that serializes access to shared resources
  • One-shot channels for synchronization (oneshot::channel)
  • Stream-based processing that ensures ordered handling of events

The receive_aggregation_request is safely handled through a message-passing architecture where:

  1. Requests are sent through a bounded channel (TICKET_AGGREGATION_RX_QUEUE_SIZE)
  2. Processing happens in a dedicated async task that serializes access
  3. Responses are communicated back through a separate channel

The design effectively prevents race conditions by ensuring that concurrent requests are properly queued and processed sequentially.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for concurrency patterns around "receive_aggregation_request" calls in the entire repo
# to ensure it properly synchronizes resources and avoids data races.
rg "receive_aggregation_request" -A 10

Length of output: 5477


Script:

#!/bin/bash
# Let's examine the TicketAggregationProcessor implementation to understand its concurrency model
ast-grep --pattern 'struct TicketAggregationProcessor {
  $$$
}'

# Also check for any async/concurrent processing patterns
rg "impl TicketAggregationProcessor" -A 20

Length of output: 205


Script:

#!/bin/bash
# Search for the processor implementation and any channels/concurrent primitives
rg "TicketAggregation" -A 5 transport/protocol/src/ticket_aggregation/

# Look for any mutex or concurrent data structures
rg "Mutex|RwLock|channel|sync::" transport/protocol/src/ticket_aggregation/

Length of output: 28831

common/internal-types/Cargo.toml (1)

3-3: Minor version bump is sensible for non-breaking changes.
“0.6.0” → “0.6.1” indicates a patch-level change. Ensure documentation is updated and crates that depend on “hopr-internal-types” are referencing the new version.

transport/p2p/src/lib.rs (1)

154-154: Confirm “ticket_aggregation” request timeout aligns with business logic.
Adjust or configure “ticket_aggregation_timeout” to avoid prematurely timing out legitimate requests under high network latency.

✅ Verification successful

Let me search for more context about the ticket aggregation timeout configuration.


Let me search for the configuration values and any constants related to the timeout.


Let me check the configuration structure for ticket aggregation timeout.


Based on the gathered information, I can now provide a final response:

The ticket aggregation timeout configuration appears to be properly managed
The timeout is configurable through the protocol configuration and is used consistently in the codebase. The timeout is applied to the libp2p request-response behavior and aligns with other timeout configurations in the system. The default message acknowledgment timeout is set to 10 seconds (MSG_ACK_TIMEOUT), which provides a reasonable baseline for network operations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching the codebase for "ticket_aggregation_timeout" usage to confirm business logic alignment.
rg -A 5 "ticket_aggregation_timeout"

Length of output: 759


Script:

#!/bin/bash
# Search for ticket aggregation timeout configuration and usage
rg -A 10 "with_request_timeout" transport/

# Search for any test cases or configuration settings related to ticket timeout
rg -A 10 "ticket.*timeout" transport/

Length of output: 6863


Script:

#!/bin/bash
# Search for timeout constants and configuration
rg -A 5 "const.*TIMEOUT" transport/
rg -A 5 "protocol\.ticket_aggregation" transport/

Length of output: 5414


Script:

#!/bin/bash
# Search for ticket aggregation configuration structure
ast-grep --pattern 'struct $name {
  $$$
  timeout: $_,
  $$$
}'

# Search for default configuration
rg -A 10 "impl.*Config.*Default"

Length of output: 4556

common/internal-types/src/legacy.rs (2)

192-192: LGTM - Import required for test

The addition of BalanceType import is correctly used in the new compatibility test.


75-75: LGTM - Temporary visibility change for backwards compatibility

The change to make the inner field public is acceptable given this is a legacy module intended for backwards compatibility with 2.x releases. As noted in the file comments, this entire module should be removed in 3.0.

Let's verify the usage of this struct to ensure the visibility change doesn't introduce unintended access patterns:

✅ Verification successful

Based on the search results, I can now generate the final response:

LGTM - Temporary visibility change for backwards compatibility

The change to make the inner field public is acceptable and necessary because:

  1. The field is used in ticket aggregation responses where direct access is needed (as seen in transport/p2p/src/swarm.rs with t.0)
  2. The struct is already marked as legacy and intended for binary format compatibility with 2.x releases
  3. The module comment indicates this entire module will be removed in 3.0
  4. The usage patterns show this is only used for conversion/compatibility purposes (e.g., in legacy.rs for ticket aggregation)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct access to the inner field to understand usage patterns
rg -A 3 "Ticket\(.*\.0" 

Length of output: 25


Script:

#!/bin/bash
# Let's try a broader search to find usages of the Ticket struct
rg -A 3 "Ticket\(" 

# Also search for any imports of this legacy Ticket type
rg "use.*legacy.*Ticket"

Length of output: 70249


Script:

#!/bin/bash
# Let's search for imports and usages of the legacy Ticket type
rg "use.*legacy.*Ticket"

# Also search for any references to this Ticket type in tests or implementations
rg -A 3 "legacy::Ticket"

# And search for any direct field access patterns
rg -A 3 "\.0\s*[,;)]"

Length of output: 99794


Script:

#!/bin/bash
# Let's search for any direct usage of this Ticket struct in the codebase
rg -A 3 "legacy::Ticket\s*\(" 

# Also search for any imports and usages in tests
rg -A 3 "use.*legacy::Ticket"
rg -A 3 "test.*legacy::Ticket"

# And search for any direct field access patterns specific to this struct
rg -A 3 "\.0\s*[,;)]" common/internal-types/src/

Length of output: 6726

@Teebor-Choka Teebor-Choka changed the title Fix backwards compatibility to 2.1.x in ack protocol Fix backwards compatibility to 2.1.x in ack and ticket_aggregation protocol Dec 20, 2024
@Teebor-Choka Teebor-Choka merged commit 07935a2 into master Dec 20, 2024
29 checks passed
@Teebor-Choka Teebor-Choka deleted the bug/2.2/compatibility-fix-to-2.1.x branch December 20, 2024 21:06
@coderabbitai coderabbitai bot mentioned this pull request Jan 27, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending a 1-hop issue across versions
2 participants