Skip to content

Commit 6b78499

Browse files
committed
multi: add tapscript root to gossip message
1 parent bf307d3 commit 6b78499

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

channeldb/models/channel_edge_info.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/btcsuite/btcd/btcutil"
99
"github.com/btcsuite/btcd/chaincfg/chainhash"
1010
"github.com/btcsuite/btcd/wire"
11+
"github.com/lightningnetwork/lnd/fn"
1112
)
1213

1314
// ChannelEdgeInfo represents a fully authenticated channel along with all its
@@ -62,6 +63,11 @@ type ChannelEdgeInfo struct {
6263
// the value output in the outpoint that created this channel.
6364
Capacity btcutil.Amount
6465

66+
// TapscriptRoot is the optional Merkle root of the tapscript tree if
67+
// this channel is a taproot channel that also commits to a tapscript
68+
// tree (custom channel).
69+
TapscriptRoot fn.Option[chainhash.Hash]
70+
6571
// ExtraOpaqueData is the set of data that was appended to this
6672
// message, some of which we may not actually know how to iterate or
6773
// parse. By holding onto this data, we ensure that we're able to

discovery/gossiper.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightningnetwork/lnd/chainntnfs"
2121
"github.com/lightningnetwork/lnd/channeldb"
2222
"github.com/lightningnetwork/lnd/channeldb/models"
23+
"github.com/lightningnetwork/lnd/fn"
2324
"github.com/lightningnetwork/lnd/keychain"
2425
"github.com/lightningnetwork/lnd/kvdb"
2526
"github.com/lightningnetwork/lnd/lnpeer"
@@ -82,9 +83,10 @@ var (
8283
// can provide that serve useful when processing a specific network
8384
// announcement.
8485
type optionalMsgFields struct {
85-
capacity *btcutil.Amount
86-
channelPoint *wire.OutPoint
87-
remoteAlias *lnwire.ShortChannelID
86+
capacity *btcutil.Amount
87+
channelPoint *wire.OutPoint
88+
remoteAlias *lnwire.ShortChannelID
89+
tapscriptRoot fn.Option[chainhash.Hash]
8890
}
8991

9092
// apply applies the optional fields within the functional options.
@@ -115,6 +117,14 @@ func ChannelPoint(op wire.OutPoint) OptionalMsgField {
115117
}
116118
}
117119

120+
// TapscriptRoot is an optional field that lets the gossiper know of the root of
121+
// the tapscript tree for a custom channel.
122+
func TapscriptRoot(root fn.Option[chainhash.Hash]) OptionalMsgField {
123+
return func(f *optionalMsgFields) {
124+
f.tapscriptRoot = root
125+
}
126+
}
127+
118128
// RemoteAlias is an optional field that lets the gossiper know that a locally
119129
// sent channel update is actually an update for the peer that should replace
120130
// the ShortChannelID field with the remote's alias. This is only used for
@@ -2513,6 +2523,9 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
25132523
cp := *nMsg.optionalMsgFields.channelPoint
25142524
edge.ChannelPoint = cp
25152525
}
2526+
2527+
// Optional tapscript root for custom channels.
2528+
edge.TapscriptRoot = nMsg.optionalMsgFields.tapscriptRoot
25162529
}
25172530

25182531
log.Debugf("Adding edge for short_chan_id: %v",

funding/manager.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
34653465
errChan := f.cfg.SendAnnouncement(
34663466
ann.chanAnn, discovery.ChannelCapacity(completeChan.Capacity),
34673467
discovery.ChannelPoint(completeChan.FundingOutpoint),
3468+
discovery.TapscriptRoot(completeChan.TapscriptRoot),
34683469
)
34693470
select {
34703471
case err := <-errChan:
@@ -4393,9 +4394,9 @@ func (f *Manager) announceChannel(localIDKey, remoteIDKey *btcec.PublicKey,
43934394
//
43944395
// We can pass in zeroes for the min and max htlc policy, because we
43954396
// only use the channel announcement message from the returned struct.
4396-
ann, err := f.newChanAnnouncement(localIDKey, remoteIDKey,
4397-
localFundingKey, remoteFundingKey, shortChanID, chanID,
4398-
0, 0, nil, chanType,
4397+
ann, err := f.newChanAnnouncement(
4398+
localIDKey, remoteIDKey, localFundingKey, remoteFundingKey,
4399+
shortChanID, chanID, 0, 0, nil, chanType,
43994400
)
44004401
if err != nil {
44014402
log.Errorf("can't generate channel announcement: %v", err)

routing/router.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"github.com/btcsuite/btcd/btcec/v2"
1414
"github.com/btcsuite/btcd/btcutil"
15+
"github.com/btcsuite/btcd/chaincfg/chainhash"
1516
"github.com/btcsuite/btcd/wire"
1617
"github.com/davecgh/go-spew/spew"
1718
"github.com/go-errors/errors"
@@ -1510,8 +1511,8 @@ func (r *ChannelRouter) addZombieEdge(chanID uint64) error {
15101511
// segwit v1 (taproot) channels.
15111512
//
15121513
// TODO(roasbeef: export and use elsewhere?
1513-
func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
1514-
chanFeatures []byte) ([]byte, error) {
1514+
func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte, chanFeatures []byte,
1515+
tapscriptRoot fn.Option[chainhash.Hash]) ([]byte, error) {
15151516

15161517
legacyFundingScript := func() ([]byte, error) {
15171518
witnessScript, err := input.GenMultiSigScript(
@@ -1557,8 +1558,15 @@ func makeFundingScript(bitcoinKey1, bitcoinKey2 []byte,
15571558
return nil, err
15581559
}
15591560

1561+
var fundingOpts []input.FundingScriptOpt
1562+
tapscriptRoot.WhenSome(func(root chainhash.Hash) {
1563+
fundingOpts = append(
1564+
fundingOpts, input.WithTapscriptRoot(root),
1565+
)
1566+
})
1567+
15601568
fundingScript, _, err := input.GenTaprootFundingScript(
1561-
pubKey1, pubKey2, 0,
1569+
pubKey1, pubKey2, 0, fundingOpts...,
15621570
)
15631571
if err != nil {
15641572
return nil, err
@@ -1683,7 +1691,7 @@ func (r *ChannelRouter) processUpdate(msg interface{},
16831691
// reality.
16841692
fundingPkScript, err := makeFundingScript(
16851693
msg.BitcoinKey1Bytes[:], msg.BitcoinKey2Bytes[:],
1686-
msg.Features,
1694+
msg.Features, msg.TapscriptRoot,
16871695
)
16881696
if err != nil {
16891697
return err

0 commit comments

Comments
 (0)