Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Avoid retrying over previously failed blinded paths by valentinewallace · Pull Request #2818 · lightningdevkit/rust-lightning · GitHub
Skip to content

Avoid retrying over previously failed blinded paths - #2818

Merged
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries
Jan 17, 2024
Merged

Avoid retrying over previously failed blinded paths#2818
TheBlueMatt merged 7 commits into
lightningdevkit:mainfrom
valentinewallace:2024-01-blinded-path-retries

Conversation

@valentinewallace

Copy link
Copy Markdown
Contributor

This is important for production usage of blinded routes, for payment reliability.

Partially addresses #1970.

@valentinewallacevalentinewallace added this to the 0.0.120 milestone Jan 9, 2024
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 228edfa to 9575735CompareJanuary 9, 2024 17:16
@codecov-commenter

codecov-commenter commented Jan 9, 2024

Copy link
Copy Markdown

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (0d513fd) 88.42% compared to head (1a7f79d) 89.36%.
Report is 64 commits behind head on main.

❗ Current head 1a7f79d differs from pull request most recent head 5c87f40. Consider uploading reports for the commit 5c87f40 to get more accurate results

FilesPatch %Lines
lightning/src/ln/onion_utils.rs54.54%3 Missing and 2 partials ⚠️
lightning/src/ln/outbound_payment.rs87.50%0 Missing and 2 partials ⚠️
lightning/src/routing/router.rs93.54%2 Missing ⚠️
lightning/src/ln/blinded_payment_tests.rs99.10%1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@ Coverage Diff @@## main #2818 +/- ##
==========================================
+ Coverage 88.42% 89.36% +0.93% 
==========================================
Files 114 114 Lines 91946 97543 +5597 Branches 91946 97543 +5597 ==========================================
+ Hits 81304 87168 +5864 + Misses 8129 7971 -158 + Partials 2513 2404 -109 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 9575735 to 5092908CompareJanuary 10, 2024 20:49
@valentinewallacevalentinewallace mentioned this pull request Jan 10, 2024
60 tasks
Comment threadlightning/src/ln/onion_utils.rs Outdated
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 5092908 to 1a7f79dCompareJanuary 12, 2024 16:42
@coderabbitai

coderabbitaiBot commented Jan 12, 2024

Copy link
Copy Markdown

Walkthrough

The updates focus on improving the handling of blinded payment paths within the Lightning Network's codebase. New functionalities include tracking payment failure reasons, refining the process of establishing blinded payment paths, and enhancing route parameter construction. Additionally, there's an emphasis on retry logic for failed payment paths and better error handling within the onion routing mechanism, specifically noting when failures occur within blinded paths.

Changes

File PathChange Summary
.../blinded_payment_tests.rsAdded PaymentFailureReason, refactored blinded_payment_path, and new test blinded_path_retries.
.../onion_utils.rsUpdated DecodedOnionFailure and process_onion_failure for blinded path failure tracking.
.../outbound_payment.rsUpdated outbound_payment.rs with changes related to failure handling.
.../router.rsEnhanced PaymentParameters with failed blinded path tracking and added new methods for handling.

Poem

In the code where the lightning flashes bright, 🌩️
Paths are blinded, hidden from sight.
With each failure, we learn and retry,
CodeRabbit hops on, never shy! 🐇💻✨

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4b70921 and 1a7f79d.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Additional comments: 28
lightning/src/ln/blinded_payment_tests.rs (4)
  • 13-13: The addition of PaymentFailureReason to the events module is a good practice as it allows for more descriptive error handling in the payment process.

  • 59-78: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [30-66]

The refactoring of the blinded_payment_path function to return a tuple of BlindedPayInfo and BlindedPath is a significant change. Ensure that all usages of this function have been updated to handle the new return type.

  • 68-75: The get_blinded_route_parameters function has been modified to use the refactored blinded_payment_path function. This change should be verified to ensure that the RouteParameters are constructed correctly with the new return type of blinded_payment_path.
Verification successful

The get_blinded_route_parameters function correctly uses the tuple returned by blinded_payment_path to construct RouteParameters. The blinded_payment_path function returns a tuple (BlindedPayInfo, BlindedPath), which is then passed into PaymentParameters::blinded within a vec![] to create the RouteParameters.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that `get_blinded_route_parameters` correctly constructs `RouteParameters` using the new `blinded_payment_path` return type.
ast-grep --lang rust --pattern $'get_blinded_route_parameters($_, $_, $_, $_, $_)'

Length of output: 2489



Script:

#!/bin/bash# Check the implementation of `get_blinded_route_parameters` and the return type of `blinded_payment_path`
rg "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 215



Script:

#!/bin/bash# Retrieve the full implementation of `get_blinded_route_parameters` and `blinded_payment_path` to verify the return type and usage.
rg -A 10 "fn get_blinded_route_parameters" lightning/src/ln/blinded_payment_tests.rs
rg -A 10 "fn blinded_payment_path" lightning/src/ln/blinded_payment_tests.rs

Length of output: 1061

* 712-815: The new test `blinded_path_retries` is added to verify the retry behavior of blinded payment paths. It's important to ensure that this test covers all relevant scenarios, including the failure and retry mechanisms. The test seems comprehensive, but it's crucial to check that it fails when expected and that the retry logic is sound.
Verification successful

The blinded_path_retries test function has been successfully located and its contents displayed. The test sets up a network topology, creates channels, and simulates a payment process with retries over blinded paths. It includes assertions to check the correct behavior when a payment fails and when all blinded paths have been exhausted.

The test appears to cover:

  • The setup of a network with a specific topology for testing blinded paths.
  • The creation of a payment with blinded route hints.
  • The simulation of a payment failure through a blinded path.
  • The handling of a failed payment and the processing of the retry logic.
  • The assertion that the payment fails permanently when all blinded paths have been tried and no more retries are available.

Based on the provided output, the test seems to be comprehensive in terms of testing the retry behavior of blinded payment paths, including the failure and retry mechanisms. It checks for both temporary failure (allowing for a retry) and permanent failure (when no more retries are possible).

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that the new test `blinded_path_retries` is comprehensive and covers all relevant scenarios.
ast-grep --lang rust --pattern $'fn blinded_path_retries()'

Length of output: 60



Script:

#!/bin/bash# Adjusting the pattern to match the function definition correctly.
ast-grep --lang rust --pattern $'fn blinded_path_retries($_) { $$$ }'

Length of output: 70



Script:

#!/bin/bash# Using rg to search for the function definition within the file.
rg "fn blinded_path_retries"

Length of output: 100



Script:

#!/bin/bash# Display the contents of the `blinded_path_retries` function to examine its comprehensiveness.
cat lightning/src/ln/blinded_payment_tests.rs | sed -n '/fn blinded_path_retries()/,/^}/p'

Length of output: 4727

lightning/src/ln/onion_utils.rs (10)
  • 432-432: The addition of the failed_within_blinded_path field to the DecodedOnionFailure struct is consistent with the PR's objective to track failures within blinded paths.

  • 467-467: The failed_within_blinded_path field is correctly initialized within the FailureLearnings struct, which is used to capture information about the failure for further processing.

  • 493-494: The failed_within_blinded_path field is correctly set to true when an error is detected from within a blinded route, which aligns with the PR's goal.

  • 526-527: Again, the failed_within_blinded_path field is set to true when the failing hop is within a multi-hop blinded path, which is consistent with the intended logic.

  • 557-558: The failed_within_blinded_path field is set to false when the error is not related to a blinded path, which is correct behavior.

  • 714-715: The failed_within_blinded_path field is correctly assigned to the DecodedOnionFailure struct based on the FailureLearnings struct, ensuring that the information about the failure is preserved.

  • 729-729: The failed_within_blinded_path field is correctly included in the construction of the DecodedOnionFailure struct, which is the final step in processing the onion failure.

  • 740-740: The failed_within_blinded_path field is set to false by default when no specific failure learnings are available, which is a safe default.

  • 888-888: The failed_within_blinded_path field is correctly set to false when decoding a failure from the first hop, as this is not a blinded path scenario.

  • 723-732: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [432-888]

The changes made to the DecodedOnionFailure struct and the process_onion_failure function are consistent with the PR's objectives to enhance the reliability of blinded routes by tracking and avoiding failed paths. The failed_within_blinded_path field has been correctly added and utilized throughout the relevant functions to ensure that once a blinded path fails, it is not retried in subsequent payment attempts.

lightning/src/ln/outbound_payment.rs (6)
  • 22-22: The import of BlindedTail on line 22 suggests that there are changes related to blinded paths, which aligns with the PR's objectives.

  • 132-136: The method insert_previously_failed_blinded_path on lines 132-136 is a new addition that allows marking a blinded path as failed. This is a key part of the PR's functionality to avoid retrying failed blinded paths.

  • 1612-1617: The code on lines 1612-1617 is under a cfg(test) flag, which means it's only compiled for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

  • 1612-1617: The use of cfg(test) on lines 1612-1617 indicates that the following code is only for testing purposes. It's important to ensure that the test code is consistent with the production code logic. The DecodedOnionFailure struct is being used here, which is relevant to the handling of onion routing failures.

  • 1656-1661: Lines 1656-1661 handle the case where a failure occurs within a blinded path. This is a new check introduced in this PR, and it's crucial for the new functionality to track failures in blinded paths correctly.

lightning/src/routing/router.rs (8)
  • 715-718: The addition of previously_failed_blinded_path_idxs to PaymentParameters is consistent with the PR's objective to track failed blinded paths. Ensure that the type u64 is appropriate for indexing and that there are no potential overflows or underflows when casting indices to this type.

  • 740-740: In the Writeable implementation for PaymentParameters, the new field previously_failed_blinded_path_idxs is serialized with a tag of 11. Verify that this tag does not conflict with any existing serialization tags and that it follows the serialization format's guidelines.

Verification successful

The executed script was intended to search for the use of tag 11 in the serialization code within router.rs. The absence of output from the rg command suggests that there are no other instances of tag 11 being used in the Writeable implementation for PaymentParameters or elsewhere in the router.rs file. This indicates that the tag 11 does not conflict with any existing serialization tags within that file.

Based on the information gathered, it can be concluded that the use of tag 11 for the field previously_failed_blinded_path_idxs in the Writeable implementation for PaymentParameters does not conflict with any other serialization tags in the router.rs file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Verify that tag 11 is not used by other fields in PaymentParameters serialization
rg "write_tlv!.*\(11," src/routing/router.rs

Length of output: 108



Script:

#!/bin/bash# First, find the correct path for `router.rs`
fd router.rs
# If the file exists, then search for the use of tag 11 in the serialization within `router.rs`# This command will be executed only if `router.rs` is found
fd router.rs --exec rg "write_tlv!.*\(11,"

Length of output: 110



Script:

#!/bin/bash# Directly search for the use of tag 11 in the serialization within `router.rs`
rg "write_tlv!.*\(11," lightning/src/routing/router.rs

Length of output: 56

* 759-759: In the `ReadableArgs` implementation, `previously_failed_blinded_path_idxs` is marked as optional. This is a good approach for backward compatibility. However, ensure that the rest of the code correctly handles the case when this vector is not present in the data.
  • 783-783: The default value for previously_failed_blinded_path_idxs is an empty vector, which is appropriate. Confirm that there are no scenarios where a non-empty default would be necessary.

  • 802-802: The initialization of previously_failed_blinded_path_idxs with an empty vector in the new and with_max_channel_saturation_power_of_half methods is consistent and ensures that the field is properly initialized in all constructors.

Also applies to: 841-841

  • 918-929: The insert_previously_failed_blinded_path method adds an index to previously_failed_blinded_path_idxs. Ensure that there is logic in place to prevent duplicate indices from being added, as this could lead to inefficiencies or unexpected behavior.

  • 1386-1394: The blinded_hint_idx method provides a way to retrieve the index of a blinded hint. This is a utility method that will likely be used in multiple places. Confirm that the method is used consistently and that the returned index is always valid.

  • 2146-2154: The logic to check if a payment failed on a specific channel or blinded path is correct. It uses the new fields to determine if a channel or blinded path index should be avoided. Ensure that the unwrap call on line 2150 is safe and will not cause a panic in any scenario.

Verification successful

The review comment has been verified. The unwrap() call on line 2150 in router.rs is preceded by a check that ensures it is safe to use, as it is only called if blinded_hint_idx().is_some() returns true. This means the unwrap() will not cause a panic in this scenario.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash# Check for all usages of blinded_hint_idx to ensure it's always called when Some
rg "blinded_hint_idx\(\)" src/routing/router.rs

Length of output: 111



Script:

#!/bin/bash# First, find the correct path for the router.rs file
fd 'router.rs'# If the file is found, then search for the usages of blinded_hint_idx()# The output of fd will be used to ensure the correct file path is used

Length of output: 65



Script:

#!/bin/bash# Now that we have the correct path, search for the usages of blinded_hint_idx() in router.rs
rg "blinded_hint_idx\(\)" lightning/src/routing/router.rs

Length of output: 175

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Squashing is fine by me. Looks like then the first two commits can be dropped.

Comment on lines +921 to +922
if failed_blinded_tail.hops == path.blinded_hops &&
failed_blinded_tail.blinding_point == path.blinding_point

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In practice, would simply checking the blinding_point be sufficient? Or at very least only checking the blinded_node_id of each hop instead of all its data?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

In practice, that would most likely be fine. In practice there also shouldn't be too much data to compare, though.

Comment threadlightning/src/routing/router.rs
@valentinewallace
valentinewallaceforce-pushed the 2024-01-blinded-path-retries branch from 1a7f79d to 5c87f40CompareJanuary 17, 2024 15:55

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fbeb7ac and 5c87f40.
Files selected for processing (4)
  • lightning/src/ln/blinded_payment_tests.rs (4 hunks)
  • lightning/src/ln/onion_utils.rs (9 hunks)
  • lightning/src/ln/outbound_payment.rs (5 hunks)
  • lightning/src/routing/router.rs (9 hunks)
Files skipped from review as they are similar to previous changes (4)
  • lightning/src/ln/blinded_payment_tests.rs
  • lightning/src/ln/onion_utils.rs
  • lightning/src/ln/outbound_payment.rs
  • lightning/src/routing/router.rs

@TheBlueMatt
TheBlueMatt merged commit 871db63 into lightningdevkit:mainJan 17, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@valentinewallace@codecov-commenter@TheBlueMatt@jkczyz