@@ -38,27 +38,33 @@ const (
38
38
// We'll try to sweep with MuSig2 at most 10 times. If that fails we'll
39
39
// fail back to using standard scriptspend sweep.
40
40
maxMusigSweepRetries = 10
41
- )
42
41
43
- var (
44
42
// MinLoopOutPreimageRevealDelta configures the minimum number of
45
43
// remaining blocks before htlc expiry required to reveal preimage.
46
- MinLoopOutPreimageRevealDelta int32 = 20
44
+ MinLoopOutPreimageRevealDelta = 20
47
45
48
46
// DefaultSweepConfTarget is the default confirmation target we'll use
49
47
// when sweeping on-chain HTLCs.
50
- DefaultSweepConfTarget int32 = 9
48
+ DefaultSweepConfTarget = 9
51
49
52
50
// DefaultHtlcConfTarget is the default confirmation target we'll use
53
51
// for on-chain htlcs published by the swap client for Loop In.
54
- DefaultHtlcConfTarget int32 = 6
52
+ DefaultHtlcConfTarget = 6
55
53
56
54
// DefaultSweepConfTargetDelta is the delta of blocks from a Loop Out
57
- // swap's expiration height at which we begin to use the default sweep
58
- // confirmation target.
59
- //
60
- // TODO(wilmer): tune?
61
- DefaultSweepConfTargetDelta = DefaultSweepConfTarget * 2
55
+ // swap's expiration height at which we begin to cap the sweep
56
+ // confirmation target with urgentSweepConfTarget and multiply feerate
57
+ // by factor urgentSweepConfTargetFactor.
58
+ DefaultSweepConfTargetDelta = 10
59
+
60
+ // urgentSweepConfTarget is the confirmation target we'll use when the
61
+ // loop-out swap is about to expire (<= DefaultSweepConfTargetDelta
62
+ // blocks to expire).
63
+ urgentSweepConfTarget = 3
64
+
65
+ // urgentSweepConfTargetFactor is the factor we apply to feerate of
66
+ // loop-out sweep if it is about to expire.
67
+ urgentSweepConfTargetFactor = 1.1
62
68
)
63
69
64
70
// loopOutSwap contains all the in-memory state related to a pending loop out
@@ -1169,12 +1175,12 @@ func (s *loopOutSwap) waitForHtlcSpendConfirmedV2(globalCtx context.Context,
1169
1175
timerChan = s .timerFactory (repushDelay )
1170
1176
1171
1177
case <- timerChan :
1172
- // sweepConfTarget will return false if the preimage is
1178
+ // canSweep will return false if the preimage is
1173
1179
// not revealed yet but the conf target is closer than
1174
1180
// 20 blocks. In this case to be sure we won't attempt
1175
1181
// to sweep at all and we won't reveal the preimage
1176
1182
// either.
1177
- _ , canSweep := s .sweepConfTarget ()
1183
+ canSweep := s .canSweep ()
1178
1184
if ! canSweep {
1179
1185
s .log .Infof ("Aborting swap, timed " +
1180
1186
"out on-chain" )
@@ -1375,9 +1381,9 @@ func validateLoopOutContract(lnd *lndclient.LndServices, request *OutRequest,
1375
1381
return nil
1376
1382
}
1377
1383
1378
- // sweepConfTarget returns the confirmation target for the htlc sweep or false
1379
- // if we're too late.
1380
- func (s * loopOutSwap ) sweepConfTarget () ( int32 , bool ) {
1384
+ // canSweep will return false if the preimage is not revealed yet but the conf
1385
+ // target is closer than 20 blocks (i.e. it is too late to reveal the preimage) .
1386
+ func (s * loopOutSwap ) canSweep () bool {
1381
1387
remainingBlocks := s .CltvExpiry - s .height
1382
1388
blocksToLastReveal := remainingBlocks - MinLoopOutPreimageRevealDelta
1383
1389
preimageRevealed := s .state == loopdb .StatePreimageRevealed
@@ -1393,20 +1399,8 @@ func (s *loopOutSwap) sweepConfTarget() (int32, bool) {
1393
1399
s .height )
1394
1400
1395
1401
s .state = loopdb .StateFailTimeout
1396
- return 0 , false
1397
- }
1398
-
1399
- // Calculate the transaction fee based on the confirmation target
1400
- // required to sweep the HTLC before the timeout. We'll use the
1401
- // confirmation target provided by the client unless we've come too
1402
- // close to the expiration height, in which case we'll use the default
1403
- // if it is better than what the client provided.
1404
- confTarget := s .SweepConfTarget
1405
- if remainingBlocks <= DefaultSweepConfTargetDelta &&
1406
- confTarget > DefaultSweepConfTarget {
1407
-
1408
- confTarget = DefaultSweepConfTarget
1402
+ return false
1409
1403
}
1410
1404
1411
- return confTarget , true
1405
+ return true
1412
1406
}
0 commit comments