Skip to content

staticaddr: surface mempool deposits immediately#1104

Open
hieblmi wants to merge 10 commits intolightninglabs:masterfrom
hieblmi:dyn-conf-tracker
Open

staticaddr: surface mempool deposits immediately#1104
hieblmi wants to merge 10 commits intolightninglabs:masterfrom
hieblmi:dyn-conf-tracker

Conversation

@hieblmi
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi commented Mar 24, 2026

This PR does the following:

  • It changes static-address deposit handling so deposits are tracked as soon as they appear in the mempool, not only after they confirm.
  • It exposes those unconfirmed deposits through the static-address RPC/CLI flows, including summary totals and expiry-related metadata.
  • It allows static loop-ins to consider unconfirmed deposits, while still preferring confirmed deposits first during auto-selection.
  • It adds clearer user messaging for low-confirmation deposits, warning that swap execution may be delayed by the server’s confirmation-risk policy.
  • It keeps the safety boundary for other spend paths: withdrawals and static-address channel opens still require confirmed deposits.
  • It makes withdraw --all stricter so it fails instead of silently skipping unconfirmed deposits.
  • It preserves deposit identity across RBF/replacement scenarios, so a logical deposit can survive an outpoint change without losing associated loop-in state.
  • It hides replaced/vanished deposits from normal listings while still retaining them internally as historical records.
  • It hardens loop-in lifecycle handling by canceling orphan invoices on early failures and by aborting cleanly if selected deposits are replaced before payment
    settles.
  • It improves recovery/cleanup behavior around deposit finalization and restart handling, reducing cases where state can get stuck or become inconsistent.
  • It adds substantial test coverage around confirmation tracking, reconciliation, rebinding, loop-in selection, RPC behavior, and CLI warnings.

@hieblmi hieblmi self-assigned this Mar 24, 2026
@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 significantly improves the user experience for static-address deposits by making them available for certain operations, specifically loop-ins, as soon as they are detected in the mempool. This change reduces the waiting time for users by removing the previous requirement for a minimum number of confirmations before a deposit could be utilized. The underlying logic has been updated to correctly track and manage the state and expiry of these newly visible unconfirmed deposits, while ensuring that more sensitive operations like withdrawals and channel opens still adhere to confirmation requirements.

Highlights

  • Immediate Deposit Visibility: Static-address deposits are now marked as 'Deposited' and become visible immediately upon detection in the wallet, rather than waiting for a minimum confirmation threshold.
  • Unconfirmed Deposit Tracking: The system now tracks unconfirmed deposits with a ConfirmationHeight of 0, and their first confirmation height is backfilled once the transaction confirms on the blockchain.
  • Expiry Logic for Unconfirmed Deposits: Unconfirmed deposits are treated as not yet expired, as their CSV (CheckSequenceVerify) timeout has not yet begun.
  • Loop-in Selection Enhancement: The static loop-in deposit selection process has been updated to consider and allow the use of unconfirmed deposits.
  • Confirmation Requirement for Other Flows: Cooperative withdrawal and channel-open flows continue to reject unconfirmed deposits, maintaining the requirement for confirmed funds for these operations.

🧠 New Feature in Public Preview: You can now enable Memory 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 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 counter productive. 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.

Copy link
Copy Markdown

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

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 refactors the static address deposit management by decoupling the 'Deposited' state from a minimum confirmation count. Deposits are now considered 'Deposited' as soon as they are detected, even if unconfirmed, and their actual confirmation height is tracked. This change impacts how unspent deposits are listed, how expiry is calculated (introducing depositBlocksUntilExpiry and confirmationHeightForUtxo helpers), and how IsExpired and IsSwappable functions behave for unconfirmed deposits. While unconfirmed deposits are now available for loop-ins, explicit checks have been added to openchannel and withdraw managers to ensure only confirmed deposits are used for these operations. The deposit.Manager now updates currentHeight and reconciles deposits on every new block, making the system more responsive. A review comment suggests that the pollDeposits function might be redundant given that reconcileDeposits is now called on every new block, proposing its removal for efficiency and logic simplification.

case height := <-newBlockChan:
m.currentHeight.Store(uint32(height))

err := m.reconcileDeposits(ctx)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Now that reconcileDeposits is called on every new block, the periodic polling started by pollDeposits seems redundant. Reconciling on new blocks is more efficient and responsive than polling on a fixed interval.

Consider removing the pollDeposits function and its call on line 127 to avoid unnecessary work and simplify the logic.

