Skip to content

staticaddr: dynamic deposit conf target#1065

Open
hieblmi wants to merge 23 commits intolightninglabs:masterfrom
hieblmi:dyn-deposit-confs
Open

staticaddr: dynamic deposit conf target#1065
hieblmi wants to merge 23 commits intolightninglabs:masterfrom
hieblmi:dyn-deposit-confs

Conversation

@hieblmi
Copy link
Collaborator

@hieblmi hieblmi commented Jan 9, 2026

Update static address loop-in client to support dynamic server-side confirmation requirements.

Changes:

  • Reduce MinConfs from 6 to 1 to allow faster swap attempts for small amounts while the server enforces risk-based confirmation requirements
  • Update SelectDeposits to prioritize more-confirmed deposits first, increasing the likelihood of server acceptance when dynamic requirements apply
  • Add client-side logging of insufficient confirmation details from server errors, helping users understand when deposits need more confirmations before retrying

Proto updates:

  • Add DepositConfirmationStatus message with current/required confirmations and blocks to wait
  • Add InsufficientConfirmationsDetails message for structured error responses

Backwards compatible: Clients with older servers will continue to work normally. The server determines actual confirmation requirements.

@gemini-code-assist
Copy link

Summary of Changes

Hello @hieblmi, 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 updates the static address loop-in client to dynamically adapt to server-side confirmation requirements. It streamlines the process for small swaps by reducing the client's minimum confirmation threshold, intelligently prioritizes deposits based on their confirmation status, and provides clearer feedback to users when deposits require additional confirmations. These changes improve the client's efficiency and user experience when interacting with servers that implement risk-based confirmation policies.

Highlights

  • Reduced Minimum Confirmations: The client's MinConfs constant has been lowered from 6 to 1. This change allows for faster swap attempts, particularly for smaller amounts, by relying on the server's dynamic, risk-based confirmation requirements.
  • Optimized Deposit Selection Logic: The SelectDeposits function now prioritizes deposits based on a new sorting order: first by the number of confirmations (more confirmed deposits are preferred), then by larger amounts, and finally by those expiring sooner. This increases the likelihood of server acceptance when dynamic confirmation rules are in effect.
  • Enhanced Client-Side Error Logging: New client-side logging has been implemented to provide detailed information when a server returns an 'insufficient confirmations' error. This helps users understand precisely why a deposit might need more confirmations before a retry.
  • New Protocol Buffer Messages: Two new protobuf messages, DepositConfirmationStatus and InsufficientConfirmationsDetails, have been introduced. These messages provide a structured way for the server to communicate detailed confirmation requirements and statuses to the client.

🧠 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 changed the title Dyn deposit confs staticaddr: dynamic deposit conf target matching legacy loop-in Jan 9, 2026
Copy link

@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 introduces support for dynamic server-side confirmation requirements for static address loop-ins. The client's minimum confirmation requirement is lowered to 1, and the deposit selection logic is updated to prioritize deposits with more confirmations. Additionally, the client now logs detailed information when a swap fails due to insufficient confirmations, improving user feedback. The changes look good and align with the goal of providing more flexibility for loop-in swaps. I've added a couple of minor suggestions to improve log message formatting for better readability.

Comment on lines +933 to +934
log.Warnf("Insufficient deposit confirmations, max wait: "+
"%d blocks", confDetails.MaxBlocksToWait)

Choose a reason for hiding this comment

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

medium

For better readability and to avoid string concatenation, you can include the full format string directly in log.Warnf.

log.Warnf("Insufficient deposit confirmations, max wait: %d blocks", confDetails.MaxBlocksToWait)

Comment on lines +937 to +940
log.Warnf(" Deposit %s: %d/%d confirmations "+
"(need %d more blocks)",
dep.Outpoint, dep.CurrentConfirmations,
dep.RequiredConfirmations, dep.BlocksToWait)

Choose a reason for hiding this comment

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

medium

For better readability and to avoid string concatenation, you can include the full format string directly in log.Warnf.

log.Warnf("  Deposit %s: %d/%d confirmations (need %d more blocks)",
    dep.Outpoint, dep.CurrentConfirmations,
    dep.RequiredConfirmations, dep.BlocksToWait)

