Skip to content

staticaddr: dynamic deposit conf target#1097

Closed
hieblmi wants to merge 2 commits into
lightninglabs:masterfrom
hieblmi:dyn-deposit-confs
Closed

staticaddr: dynamic deposit conf target#1097
hieblmi wants to merge 2 commits into
lightninglabs:masterfrom
hieblmi:dyn-deposit-confs

Conversation

@hieblmi
Copy link
Copy Markdown
Collaborator

@hieblmi hieblmi commented Mar 16, 2026

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

Changes:

  • Reduce MinConfs from 6 to 3 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
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 enhances the static address loop-in client to gracefully handle dynamic confirmation requirements imposed by the server. By reducing the client's default minimum confirmation threshold and intelligently prioritizing deposits with higher confirmation counts, the system can now facilitate quicker and more reliable loop-in swaps, especially for smaller transactions. Additionally, improved error logging provides users with actionable insights when deposits require more confirmations.

Highlights

  • Reduced Minimum Confirmations: The MinConfs for deposits has been lowered from 6 to 3, enabling faster swap attempts for smaller amounts while the server enforces risk-based confirmation requirements.
  • Prioritized Deposit Selection: The SelectDeposits function now prioritizes deposits with more confirmations, increasing the likelihood of server acceptance when dynamic requirements apply.
  • Enhanced Client-Side Logging: New client-side logging provides detailed information about insufficient confirmation errors from the server, helping users understand why a retry might be needed.
  • New Protobuf Messages: Introduced DepositConfirmationStatus and InsufficientConfirmationsDetails protobuf messages to convey structured error responses regarding deposit confirmations.

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

Changelog
  • staticaddr/deposit/manager.go
    • Reduced MinConfs from 6 to 3.
  • staticaddr/loopin/actions.go
    • Imported google.golang.org/grpc/status.
    • Added a call to logInsufficientConfirmationsDetails when a loop-in initiation fails.
    • Implemented logInsufficientConfirmationsDetails to parse and log structured gRPC error details about insufficient confirmations.
  • staticaddr/loopin/manager.go
    • Updated the SelectDeposits function's sorting logic to prioritize deposits by confirmation count (descending), then by amount (descending), and finally by blocks-until-expiry (ascending).
    • Revised the function's comment to reflect the new sorting priorities.
  • staticaddr/loopin/manager_test.go
    • Updated the TestSelectDeposits function's description to mention the new sorting priority.
    • Added testBlockHeight and testCsvExpiry constants for more realistic test scenarios.
    • Modified existing test cases and added new ones to validate the updated deposit selection logic, specifically focusing on confirmation priority.
  • swapserverrpc/staticaddr.pb.go
    • Generated Go code for the new InsufficientConfirmationsDetails and DepositConfirmationStatus protobuf messages.
    • Updated message and dependency counts.
  • swapserverrpc/staticaddr.proto
    • Defined new protobuf messages: InsufficientConfirmationsDetails (containing a list of DepositConfirmationStatus and max_blocks_to_wait) and DepositConfirmationStatus (detailing outpoint, current/required confirmations, and blocks to wait).
Activity
  • The author, hieblmi, updated the static address loop-in client to support dynamic server-side confirmation requirements.
  • The author reduced the MinConfs from 6 to 3 to allow faster swap attempts for small amounts.
  • The author updated SelectDeposits to prioritize more-confirmed deposits.
  • The author added client-side logging of insufficient confirmation details from server errors.
  • The author included proto updates for DepositConfirmationStatus and InsufficientConfirmationsDetails messages.
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.

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

The pull request introduces dynamic deposit confirmation targets, which is a valuable improvement for optimizing swap attempts. The changes include reducing the minimum confirmations, prioritizing more-confirmed deposits, and adding client-side logging for insufficient confirmation errors. New protobuf messages have been added to support structured error responses. The overall direction of these changes is positive for improving the flexibility and user feedback of the static address loop-in client.

However, there is an inconsistency in the SelectDeposits function's sorting logic. While the comments indicate three sorting priorities (more confirmations, larger amounts, and expiring sooner), the implemented code only accounts for the first two. The 'expiring sooner first' logic, which was present in the previous version as a tie-breaker, appears to have been removed from the current implementation. This could lead to suboptimal selection of deposits, especially for time-sensitive ones.

Comment thread staticaddr/loopin/manager.go
Comment thread staticaddr/loopin/manager_test.go
@hieblmi hieblmi force-pushed the dyn-deposit-confs branch 4 times, most recently from 203c29a to 8321cc2 Compare March 19, 2026 08:52
@hieblmi
Copy link
Copy Markdown
Collaborator Author

hieblmi commented Mar 19, 2026

@claude review this

@hieblmi hieblmi requested a review from starius March 19, 2026 09:20
hieblmi added 2 commits March 20, 2026 13:50
Add DepositConfirmationStatus and InsufficientConfirmationsDetails
messages to support structured error responses when deposits lack
sufficient confirmations for dynamic risk requirements.

(cherry picked from commit 69a0798)
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.

(cherry picked from commit 66a17f4)
@hieblmi hieblmi force-pushed the dyn-deposit-confs branch from 8321cc2 to d22be64 Compare March 20, 2026 12:50
@lightninglabs-deploy
Copy link
Copy Markdown

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

// deposit to be considered available for loop-ins, coop-spends and
// timeouts.
MinConfs = 6
MinConfs = 3
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We need to hold this PR until we deploy the server side. Otherwise a new client might send its deposits too early to an old server.

// SelectDeposits sorts the deposits to optimize for successful swaps with
// dynamic confirmation requirements: 1) more confirmations first (higher chance
// of server acceptance), 2) larger amounts first (to minimize number of deposits
// used), 3) expiring sooner first (prioritize time-sensitive deposits).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SelectDeposits can now turn a valid amount-only swap into a more expensive or failing one because it switched to a confirmations-first greedy prefix instead of actually optimizing the chosen subset. The new logic sorts primarily by confirmations and then keeps taking the first deposits until the target is covered in staticaddr/loopin/manager.go:853-930.

That means a set like 500k@10 conf, 500k@9 conf, 1,000k@8 conf for a 1,000k target now selects two inputs instead of the exact one-input match. This is not just a UX issue: the chosen input count feeds the quote path in staticaddr/loopin/manager.go:729-742, and the later HTLC fee guards scale with f.loopIn.htlcWeight(hasChange) in staticaddr/loopin/actions.go:221-270. So the new order can produce avoidable ErrSwapFeeTooHigh or ErrFeeTooHigh failures, or simply worse fees, even when a slightly younger single deposit would already have been acceptable to the server.

If the client wants to prefer older deposits, they need a subset selection strategy that still minimizes input count and fee impact, or at least a second pass that prefers exact or lower-input covers before falling back to the confirmations-first prefix.

if err != nil {
// Check if this is an insufficient confirmations error and log
// the details to help the user understand what's needed.
logInsufficientConfirmationsDetails(err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The new normal insufficient-confirmation path leaks an invoice. InitHtlcAction creates the swap invoice before it calls ServerStaticAddressLoopIn in staticaddr/loopin/actions.go:109-148. If the server rejects the request, the new branch only logs the structured details and returns HandleError in staticaddr/loopin/actions.go:149-157.

The only invoice cancel path I found is much later in the payment-timeout monitor in staticaddr/loopin/actions.go:558-569, which is never reached for this early failure.

Early ServerStaticAddressLoopIn failures, and the follow-on fee-validation failures in staticaddr/loopin/actions.go:231-270, should cancel the freshly created invoice before unlocking the deposits.

@hieblmi hieblmi closed this Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants