@@ -862,8 +862,30 @@ func (m *Manager) GetAllSwaps(ctx context.Context) ([]*StaticAddressLoopIn,
862862// are needed to cover the amount requested without leaving a dust change. It
863863// returns an error if the sum of deposits minus dust is less than the requested
864864// amount.
865- func SelectDeposits (targetAmount btcutil.Amount , deposits []* deposit.Deposit ,
866- csvExpiry uint32 , blockHeight uint32 ) ([]* deposit.Deposit , error ) {
865+ func SelectDeposits (targetAmount btcutil.Amount ,
866+ unfilteredDeposits []* deposit.Deposit , csvExpiry uint32 ,
867+ blockHeight uint32 ) ([]* deposit.Deposit , error ) {
868+
869+ // Filter out deposits that are too close to expiry to be swapped.
870+ var deposits []* deposit.Deposit
871+ for _ , d := range unfilteredDeposits {
872+ depositExpiryHeight := d .ConfirmationHeight + int64 (csvExpiry )
873+
874+ // The htlc expiry height is the current height plus the htlc
875+ // cltv delta.
876+ htlcExpiryHeight := blockHeight + DefaultLoopInOnChainCltvDelta
877+
878+ // Ensure that the deposit doesn't expire before the htlc.
879+ if depositExpiryHeight < int64 (htlcExpiryHeight +
880+ DepositHtlcDelta ) {
881+ log .Debugf ("Skipping deposit %s as it expires close " +
882+ "to the htlc" , d .OutPoint .String ())
883+
884+ continue
885+ }
886+
887+ deposits = append (deposits , d )
888+ }
867889
868890 // Sort the deposits by amount in descending order, then by
869891 // blocks-until-expiry in ascending order.
0 commit comments