Skip to content

routerrpc: refuse local dispatch on a switchrpc build - #11545

Draft
calvinrzachman wants to merge 3 commits into
lightningnetwork:masterfrom
calvinrzachman:routerrpc-local-payment-dispatch-guard
Draft

calvinrzachman wants to merge 3 commits into
lightningnetwork:masterfrom
calvinrzachman:routerrpc-local-payment-dispatch-guard

Conversation

@calvinrzachman

@calvinrzachman calvinrzachman commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Change Description

Replaces #11013, which was closed when its base branch was deleted after #11282 merged. The change is the same, rebased onto master.

The v0.22 release notes say that only one entity, the local router or one external router, may dispatch HTLC attempts through the switch, and that running two "will lead to undefined behavior and potential loss of funds". Nothing enforced it. Both routers draw attempt IDs from independent sequencers into one shared attempt store, so a locally sent payment can collide with an in-flight external attempt and deliver one payment's result to the other caller.

This makes the rule enforced rather than a matter of operational discipline. routerrpc.SendPaymentV2 and SendToRouteV2 now return codes.FailedPrecondition on a switchrpc build; they are the only two RPCs that can originate an attempt. --enable-local-payment-dispatch opts back in for a node that wants the embedded router anyway, with a warning at startup.

Attempt store cleanup and the external-management DB marker stay tied to the build tag rather than to this flag. Both are destructive to an external router's state, so a wrong config value should not be able to reach them.

Alternatives considered

  • Guarding at ControlTower.InitPayment instead of the handlers. That works, since SendOnion never touches the control tower. I chose the handlers to keep the switchrpc concept in the RPC layer. Switch.SendHTLC is not an option, since nothing there says which router is calling.
  • No flag at all, with the guard always on in a switchrpc build. The itest binary is built with that tag, so every itest that sends a payment would fail. Making this work means splitting the itest suite so only some of it builds with the tag.
  • Drawing every attempt ID from one sequencer, so the two routers cannot collide at all. Attempt key translation does this by mapping each switchrpc client's key to an ID from the router's own sequencer, and makes this guard unnecessary, but it is a larger change in the switch core.

NOTE: This would not be needed once attempt key translation (#11572) lands, since the local router and switchrpc clients could then share a node without colliding in the attempt store. If it lands first, this PR can be closed.

Testing

  • New unit tests in lnrpc/routerrpc and config_test.go cover the guard decision, both handlers, and the build-tag validation. There is also a new itest:
make itest icase='local payment dispatch guard'

A gateway that hands its payment lifecycle to an external router over
the switchrpc interface still exposes a working embedded router. Both
draw HTLC attempt IDs from independent sequencers into one shared,
unowned attempt store, so overlapping IDs can deliver one payment's
result to the wrong caller. Nothing prevents that today except operator
discipline, meaning no manual payment RPCs and no tooling that reaches
for routerrpc against a gateway.

Refuse SendPaymentV2 and SendToRouteV2 with codes.FailedPrecondition on
a switchrpc build, and add an enable-local-payment-dispatch flag for a
node that wants the embedded router anyway. The check lives in the two
routerrpc handlers, not an interceptor, since the blocked set is two
methods and a named check keeps rpcperms free of payment semantics.

The flag governs payment origination only. Skipping attempt store
cleanup and marking the HTLC attempt database follow the build tag,
because both are destructive to an external router's state and should
not be reachable from a config file. Startup warns when the two differ.

The itest binary carries the switchrpc tag, so the harness opts every
node in and the guard test opts one back out through a node option.
Assert the guard refuses SendPaymentV2 and SendToRouteV2 on a node that
keeps the switchrpc build default, while QueryRoutes, EstimateRouteFee
and the HTLC interceptor stream keep answering, since an external router
depends on all three.
Record the local payment dispatch guard in a fragment rather than the
version-wide v0.22 document, which is now only edited when a release is
prepared. The entry also notes that a switchrpc binary rewrites the
external management marker on startup, so migrating back to the embedded
router after DisableRemoteRouter is a binary swap.
@github-actions github-actions Bot added ci-hold CI is held; remove this label to run CI severity-high Requires knowledgeable engineer review labels Nov 10, 2026
@github-actions

Copy link
Copy Markdown

🟠 PR Severity: HIGH

gh pr view | 13 files | 349 lines changed

🟠 High (2 files)
  • lnrpc/routerrpc/config.go - lnrpc/* RPC config surface for the router subserver
  • lnrpc/routerrpc/router_server.go - lnrpc/* RPC/API definitions (router service)
🟡 Medium (2 files)
  • config.go - core daemon configuration, uncategorized Go file
  • subrpcserver_config.go - uncategorized Go file
🟢 Low (9 files)
  • config_test.go - test-only change
  • docs/release-notes/unreleased/11013.md - release notes
  • itest/list_on_test.go - itest
  • itest/lnd_local_payment_dispatch_test.go - itest
  • lnrpc/routerrpc/router_server_guard_test.go - test-only change
  • lntest/harness.go - lntest harness
  • lntest/harness_node_manager.go - lntest harness
  • lntest/node/config.go - lntest harness
  • sample-lnd.conf - sample config, non-code

Analysis

The highest-severity files touched are under lnrpc/routerrpc/ (RPC/API surface), which classifies this PR as HIGH. Supporting changes are a new daemon config option (config.go, subrpcserver_config.go) plus itest/lntest harness updates and a release note to exercise the new router RPC guard behavior. File count (13) and non-test/non-generated line count (~124 lines) are both well under the bump thresholds, and no CRITICAL packages are touched, so no severity escalation applies.


To override, add a severity-override-{critical,high,medium,low} label.

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

Labels

ci-hold CI is held; remove this label to run CI severity-high Requires knowledgeable engineer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant