Merge pull request #698 from sputn1ck/io_reservation_expiry

This commit is contained in:
Konstantin Nick 2024-02-12 12:33:05 +01:00 committed by GitHub
commit 6a62cd02d7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 74 additions and 17 deletions

View file

@ -21,7 +21,7 @@ import (
"github.com/lightningnetwork/lnd/lntypes"
)
var (
const (
// Define route independent max routing fees. We have currently no way
// to get a reliable estimate of the routing fees. Best we can do is
// the minimum routing fees, which is not very indicative.
@ -46,6 +46,10 @@ var (
// defaultPollPaymentTime is the default time to poll the server for the
// payment status.
defaultPollPaymentTime = time.Second * 15
// htlcExpiryDelta is the delta in blocks we require between the htlc
// expiry and reservation expiry.
htlcExpiryDelta = int32(40)
)
// InitInstantOutCtx contains the context for the InitInstantOutAction.
@ -96,6 +100,15 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType {
reservationAmt += uint64(res.Value)
reservationIds = append(reservationIds, resId[:])
reservations = append(reservations, res)
// Check that the reservation expiry is larger than the cltv
// expiry of the swap, with an additional delta to allow for
// preimage reveal.
if int32(res.Expiry) < initCtx.cltvExpiry+htlcExpiryDelta {
return f.HandleError(fmt.Errorf("reservation %x has "+
"expiry %v which is less than the swap expiry %v",
resId, res.Expiry, initCtx.cltvExpiry))
}
}
// Create the preimage for the swap.

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/loop/fsm"
"github.com/lightninglabs/loop/instantout/reservation"
looprpc "github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lntypes"
@ -169,15 +170,10 @@ func (m *Manager) NewInstantOut(ctx context.Context,
// waiting for sweepless sweep to be confirmed.
err = instantOut.DefaultObserver.WaitForState(
ctx, defaultStateWaitTime, WaitForSweeplessSweepConfirmed,
fsm.WithAbortEarlyOnErrorOption(),
)
if err != nil {
if instantOut.LastActionError != nil {
return instantOut, fmt.Errorf(
"error waiting for sweepless sweep "+
"confirmed: %w", instantOut.LastActionError,
)
}
return instantOut, nil
return nil, err
}
return instantOut, nil