@@ -236,6 +236,8 @@ type chanAuxData struct {
236236 realScid tlv.RecordT [tlv.TlvType4 , lnwire.ShortChannelID ]
237237
238238 memo tlv.OptionalRecordT [tlv.TlvType5 , []byte ]
239+
240+ tapscriptRoot tlv.OptionalRecordT [tlv.TlvType6 , [32 ]byte ]
239241}
240242
241243// toOpeChan converts the chanAuxData to an OpenChannel by setting the relevant
@@ -248,6 +250,9 @@ func (c *chanAuxData) toOpenChan(o *OpenChannel) {
248250 c .memo .WhenSomeV (func (memo []byte ) {
249251 o .Memo = memo
250252 })
253+ c .tapscriptRoot .WhenSomeV (func (h [32 ]byte ) {
254+ o .TapscriptRoot = fn .Some (chainhash .Hash (h ))
255+ })
251256}
252257
253258// newChanAuxDataFromChan creates a new chanAuxData from the given channel.
@@ -267,11 +272,16 @@ func newChanAuxDataFromChan(openChan *OpenChannel) *chanAuxData {
267272 ),
268273 }
269274
270- if len (openChan .Memo ) = = 0 {
275+ if len (openChan .Memo ) ! = 0 {
271276 c .memo = tlv .SomeRecordT (
272277 tlv.NewPrimitiveRecord [tlv.TlvType5 ](openChan .Memo ),
273278 )
274279 }
280+ openChan .TapscriptRoot .WhenSome (func (h chainhash.Hash ) {
281+ c .tapscriptRoot = tlv .SomeRecordT (
282+ tlv.NewPrimitiveRecord [tlv.TlvType6 ]([32 ]byte (h )),
283+ )
284+ })
275285
276286 return c
277287}
@@ -353,6 +363,11 @@ const (
353363 // SimpleTaprootFeatureBit indicates that the simple-taproot-chans
354364 // feature bit was negotiated during the lifetime of the channel.
355365 SimpleTaprootFeatureBit ChannelType = 1 << 10
366+
367+ // TapscriptRootBit indicates that this is a musig2 channel with a top
368+ // level tapscript commitment. This MUST be set along with the
369+ // SimpleTaprootFeatureBit.
370+ TapscriptRootBit ChannelType = 1 << 11
356371)
357372
358373// IsSingleFunder returns true if the channel type if one of the known single
@@ -423,6 +438,12 @@ func (c ChannelType) IsTaproot() bool {
423438 return c & SimpleTaprootFeatureBit == SimpleTaprootFeatureBit
424439}
425440
441+ // HasTapscriptRoot returns true if the channel is using a top level tapscript
442+ // root commmitment.
443+ func (c ChannelType ) HasTapscriptRoot () bool {
444+ return c & TapscriptRootBit == TapscriptRootBit
445+ }
446+
426447// ChannelConstraints represents a set of constraints meant to allow a node to
427448// limit their exposure, enact flow control and ensure that all HTLCs are
428449// economically relevant. This struct will be mirrored for both sides of the
@@ -3980,6 +4001,9 @@ func putChanInfo(chanBucket kvdb.RwBucket, channel *OpenChannel) error {
39804001 auxData .memo .WhenSome (func (memo tlv.RecordT [tlv.TlvType5 , []byte ]) {
39814002 tlvRecords = append (tlvRecords , memo .Record ())
39824003 })
4004+ auxData .tapscriptRoot .WhenSome (func (root tlv.RecordT [tlv.TlvType6 , [32 ]byte ]) { //nolint:lll
4005+ tlvRecords = append (tlvRecords , root .Record ())
4006+ })
39834007
39844008 // Create the tlv stream.
39854009 tlvStream , err := tlv .NewStream (tlvRecords ... )
@@ -4178,24 +4202,34 @@ func fetchChanInfo(chanBucket kvdb.RBucket, channel *OpenChannel) error {
41784202 }
41794203
41804204 var auxData chanAuxData
4181- zeroMemo := auxData .memo .Zero ()
4205+ memo := auxData .memo .Zero ()
4206+ tapscriptRoot := auxData .tapscriptRoot .Zero ()
41824207
41834208 // Create the tlv stream.
41844209 tlvStream , err := tlv .NewStream (
41854210 auxData .revokeKeyLoc .Record (),
41864211 auxData .initialLocalBalance .Record (),
41874212 auxData .initialRemoteBalance .Record (),
41884213 auxData .realScid .Record (),
4189- zeroMemo .Record (),
4214+ memo .Record (),
4215+ tapscriptRoot .Record (),
41904216 )
41914217 if err != nil {
41924218 return err
41934219 }
41944220
4195- if err := tlvStream .Decode (r ); err != nil {
4221+ tlvs , err := tlvStream .DecodeWithParsedTypes (r )
4222+ if err != nil {
41964223 return err
41974224 }
41984225
4226+ if _ , ok := tlvs [memo .TlvType ()]; ok {
4227+ auxData .memo = tlv .SomeRecordT (memo )
4228+ }
4229+ if _ , ok := tlvs [tapscriptRoot .TlvType ()]; ok {
4230+ auxData .tapscriptRoot = tlv .SomeRecordT (tapscriptRoot )
4231+ }
4232+
41994233 // Assign all the relevant fields from the aux data into the actual
42004234 // open channel.
42014235 auxData .toOpenChan (channel )
0 commit comments