@hieblmi hieblmi force-pushed the dyn-conf-tracker branch 2 times, most recently from 43803c4 to 77cfd21 Compare March 25, 2026 10:34
@hieblmi hieblmi force-pushed the dyn-conf-tracker branch 3 times, most recently from 38c90ee to f61d02f Compare April 10, 2026 12:19
@hieblmi hieblmi force-pushed the dyn-conf-tracker branch 3 times, most recently from b4fe625 to 5bba57d Compare April 15, 2026 14:08
@hieblmi hieblmi requested review from bhandras and starius April 15, 2026 14:33
Comment thread staticaddr/deposit/manager.go Outdated
Comment thread staticaddr/loopin/manager.go
Comment thread staticaddr/loopin/manager.go
@hieblmi hieblmi force-pushed the dyn-conf-tracker branch 2 times, most recently from 14d52be to 6babc2d Compare April 16, 2026 09:40
@hieblmi hieblmi requested a review from starius April 16, 2026 12:32
@hieblmi hieblmi force-pushed the dyn-conf-tracker branch 11 times, most recently from 6372ed8 to 09ecf87 Compare April 27, 2026 09:39
@lightninglabs-deploy
Copy link
Copy Markdown

@starius: review reminder
@hieblmi, remember to re-request review from reviewers when ready

hieblmi added 7 commits April 28, 2026 09:50
Surface static-address deposits as soon as they appear in the wallet instead
of waiting for the old six-confirmation readiness threshold.

Reconcile the wallet view on startup, on each block, and on the polling ticker
so mempool deposits are created immediately. Backfill the first confirmation
height once those outputs confirm, protect unconfirmed deposits from expiry,
and mark vanished unconfirmed outpoints as Replaced so RBFed-away deposits stop
showing up in RPCs.

Expose the new state through static-address RPCs by deriving availability and
summary totals from stored deposit state, reporting sensible expiry data for
unconfirmed outputs, and hiding Replaced records from normal listings.
Allow static loop-ins to select unconfirmed deposits because their CSV timeout
has not started yet, while still preferring confirmed outputs during automatic
selection.

Keep confirmed-input requirements for channel opens and withdrawals now that
Deposited includes mempool outputs. Filter unconfirmed deposits out of automatic
selection for those flows and fail manual requests that reference them, so the
client does not build PSBTs or withdrawal attempts with unusable inputs.

Treat deposit.MinConfs as the legacy readiness threshold rather than the single
source of truth for all flows. Loop-in readiness is now governed by server
confirmation-risk policy, while withdrawals and channel opens keep their
confirmed-input checks.
Remove the old "no confirmed deposits available" error now that mempool
deposits are listed immediately and can be selected for static loop-ins.

Reproduce the server static-address deposit selection order in the CLI using
the already-returned deposit metadata. This keeps the low-confirmation warning
focused on the deposits auto-selection would actually choose, so users only see
it when the swap payment may wait for the server confirmation-risk policy.
If InitHtlcAction creates the private swap invoice but fails before the loop-in
is stored, the retry path otherwise leaves behind a live orphan invoice.

Cancel that invoice on the early error path with a detached, timeout-limited
context, and reuse the same helper when tearing down the monitor path. This
keeps failed initialization attempts from leaving invoices that no local swap
can complete.
FinalizeDepositAction only needs to tell the manager to remove the FSM from its
active set, but the old synchronous send was still tied to the caller context
and could race with request cancellation or a busy manager loop.

Send the cleanup notification asynchronously and tie it to the FSM lifetime
instead. Withdrawal completion no longer blocks while deposit locks are held
just because the original request context was canceled.
Keep replacement UTXOs as fresh deposits while preserving the original deposit
record and selected outpoint snapshot for pending swaps.

Before signing a static loop-in HTLC, check each original selected outpoint with
GetTxOut(..., includeMempool=true). Cancel the pending invoice only when that
check reports an original outpoint unavailable; lookup errors fail the action
without canceling so transient chain backend errors do not incorrectly abandon
the swap.

Keep recovered loop-ins using their stored outpoint snapshot and cover
replacement discovery and cancellation in tests.
ListUnspentDeposits now reports only wallet UTXOs that have an active Deposited
record. That matches the static loop-in admission path and avoids exposing
wallet-seen outputs that are not ready for loop-in selection.

Make local notification fan-out non-blocking for best-effort categories so a
slow subscriber cannot stall the notification manager while it holds the
subscriber lock. Static loop-in sweep signing requests remain blocking because
they are work requests required for sweepbatcher presigning and must not be
dropped.
hieblmi added 2 commits April 28, 2026 13:27
Wait for the server's static loop-in risk-accepted notification before starting
the client payment deadline. The server may intentionally hold the swap at the
confirmation-risk gate after HTLC signing, and the client deadline should not
run while that server-side wait is still in progress.

Cache risk-accepted notifications by swap hash inside the local notification
manager and replay them to the per-swap subscriber. This covers both reconnects
and the internal race where the global notification stream receives the server
event before the static loop-in FSM registers its waiter.
Add client handling for the server's static loop-in risk-rejected notification.
If the server aborts confirmation-risk waiting before payment, the client fails
the local swap instead of waiting for a payment deadline that will never start.

Cache rejected notifications by swap hash using the same replay path as accepted
notifications, and clear the opposite cached state when a final risk decision is
received. This keeps reconnect and subscription-order races from stranding the
client in the risk wait.
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