From 960a78be3d43951709f296bd8007472c8a146196 Mon Sep 17 00:00:00 2001 From: sputn1ck Date: Tue, 25 Apr 2023 16:06:32 +0200 Subject: [PATCH] protocol: set musig2 to be the stable version This commit changes the stable protocol version to be the Musig2 protocol. The experimental version is set to the stable version in order for the flag to still work if a user has it set. --- client_test.go | 12 +-- loopdb/protocol_version.go | 4 +- loopdb/protocol_version_test.go | 4 +- loopout_test.go | 134 -------------------------------- release_notes.md | 1 + 5 files changed, 13 insertions(+), 142 deletions(-) diff --git a/client_test.go b/client_test.go index 2e58574..18c24cc 100644 --- a/client_test.go +++ b/client_test.go @@ -69,7 +69,7 @@ func TestLoopOutSuccess(t *testing.T) { testLoopOutSuccess(ctx, testRequest.Amount, info.SwapHash, signalPrepaymentResult, signalSwapPaymentResult, false, - confIntent, swap.HtlcV2, + confIntent, swap.HtlcV3, ) } @@ -154,6 +154,7 @@ func TestLoopOutResume(t *testing.T) { loopdb.ProtocolVersionUnrecorded, loopdb.ProtocolVersionHtlcV2, loopdb.ProtocolVersionHtlcV3, + loopdb.ProtocolVersionMuSig2, } for _, version := range storedVersion { @@ -339,13 +340,13 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash, // preimage before sweeping in order for the server to trust us with // our MuSig2 signing attempts. if scriptVersion == swap.HtlcV3 { - ctx.assertPreimagePush(testPreimage) + ctx.assertPreimagePush(ctx.store.loopOutSwaps[hash].Preimage) // Try MuSig2 signing first and fail it so that we go for a // normal sweep. for i := 0; i < maxMusigSweepRetries; i++ { ctx.expiryChan <- testTime - ctx.assertPreimagePush(testPreimage) + ctx.assertPreimagePush(ctx.store.loopOutSwaps[hash].Preimage) } <-ctx.Context.Lnd.SignOutputRawChannel } @@ -380,10 +381,11 @@ func testLoopOutSuccess(ctx *testContext, amt btcutil.Amount, hash lntypes.Hash, if scriptVersion != swap.HtlcV3 { ctx.assertPreimagePush(preimage) - // Simulate server pulling payment. - signalSwapPaymentResult(nil) } + // Simulate server pulling payment. + signalSwapPaymentResult(nil) + ctx.NotifySpend(sweepTx, 0) ctx.assertStatus(loopdb.StateSuccess) diff --git a/loopdb/protocol_version.go b/loopdb/protocol_version.go index a9fdee8..180f644 100644 --- a/loopdb/protocol_version.go +++ b/loopdb/protocol_version.go @@ -64,11 +64,11 @@ const ( // stableRPCProtocolVersion defines the current stable RPC protocol // version. - stableRPCProtocolVersion = looprpc.ProtocolVersion_ROUTING_PLUGIN + stableRPCProtocolVersion = looprpc.ProtocolVersion_MUSIG2 // experimentalRPCProtocolVersion defines the RPC protocol version that // includes all currently experimentally released features. - experimentalRPCProtocolVersion = looprpc.ProtocolVersion_MUSIG2 + experimentalRPCProtocolVersion = stableRPCProtocolVersion ) var ( diff --git a/loopdb/protocol_version_test.go b/loopdb/protocol_version_test.go index 2e7f7f5..203a571 100644 --- a/loopdb/protocol_version_test.go +++ b/loopdb/protocol_version_test.go @@ -25,6 +25,7 @@ func TestProtocolVersionSanity(t *testing.T) { ProtocolVersionProbe, ProtocolVersionRoutingPlugin, ProtocolVersionHtlcV3, + ProtocolVersionMuSig2, } rpcVersions := [...]looprpc.ProtocolVersion{ @@ -39,6 +40,7 @@ func TestProtocolVersionSanity(t *testing.T) { looprpc.ProtocolVersion_PROBE, looprpc.ProtocolVersion_ROUTING_PLUGIN, looprpc.ProtocolVersion_HTLC_V3, + looprpc.ProtocolVersion_MUSIG2, } require.Equal(t, len(versions), len(rpcVersions)) @@ -49,7 +51,7 @@ func TestProtocolVersionSanity(t *testing.T) { // Finally test that the current version contants are up to date require.Equal(t, CurrentProtocolVersion(), - versions[len(versions)-2], + versions[len(versions)-1], ) require.Equal(t, diff --git a/loopout_test.go b/loopout_test.go index 6853e07..31a3ed5 100644 --- a/loopout_test.go +++ b/loopout_test.go @@ -694,140 +694,6 @@ func testPreimagePush(t *testing.T) { require.NoError(t, <-errChan) } -// TestExpiryBeforeReveal tests the case where the on-chain HTLC expires before -// we have revealed our preimage, demonstrating that we do not reveal our -// preimage once we've reached our expiry height. -func TestExpiryBeforeReveal(t *testing.T) { - t.Run("stable protocol", func(t *testing.T) { - testExpiryBeforeReveal(t) - }) - - // Note that there's no point of testing this case with the new - // protocol where we use taproot htlc and attempt MuSig2 sweep. The - // reason is that the preimage is revealed to the server once the - // htlc is confirmed in order to facilitate the cooperative signing of - // the sweep transaction. -} - -func testExpiryBeforeReveal(t *testing.T) { - defer test.Guard(t)() - - lnd := test.NewMockLnd() - ctx := test.NewContext(t, lnd) - server := newServerMock(lnd) - - testReq := *testRequest - - // Set on-chain HTLC CLTV. - testReq.Expiry = ctx.Lnd.Height + testLoopOutMinOnChainCltvDelta - - // Set our fee estimate to higher than our max miner fee will allow. - lnd.SetFeeEstimate(testReq.SweepConfTarget, chainfee.SatPerKWeight( - testReq.MaxMinerFee*2, - )) - - // Setup the cfg using mock server and init a loop out request. - cfg := newSwapConfig( - &lnd.LndServices, newStoreMock(t), server, - ) - initResult, err := newLoopOutSwap( - context.Background(), cfg, ctx.Lnd.Height, &testReq, - ) - require.NoError(t, err) - swap := initResult.swap - - // Set up the required dependencies to execute the swap. - sweeper := &sweep.Sweeper{Lnd: &lnd.LndServices} - blockEpochChan := make(chan interface{}) - statusChan := make(chan SwapInfo) - expiryChan := make(chan time.Time) - timerFactory := func(_ time.Duration) <-chan time.Time { - return expiryChan - } - - errChan := make(chan error) - go func() { - err := swap.execute(context.Background(), &executeConfig{ - statusChan: statusChan, - blockEpochChan: blockEpochChan, - timerFactory: timerFactory, - sweeper: sweeper, - verifySchnorrSig: mockVerifySchnorrSigFail, - }, ctx.Lnd.Height) - if err != nil { - log.Error(err) - } - errChan <- err - }() - - // The swap should be found in its initial state. - cfg.store.(*storeMock).assertLoopOutStored() - state := <-statusChan - require.Equal(t, loopdb.StateInitiated, state.State) - - // We'll then pay both the swap and prepay invoice, which should trigger - // the server to publish the on-chain HTLC. - signalSwapPaymentResult := ctx.AssertPaid(swapInvoiceDesc) - signalPrepaymentResult := ctx.AssertPaid(prepayInvoiceDesc) - - signalSwapPaymentResult(nil) - signalPrepaymentResult(nil) - - // Notify the confirmation notification for the HTLC. - ctx.AssertRegisterConf(false, defaultConfirmations) - - // Advance the block height to get the HTLC confirmed. - height := ctx.Lnd.Height + 1 - blockEpochChan <- height - - htlcTx := wire.NewMsgTx(2) - htlcTx.AddTxOut(&wire.TxOut{ - Value: int64(swap.AmountRequested), - PkScript: swap.htlc.PkScript, - }) - ctx.NotifyConf(htlcTx) - - // The client should then register for a spend of the HTLC and attempt - // to sweep it using the custom confirmation target. - ctx.AssertRegisterSpendNtfn(swap.htlc.PkScript) - - // Assert that we made a query to track our payment, as required for - // preimage push tracking. - ctx.AssertTrackPayment() - - // Tick the expiry channel. Because our max miner fee is too high, we - // won't attempt a sweep at this point. - expiryChan <- testTime - - // Since we don't have a reliable mechanism to non-intrusively avoid - // races by setting the fee estimate too soon, let's sleep here a bit - // to ensure the first sweep fails. - time.Sleep(500 * time.Millisecond) - - // Now we decrease our conf target to less than our max miner fee. - lnd.SetFeeEstimate(testReq.SweepConfTarget, chainfee.SatPerKWeight( - testReq.MaxMinerFee/2, - )) - - // Advance the block height to the point where we would do timeout - // instead of pushing the preimage. - blockEpochChan <- testReq.Expiry + height - - // Tick our expiry channel again to trigger another sweep attempt. - expiryChan <- testTime - - // We should see our swap marked as failed. - cfg.store.(*storeMock).assertLoopOutState( - loopdb.StateFailTimeout, - ) - status := <-statusChan - require.Equal( - t, status.State, loopdb.StateFailTimeout, - ) - - require.Nil(t, <-errChan) -} - // TestFailedOffChainCancelation tests sending of a cancelation message to // the server when a swap fails due to off-chain routing. func TestFailedOffChainCancelation(t *testing.T) { diff --git a/release_notes.md b/release_notes.md index c71d135..3cbf37d 100644 --- a/release_notes.md +++ b/release_notes.md @@ -13,6 +13,7 @@ This file tracks release notes for the loop client. * Once the version bump PR is merged and tagged, add the release notes to the tag on GitHub. ## Next release +* Set musig2 to be the default swap protocol. #### New Features