Skip to content

Commit a7ab998

Browse files
committed
instantout: check reservation expiry
1 parent 1a31bbf commit a7ab998

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

instantout/actions.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/lightningnetwork/lnd/lntypes"
2222
)
2323

24-
var (
24+
const (
2525
// Define route independent max routing fees. We have currently no way
2626
// to get a reliable estimate of the routing fees. Best we can do is
2727
// the minimum routing fees, which is not very indicative.
@@ -46,6 +46,10 @@ var (
4646
// defaultPollPaymentTime is the default time to poll the server for the
4747
// payment status.
4848
defaultPollPaymentTime = time.Second * 15
49+
50+
// htlcExpiryDelta is the delta in blocks we require between the htlc
51+
// expiry and reservation expiry.
52+
htlcExpiryDelta = int32(40)
4953
)
5054

5155
// InitInstantOutCtx contains the context for the InitInstantOutAction.
@@ -96,6 +100,15 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType {
96100
reservationAmt += uint64(res.Value)
97101
reservationIds = append(reservationIds, resId[:])
98102
reservations = append(reservations, res)
103+
104+
// Check that the reservation expiry is larger than the cltv
105+
// expiry of the swap, with an additional delta to allow for
106+
// preimage reveal.
107+
if int32(res.Expiry) < initCtx.cltvExpiry+htlcExpiryDelta {
108+
return f.HandleError(fmt.Errorf("reservation %x has "+
109+
"expiry %v which is less than the swap expiry %v",
110+
resId, res.Expiry, initCtx.cltvExpiry))
111+
}
99112
}
100113

101114
// Create the preimage for the swap.

instantout/manager.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/btcsuite/btcd/btcutil"
11+
"github.com/lightninglabs/loop/fsm"
1112
"github.com/lightninglabs/loop/instantout/reservation"
1213
"github.com/lightninglabs/loop/swapserverrpc"
1314
"github.com/lightningnetwork/lnd/lntypes"
@@ -169,15 +170,10 @@ func (m *Manager) NewInstantOut(ctx context.Context,
169170
// waiting for sweepless sweep to be confirmed.
170171
err = instantOut.DefaultObserver.WaitForState(
171172
ctx, defaultStateWaitTime, WaitForSweeplessSweepConfirmed,
173+
fsm.WithAbortEarlyOnErrorOption(),
172174
)
173175
if err != nil {
174-
if instantOut.LastActionError != nil {
175-
return instantOut, fmt.Errorf(
176-
"error waiting for sweepless sweep "+
177-
"confirmed: %w", instantOut.LastActionError,
178-
)
179-
}
180-
return instantOut, nil
176+
return nil, err
181177
}
182178

183179
return instantOut, nil

0 commit comments

Comments
 (0)