• 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

52.38
/lnwire/commit_sig.go
1
package lnwire
2

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

7
        "github.com/lightningnetwork/lnd/tlv"
8
        "pgregory.net/rapid"
9
)
10

11
// CommitSig is sent by either side to stage any pending HTLC's in the
12
// receiver's pending set into a new commitment state. Implicitly, the new
13
// commitment transaction constructed which has been signed by CommitSig
14
// includes all HTLC's in the remote node's pending set. A CommitSig message
15
// may be sent after a series of UpdateAddHTLC/UpdateFulfillHTLC messages in
16
// order to batch add several HTLC's with a single signature covering all
17
// implicitly accepted HTLC's.
18
type CommitSig struct {
19
        // ChanID uniquely identifies to which currently active channel this
20
        // CommitSig applies to.
21
        ChanID ChannelID
22

23
        // CommitSig is Alice's signature for Bob's new commitment transaction.
24
        // Alice is able to send this signature without requesting any
25
        // additional data due to the piggybacking of Bob's next revocation
26
        // hash in his prior RevokeAndAck message, as well as the canonical
27
        // ordering used for all inputs/outputs within commitment transactions.
28
        // If initiating a new commitment state, this signature should ONLY
29
        // cover all of the sending party's pending log updates, and the log
30
        // updates of the remote party that have been ACK'd.
31
        CommitSig Sig
32

33
        // HtlcSigs is a signature for each relevant HTLC output within the
34
        // created commitment. The order of the signatures is expected to be
35
        // identical to the placement of the HTLC's within the BIP 69 sorted
36
        // commitment transaction. For each outgoing HTLC (from the PoV of the
37
        // sender of this message), a signature for an HTLC timeout transaction
38
        // should be signed, for each incoming HTLC the HTLC timeout
39
        // transaction should be signed.
40
        HtlcSigs []Sig
41

42
        // PartialSig is used to transmit a musig2 extended partial signature
43
        // that also carries along the public nonce of the signer.
44
        //
45
        // NOTE: This field is only populated if a musig2 taproot channel is
46
        // being signed for. In this case, the above Sig type MUST be blank.
47
        PartialSig OptPartialSigWithNonceTLV
48

49
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
50
        // intended for inclusion in the ExtraData field.
51
        CustomRecords CustomRecords
52

53
        // ExtraData is the set of data that was appended to this message to
54
        // fill out the full maximum transport message size. These fields can
55
        // be used to specify optional data such as custom TLV fields.
56
        ExtraData ExtraOpaqueData
57
}
58

59
// NewCommitSig creates a new empty CommitSig message.
UNCOV
60
func NewCommitSig() *CommitSig {
×
UNCOV
61
        return &CommitSig{}
×
UNCOV
62
}
×
63

64
// A compile time check to ensure CommitSig implements the lnwire.Message
65
// interface.
66
var _ Message = (*CommitSig)(nil)
67

68
// A compile time check to ensure CommitSig implements the lnwire.SizeableMessage interface.
69
var _ SizeableMessage = (*CommitSig)(nil)
70

71
// A compile time check to ensure CommitSig implements the lnwire.TestMessage interface.
72
var _ TestMessage = (*CommitSig)(nil)
73

74
// Decode deserializes a serialized CommitSig message stored in the
75
// passed io.Reader observing the specified protocol version.
76
//
77
// This is part of the lnwire.Message interface.
78
func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
3✔
79
        // msgExtraData is a temporary variable used to read the message extra
3✔
80
        // data field from the reader.
3✔
81
        var msgExtraData ExtraOpaqueData
3✔
82

3✔
83
        err := ReadElements(r,
3✔
84
                &c.ChanID,
3✔
85
                &c.CommitSig,
3✔
86
                &c.HtlcSigs,
3✔
87
                &msgExtraData,
3✔
88
        )
3✔
89
        if err != nil {
3✔
UNCOV
90
                return err
×
UNCOV
91
        }
×
92

93
        // Extract TLV records from the extra data field.
94
        partialSig := c.PartialSig.Zero()
3✔
95

3✔
96
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
3✔
97
                msgExtraData, &partialSig,
3✔
98
        )
