lightninglabs / lightninglabs/loop
Avoid re-importing all static-address tapscripts on every startup
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 595
- Forks
- 135
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 12
Description
Problem
Multi-address static-address support causes Loop's persisted address set to grow over time: one address can be added by loop static new, each fractional loop-in, and each withdrawal that creates change.
During startup, the static-address manager currently calls ImportTaprootScript sequentially for every persisted address. On a normal restart, these are duplicate wallet write RPCs. This makes startup cost grow with the full address history, relies on matching LND's "already exists" error text, and can eventually run into the manager's initialization timeout.
Originally raised by @starius in this PR #1139 comment.
Proposed improvement
- Call WalletKit
ListAddressesonce and build a set of addresses already imported into LND. - Load every persisted static-address record and derive its P2TR address locally.
- Call
ImportTaprootScriptonly for addresses missing from LND. - Build the in-memory script index from every persisted address, whether or not it needed importing.
The Loop database should remain the source of truth. In particular, avoid a database-only "imported" flag because it can become stale if the user replaces or restores the LND wallet. Comparing against LND on startup preserves the current repair behavior.
LND currently has no batch ImportTapscript RPC, so a wallet with all scripts missing still requires individual imports. Bounded concurrency could improve that uncommon recovery path; the longer-term solution would be an LND batch-import RPC backed by one wallet transaction.
Validation
- Measure LND and Loop startup with 0, 100, and 1,000 persisted static addresses.
- Cover the normal restart case where every script is already imported.
- Cover fully and partially missing scripts, including a replaced LND wallet.
- Verify the runtime script index contains every persisted address in all cases.
- Verify normal restarts do not issue duplicate import RPCs.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Trace the static-address manager startup path, WalletKit ListAddresses and ImportTaprootScript calls, persisted static-address loading, and runtime script-index construction. Add coverage for fully imported, partially missing, and replaced-wallet cases, then verify every persisted address is indexed and already imported scripts are not re-imported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100