lnwire: add PartialSig to FundingSigned

This commit is contained in:
Olaoluwa Osuntokun 2023-01-16 19:40:03 -08:00
parent 292b8db8f0
commit 79c473cc46
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

View File

@ -3,6 +3,8 @@ package lnwire
import ( import (
"bytes" "bytes"
"io" "io"
"github.com/lightningnetwork/lnd/tlv"
) )
// FundingSigned is sent from Bob (the responder) to Alice (the initiator) // FundingSigned is sent from Bob (the responder) to Alice (the initiator)
@ -17,6 +19,13 @@ type FundingSigned struct {
// transaction. // transaction.
CommitSig Sig 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 // ExtraData is the set of data that was appended to this message to
// fill out the full maximum transport message size. These fields can // fill out the full maximum transport message size. These fields can
// be used to specify optional data such as custom TLV fields. // be used to specify optional data such as custom TLV fields.
@ -33,6 +42,15 @@ var _ Message = (*FundingSigned)(nil)
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (f *FundingSigned) Encode(w *bytes.Buffer, pver uint32) error { func (f *FundingSigned) 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 := WriteChannelID(w, f.ChanID); err != nil { if err := WriteChannelID(w, f.ChanID); err != nil {
return err return err
} }
@ -50,7 +68,34 @@ func (f *FundingSigned) Encode(w *bytes.Buffer, pver uint32) error {
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (f *FundingSigned) Decode(r io.Reader, pver uint32) error { func (f *FundingSigned) Decode(r io.Reader, pver uint32) error {
return ReadElements(r, &f.ChanID, &f.CommitSig, &f.ExtraData) err := ReadElements(r, &f.ChanID, &f.CommitSig)
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 // MsgType returns the uint32 code which uniquely identifies this message as a