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

lightningnetwork / lnd / 13982721865

21 Mar 2025 01:30AM UTC coverage: 58.587% (-0.5%) from 59.126%
13982721865

Pull #9623

github

web-flow
Merge 05a6b6838 into 5d921723b
Pull Request #9623: Size msg test msg

0 of 1572 new or added lines in 43 files covered. (0.0%)

17 existing lines in 5 files now uncovered.

96767 of 165169 relevant lines covered (58.59%)

1.82 hits per line

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

70.97
/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 {
3✔
76
        // msgExtraData is a temporary variable used to read the message extra
3✔
77
        // data field from the reader.
3✔
78
        var msgExtraData ExtraOpaqueData
3✔
79

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

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

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

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

105
        c.CustomRecords = customRecords
3✔
106
        c.ExtraData = extraData
3✔
107

3✔
108
        return nil
3✔
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 {
3✔
116
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
117
        c.PartialSig.WhenSome(func(sig PartialSigWithNonceTLV) {
6✔
118
                recordProducers = append(recordProducers, &sig)
3✔
119
        })
3✔
120

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

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

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

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

140
        return WriteBytes(w, extraData)
3✔
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 {
3✔
148
        return MsgCommitSig
3✔
149
}
3✔
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.
NEW
162
func (c *CommitSig) SerializedSize() (uint32, error) {
×
NEW
163
        return MessageSerializedSize(c)
×
NEW
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