3✔
99
        if err != nil {
3✔
UNCOV
100
                return err
×
UNCOV
101
        }
×
102

103
        // Set the corresponding TLV types if they were included in the stream.
104
        if _, ok := parsed[partialSig.TlvType()]; ok {
6✔
105
                c.PartialSig = tlv.SomeRecordT(partialSig)
3✔
106
        }
3✔
107

108
        c.CustomRecords = customRecords
3✔
109
        c.ExtraData = extraData
3✔
110

3✔
111
        return nil
3✔
112
}
113

114
// Encode serializes the target CommitSig into the passed io.Writer
115
// observing the protocol version specified.
116
//
117
// This is part of the lnwire.Message interface.
118
func (c *CommitSig) Encode(w *bytes.Buffer, pver uint32) error {
3✔
119
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
120
        c.PartialSig.WhenSome(func(sig PartialSigWithNonceTLV) {
6✔
121
                recordProducers = append(recordProducers, &sig)
3✔
122
        })
3✔
123

124
        extraData, err := MergeAndEncode(
3✔
125
                recordProducers, c.ExtraData, c.CustomRecords,
3✔
126
        )
3✔
127
        if err != nil {
3✔
UNCOV
128
                return err
×
UNCOV
129
        }
×
130

131
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
UNCOV
132
                return err
×
UNCOV
133
        }
×
134

135
        if err := WriteSig(w, c.CommitSig); err != nil {
3✔
UNCOV
136
                return err
×
UNCOV
137
        }
×
138

139
        if err := WriteSigs(w, c.HtlcSigs); err != nil {
3✔
UNCOV
140
                return err
×
UNCOV
141
        }
×
142

143
        return WriteBytes(w, extraData)
3✔
144
}
145

146
// MsgType returns the integer uniquely identifying this message type on the
147
// wire.
148
//
149
// This is part of the lnwire.Message interface.
150
func (c *CommitSig) MsgType() MessageType {
3✔
151
        return MsgCommitSig
3✔
152
}
3✔
153

154
// TargetChanID returns the channel id of the link for which this message is
155
// intended.
156
//
157
// NOTE: Part of peer.LinkUpdater interface.
158
func (c *CommitSig) TargetChanID() ChannelID {
3✔
159
        return c.ChanID
3✔
160
}
3✔
161

162
// SerializedSize returns the serialized size of the message in bytes.
163
//
164
// This is part of the lnwire.SizeableMessage interface.
NEW
165
func (c *CommitSig) SerializedSize() (uint32, error) {
×
NEW
166
        return MessageSerializedSize(c)
×
NEW
167
}
×
168

169
// RandTestMessage populates the message with random data suitable for testing.
170
// It uses the rapid testing framework to generate random values.
171
//
172
// This is part of the TestMessage interface.
NEW
173
func (c *CommitSig) RandTestMessage(t *rapid.T) Message {
×
NEW
174
        cr, _ := RandCustomRecords(t, nil, true)
×
NEW
175
        sig := &CommitSig{
×
NEW
176
                ChanID:        RandChannelID(t),
×
NEW
177
                CommitSig:     RandSignature(t),
×
NEW
178
                CustomRecords: cr,
×
NEW
179
        }
×
NEW
180

×
NEW
181
        numHtlcSigs := rapid.IntRange(0, 20).Draw(t, "numHtlcSigs")
×
NEW
182
        htlcSigs := make([]Sig, numHtlcSigs)
×
NEW
183
        for i := 0; i < numHtlcSigs; i++ {
×
NEW
184
                htlcSigs[i] = RandSignature(t)
×
NEW
185
        }
×
186

NEW
187
        if len(htlcSigs) > 0 {
×
NEW
188
                sig.HtlcSigs = htlcSigs
×
NEW
189
        }
×
190

NEW
191
        includePartialSig := rapid.Bool().Draw(t, "includePartialSig")
×
NEW
192
        if includePartialSig {
×
NEW
193
                sigWithNonce := RandPartialSigWithNonce(t)
×
NEW
194
                sig.PartialSig = MaybePartialSigWithNonce(sigWithNonce)
×
NEW
195
        }
×
196

NEW
197
        return sig
×
198
}
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