lnwire: add LocalNonce to FundingLocked

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

View File

@ -27,6 +27,12 @@ type ChannelReady struct {
// ShortChannelID for forwarding. // ShortChannelID for forwarding.
AliasScid *ShortChannelID AliasScid *ShortChannelID
// NextLocalNonce is an optional field that stores a local musig2 nonce.
// This will only be populated if the simple taproot channels type was
// negotiated. This is the local nonce that will be used by the sender
// to accept a new commitment state transition.
NextLocalNonce *Musig2Nonce
// 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.
@ -39,7 +45,7 @@ func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady {
return &ChannelReady{ return &ChannelReady{
ChanID: cid, ChanID: cid,
NextPerCommitmentPoint: npcp, NextPerCommitmentPoint: npcp,
ExtraData: make([]byte, 0), ExtraData: nil,
} }
} }
@ -57,16 +63,25 @@ func (c *ChannelReady) Decode(r io.Reader, _ uint32) error {
err := ReadElements(r, err := ReadElements(r,
&c.ChanID, &c.ChanID,
&c.NextPerCommitmentPoint, &c.NextPerCommitmentPoint,
&c.ExtraData,
) )
if err != nil { if err != nil {
return err return err
} }
var tlvRecords ExtraOpaqueData
if err := ReadElements(r, &tlvRecords); err != nil {
return err
}
// Next we'll parse out the set of known records. For now, this is just // Next we'll parse out the set of known records. For now, this is just
// the AliasScidRecordType. // the AliasScidRecordType.
var aliasScid ShortChannelID var (
typeMap, err := c.ExtraData.ExtractRecords(&aliasScid) aliasScid ShortChannelID
localNonce Musig2Nonce
)
typeMap, err := tlvRecords.ExtractRecords(
&aliasScid, &localNonce,
)
if err != nil { if err != nil {
return err return err
} }
@ -76,6 +91,13 @@ func (c *ChannelReady) Decode(r io.Reader, _ uint32) error {
if val, ok := typeMap[AliasScidRecordType]; ok && val == nil { if val, ok := typeMap[AliasScidRecordType]; ok && val == nil {
c.AliasScid = &aliasScid c.AliasScid = &aliasScid
} }
if val, ok := typeMap[NonceRecordType]; ok && val == nil {
c.NextLocalNonce = &localNonce
}
if len(tlvRecords) != 0 {
c.ExtraData = tlvRecords
}
return nil return nil
} }
@ -95,12 +117,16 @@ func (c *ChannelReady) Encode(w *bytes.Buffer, _ uint32) error {
} }
// We'll only encode the AliasScid in a TLV segment if it exists. // We'll only encode the AliasScid in a TLV segment if it exists.
recordProducers := make([]tlv.RecordProducer, 0, 2)
if c.AliasScid != nil { if c.AliasScid != nil {
recordProducers := []tlv.RecordProducer{c.AliasScid} recordProducers = append(recordProducers, c.AliasScid)
err := EncodeMessageExtraData(&c.ExtraData, recordProducers...) }
if err != nil { if c.NextLocalNonce != nil {
return err recordProducers = append(recordProducers, c.NextLocalNonce)
} }
err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
if err != nil {
return err
} }
return WriteBytes(w, c.ExtraData) return WriteBytes(w, c.ExtraData)