mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
loopin: public scope for ValidateLoopInContract
This commit is contained in:
parent
c11e90138b
commit
2b31a48323
2 changed files with 19 additions and 5 deletions
|
|
@ -43,9 +43,13 @@ var (
|
|||
ErrSwapAmountTooHigh = errors.New("swap amount too high")
|
||||
|
||||
// ErrExpiryTooFar is returned when the server proposes an expiry that
|
||||
// is too soon for us.
|
||||
// is too far in the future.
|
||||
ErrExpiryTooFar = errors.New("swap expiry too far")
|
||||
|
||||
// ErrExpiryTooSoon is returned when the server proposes an expiry that
|
||||
// is too soon.
|
||||
ErrExpiryTooSoon = errors.New("swap expiry too soon")
|
||||
|
||||
// ErrInsufficientBalance indicates insufficient confirmed balance to
|
||||
// publish a swap.
|
||||
ErrInsufficientBalance = errors.New("insufficient confirmed balance")
|
||||
|
|
|
|||
18
loopin.go
18
loopin.go
|
|
@ -38,6 +38,10 @@ var (
|
|||
// getting us to lock up our funds to an arbitrary point in the future.
|
||||
MaxLoopInAcceptDelta = int32(1500)
|
||||
|
||||
// MinLoopInExpiryDelta defines the minimum number of remaining blocks
|
||||
// that we accept until htlc expiry path that opens up for us to sweep.
|
||||
MinLoopInExpiryDelta = int32(100)
|
||||
|
||||
// MinLoopInPublishDelta defines the minimum number of remaining blocks
|
||||
// until on-chain htlc expiry required to proceed to publishing the htlc
|
||||
// tx. This value isn't critical, as we could even safely publish the
|
||||
|
|
@ -248,7 +252,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
|
|||
|
||||
// Validate if the response parameters are outside our allowed range
|
||||
// preventing us from continuing with a swap.
|
||||
err = validateLoopInContract(currentHeight, swapResp)
|
||||
err = ValidateLoopInContract(currentHeight, swapResp.expiry)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -429,14 +433,20 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
|
|||
return swap, nil
|
||||
}
|
||||
|
||||
// validateLoopInContract validates the contract parameters against our request.
|
||||
func validateLoopInContract(height int32, response *newLoopInResponse) error {
|
||||
// ValidateLoopInContract validates the contract parameters against our
|
||||
// configured maximum values.
|
||||
func ValidateLoopInContract(height int32, htlcExpiry int32) error {
|
||||
// Verify that we are not forced to publish a htlc that locks up our
|
||||
// funds for too long in case the server doesn't follow through.
|
||||
if response.expiry-height > MaxLoopInAcceptDelta {
|
||||
if htlcExpiry-height > MaxLoopInAcceptDelta {
|
||||
return ErrExpiryTooFar
|
||||
}
|
||||
|
||||
// Ensure that the expiry height is in the future.
|
||||
if htlcExpiry < height+MinLoopInExpiryDelta {
|
||||
return ErrExpiryTooSoon
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue