Skip to content

staticaddr: multi-address - #1139

Open
hieblmi wants to merge 22 commits into
lightninglabs:masterfrom
hieblmi:multi-address
Open

staticaddr: multi-address#1139
hieblmi wants to merge 22 commits into
lightninglabs:masterfrom
hieblmi:multi-address

Conversation

@hieblmi

@hieblmi hieblmi commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

This is PR 1 of 3 in the static-address multi-address stack. It adds the core
multi-address feature; the two dependent PRs isolate address startup and
withdrawal replacement hardening.

Static-address deposits now retain the concrete address parameters they were
sent to instead of assuming every deposit belongs to one reusable output
script. Loop-ins and withdrawals can therefore spend deposits received across
multiple derived static addresses.

Key Changes

  • Persist per-deposit static-address ownership and restore it across restarts.
  • Sign each deposit input with the address parameters that created it.
  • Send per-input client keys to the server for multi-address proof validation.
  • Derive and persist fresh receive and operation-specific change addresses.
  • Record confirmed loop-in HTLC outpoints and validate their inputs.
  • Add CLI support for creating and optionally funding a fresh static address
    with SendCoins.
  • Expose each deposit's receiving address through the RPC and CLI.

Recovery

Recovery derives receive and change candidates from the immutable static
address seed, scans wallet-visible UTXOs, and reconciles matching deposits back
into loopd with their owning address parameters.

Stack

  1. This PR — multi-address core
  2. staticaddr/address: harden multi-address startup #1214 — address startup hardening
  3. staticaddr/withdraw: harden replacement monitoring #1215 — withdrawal replacement hardening

Testing

  • go test -count=1 ./...
  • make unit-race
  • go vet ./...
  • golangci-lint run
  • make mod-check docs-check fsm-check rpc-js-compile
  • git diff --check

Pull Request Checklist

  • Added entries to docs/release-notes/release-notes-next.md.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, 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 pull request introduces multi-address support for static-address deposits, significantly increasing the flexibility of loop-in and withdrawal operations. By persisting per-deposit address parameters and implementing a generation-based recovery flow, the system ensures that funds remain accessible even after local data loss. Additionally, the PR includes robust CLI updates for address funding and improved deposit reconciliation logic to handle mempool-level changes and chain reorgs.

Highlights

  • Multi-Address Support: Deposits now retain concrete address parameters, enabling loop-ins and withdrawals to spend funds received across multiple derived static addresses.
  • Recovery Flow: Implemented a generation-based recovery system using encrypted backups tied to L402 tokens, allowing for the restoration of static address state and deposit reconciliation.
  • CLI Enhancements: Added a new 'recover' command and extended 'loop static new' to support optional funding of static addresses via SendCoins.
  • Deposit Reconciliation: Improved deposit handling to better manage unconfirmed outputs and automatically mark vanished deposits as replaced.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 the 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 counterproductive. 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.

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.

@hieblmi hieblmi self-assigned this May 8, 2026

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

Copy link
Copy Markdown

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 implements a robust recovery system for Loop's static addresses and L402 tokens, utilizing encrypted immutable backups. Key additions include a new recover CLI command, a dedicated recovery package for backup orchestration, and significant updates to the address and deposit managers to support multi-address derivation and mempool-aware reconciliation. The loop-in FSM is also enhanced to handle fractional swaps with static change outputs and server-side risk notifications. Feedback focuses on improving the clarity of change amount logic, optimizing the performance of multiset matching during change verification, and making the retry limit for stable block height lookups configurable.

Comment thread staticaddr/loopin/manager.go
Comment thread staticaddr/loopin/manager.go Outdated
Comment thread staticaddr/deposit/manager.go Outdated

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

Copy link
Copy Markdown

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 static address recovery for Loop, enabling the restoration of L402 and static-address state from encrypted backups. It also adds support for fractional loop-ins by implementing change address derivation and handling, along with improved deposit reconciliation and validation logic. My review identified several critical issues regarding notification replay logic, performance concerns with wallet transaction scanning, and potential address leakage during retries.

Comment thread notifications/manager.go Outdated
Comment thread notifications/manager.go Outdated
Comment thread staticaddr/loopin/txout_checker.go Outdated
Comment thread staticaddr/loopin/actions.go
@hieblmi
hieblmi force-pushed the multi-address branch 15 times, most recently from bc06754 to 242a3e1 Compare May 18, 2026 08:37
@hieblmi
hieblmi force-pushed the multi-address branch 7 times, most recently from 5a5c613 to c1c691e Compare July 10, 2026 13:53
@hieblmi
hieblmi force-pushed the multi-address branch 2 times, most recently from 82ce8fa to e481301 Compare July 17, 2026 12:50
@hieblmi
hieblmi force-pushed the multi-address branch 2 times, most recently from 0a947a5 to 5600cbe Compare August 27, 2026 09:59
@hieblmi
hieblmi force-pushed the multi-address branch 2 times, most recently from ed02b6e to e392069 Compare August 27, 2026 10:40
Associate every deposit with the static address parameters that created
it. This lets restored deposits recover the correct script and signing
keys instead of assuming the legacy root address.
Create receive and change addresses from locally derived client keys
while reusing the server key and expiry from the legacy seed. Persist,
import, and activate each script before returning it to callers.

