-
Notifications
You must be signed in to change notification settings - Fork 97
Fix backwards compatibility to 2.1.x in ack
and ticket_aggregation
protocol
#6751
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
Conversation
📝 Walkthrough📝 WalkthroughWalkthroughThe pull request introduces changes across multiple files, primarily focusing on testing and structural modifications. A new test for binary compatibility of the Changes
Assessment against linked issues
Suggested Labels
Suggested Reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
6d53f46
to
da0d728
Compare
da0d728
to
bb3da6b
Compare
There was a problem hiding this 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:
- Why this specific binary representation is considered the correct v2 format
- What are the key differences between v2 and other versions
- 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
andOffchainSignature
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:
- Adding a comment explaining why these changes need to be reverted in 3.0
- Creating tracking issues for the 3.0 changes
- Documenting the compatibility implications of these changes
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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
andtransport/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
There was a problem hiding this 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 efficiencyWhile the test effectively verifies binary compatibility, consider these improvements:
- Document the significance of the test vector values and which versions are being tested for compatibility
- 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
⛔ 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:
- Requests are sent through a bounded channel (
TICKET_AGGREGATION_RX_QUEUE_SIZE
) - Processing happens in a dedicated async task that serializes access
- 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:
- The field is used in ticket aggregation responses where direct access is needed (as seen in
transport/p2p/src/swarm.rs
witht.0
) - The struct is already marked as legacy and intended for binary format compatibility with 2.x releases
- The module comment indicates this entire module will be removed in 3.0
- 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
ack
protocolack
and ticket_aggregation
protocol
Fixes failing test for the backwards compatibility issue, where the internal representation of the
OffchainSigner
:ack
binary formatticket aggregation
binary formatNotes
Fixes #6738