Skip to content

Avoid same peer rebalances#522

Open
markettes wants to merge 6 commits into
mainfrom
fix/block-rebalance-same-peer
Open

Avoid same peer rebalances#522
markettes wants to merge 6 commits into
mainfrom
fix/block-rebalance-same-peer

Conversation

@markettes

Copy link
Copy Markdown
Contributor
  • Mandatory on RebalanceRequest: SourceChannelId is now int and TargetPubkey is now string (both previously nullable). RebalanceService.RebalanceAsync validates each up front with a
    clear ArgumentException.
  • gRPC: RequestRebalance rejects requests missing source_channel_id or target_pubkey with StatusCode.InvalidArgument before reaching the service. Proto field comments updated to mark
    both required (the optional wire-protocol modifier stays so existing serialized payloads still parse).
  • No-op guard: the service also rejects requests where the receiving peer (TargetPubkey) is the same peer as the source channel's counterparty — that would route the sats straight back
    and accomplish nothing.
  • Modal (NewRebalanceModal.razor): "(optional)" label and "let LND choose" placeholder removed; receiving-peer dropdown filters out the source channel's counterparty; CanSubmit requires
    both fields and forbids the no-op combination; if the user changes the source channel and the previously-picked receiving peer becomes invalid, it gets cleared.

The Rebalance model fields are intentionally left nullable in this PR — tightening the DB schema needs a data backfill / cleanup decision that's out of scope here.

@markettes markettes marked this pull request as ready for review June 19, 2026 09:49
@markettes markettes requested review from Jossec101 and Copilot June 19, 2026 09:49

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 makes rebalance requests stricter and prevents “no-op” rebalances by requiring SourceChannelId and TargetPubkey end-to-end (UI → gRPC → domain), and adding a guard to reject selecting the source channel’s counterparty as the receiving peer.

Changes:

  • Make RebalanceRequest.SourceChannelId and RebalanceRequest.TargetPubkey mandatory and validate them early in RebalanceService.RebalanceAsync.
  • Add gRPC-layer InvalidArgument guards for missing/invalid source_channel_id and target_pubkey before the node lookup.
  • Update the rebalance modal to require a receiving peer and filter out the source channel counterparty; expand/adjust test coverage accordingly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test/NodeGuard.Tests/Services/RebalanceServiceTests.cs Updates existing tests for new required request fields and adds new validation/no-op-guard tests.
test/NodeGuard.Tests/Rpc/NodeGuardServiceTests.cs Adds gRPC validation tests for missing required fields and updates existing cases to reach intended code paths.
src/Shared/NewRebalanceModal.razor Makes receiving peer required, filters out counterparty peer, and enforces submission constraints in the UI.
src/Services/RebalanceService.cs Changes RebalanceRequest to non-nullable fields and adds validation + no-op counterparty guard in RebalanceAsync.
src/Rpc/NodeGuardService.cs Rejects missing/invalid source_channel_id and target_pubkey with InvalidArgument before calling the domain service.
src/Proto/nodeguard.proto Updates field comments to mark source_channel_id and target_pubkey as required (keeping wire optional).

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

Comment thread test/NodeGuard.Tests/Services/RebalanceServiceTests.cs
Comment thread src/Shared/NewRebalanceModal.razor Outdated
Comment thread test/NodeGuard.Tests/Services/RebalanceServiceTests.cs
Comment thread src/Services/RebalanceService.cs Outdated
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