mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
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:
parent
0223caa370
commit
1c89ff83f1
2 changed files with 26 additions and 2 deletions
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue