diff --git a/lnwire/funding_created.go b/lnwire/funding_created.go index 02b513471..f8128ff76 100644 --- a/lnwire/funding_created.go +++ b/lnwire/funding_created.go @@ -5,6 +5,7 @@ import ( "io" "github.com/btcsuite/btcd/wire" + "github.com/lightningnetwork/lnd/tlv" ) // FundingCreated is sent from Alice (the initiator) to Bob (the responder), @@ -26,6 +27,13 @@ type FundingCreated struct { // transaction. CommitSig Sig + // PartialSig is used to transmit a musig2 extended partial signature + // that also carries along the public nonce of the signer. + // + // NOTE: This field is only populated if a musig2 taproot channel is + // being signed for. In this case, the above Sig type MUST be blank. + PartialSig *PartialSigWithNonce + // ExtraData is the set of data that was appended to this message to // fill out the full maximum transport message size. These fields can // be used to specify optional data such as custom TLV fields. @@ -42,6 +50,15 @@ var _ Message = (*FundingCreated)(nil) // // This is part of the lnwire.Message interface. func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error { + recordProducers := make([]tlv.RecordProducer, 0, 1) + if f.PartialSig != nil { + recordProducers = append(recordProducers, f.PartialSig) + } + err := EncodeMessageExtraData(&f.ExtraData, recordProducers...) + if err != nil { + return err + } + if err := WriteBytes(w, f.PendingChannelID[:]); err != nil { return err } @@ -63,10 +80,36 @@ func (f *FundingCreated) Encode(w *bytes.Buffer, pver uint32) error { // // This is part of the lnwire.Message interface. func (f *FundingCreated) Decode(r io.Reader, pver uint32) error { - return ReadElements( + err := ReadElements( r, f.PendingChannelID[:], &f.FundingPoint, &f.CommitSig, - &f.ExtraData, ) + if err != nil { + return err + } + + var tlvRecords ExtraOpaqueData + if err := ReadElements(r, &tlvRecords); err != nil { + return err + } + + var ( + partialSig PartialSigWithNonce + ) + typeMap, err := tlvRecords.ExtractRecords(&partialSig) + if err != nil { + return err + } + + // Set the corresponding TLV types if they were included in the stream. + if val, ok := typeMap[PartialSigWithNonceRecordType]; ok && val == nil { + f.PartialSig = &partialSig + } + + if len(tlvRecords) != 0 { + f.ExtraData = tlvRecords + } + + return nil } // MsgType returns the uint32 code which uniquely identifies this message as a