Skip to content

Conversation

NumberFour8
Copy link
Contributor

The following changes were missed in the merge-back PRs from saint-louis:
- #6338
- #6437
@NumberFour8 NumberFour8 added this to the 2.2.0-rc.1 milestone Nov 7, 2024
@NumberFour8 NumberFour8 requested a review from a team November 7, 2024 17:39
@NumberFour8 NumberFour8 self-assigned this Nov 7, 2024
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes in this pull request involve modifications to the HOPR protocol's configuration and logic related to ticket redemption strategies. A new parameter, minimum_redeem_ticket_value, has been added to the configuration file, specifying the minimum HOPR value required for redeeming tickets. Additionally, the logic in the AutoRedeemingStrategy has been updated to reflect this new parameter, along with adjustments to existing values and the introduction of new functions. Documentation has also been refined for clarity, ensuring that the purpose of parameters is well understood.

Changes

File Change Summary
hoprd/hoprd/example_cfg.yaml - Added minimum_redeem_ticket_value (default: "2000000000000000000 HOPR").
- Updated on_close_redeem_single_tickets_value_min from "90000000000000000 HOPR" to "2000000000000000000 HOPR".
logic/strategy/src/auto_redeeming.rs - Replaced thirty_hopr with single_ticket_redeem (sets balance to 2 HOPR).
- Added min_redeem_hopr function (minimum redeemable balance of 90 HOPR).
- Updated AutoRedeemingStrategyConfig to include minimum_redeem_ticket_value.
- Modified on_acknowledged_winning_ticket to check against minimum_redeem_ticket_value.
- Updated on_own_channel_changed to ensure ticket redemption meets the new threshold.
logic/strategy/src/lib.rs - Updated variable name from on_close_redeem_single_tickets_value_min to minimum_redeem_ticket_value.
- Changed value for on_close_redeem_single_tickets_value_min to 2 HOPR.

Possibly related issues

Possibly related PRs

Suggested labels

crate:core-strategy, crate:hoprd, crate:hoprd-api

Suggested reviewers

  • QYuQianchen

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.

@NumberFour8 NumberFour8 marked this pull request as ready for review November 7, 2024 17:40
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 (3)
logic/strategy/src/auto_redeeming.rs (3)

31-35: Consider defining constants instead of functions for fixed values

Since single_ticket_redeem and min_redeem_hopr return fixed values without performing any computation, consider defining them as constants. This can improve readability and eliminate unnecessary function calls.

Apply this diff to refactor:

-fn single_ticket_redeem() -> Balance {
-    Balance::new_from_str("2000000000000000000", BalanceType::HOPR)
-}
+const SINGLE_TICKET_REDEEM: Balance = Balance::new_from_str("2000000000000000000", BalanceType::HOPR);

-fn min_redeem_hopr() -> Balance {
-    Balance::new_from_str("90000000000000000", BalanceType::HOPR)
-}
+const MIN_REDEEM_HOPR: Balance = Balance::new_from_str("90000000000000000", BalanceType::HOPR);

Then update references accordingly:

-#[serde(default = "single_ticket_redeem")]
+#[serde(default = "|| SINGLE_TICKET_REDEEM")]
-#[serde(default = "min_redeem_hopr")]
+#[serde(default = "|| MIN_REDEEM_HOPR")]

49-57: Ensure consistency in default value definitions

The default value for minimum_redeem_ticket_value is specified in both the min_redeem_hopr function and the #[default(...)] attribute. To avoid duplication and potential inconsistencies, consider defining the default value in one place.

You can remove the #[default(...)] attribute and rely on #[serde(default = "min_redeem_hopr")] (or || MIN_REDEEM_HOPR if converted to a constant):

-#[default(Balance::new_from_str("90000000000000000", BalanceType::HOPR))]
 pub minimum_redeem_ticket_value: Balance,

Alternatively, if you switch to constants:

#[serde(default = "|| MIN_REDEEM_HOPR")]
pub minimum_redeem_ticket_value: Balance,

285-285: Consider adding tests with non-zero minimum_redeem_ticket_value

In several tests, minimum_redeem_ticket_value is set to zero. Adding tests with non-zero values can help ensure consistent behavior across different configurations and catch potential edge cases.

Also applies to: 316-316, 397-397, 441-441

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between efa963d and f6d36a1.

📒 Files selected for processing (3)
  • hoprd/hoprd/example_cfg.yaml (1 hunks)
  • logic/strategy/src/auto_redeeming.rs (8 hunks)
  • logic/strategy/src/lib.rs (5 hunks)
🔇 Additional comments (8)
logic/strategy/src/lib.rs (4)

19-21: Documentation improvements look good!

