@@ -862,8 +862,31 @@ 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+
882+ log .Debugf ("Skipping deposit %s as it expires before " +
883+ "the htlc" , d .OutPoint .String ())
884+
885+ continue
886+ }
887+
888+ deposits = append (deposits , d )
889+ }
867890
868891 // Sort the deposits by amount in descending order, then by
869892 // blocks-until-expiry in ascending order.
0 commit comments