@hieblmi hieblmi self-assigned this Jan 9, 2026
@hieblmi hieblmi marked this pull request as draft January 9, 2026 13:45
@levmi levmi added this to the e window super small milestone Jan 29, 2026
@hieblmi hieblmi force-pushed the dyn-deposit-confs branch 9 times, most recently from 48555a2 to bb2cfd2 Compare February 4, 2026 19:48
@hieblmi hieblmi marked this pull request as ready for review February 6, 2026 13:47
@hieblmi hieblmi changed the title staticaddr: dynamic deposit conf target matching legacy loop-in staticaddr: dynamic deposit conf target Feb 12, 2026
@lightninglabs-deploy
Copy link

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

In successive commits we want to access lnrpc specifc methods
and objects, so here we import github.com/lightningnetwork/lnd v0.20.1-beta
into looprpc and update relevant versions.
…lRequest

In this commit we import the lnd's lightning.proto into client.proto to
then be able to use lnrpc.OutPoint and lnrpc.OpenChannelRequest instead
of the looprpc.OutPoint type.
This is safe because the lnrpc and looprpc versions of OutPoint are the
same type.
Add macaroon permissions for the new StaticOpenChannel RPC method
and change StaticAddressLoopIn action from read to execute to match
other swap operations.
Block-based deposit fetching from the internal lnd wallet was
susceptible to wallet syncing issues. Replace it with interval-based
polling. Reconciliation errors are now logged instead of being fatal,
improving resilience during transient failures.
Protect the shimPending variable with a sync.Mutex since it is accessed
from multiple goroutines: the main loop goroutine and the server error
handling goroutine. Without synchronization this is a data race.
Return an error instead of just logging when chainhash.NewHash fails in
the ChanPending handler. The hash variable would be nil and crash on the
subsequent String() call.
…ublished

Both OpeningChannel and ChannelPublished lacked OnExpiry transitions.
handleBlockNotification fires OnExpiry on every new block once the
deposit is expired, regardless of the current state. Since both states
use NoOpAction or FinalizeDepositAction which release the FSM mutex
briefly, an OnExpiry SendEvent can sneak in. Add self-transitions so
the event is safely absorbed.
Duplicate outpoints in the request lead to fee miscalculation and an
invalid PSBT with the same input listed twice. Validate early and return
a clear error message.
Remove unreachable error check after filterNewDeposits which does not
return an error. The err variable was already handled from the
ListUnspent call above and could never be non-nil at this point.
If the PSBT finalize step succeeds but the stream fails before
ChanPending, deposits would remain stuck in OpeningChannel until the
next daemon restart. Run the recovery logic immediately so deposits are
resolved without requiring a restart.
Add tests for the following edge cases requested in review:

- Reorg: channel tx reorged, UTXOs reappear as unspent, deposits
  return to Deposited state.
- Daemon restart during channel opening: deposits in OpeningChannel
  recovered based on UTXO status (spent → ChannelPublished, unspent →
  Deposited).
- Mempool eviction: tx evicted, UTXOs unspent, deposits return to
  Deposited.
- Mempool rejection: tx never accepted, same recovery as eviction.
- Stream errors: lnd stream fails before PSBT finalize, error returned
  without errPsbtFinalized so deposits can be safely rolled back.
- PSBT finalize then stream abort: finalize succeeds but stream dies
  before ChanPending, error wrapped with errPsbtFinalized so caller
  triggers recovery instead of blind rollback.
- Duplicate outpoints: already covered by TestOpenChannelDuplicateOutpoints.
Add DepositConfirmationStatus and InsufficientConfirmationsDetails
messages to support structured error responses when deposits lack
sufficient confirmations for dynamic risk requirements.
Reduce MinConfs from 6 to 3 to allow faster swap attempts while the
server enforces risk-based confirmation requirements. Update
SelectDeposits to prioritize more-confirmed deposits first, increasing
the likelihood of server acceptance. Add client-side logging of
insufficient confirmation details from server error responses.
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.

3 participants