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

lightningnetwork / lnd / 14757563406

30 Apr 2025 02:52PM UTC coverage: 69.041% (+0.009%) from 69.032%
14757563406

Pull #9770

github

web-flow
Merge dc7d1c9f4 into b068d79df
Pull Request #9770: routing+migration: fix mission control migration with nil failure msg

105 of 118 new or added lines in 3 files covered. (88.98%)

63 existing lines in 16 files now uncovered.

133927 of 193983 relevant lines covered (69.04%)

22092.0 hits per line

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

80.65
/lnwire/commit_sig.go
1
package lnwire
2

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

7
        "github.com/lightningnetwork/lnd/tlv"
8
)
9

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

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

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

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

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

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

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

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

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

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

2,227✔
80
        err := ReadElements(r,
2,227✔
81
                &c.ChanID,
2,227✔
82
                &c.CommitSig,
2,227✔
83
                &c.HtlcSigs,
2,227✔
84
                &msgExtraData,
2,227✔
85
        )
2,227✔
86
        if err != nil {
2,241✔
87
                return err
14✔
88
        }
14✔
89

90
        // Extract TLV records from the extra data field.
91
        partialSig := c.PartialSig.Zero()
2,213✔
92

2,213✔
93
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
2,213✔
94
                msgExtraData, &partialSig,
2,213✔
95
        )
2,213✔
96
        if err != nil {
2,261✔
97
                return err
48✔
98
        }
48✔
99

100
        // Set the corresponding TLV types if they were included in the stream.
101
        if _, ok := parsed[partialSig.TlvType()]; ok {
2,222✔
102
                c.PartialSig = tlv.SomeRecordT(partialSig)
57✔
103
        }
57✔
104

105
        c.CustomRecords = customRecords
2,165✔
106
        c.ExtraData = extraData
2,165✔
107

2,165✔
108
        return nil
2,165✔
109
}
110

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

121
        extraData, err := MergeAndEncode(
4,168✔
122
                recordProducers, c.ExtraData, c.CustomRecords,
4,168✔
123
        )
4,168✔
124
        if err != nil {
4,169✔
125
                return err
1✔
126
        }
1✔
127

128
        if err := WriteChannelID(w, c.ChanID); err != nil {
4,167✔
129
                return err
×
130
        }
×
131

132
        if err := WriteSig(w, c.CommitSig); err != nil {
4,167✔
133
                return err
×
134
        }
×
135

136
        if err := WriteSigs(w, c.HtlcSigs); err != nil {
4,167✔
137
                return err
×
138
        }
×
139

140
        return WriteBytes(w, extraData)
4,167✔
141
}
142

143
// MsgType returns the integer uniquely identifying this message type on the
144
// wire.
145
//
146
// This is part of the lnwire.Message interface.
147
func (c *CommitSig) MsgType() MessageType {
5,755✔
148
        return MsgCommitSig
5,755✔
149
}
5,755✔
150

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

159
// SerializedSize returns the serialized size of the message in bytes.
160
//
161
// This is part of the lnwire.SizeableMessage interface.
UNCOV
162
func (c *CommitSig) SerializedSize() (uint32, error) {
×
UNCOV
163
        return MessageSerializedSize(c)
×
UNCOV
164
}
×
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