Rebuild the active address index on startup, import only scripts missing
from lnd, and serialize issuance without blocking address reads.
hieblmi added 19 commits August 27, 2026 15:25
Look up each newly discovered wallet UTXO by script and persist the
matching active-address parameters on the deposit. Reject unknown
scripts before allocating the timeout sweep address.

Use the per-deposit parameters when constructing the FSM, sign
descriptor, and unilateral expiry sweep so derived-address recovery uses
its owning script and key.
Register timeout-sweep confirmations by destination script instead of
the originally published txid. This lets recovery detect an RBF
replacement after restart with a stale txid.
Construct each cooperative MuSig2 session from the address parameters
stored on its deposit. This prepares loop-ins and withdrawals to sign
inputs belonging to different derived static addresses.

Clean up sessions created before a later setup failure. Reject duplicate
deposit outpoints to avoid leaking signer state.

Validate transaction inputs, session handles, and nonce counts before
signing so malformed responses fail before any signer operation.
Map every selected outpoint to the static address descriptor that
derived its deposit and include those descriptors in loop-in requests.
This lets the server validate mixed-address inputs independently of
request order.
Include the derivation key for every withdrawal input in the server
request. This lets the server validate and sign withdrawals that combine
deposits from multiple derived addresses.
Join restored deposits with their persisted static-address rows and
hydrate pre-migration deposits from the legacy root address. Return
complete ownership metadata from deposit reads and use each deposit's
own expiry during loop-in selection.
Create and persist a fresh static change address for fractional
loop-ins. Send the change descriptor to the server and verify
operation-specific change outputs in cooperative sweep batches.
Create a fresh static address for partial-withdrawal change and persist
that output from the confirmed transaction. Keep all withdrawal outputs
in the PSBT without separate signing metadata while preserving
full-withdrawal behavior.
Let loop static deposit create a fresh receive address and optionally
fund it through lnd SendCoins. Validate funding arguments before address
creation, expose the nested request through the client RPC, and require
swap:execute permission for the mutating request. Regenerate the RPC
artifacts, CLI documentation, and replay fixtures for the new command
behavior.
Include the owning static address in every deposit RPC response and CLI
listing. Users can distinguish deposits created by different receive and
change addresses without reconstructing scripts externally. Update
generated RPC artifacts and command replay fixtures for the new field.
Declare f through the urfave/cli alias field instead of embedding it
in the flag name. Cover both the long and short forms with a parsing
test.
Reject non-forced funding when stdin is not interactive and write
the prompt to stderr. Create and fund the address in one RPC after
confirmation so canceled requests leave no unused address.
Multi-address loop-ins sign and construct transactions from the
parameters attached to each deposit and their dedicated change address.
The legacy root address fields therefore became write-only, but
populating them could still abort signing, sweep handling, or recovery
when the root lookup failed.

Remove those fields and lookups, select the FSM from the protocol
version persisted with the swap, and set that version before
constructing new state machines. Keep the root-parameter lookup used by
autoloop expiry calculation and add regression coverage for recovery and
unsupported persisted versions.
The CLI previously recognized an uninitialized static-address seed by
searching arbitrary gRPC error text. Any wrapping or wording change
could suppress the L402 backup warning before a user funded a newly
derived address.

Map ErrNoStaticAddress to codes.NotFound at the RPC boundary and
classify that status in the CLI. Retain compatibility with older daemons
only for an exact Unknown-status message, avoiding the broad substring
match, and cover both sides with regression tests.
A static-address account can now receive deposits across multiple
derived addresses, so the singular summary field can no longer describe
the current receive address. Removing or repurposing field 1 would break
existing clients.

Keep the wire value as the legacy/root derivation address, formally
deprecate it, document the expiry as the shared CSV delay, and direct
CLI users to derive a fresh receive address. Rename the server locals to
make the compatibility behavior explicit and regenerate protobuf and
Swagger artifacts.
Cover per-deposit loop-in proofs and operation-specific change outputs,
then reconstruct address, deposit, loop-in, and withdrawal stores to
verify ownership and change metadata survive restart.
Document fresh receive-address derivation, lazy seed initialization, and
the swap:execute permission required by address creation. Regenerate the
CLI, gRPC, Swagger, and man-page documentation and add feature,
breaking-change, and recovery release notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants