staticaddr/loopin: account for autoloop deposit expiry

Use the shared deposit-expiry helper when building autoloop DP
candidates so unconfirmed deposits do not look like the
earliest-expiring options.

This keeps the no-change selector's expiry tie-break aligned with the
generic loop-in deposit selection rules.
This commit is contained in:
Slyghtning 2026-07-06 11:59:22 +02:00
parent 0223caa370
commit 1c89ff83f1
No known key found for this signature in database
GPG key ID: F82D456EA023C9BF
2 changed files with 26 additions and 2 deletions

View file

@ -246,8 +246,10 @@ func filterAutoloopCandidateDeposits(maxAmount btcutil.Amount,
continue
}
residualLife := confirmationHeight +
int64(csvExpiry) - int64(blockHeight)
residualLife := int64(blocksUntilDepositExpiry(
uint32(confirmationHeight),
blockHeight, csvExpiry,
))
eligibleDeposits = append(
eligibleDeposits, autoloopCandidateDeposit{

View file

@ -80,6 +80,28 @@ func TestSelectNoChangeDepositsWithMemoryBudget(t *testing.T) {
}
}
// TestSelectNoChangeDepositsPrefersConfirmedTie verifies unconfirmed deposits
// are not treated as earlier-expiring than confirmed deposits. Their CSV timer
// has not started yet, so a same-value confirmed deposit should win the expiry
// tie-break.
func TestSelectNoChangeDepositsPrefersConfirmedTie(t *testing.T) {
t.Parallel()
unconfirmed := makeDeposit(34, 0, 5_000, 0)
confirmed := makeDeposit(35, 0, 5_000, 200)
deposits, err := selectNoChangeDeposits(
5_000, 5_000, []*deposit.Deposit{
unconfirmed, confirmed,
}, 1_000, 100, nil,
)
require.NoError(t, err)
require.Equal(
t, []string{confirmed.OutPoint.String()},
depositOutpoints(deposits),
)
}
// TestAutoloopDPSizing verifies the bucket sizing math. These cases are easier
// to understand directly than by inferring the step from a larger selector
// behavior test.