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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

0.0
/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
        "pgregory.net/rapid"
11
)
12

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

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

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

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

41
// A compile time check to ensure DynAck implements the lnwire.Message
42
// interface.
43
var _ Message = (*DynAck)(nil)
44

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

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

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

UNCOV
62
        var tlvRecords []tlv.Record
×
UNCOV
63
        da.LocalNonce.WhenSome(func(nonce Musig2Nonce) {
×
UNCOV
64
                tlvRecords = append(
×
UNCOV
65
                        tlvRecords, tlv.MakeStaticRecord(
×
UNCOV
66
                                DALocalMusig2Pubnonce, &nonce,
×
UNCOV
67
                                musig2.PubNonceSize, nonceTypeEncoder,
×
UNCOV
68
                                nonceTypeDecoder,
×
UNCOV
69
                        ),
×
UNCOV
70
                )
×
UNCOV
71
        })
×
UNCOV
72
        tlv.SortRecords(tlvRecords)
×
UNCOV
73

×
UNCOV
74
        tlvStream, err := tlv.NewStream(tlvRecords...)
×
UNCOV
75
        if err != nil {
×
76
                return err
×
77
        }
×
78

UNCOV
79
        var extraBytesWriter bytes.Buffer
×
UNCOV
80
        if err := tlvStream.Encode(&extraBytesWriter); err != nil {
×
81
                return err
×
82
        }
×
83

UNCOV
84
        da.ExtraData = ExtraOpaqueData(extraBytesWriter.Bytes())
×
UNCOV
85

×
UNCOV
86
        return WriteBytes(w, da.ExtraData)
×
87
}
88

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

100
        // Parse out TLV records.
UNCOV
101
        var tlvRecords ExtraOpaqueData
×
UNCOV
102
        if err := ReadElement(r, &tlvRecords); err != nil {
×
103
                return err
×
104
        }
×
105

106
        // Prepare receiving buffers to be filled by TLV extraction.
UNCOV
107
        var localNonceScratch Musig2Nonce
×
UNCOV
108
        localNonce := tlv.MakeStaticRecord(
×
UNCOV
109
                DALocalMusig2Pubnonce, &localNonceScratch, musig2.PubNonceSize,
×
UNCOV
110
                nonceTypeEncoder, nonceTypeDecoder,
×
UNCOV
111
        )
×
UNCOV
112

×
UNCOV
113
        // Create set of Records to read TLV bytestream into.
×
UNCOV
114
        records := []tlv.Record{localNonce}
×
UNCOV
115
        tlv.SortRecords(records)
×
UNCOV
116

×
UNCOV
117
        // Read TLV stream into record set.
×
UNCOV
118
        extraBytesReader := bytes.NewReader(tlvRecords)
×
UNCOV
119
        tlvStream, err := tlv.NewStream(records...)
×
UNCOV
120
        if err != nil {
×
121
                return err
×
122
        }
×
UNCOV
123
        typeMap, err := tlvStream.DecodeWithParsedTypesP2P(extraBytesReader)
×
UNCOV
124
        if err != nil {
×
UNCOV
125
                return err
×
UNCOV
126
        }
×
127

128
        // Check the results of the TLV Stream decoding and appropriately set
129
        // message fields.
UNCOV
130
        if val, ok := typeMap[DALocalMusig2Pubnonce]; ok && val == nil {
×
UNCOV
131
                da.LocalNonce = fn.Some(localNonceScratch)
×
UNCOV
132
        }
×
133

UNCOV
134
        if len(tlvRecords) != 0 {
×
UNCOV
135
                da.ExtraData = tlvRecords
×
UNCOV
136
        }
×
137

UNCOV
138
        return nil
×
139
}
140

141
// MsgType returns the MessageType code which uniquely identifies this message
142
// as a DynAck on the wire.
143
//
144
// This is part of the lnwire.Message interface.
UNCOV
145
func (da *DynAck) MsgType() MessageType {
×
UNCOV
146
        return MsgDynAck
×
UNCOV
147
}
×
148

149
// SerializedSize returns the serialized size of the message in bytes.
150
//
151
// This is part of the lnwire.SizeableMessage interface.
NEW
152
func (da *DynAck) SerializedSize() (uint32, error) {
×
NEW
153
        return MessageSerializedSize(da)
×
NEW
154
}
×
155

156
// RandTestMessage populates the message with random data suitable for testing.
157
// It uses the rapid testing framework to generate random values.
158
//
159
// This is part of the TestMessage interface.
NEW
160
func (da *DynAck) RandTestMessage(t *rapid.T) Message {
×
NEW
161
        msg := &DynAck{
×
NEW
162
                ChanID:    RandChannelID(t),
×
NEW
163
                ExtraData: RandExtraOpaqueData(t, nil),
×
NEW
164
        }
×
NEW
165

×
NEW
166
        includeLocalNonce := rapid.Bool().Draw(t, "includeLocalNonce")
×
NEW
167

×
NEW
168
        if includeLocalNonce {
×
NEW
169
                msg.LocalNonce = fn.Some(RandMusig2Nonce(t))
×
NEW
170
        }
×
171

NEW
172
        return msg
×
173
}
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