Skip to content

Handle same-peer loop in rebalance process#518

Closed
markettes wants to merge 0 commit into
mainfrom
fix/block-rebalance-same-peer
Closed

Handle same-peer loop in rebalance process#518
markettes wants to merge 0 commit into
mainfrom
fix/block-rebalance-same-peer

Conversation

@markettes

Copy link
Copy Markdown
Contributor

Implement logic to detect when a probed route's last hop is the source node, treating it as a NoRoute scenario. Add unit tests to ensure proper handling of this case.

Copilot AI 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.

Pull request overview

This PR updates the rebalance execution flow to detect a “same-peer loop” scenario during route probing (where a probed route loops back to the source node) and treat it as a NoRoute outcome, plus adds unit coverage to ensure payments are not dispatched in that case.

Changes:

  • Add rebalance probe validation that flips the attempt to NoRoute when the probed route’s last hop is the source node.
  • Add a unit test to verify the loop case schedules a retry and does not call SendPaymentV2Async.
  • Update existing tests’ probe stubs to return non-empty routes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Services/RebalanceService.cs Adds same-peer loop detection during probe success handling and maps it to the existing NoRoute retry path.
test/NodeGuard.Tests/Services/RebalanceServiceTests.cs Adds coverage for the new loop detection behavior and adjusts existing probe-success stubs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Services/RebalanceService.cs Outdated
Comment on lines +261 to +265
if (success.Route.Hops[^1].PubKey == rebalance.SourceNodePubKey)
{
_logger.LogInformation(
"Rebalance {RebalanceId} probe route's last hop is the source node itself; treating as NoRoute",
rebalance.Id);
@markettes markettes closed this Jun 19, 2026
@markettes markettes force-pushed the fix/block-rebalance-same-peer branch from 60138d0 to 9f38d37 Compare June 19, 2026 07:00
Sign up for free to 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.

2 participants