@@ -11,8 +11,10 @@ import (
1111 "github.com/btcsuite/btcd/btcec/v2"
1212 "github.com/btcsuite/btcd/btcec/v2/schnorr"
1313 "github.com/btcsuite/btcd/btcutil"
14+ "github.com/btcsuite/btcd/chaincfg/chainhash"
1415 "github.com/btcsuite/btcd/txscript"
1516 "github.com/btcsuite/btcd/wire"
17+ "github.com/lightningnetwork/lnd/funding"
1618 "github.com/lightningnetwork/lnd/input"
1719 "github.com/lightningnetwork/lnd/lnrpc"
1820 "github.com/lightningnetwork/lnd/lnrpc/chainrpc"
@@ -1498,3 +1500,82 @@ func createMuSigSessions(ctx context.Context, t *harnessTest,
14981500
14991501 return internalKey , combinedKey , sessResp1 , sessResp2 , sessResp3
15001502}
1503+
1504+ // assertTaprootDeliveryUsed returns true if a Taproot addr was used in the
1505+ // co-op close transaction.
1506+ func assertTaprootDeliveryUsed (net * lntest.NetworkHarness ,
1507+ t * harnessTest , closingTxid * chainhash.Hash ) bool {
1508+
1509+ tx , err := net .Miner .Client .GetRawTransaction (closingTxid )
1510+ require .NoError (t .t , err , "unable to get closing tx" )
1511+
1512+ for _ , txOut := range tx .MsgTx ().TxOut {
1513+ if ! txscript .IsPayToTaproot (txOut .PkScript ) {
1514+ return false
1515+ }
1516+ }
1517+
1518+ return true
1519+ }
1520+
1521+ // testTaprootCoopClose asserts that if both peers signal ShutdownAnySegwit,
1522+ // then a taproot closing addr is used. Otherwise, we shouldn't expect one to
1523+ // be used.
1524+ func testTaprootCoopClose (net * lntest.NetworkHarness , t * harnessTest ) {
1525+ // We'll start by making two new nodes, and funding a channel between
1526+ // them.
1527+ carol := net .NewNode (t .t , "Carol" , nil )
1528+ defer shutdownAndAssert (net , t , carol )
1529+
1530+ net .SendCoins (t .t , btcutil .SatoshiPerBitcoin , carol )
1531+
1532+ dave := net .NewNode (t .t , "Dave" , nil )
1533+ defer shutdownAndAssert (net , t , dave )
1534+
1535+ net .EnsureConnected (t .t , carol , dave )
1536+
1537+ chanAmt := funding .MaxBtcFundingAmount
1538+ pushAmt := btcutil .Amount (100000 )
1539+ satPerVbyte := btcutil .Amount (1 )
1540+
1541+ // We'll now open a channel between Carol and Dave.
1542+ chanPoint := openChannelAndAssert (
1543+ t , net , carol , dave ,
1544+ lntest.OpenChannelParams {
1545+ Amt : chanAmt ,
1546+ PushAmt : pushAmt ,
1547+ SatPerVByte : satPerVbyte ,
1548+ },
1549+ )
1550+
1551+ // We'll now close out the channel and obtain the closing TXID.
1552+ closingTxid := closeChannelAndAssert (t , net , carol , chanPoint , false )
1553+
1554+ // We expect that the closing transaction only has P2TR addresses.
1555+ require .True (t .t , assertTaprootDeliveryUsed (net , t , closingTxid ),
1556+ "taproot addr not used!" )
1557+
1558+ // Now we'll bring Eve into the mix, Eve is running older software that
1559+ // doesn't understand Taproot.
1560+ eveArgs := []string {"--protocol.no-any-segwit" }
1561+ eve := net .NewNode (t .t , "Eve" , eveArgs )
1562+ defer shutdownAndAssert (net , t , eve )
1563+
1564+ net .EnsureConnected (t .t , carol , eve )
1565+
1566+ // We'll now open up a chanel again between Carol and Eve.
1567+ chanPoint = openChannelAndAssert (
1568+ t , net , carol , eve ,
1569+ lntest.OpenChannelParams {
1570+ Amt : chanAmt ,
1571+ PushAmt : pushAmt ,
1572+ SatPerVByte : satPerVbyte ,
1573+ },
1574+ )
1575+
1576+ // We'll now close out this channel and expect that no Taproot
1577+ // addresses are used in the co-op close transaction.
1578+ closingTxid = closeChannelAndAssert (t , net , carol , chanPoint , false )
1579+ require .False (t .t , assertTaprootDeliveryUsed (net , t , closingTxid ),
1580+ "taproot addr shouldn't be used!" )
1581+ }
0 commit comments