Skip to content

staticaddr: dynamic deposit conf target#1097

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

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

Conversation

@hieblmi
Copy link
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.

hieblmi added 2 commits March 16, 2026 13:54
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)
@gemini-code-assist
Copy link

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

@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 on lines 884 to 903
sort.Slice(deposits, func(i, j int) bool {
if deposits[i].Value == deposits[j].Value {
iExp := uint32(deposits[i].ConfirmationHeight) +
csvExpiry - blockHeight
jExp := uint32(deposits[j].ConfirmationHeight) +
csvExpiry - blockHeight

return iExp < jExp
// Primary: more confirmations first. Guard against the
// theoretical case where ConfirmationHeight > blockHeight
// (e.g. during a transient reorg inconsistency).
var iConfs, jConfs uint32
if blockHeight > uint32(deposits[i].ConfirmationHeight) {
iConfs = blockHeight -
uint32(deposits[i].ConfirmationHeight)
}
if blockHeight > uint32(deposits[j].ConfirmationHeight) {
jConfs = blockHeight -
uint32(deposits[j].ConfirmationHeight)
}
if iConfs != jConfs {
return iConfs > jConfs
}

// Secondary: larger amounts first.
return deposits[i].Value > deposits[j].Value
})

Choose a reason for hiding this comment

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

high

The updated comment for SelectDeposits (lines 853-859) and the inline comment here (lines 880-883) state three sorting priorities:

  1. More confirmations first.
  2. Larger amounts first.
  3. Expiring sooner first.

However, the sort.Slice implementation only includes the first two priorities. The third priority, "expiring sooner first," which was previously a tie-breaker for deposits with equal values, is no longer present in the sorting logic. This discrepancy between the documented behavior and the actual implementation could lead to suboptimal deposit selection, particularly for deposits that are time-sensitive but have similar confirmation counts and values.

Consider re-introducing the expiry-based tie-breaker or updating the comments to accurately reflect the implemented sorting logic.

sort.Slice(deposits, func(i, j int) bool {
		// Primary: more confirmations first. Guard against the
		// theoretical case where ConfirmationHeight > blockHeight
		// (e.g. during a transient reorg inconsistency).
		var iConfs, jConfs uint32
		if blockHeight > uint32(deposits[i].ConfirmationHeight) {
			iConfs = blockHeight -
				uint32(deposits[i].ConfirmationHeight)
		}
		if blockHeight > uint32(deposits[j].ConfirmationHeight) {
			jConfs = blockHeight -
				uint32(deposits[j].ConfirmationHeight)
		}
		if iConfs != jConfs {
			return iConfs > jConfs
		}

		// Secondary: larger amounts first.
		if deposits[i].Value != deposits[j].Value {
			return deposits[i].Value > deposits[j].Value
		}

		// Tertiary: expiring sooner first.
		iExp := uint32(deposits[i].ConfirmationHeight) +
			csvExpiry - blockHeight
		jExp := uint32(deposits[j].ConfirmationHeight) +
			csvExpiry - blockHeight

		return iExp < jExp
	})

Comment on lines +29 to +30
// Sorting priority: 1) more confirmations first, 2) larger amounts first,
// 3) expiring sooner first.

Choose a reason for hiding this comment

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

medium

The comment here states "3) expiring sooner first" as a sorting priority, but the SelectDeposits function's implementation (in staticaddr/loopin/manager.go) does not include this logic. This creates an inconsistency between the test description and the actual code behavior. Please update the comment to accurately reflect the implemented sorting priorities, or adjust the SelectDeposits function to include this priority.

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.

1 participant