Skip to content

Commit f2d798c

Browse files
authored
Merge pull request #574 from sputn1ck/musig2_default
protocol: set musig2 to be the stable version
2 parents 39bb43c + 960a78b commit f2d798c

File tree

5 files changed

+13
-142
lines changed

5 files changed

+13
-142
lines changed

client_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestLoopOutSuccess(t *testing.T) {
6969

7070
testLoopOutSuccess(ctx, testRequest.Amount, info.SwapHash,
7171
signalPrepaymentResult, signalSwapPaymentResult, false,
72-
confIntent, swap.HtlcV2,
72+
confIntent, swap.HtlcV3,
7373
)
7474
}
7575

@@ -154,6 +154,7 @@ func TestLoopOutResume(t *testing.T) {
154154
loopdb.ProtocolVersionUnrecorded,
155155
loopdb.ProtocolVersionHtlcV2,
156156
loopdb.ProtocolVersionHtlcV3,
157+
loopdb.ProtocolVersionMuSig2,
157158
}
158159

159160
for _, version := range storedVersion {
@@ -339,13 +340,13 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
339340
// preimage before sweeping in order for the server to trust us with
340341
// our MuSig2 signing attempts.
341342
if scriptVersion == swap.HtlcV3 {
342-
ctx.assertPreimagePush(testPreimage)
343+
ctx.assertPreimagePush(ctx.store.loopOutSwaps[hash].Preimage)
343344

344345
// Try MuSig2 signing first and fail it so that we go for a
345346
// normal sweep.
346347
for i := 0; i < maxMusigSweepRetries; i++ {
347348
ctx.expiryChan <- testTime
348-
ctx.assertPreimagePush(testPreimage)
349+
ctx.assertPreimagePush(ctx.store.loopOutSwaps[hash].Preimage)
349350
}
350351
<-ctx.Context.Lnd.SignOutputRawChannel
351352
}
@@ -380,10 +381,11 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash,
380381

381382
if scriptVersion != swap.HtlcV3 {
382383
ctx.assertPreimagePush(preimage)
383-
// Simulate server pulling payment.
384-
signalSwapPaymentResult(nil)
385384
}
386385

386+
// Simulate server pulling payment.
387+
signalSwapPaymentResult(nil)
388+
387389
ctx.NotifySpend(sweepTx, 0)
388390

389391
ctx.assertStatus(loopdb.StateSuccess)

loopdb/protocol_version.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ const (
6464

6565
// stableRPCProtocolVersion defines the current stable RPC protocol
6666
// version.
67-
stableRPCProtocolVersion = looprpc.ProtocolVersion_ROUTING_PLUGIN
67+
stableRPCProtocolVersion = looprpc.ProtocolVersion_MUSIG2
6868

6969
// experimentalRPCProtocolVersion defines the RPC protocol version that
7070
// includes all currently experimentally released features.
71-
experimentalRPCProtocolVersion = looprpc.ProtocolVersion_MUSIG2
71+
experimentalRPCProtocolVersion = stableRPCProtocolVersion
7272
)
7373

7474
var (

loopdb/protocol_version_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestProtocolVersionSanity(t *testing.T) {
2525
ProtocolVersionProbe,
2626
ProtocolVersionRoutingPlugin,
2727
ProtocolVersionHtlcV3,
28+
ProtocolVersionMuSig2,
2829
}
2930

3031
rpcVersions := [...]looprpc.ProtocolVersion{
@@ -39,6 +40,7 @@ func TestProtocolVersionSanity(t *testing.T) {
3940
looprpc.ProtocolVersion_PROBE,
4041
looprpc.ProtocolVersion_ROUTING_PLUGIN,
4142
looprpc.ProtocolVersion_HTLC_V3,
43+
looprpc.ProtocolVersion_MUSIG2,
4244
}
4345

4446
require.Equal(t, len(versions), len(rpcVersions))
@@ -49,7 +51,7 @@ func TestProtocolVersionSanity(t *testing.T) {
4951
// Finally test that the current version contants are up to date
5052
require.Equal(t,
5153
CurrentProtocolVersion(),
52-
versions[len(versions)-2],
54+
versions[len(versions)-1],
5355
)
5456

5557
require.Equal(t,

loopout_test.go

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -694,140 +694,6 @@ func testPreimagePush(t *testing.T) {
694694
require.NoError(t, <-errChan)
695695
}
696696

697-
// TestExpiryBeforeReveal tests the case where the on-chain HTLC expires before
698-
// we have revealed our preimage, demonstrating that we do not reveal our
699-
// preimage once we've reached our expiry height.
700-
func TestExpiryBeforeReveal(t *testing.T) {
701-
t.Run("stable protocol", func(t *testing.T) {
702-
testExpiryBeforeReveal(t)
703-
})
704-
705-
// Note that there's no point of testing this case with the new
706-
// protocol where we use taproot htlc and attempt MuSig2 sweep. The
707-
// reason is that the preimage is revealed to the server once the
708-
// htlc is confirmed in order to facilitate the cooperative signing of
709-
// the sweep transaction.
710-
}
711-
712-
func testExpiryBeforeReveal(t *testing.T) {
713-
defer test.Guard(t)()
714-
715-
lnd := test.NewMockLnd()
716-
ctx := test.NewContext(t, lnd)
717-
server := newServerMock(lnd)
718-
719-
testReq := *testRequest
720-
721-
// Set on-chain HTLC CLTV.
722-
testReq.Expiry = ctx.Lnd.Height + testLoopOutMinOnChainCltvDelta
723-
724-
// Set our fee estimate to higher than our max miner fee will allow.
725-
lnd.SetFeeEstimate(testReq.SweepConfTarget, chainfee.SatPerKWeight(
726-
testReq.MaxMinerFee*2,
727-
))
728-
729-
// Setup the cfg using mock server and init a loop out request.
730-
cfg := newSwapConfig(
731-
&lnd.LndServices, newStoreMock(t), server,
732-
)
733-
initResult, err := newLoopOutSwap(
734-
context.Background(), cfg, ctx.Lnd.Height, &testReq,
735-
)
736-
require.NoError(t, err)
737-
swap := initResult.swap
738-
739-
// Set up the required dependencies to execute the swap.
740-
sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices}
741-
blockEpochChan := make(chan interface{})
742-
statusChan := make(chan SwapInfo)
743-
expiryChan := make(chan time.Time)
744-
timerFactory := func(_ time.Duration) <-chan time.Time {
745-
return expiryChan
746-
}
747-
748-
errChan := make(chan error)
749-
go func() {
750-
err := swap.execute(context.Background(), &executeConfig{
751-
statusChan: statusChan,
752-
blockEpochChan: blockEpochChan,
753-
timerFactory: timerFactory,
754-
sweeper: sweeper,
755-
verifySchnorrSig: mockVerifySchnorrSigFail,
756-
}, ctx.Lnd.Height)
757-
if err != nil {
758-
log.Error(err)
759-
}
760-
errChan <- err
761-
}()
762-
763-
// The swap should be found in its initial state.
764-
cfg.store.(*storeMock).assertLoopOutStored()
765-
state := <-statusChan
766-
require.Equal(t, loopdb.StateInitiated, state.State)
767-
768-
// We'll then pay both the swap and prepay invoice, which should trigger
769-
// the server to publish the on-chain HTLC.
770-
signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc)
771-
signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc)
772-
773-
signalSwapPaymentResult(nil)
774-
signalPrepaymentResult(nil)
775-
776-
// Notify the confirmation notification for the HTLC.
777-
ctx.AssertRegisterConf(false, defaultConfirmations)
778-
779-
// Advance the block height to get the HTLC confirmed.
780-
height := ctx.Lnd.Height + 1
781-
blockEpochChan <- height
782-
783-
htlcTx := wire.NewMsgTx(2)
784-
htlcTx.AddTxOut(&wire.TxOut{
785-
Value: int64(swap.AmountRequested),
786-
PkScript: swap.htlc.PkScript,
787-
})
788-
ctx.NotifyConf(htlcTx)
789-
790-
// The client should then register for a spend of the HTLC and attempt
791-
// to sweep it using the custom confirmation target.
792-
ctx.AssertRegisterSpendNtfn(swap.htlc.PkScript)
793-
794-
// Assert that we made a query to track our payment, as required for
795-
// preimage push tracking.
796-
ctx.AssertTrackPayment()
797-
798-
// Tick the expiry channel. Because our max miner fee is too high, we
799-
// won't attempt a sweep at this point.
800-
expiryChan <- testTime
801-
802-
// Since we don't have a reliable mechanism to non-intrusively avoid
803-
// races by setting the fee estimate too soon, let's sleep here a bit
804-
// to ensure the first sweep fails.
805-
time.Sleep(500 * time.Millisecond)
806-
807-
// Now we decrease our conf target to less than our max miner fee.
808-
lnd.SetFeeEstimate(testReq.SweepConfTarget, chainfee.SatPerKWeight(
809-
testReq.MaxMinerFee/2,
810-
))
811-
812-
// Advance the block height to the point where we would do timeout
813-
// instead of pushing the preimage.
814-
blockEpochChan <- testReq.Expiry + height
815-
816-
// Tick our expiry channel again to trigger another sweep attempt.
817-
expiryChan <- testTime
818-
819-
// We should see our swap marked as failed.
820-
cfg.store.(*storeMock).assertLoopOutState(
821-
loopdb.StateFailTimeout,
822-
)
823-
status := <-statusChan
824-
require.Equal(
825-
t, status.State, loopdb.StateFailTimeout,
826-
)
827-
828-
require.Nil(t, <-errChan)
829-
}
830-
831697
// TestFailedOffChainCancelation tests sending of a cancelation message to
832698
// the server when a swap fails due to off-chain routing.
833699
func TestFailedOffChainCancelation(t *testing.T) {

release_notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This file tracks release notes for the loop client.
1313
* Once the version bump PR is merged and tagged, add the release notes to the tag on GitHub.
1414

1515
## Next release
16+
* Set musig2 to be the default swap protocol.
1617

1718
#### New Features
1819

0 commit comments

Comments
 (0)