Skip to content

Commit 82b58e5

Browse files
committed
loopout: attempt cooperative musig2 sweep
This commit adds optional cooperative musig2 sweep by calling the server to create a partial signature for the sweep if we'd otherwise be allowed to spend the htlc. If the cooperative musig2 spend fails, we always fall back to use the scriptpath spend.
1 parent 32557a5 commit 82b58e5

File tree

5 files changed

+546
-101
lines changed

5 files changed

+546
-101
lines changed

client_test.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ func testLoopOutResume(t *testing.T, confs uint32, expired, preimageRevealed,
309309

310310
// Because there is no reliable payment yet, an invoice is assumed to be
311311
// paid after resume.
312-
313312
testLoopOutSuccess(ctx, amt, hash,
314313
func(r error) {},
315314
func(r error) {},
@@ -336,14 +335,31 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
336335
// Publish tick.
337336
ctx.expiryChan <- testTime
338337

339-
// Expect a signing request.
340-
<-ctx.Lnd.SignOutputRawChannel
338+
// Expect a signing request in the non taproot case.
339+
if scriptVersion != swap.HtlcV3 {
340+
<-ctx.Lnd.SignOutputRawChannel
341+
}
341342

342343
if !preimageRevealed {
343344
ctx.assertStatus(loopdb.StatePreimageRevealed)
344345
ctx.assertStorePreimageReveal()
345346
}
346347

348+
// When using taproot htlcs the flow is different as we do reveal the
349+
// preimage before sweeping in order for the server to trust us with
350+
// our MuSig2 signing attempts.
351+
if scriptVersion == swap.HtlcV3 {
352+
ctx.assertPreimagePush(testPreimage)
353+
354+
// Try MuSig2 signing first and fail it so that we go for a
355+
// normal sweep.
356+
for i := 0; i < maxMusigSweepRetries; i++ {
357+
ctx.expiryChan <- testTime
358+
ctx.assertPreimagePush(testPreimage)
359+
}
360+
<-ctx.Lnd.SignOutputRawChannel
361+
}
362+
347363
// Expect client on-chain sweep of HTLC.
348364
sweepTx := ctx.ReceiveTx()
349365

@@ -376,10 +392,11 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
376392
preimage, err := lntypes.MakePreimage(clientPreImage)
377393
require.NoError(ctx.T, err)
378394

379-
ctx.assertPreimagePush(preimage)
380-
381-
// Simulate server pulling payment.
382-
signalSwapPaymentResult(nil)
395+
if scriptVersion != swap.HtlcV3 {
396+
ctx.assertPreimagePush(preimage)
397+
// Simulate server pulling payment.
398+
signalSwapPaymentResult(nil)
399+
}
383400

384401
ctx.NotifySpend(sweepTx, 0)
385402

0 commit comments

Comments
 (0)