• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15858991938

24 Jun 2025 06:51PM UTC coverage: 55.808% (-2.4%) from 58.173%
15858991938

Pull #9148

github

web-flow
Merge 0e921d6a5 into 29ff13d83
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

232 of 267 new or added lines in 5 files covered. (86.89%)

24606 existing lines in 281 files now uncovered.

108380 of 194201 relevant lines covered (55.81%)

22488.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.17
/lnwire/dyn_ack.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
8
        "github.com/lightningnetwork/lnd/fn/v2"
9
        "github.com/lightningnetwork/lnd/tlv"
10
)
11

12
const (
13
        // DALocalMusig2Pubnonce is the TLV type number that identifies the
14
        // musig2 public nonce that we need to verify the commitment transaction
15
        // signature.
16
        DALocalMusig2Pubnonce tlv.Type = 0
17
)
18

19
// DynAck is the message used to accept the parameters of a dynamic commitment
20
// negotiation. Additional optional parameters will need to be present depending
21
// on the details of the dynamic commitment upgrade.
22
type DynAck struct {
23
        // ChanID is the ChannelID of the channel that is currently undergoing
24
        // a dynamic commitment negotiation
25
        ChanID ChannelID
26

27
        // Sig is a signature that acknowledges and approves the parameters
28
        // that were requested in the DynPropose
29
        Sig Sig
30

31
        // LocalNonce is an optional field that is transmitted when accepting
32
        // a dynamic commitment upgrade to Taproot Channels. This nonce will be
33
        // used to verify the first commitment transaction signature. This will
34
        // only be populated if the DynPropose we are responding to specifies
35
        // taproot channels in the ChannelType field.
36
        LocalNonce fn.Option[Musig2Nonce]
37

38
        // ExtraData is the set of data that was appended to this message to
39
        // fill out the full maximum transport message size. These fields can
40
        // be used to specify optional data such as custom TLV fields.
41
        ExtraData ExtraOpaqueData
42
}
43

44
// A compile time check to ensure DynAck implements the lnwire.Message
45
// interface.
46
var _ Message = (*DynAck)(nil)
47

48
// A compile time check to ensure DynAck implements the lnwire.SizeableMessage
49
// interface.
50
var _ SizeableMessage = (*DynAck)(nil)
51

52
// Encode serializes the target DynAck into the passed io.Writer. Serialization
53
// will observe the rules defined by the passed protocol version.
54
//
55
// This is a part of the lnwire.Message interface.
56
func (da *DynAck) Encode(w *bytes.Buffer, _ uint32) error {
100✔
57
        if err := WriteChannelID(w, da.ChanID); err != nil {
100✔
58
                return err
×
59
        }
×
60

61
        if err := WriteSig(w, da.Sig); err != nil {
100✔
NEW
62
                return err
×
NEW
63
        }
×
64

65
        var tlvRecords []tlv.Record
100✔
66
        da.LocalNonce.WhenSome(func(nonce Musig2Nonce) {
161✔
67
                tlvRecords = append(
61✔
68
                        tlvRecords, tlv.MakeStaticRecord(
61✔
69
                                DALocalMusig2Pubnonce, &nonce,
61✔
70
                                musig2.PubNonceSize, nonceTypeEncoder,
61✔
71
                                nonceTypeDecoder,
61✔
72
                        ),
61✔
73
                )
61✔
74
        })
61✔
75
        tlv.SortRecords(tlvRecords)
100✔
76

100✔
77
        tlvStream, err := tlv.NewStream(tlvRecords...)
100✔
78
        if err != nil {
100✔
79
                return err
×
80
        }
×
81

82
        var extraBytesWriter bytes.Buffer
100✔
83
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
100✔
84
                return err
×
85
        }
×
86

87
        da.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
100✔
88

100✔
89
        return WriteBytes(w, da.ExtraData)
100✔
90
}
91

92
// Decode deserializes the serialized DynAck stored in the passed io.Reader into
93
// the target DynAck using the deserialization rules defined by the passed
94
// protocol version.
95
//
96
// This is a part of the lnwire.Message interface.
97
func (da *DynAck) Decode(r io.Reader, _ uint32) error {
154✔
98
        // Parse out main message.
154✔
99
        if err := ReadElements(r, &da.ChanID, &da.Sig); err != nil {
185✔
100
                return err
31✔
101
        }
31✔
102

103
        // Parse out TLV records.
104
        var tlvRecords ExtraOpaqueData
123✔
105
        if err := ReadElement(r, &tlvRecords); err != nil {
123✔
106
                return err
×
107
        }
×
108

109
        // Prepare receiving buffers to be filled by TLV extraction.
110
        var localNonceScratch Musig2Nonce
123✔
111
        localNonce := tlv.MakeStaticRecord(
123✔
112
                DALocalMusig2Pubnonce, &localNonceScratch, musig2.PubNonceSize,
123✔
113
                nonceTypeEncoder, nonceTypeDecoder,
123✔
114
        )
123✔
115

123✔
116
        // Create set of Records to read TLV bytestream into.
123✔
117
        records := []tlv.Record{localNonce}
123✔
118
        tlv.SortRecords(records)
123✔
119

123✔
120
        // Read TLV stream into record set.
123✔
121
        extraBytesReader := bytes.NewReader(tlvRecords)
123✔
122
        tlvStream, err := tlv.NewStream(records...)
123✔
123
        if err != nil {
123✔
124
                return err
×
125
        }
×
126
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
123✔
127
        if err != nil {
146✔
128
                return err
23✔
129
        }
23✔
130

131
        // Check the results of the TLV Stream decoding and appropriately set
132
        // message fields.
133
        if val, ok := typeMap[DALocalMusig2Pubnonce]; ok && val == nil {
161✔
134
                da.LocalNonce = fn.Some(localNonceScratch)
61✔
135
        }
61✔
136

137
        if len(tlvRecords) != 0 {
161✔
138
                da.ExtraData = tlvRecords
61✔
139
        }
61✔
140

141
        return nil
100✔
142
}
143

144
// MsgType returns the MessageType code which uniquely identifies this message
145
// as a DynAck on the wire.
146
//
147
// This is part of the lnwire.Message interface.
148
func (da *DynAck) MsgType() MessageType {
100✔
149
        return MsgDynAck
100✔
150
}
100✔
151

152
// SerializedSize returns the serialized size of the message in bytes.
153
//
154
// This is part of the lnwire.SizeableMessage interface.
155
func (da *DynAck) SerializedSize() (uint32, error) {
×
156
        return MessageSerializedSize(da)
×
157
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc