Skip to content

Conversation

GeorgeTsagk
Copy link
Collaborator

Description

This PR changes the impact of granting second chances to payment failures that return a fee policy update. Previously we'd immediately (within a min interval) retry a route if that was the case, but that might not be ideal (see #6883 for more info).

Instead we apply a half penalty, which discourages immediate future attempts over the same route. Other routes with greater success probability will be attempted as the penalty is not absolute but still severe. If alternative routes prove ineffective then the same route may be attempted again. It's important to be able to eventually retry the penalized route as it may be the only route available to reach the destination.

Apart from the reasons included in the issue linked above, avoiding immediate route retries is good for privacy, as it is a mitigation against an on-path adversary trying analyze time deltas of HTLCs for the purpose of locating the sender / receiver in the graph.

Testing

The weight of the penalty is not too harsh in order to allow for previously captured test cases to still pass. A new test was also added which demonstrates how alternative routes can be picked.

Refs

Closes #6883 (since it addresses all the concerns outlined in that issue)

Replaces #6891

Previously our mission control would not punish a route if a policy
failure was provided to us, in the form of a "second chance". For
various reasons outlined in
lightningnetwork#6883 we may not want to
blindly retry a route if that case is true.

With this commit we change the effect of the second chance to instead
apply penalties with half the value. This way we do not exclude this
route from future attempts and also encourage alternative route
selection.
We add a test to demonstrate that the second chance penalty can be
effective. In this test an initially cheap route is attempted but errors
with a new returned channel policy. After applying that policy we should
pick the cheaper route again, but the second-chance penalty will prevent
us from doing so. Instead an alternative route succeeds.
@GeorgeTsagk GeorgeTsagk self-assigned this Oct 8, 2025
@GeorgeTsagk GeorgeTsagk added privacy General label for issues/PRs related to the privacy implications of using the software path finding labels Oct 8, 2025
Copy link

Summary of Changes

Hello @GeorgeTsagk, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This PR modifies the routing logic to apply a 'half penalty' instead of an immediate retry when a payment fails with a fee policy update and is granted a second chance. This change aims to improve route selection by encouraging the use of alternative paths first, while still allowing the original route to be retried later. It also enhances privacy. The changes involve adjusting how failures are recorded in Mission Control and are validated with updated and new test cases.

Highlights

  • Intent: This pull request aims to reduce the immediate impact of granting 'second chances' to payment failures that include a fee policy update. Previously, such routes were immediately retried. The new approach applies a 'half penalty' instead, which discourages immediate re-attempts on the same route but allows other potentially more successful routes to be tried first. The penalized route can still be retried eventually if no other options are available. This change addresses issues related to immediate retries (specifically Remove pathfinding "second chance" logic #6883) and enhances privacy by mitigating against on-path adversaries analyzing HTLC time deltas. It replaces PR routing: remove second chance logic #6891.
  • Changes: The core logic for handling payment results in routing/missioncontrol.go has been modified. Instead of immediately returning when a second chance is granted due to a policy failure, a secondChance flag is set. If this flag is true, node-level failures are skipped, and a 'half penalty' is applied by recording the failure timestamp as if it occurred DefaultPenaltyHalfLife in the past. This makes the penalty decay faster, effectively reducing its impact. The routing/missioncontrol_test.go file was updated to reflect this new half-penalty behavior in its assertions. A new test case, TestSendPaymentErrorFeeInsufficientSecondChance, was added to routing/router_test.go. This test demonstrates how the half-penalty, combined with a fee update, can lead the router to select an alternative, slightly more expensive route on a subsequent attempt, rather than immediately retrying the initially failed route.
  • Testing: Existing test cases were updated to reflect the new half-penalty behavior. A new test, TestSendPaymentErrorFeeInsufficientSecondChance, was added to specifically validate that the half-penalty logic correctly influences route selection, causing the system to prefer alternative routes even if the original route's updated fees are still marginally better, due to the applied penalty.
  • Reviewer Activity: No specific reviewer activity or comments were provided in the context.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a significant improvement to the routing logic by applying a half-penalty for payment failures that include a fee policy update. This change discourages immediate retries on the same route, promoting the exploration of alternative paths and enhancing user privacy. The implementation is clever, using a timestamp shift to achieve the half-penalty effect.

I've identified one high-severity issue where the half-penalty is incorrectly applied to successfully forwarded hops, not just the failing one. This could negatively impact future pathfinding. A fix is suggested below.

The new tests are well-designed and effectively demonstrate the intended behavior of the new logic. Overall, this is a great enhancement to the routing mechanism.

// full penalty in order to not totally exclude this route from
// future attempts, but also encourage alternative route
// selection.
if secondChance {

Choose a reason for hiding this comment

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

high

The half-penalty should only be applied to the failing channel pair, not to the pairs that successfully forwarded the HTLC. Currently, if secondChance is true, the timestamp is adjusted for all pairs in the route, including successful ones. This incorrectly records successful forwards with a timestamp in the past, which could negatively impact future pathfinding.

The logic should be adjusted to only apply the half-penalty to the failing pair.

Suggested change
if secondChance {
if secondChance && !pairResult.success {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this check is unnecessary as a second chance is only granted upon failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

path finding privacy General label for issues/PRs related to the privacy implications of using the software

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove pathfinding "second chance" logic

1 participant