Skip to content

staticaddr: multi-address - #1139

Closed
hieblmi wants to merge 30 commits into
lightninglabs:masterfrom
hieblmi:multi-address
Closed

staticaddr: multi-address#1139
hieblmi wants to merge 30 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 added 26 commits August 28, 2026 15:29
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.
Associate fractional loop-ins with their operation-specific static
change address so recovery restores the descriptor needed to reconstruct
signed transactions. Backfill legacy fractional swaps to the original
address.
Create a fresh static address for fractional loop-in change and send its
descriptor to the server. Reconstruct signed HTLCs with the persisted
parameters and verify cooperative batch change by output script.
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.
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 and fund a fresh receive address through
lnd SendCoins. Validate funding arguments before address creation and
require explicit confirmation unless --force is set, including for
non-interactive and first-use deposits.

Resolve requested existing addresses through the active script index
rather than reconstructing every persisted address. Expose the nested
request through the client RPC, require swap:execute permission, and
cover the CLI and daemon funding paths. Regenerate RPC and CLI
documentation.
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.

Calculate blocks until expiry from each deposit owner instead of the
legacy root address, and reject deposits whose owning parameters are
missing. Centralize deposit response conversion and update generated RPC
artifacts, regression coverage, and command replay fixtures.
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 address ownership and operation-specific change
outputs across the shared SQL persistence boundary. Reconstruct the
deposit, loop-in, and withdrawal stores to verify ownership and change
metadata survive restart.
Document fresh receive-address derivation, lazy seed initialization,
funding-address lookup hardening, 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.
Follow the transaction that actually spends the watched deposit, require
its confirmed form to spend every selected withdrawal input, persist
that transaction, and stop republishing both the original and
replacement.
Identify withdrawal change through its active change-family script
instead of a fixed output index. Record amounts correctly when
confirmed replacements reorder or add outputs.
Stop republishing an obsolete withdrawal when its confirmed spender
consumes only part of the deposit group. Finalize spent deposits,
release untouched deposits, and clear stale transaction references.
handleWithdrawal starts a long-lived spend and confirmation monitor, but
the manager did not own its lifecycle. Manager.Run could return while a
monitor was still transitioning deposits, updating withdrawal rows, or
reading package-level logging state.

Track every monitor with a WaitGroup and give the run loop a child
context that is canceled on every exit path. Close request delivery,
cancel the monitors, and join them before returning. Configure the test
logger once and make monitor tests cancel and wait so consecutive race
tests cannot overlap through the global logger.
Withdrawal spend monitoring followed an RBF replacement's txid while
retaining the original destination script. Confirmation requests match
both values, so a replacement paying a newly derived destination could
remain invisible and leave deposits stuck in Withdrawing.

Build the confirmation request from the actual spending transaction, use
a positive spending height as its historical hint with the startup
height as the mempool fallback, and identify change from the confirmed
transaction's own destination. Persist the confirmation's block height
and remove both original and replacement republish entries after
resolution.

Widen the manager store dependency to an interface so the complete
transition and persistence path can be covered without a database, and
add replacement, map-cleanup, and mempool-height regression tests.
Record the exact confirmed HTLC transaction, output index, and value so
recovery sweeps the server-published output instead of reconstructing it
from legacy assumptions.
@hieblmi

hieblmi commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #1218, which contains the reviewed multi-address core. The remaining follow-ups stay stacked as #1215 (withdrawal replacement hardening) and #1217 (loop-in HTLC recovery).

@hieblmi hieblmi closed this Aug 28, 2026
@hieblmi
hieblmi deleted the multi-address branch August 28, 2026 13:48
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