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

lightningnetwork / lnd / 12058234999

27 Nov 2024 09:06PM UTC coverage: 57.847% (-1.1%) from 58.921%
12058234999

Pull #9148

github

ProofOfKeags
lnwire: convert DynPropose and DynCommit to use typed tlv records
Pull Request #9148: DynComms [2/n]: lnwire: add authenticated wire messages for Dyn*

142 of 177 new or added lines in 4 files covered. (80.23%)

19365 existing lines in 251 files now uncovered.

100876 of 174383 relevant lines covered (57.85%)

25338.28 hits per line

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

84.75
/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 {
100✔
60
        return &CommitSig{}
100✔
61
}
100✔
62

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

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

2,230✔
76
        err := ReadElements(r,
2,230✔
77
                &c.ChanID,
2,230✔
78
                &c.CommitSig,
2,230✔
79
                &c.HtlcSigs,
2,230✔
80
                &msgExtraData,
2,230✔
81
        )
2,230✔
82
        if err != nil {
2,244✔
83
                return err
14✔
84
        }
14✔
85

86
        // Extract TLV records from the extra data field.
87
        partialSig := c.PartialSig.Zero()
2,216✔
88

2,216✔
89
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
2,216✔
90
                msgExtraData, &partialSig,
2,216✔
91
        )
2,216✔
92
        if err != nil {
2,264✔
93
                return err
48✔
94
        }
48✔
95

96
        // Set the corresponding TLV types if they were included in the stream.
97
        if _, ok := parsed[partialSig.TlvType()]; ok {
2,216✔
98
                c.PartialSig = tlv.SomeRecordT(partialSig)
48✔
99
        }
48✔
100

101
        c.CustomRecords = customRecords
2,168✔
102
        c.ExtraData = extraData
2,168✔
103

2,168✔
104
        return nil
2,168✔
105
}
106

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

117
        extraData, err := MergeAndEncode(
4,177✔
118
                recordProducers, c.ExtraData, c.CustomRecords,
4,177✔
119
        )
4,177✔
120
        if err != nil {
4,178✔
121
                return err
1✔
122
        }
1✔
123

124
        if err := WriteChannelID(w, c.ChanID); err != nil {
4,176✔
125
                return err
×
126
        }
×
127

128
        if err := WriteSig(w, c.CommitSig); err != nil {
4,176✔
129
                return err
×
130
        }
×
131

132
        if err := WriteSigs(w, c.HtlcSigs); err != nil {
4,176✔
133
                return err
×
134
        }
×
135

136
        return WriteBytes(w, extraData)
4,176✔
137
}
138

139
// MsgType returns the integer uniquely identifying this message type on the
140
// wire.
141
//
142
// This is part of the lnwire.Message interface.
143
func (c *CommitSig) MsgType() MessageType {
3,396✔
144
        return MsgCommitSig
3,396✔
145
}
3,396✔
146

147
// TargetChanID returns the channel id of the link for which this message is
148
// intended.
149
//
150
// NOTE: Part of peer.LinkUpdater interface.
UNCOV
151
func (c *CommitSig) TargetChanID() ChannelID {
×
UNCOV
152
        return c.ChanID
×
UNCOV
153
}
×
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