lnd icon indicating copy to clipboard operation
lnd copied to clipboard

multi: add mode for external payment lifecycle management

Open calvinrzachman opened this issue 4 months ago • 1 comments

Change Description

To support scenarios where an external entity, such as a remote router, manages the payment lifecycle via the Switch RPC server, the node must preserve the history of HTLC attempts across restarts.

Currently, the local ChannelRouter cleans up this history on startup, which would cause the external entity to lose state and fail to properly manage in-flight payments.

This commit makes this behavior conditional on how the lnd binary is built. When compiled with the switchrpc build tag, the local ChannelRouter's automatic cleanup of the dispatcher's (Switch) attempt store on startup is disabled. This shifts the responsibility of state cleanup to the external controller, which is expected to use an RPC interface (e.g., switchrpc) to manage the lifecycle of attempts. Tying this behavior to a build tag, rather than a runtime flag, makes the binary's purpose explicit and prevents potential misconfigurations.

IMPORTANT: It is currently only safe to allow a single entity (either the local router or one external router) to dispatch attempts via the Switch at any given time. Running multiple controllers concurrently will lead to undefined behavior and potential loss of funds.

calvinrzachman avatar Aug 27 '25 04:08 calvinrzachman

@calvinrzachman, remember to re-request review from reviewers when ready

lightninglabs-deploy avatar Dec 17 '25 15:12 lightninglabs-deploy