@@ -1411,6 +1411,59 @@ func (r *ChannelRouter) addZombieEdge(chanID uint64) error {
14111411 return nil
14121412}
14131413
1414+ // makeFundingScript is used to make the funding script for both segwit v0 and
1415+ // segwit v1 (tapoort) channels.
1416+ //
1417+ // TODO(roasbeef: export and use elsewhere?
1418+ func makeFundingScript (bitcoinKey1 , bitcoinKey2 []byte ,
1419+ chanFeatures []byte ) ([]byte , error ) {
1420+
1421+ // In order to make the correct funding script, we'll need to parse the
1422+ // chanFeatures bytes into a feature vector we can interact with.
1423+ rawFeatures := lnwire .NewRawFeatureVector ()
1424+ err := rawFeatures .Decode (bytes .NewReader (chanFeatures ))
1425+ if err != nil {
1426+ return nil , fmt .Errorf ("unable to parse chan feature " +
1427+ "bits: %w" , err )
1428+ }
1429+
1430+ chanFeatureBits := lnwire .NewFeatureVector (
1431+ rawFeatures , lnwire .Features ,
1432+ )
1433+ if chanFeatureBits .HasFeature (lnwire .SimpleTaprootChannelsOptional ) {
1434+ pubKey1 , err := btcec .ParsePubKey (bitcoinKey1 )
1435+ if err != nil {
1436+ return nil , err
1437+ }
1438+ pubKey2 , err := btcec .ParsePubKey (bitcoinKey2 )
1439+ if err != nil {
1440+ return nil , err
1441+ }
1442+
1443+ fundingScript , _ , err := input .GenTaprootFundingScript (
1444+ pubKey1 , pubKey2 , 0 ,
1445+ )
1446+ if err != nil {
1447+ return nil , err
1448+ }
1449+
1450+ return fundingScript , nil
1451+ } else {
1452+ witnessScript , err := input .GenMultiSigScript (
1453+ bitcoinKey1 [:], bitcoinKey2 [:],
1454+ )
1455+ if err != nil {
1456+ return nil , err
1457+ }
1458+ pkScript , err := input .WitnessScriptHash (witnessScript )
1459+ if err != nil {
1460+ return nil , err
1461+ }
1462+
1463+ return pkScript , nil
1464+ }
1465+ }
1466+
14141467// processUpdate processes a new relate authenticated channel/edge, node or
14151468// channel/edge update network update. If the update didn't affect the internal
14161469// state of the draft due to either being out of date, invalid, or redundant,
@@ -1520,16 +1573,13 @@ func (r *ChannelRouter) processUpdate(msg interface{},
15201573 // Recreate witness output to be sure that declared in channel
15211574 // edge bitcoin keys and channel value corresponds to the
15221575 // reality.
1523- witnessScript , err := input . GenMultiSigScript (
1576+ fundingPkScript , err := makeFundingScript (
15241577 msg .BitcoinKey1Bytes [:], msg .BitcoinKey2Bytes [:],
1578+ msg .Features ,
15251579 )
15261580 if err != nil {
15271581 return err
15281582 }
1529- pkScript , err := input .WitnessScriptHash (witnessScript )
1530- if err != nil {
1531- return err
1532- }
15331583
15341584 // Next we'll validate that this channel is actually well
15351585 // formed. If this check fails, then this channel either
@@ -1539,7 +1589,7 @@ func (r *ChannelRouter) processUpdate(msg interface{},
15391589 Locator : & chanvalidate.ShortChanIDChanLocator {
15401590 ID : channelID ,
15411591 },
1542- MultiSigPkScript : pkScript ,
1592+ MultiSigPkScript : fundingPkScript ,
15431593 FundingTx : fundingTx ,
15441594 })
15451595 if err != nil {
@@ -1556,10 +1606,6 @@ func (r *ChannelRouter) processUpdate(msg interface{},
15561606 // Now that we have the funding outpoint of the channel, ensure
15571607 // that it hasn't yet been spent. If so, then this channel has
15581608 // been closed so we'll ignore it.
1559- fundingPkScript , err := input .WitnessScriptHash (witnessScript )
1560- if err != nil {
1561- return err
1562- }
15631609 chanUtxo , err := r .cfg .Chain .GetUtxo (
15641610 fundingPoint , fundingPkScript , channelID .BlockHeight ,
15651611 r .quit ,
0 commit comments