Skip to content

Commit 32e802e

Browse files
committed
loopin: public scope for ValidateLoopInContract
1 parent f28f845 commit 32e802e

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ var (
4343
ErrSwapAmountTooHigh = errors.New("swap amount too high")
4444

4545
// ErrExpiryTooFar is returned when the server proposes an expiry that
46-
// is too soon for us.
46+
// is too far in the future.
4747
ErrExpiryTooFar = errors.New("swap expiry too far")
4848

49+
// ErrExpiryTooSoon is returned when the server proposes an expiry that
50+
// is too soon.
51+
ErrExpiryTooSoon = errors.New("swap expiry too soon")
52+
4953
// ErrInsufficientBalance indicates insufficient confirmed balance to
5054
// publish a swap.
5155
ErrInsufficientBalance = errors.New("insufficient confirmed balance")

loopin.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ var (
3838
// getting us to lock up our funds to an arbitrary point in the future.
3939
MaxLoopInAcceptDelta = int32(1500)
4040

41+
// MinLoopInExpiryDelta defines the minimum number of remaining blocks
42+
// that we accept until htlc expiry path that opens up for us to sweep.
43+
MinLoopInExpiryDelta = int32(144)
44+
4145
// MinLoopInPublishDelta defines the minimum number of remaining blocks
4246
// until on-chain htlc expiry required to proceed to publishing the htlc
4347
// tx. This value isn't critical, as we could even safely publish the
@@ -248,7 +252,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
248252

249253
// Validate if the response parameters are outside our allowed range
250254
// preventing us from continuing with a swap.
251-
err = validateLoopInContract(currentHeight, swapResp)
255+
err = ValidateLoopInContract(currentHeight, swapResp.expiry)
252256
if err != nil {
253257
return nil, err
254258
}
@@ -429,14 +433,20 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
429433
return swap, nil
430434
}
431435

432-
// validateLoopInContract validates the contract parameters against our request.
433-
func validateLoopInContract(height int32, response *newLoopInResponse) error {
436+
// ValidateLoopInContract validates the contract parameters against our
437+
// configured maximum values.
438+
func ValidateLoopInContract(height int32, htlcExpiry int32) error {
434439
// Verify that we are not forced to publish a htlc that locks up our
435440
// funds for too long in case the server doesn't follow through.
436-
if response.expiry-height > MaxLoopInAcceptDelta {
441+
if htlcExpiry-height > MaxLoopInAcceptDelta {
437442
return ErrExpiryTooFar
438443
}
439444

445+
// Ensure that the expiry height is in the future.
446+
if htlcExpiry <= height+MinLoopInExpiryDelta {
447+
return ErrExpiryTooSoon
448+
}
449+
440450
return nil
441451
}
442452

0 commit comments

Comments
 (0)