mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
lnwire: add TLV extension to channel_reestablish for dynamic commitments
This commit is contained in:
parent
e5f7ed8ba1
commit
3e84d22eeb
@ -5,9 +5,24 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/lightningnetwork/lnd/fn"
|
||||||
"github.com/lightningnetwork/lnd/tlv"
|
"github.com/lightningnetwork/lnd/tlv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
CRDynHeight tlv.Type = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
// DynHeight is a newtype wrapper to get the proper RecordProducer instance
|
||||||
|
// to smoothly integrate with the ChannelReestablish Message instance.
|
||||||
|
type DynHeight uint64
|
||||||
|
|
||||||
|
// Record implements the RecordProducer interface, allowing a full tlv.Record
|
||||||
|
// object to be constructed from a DynHeight.
|
||||||
|
func (d *DynHeight) Record() tlv.Record {
|
||||||
|
return tlv.MakePrimitiveRecord(CRDynHeight, (*uint64)(d))
|
||||||
|
}
|
||||||
|
|
||||||
// ChannelReestablish is a message sent between peers that have an existing
|
// ChannelReestablish is a message sent between peers that have an existing
|
||||||
// open channel upon connection reestablishment. This message allows both sides
|
// open channel upon connection reestablishment. This message allows both sides
|
||||||
// to report their local state, and their current knowledge of the state of the
|
// to report their local state, and their current knowledge of the state of the
|
||||||
@ -70,6 +85,11 @@ type ChannelReestablish struct {
|
|||||||
// TODO(roasbeef): rename to verification nonce
|
// TODO(roasbeef): rename to verification nonce
|
||||||
LocalNonce *Musig2Nonce
|
LocalNonce *Musig2Nonce
|
||||||
|
|
||||||
|
// DynHeight is an optional field that stores the dynamic commitment
|
||||||
|
// negotiation height that is incremented upon successful completion of
|
||||||
|
// a dynamic commitment negotiation
|
||||||
|
DynHeight fn.Option[DynHeight]
|
||||||
|
|
||||||
// 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.
|
||||||
@ -121,6 +141,10 @@ func (a *ChannelReestablish) Encode(w *bytes.Buffer, pver uint32) error {
|
|||||||
if a.LocalNonce != nil {
|
if a.LocalNonce != nil {
|
||||||
recordProducers = append(recordProducers, a.LocalNonce)
|
recordProducers = append(recordProducers, a.LocalNonce)
|
||||||
}
|
}
|
||||||
|
a.DynHeight.WhenSome(func(h DynHeight) {
|
||||||
|
recordProducers = append(recordProducers, &h)
|
||||||
|
})
|
||||||
|
|
||||||
err := EncodeMessageExtraData(&a.ExtraData, recordProducers...)
|
err := EncodeMessageExtraData(&a.ExtraData, recordProducers...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -180,8 +204,9 @@ func (a *ChannelReestablish) Decode(r io.Reader, pver uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var localNonce Musig2Nonce
|
var localNonce Musig2Nonce
|
||||||
|
var dynHeight DynHeight
|
||||||
typeMap, err := tlvRecords.ExtractRecords(
|
typeMap, err := tlvRecords.ExtractRecords(
|
||||||
&localNonce,
|
&localNonce, &dynHeight,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -190,6 +215,9 @@ func (a *ChannelReestablish) Decode(r io.Reader, pver uint32) error {
|
|||||||
if val, ok := typeMap[NonceRecordType]; ok && val == nil {
|
if val, ok := typeMap[NonceRecordType]; ok && val == nil {
|
||||||
a.LocalNonce = &localNonce
|
a.LocalNonce = &localNonce
|
||||||
}
|
}
|
||||||
|
if val, ok := typeMap[CRDynHeight]; ok && val == nil {
|
||||||
|
a.DynHeight = fn.Some(dynHeight)
|
||||||
|
}
|
||||||
|
|
||||||
if len(tlvRecords) != 0 {
|
if len(tlvRecords) != 0 {
|
||||||
a.ExtraData = tlvRecords
|
a.ExtraData = tlvRecords
|
||||||
|
Loading…
Reference in New Issue
Block a user