The clarifications about CLI configuration limitations and the relationship with disableTicketAutoRedeem are accurate and helpful.


62-62: LGTM!

The documentation wording improvement maintains accuracy while being more straightforward.


121-121: Type alias addition improves code clarity!

The StrategyConfig alias provides a clear, descriptive name for the configuration type.


105-109: Please verify the significant difference in minimum redeem values

There's a notable difference between:

  • Normal operation minimum: 0.09 HOPR (minimum_redeem_ticket_value)
  • Channel close minimum: 2 HOPR (on_close_redeem_single_tickets_value_min)

This 22x difference in thresholds could impact ticket redemption behavior significantly.

hoprd/hoprd/example_cfg.yaml (2)

120-120: Verify the significant increase in minimum redemption value.

The value for on_close_redeem_single_tickets_value_min has been increased significantly from 90000000000000000 to 2000000000000000000 HOPR. This represents more than a 20x increase in the minimum value required for redeeming single tickets when a channel is closing.

Let's verify if this value aligns with other protocol configurations and documentation:

#!/bin/bash
# Search for documentation or test files that might reference these values
rg -B 2 -A 2 "2000000000000000000" --glob "*.{md,rs,js,ts}"

111-116: Consider aligning example values for consistency.

The commented example value for minimum_redeem_ticket_value (90000000000000000 HOPR) differs from the value used in on_close_redeem_single_tickets_value_min (2000000000000000000 HOPR). Consider aligning these values for consistency in the example configuration, as they serve similar purposes in different contexts.

Let's verify if these values are consistent with other configuration files:

logic/strategy/src/auto_redeeming.rs (2)

329-361: Excellent addition of tests for minimum_redeem_ticket_value logic

The test test_auto_redeeming_strategy_redeem_minimum_ticket_amount effectively verifies that tickets below the threshold are not redeemed and those at or above the threshold are redeemed. This enhances confidence in the correctness of the implementation.


104-106: Validate logical conditions for ticket redemption

The updated condition combines redeem_only_aggregated and minimum_redeem_ticket_value checks. Ensure that the parentheses accurately reflect the intended logic and consider adding unit tests for edge cases to confirm the behavior.

Run the following script to review logical conditions and their usage:

✅ Verification successful

The previous ast-grep pattern might have failed due to syntax. Let's search for the method implementation and test cases to verify the logical conditions.


Let's look at both the implementation and test cases to verify the logical conditions and their coverage.


Logical conditions in ticket redemption are correctly implemented

The code and tests confirm that the logical conditions for ticket redemption are properly implemented:

  1. The parentheses in the condition (!self.cfg.redeem_only_aggregated || ack.verified_ticket().is_aggregated()) && ack.verified_ticket().amount.ge(&self.cfg.minimum_redeem_ticket_value) correctly reflect the intended logic:

    • Either redeem all tickets (when redeem_only_aggregated is false) OR the ticket is aggregated
    • AND the ticket amount meets the minimum value threshold
  2. The test suite thoroughly verifies this logic through:

    • test_auto_redeeming_strategy_redeem_agg_only: Verifies aggregated-only redemption
    • test_auto_redeeming_strategy_redeem_minimum_ticket_amount: Validates minimum amount threshold
    • Additional edge cases for channel closing scenarios

The implementation is well-tested and the logical conditions are correctly structured.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the usage of logical conditions in 'on_acknowledged_winning_ticket' method.

# Test: Extract the condition and print it for review.
ast-grep --pattern $'fn on_acknowledged_winning_ticket($_) {
  if ($_ && $_) {
    $$$
  }
  $$$
}'

Length of output: 100


Script:

#!/bin/bash
# Let's try a different approach to find the method implementation
rg -U "fn on_acknowledged_winning_ticket.*?\{.*?\}" -A 20 --multiline

# Also search for related test cases
rg -l "test.*redeem" 

Length of output: 565


Script:

#!/bin/bash
# Let's examine the test file for redeeming
cat tests/test_redeeming.py

# And check the implementation in auto_redeeming.rs
cat logic/strategy/src/auto_redeeming.rs

Length of output: 28829

@NumberFour8 NumberFour8 enabled auto-merge November 7, 2024 18:06
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 7, 2024
@NumberFour8 NumberFour8 added this pull request to the merge queue Nov 7, 2024
@NumberFour8 NumberFour8 removed this pull request from the merge queue due to a manual request Nov 7, 2024
@NumberFour8 NumberFour8 merged commit 58caef5 into master Nov 7, 2024
28 checks passed
@NumberFour8 NumberFour8 deleted the lukas/fix-missing-auto-redeem-cfg branch November 7, 2024 20:21
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.

2 participants