|
38 | 38 | // getting us to lock up our funds to an arbitrary point in the future. |
39 | 39 | MaxLoopInAcceptDelta = int32(1500) |
40 | 40 |
|
| 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 | + |
41 | 45 | // MinLoopInPublishDelta defines the minimum number of remaining blocks |
42 | 46 | // until on-chain htlc expiry required to proceed to publishing the htlc |
43 | 47 | // tx. This value isn't critical, as we could even safely publish the |
@@ -248,7 +252,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig, |
248 | 252 |
|
249 | 253 | // Validate if the response parameters are outside our allowed range |
250 | 254 | // preventing us from continuing with a swap. |
251 | | - err = validateLoopInContract(currentHeight, swapResp) |
| 255 | + err = ValidateLoopInContract(currentHeight, swapResp.expiry) |
252 | 256 | if err != nil { |
253 | 257 | return nil, err |
254 | 258 | } |
@@ -429,14 +433,20 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig, |
429 | 433 | return swap, nil |
430 | 434 | } |
431 | 435 |
|
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 { |
434 | 439 | // Verify that we are not forced to publish a htlc that locks up our |
435 | 440 | // funds for too long in case the server doesn't follow through. |
436 | | - if response.expiry-height > MaxLoopInAcceptDelta { |
| 441 | + if htlcExpiry-height > MaxLoopInAcceptDelta { |
437 | 442 | return ErrExpiryTooFar |
438 | 443 | } |
439 | 444 |
|
| 445 | + // Ensure that the expiry height is in the future. |
| 446 | + if htlcExpiry <= height+MinLoopInExpiryDelta { |
| 447 | + return ErrExpiryTooSoon |
| 448 | + } |
| 449 | + |
440 | 450 | return nil |
441 | 451 | } |
442 | 452 |
|
|
0 commit comments