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

lightningnetwork / lnd / 12313002221

13 Dec 2024 09:25AM UTC coverage: 57.486% (+8.6%) from 48.92%
12313002221

push

github

web-flow
Merge pull request #9343 from ellemouton/contextGuard

fn: expand the ContextGuard and add tests

101902 of 177264 relevant lines covered (57.49%)

24909.26 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,228✔
72
        // msgExtraData is a temporary variable used to read the message extra
2,228✔
73
        // data field from the reader.
2,228✔
74
        var msgExtraData ExtraOpaqueData
2,228✔
75

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

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

2,214✔
89
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
2,214✔
90
                msgExtraData, &partialSig,
2,214✔
91
        )
2,214✔
92
        if err != nil {
2,262✔
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,220✔
98
                c.PartialSig = tlv.SomeRecordT(partialSig)
54✔
99
        }
54✔
100

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

2,166✔
104
        return nil
2,166✔
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,173✔
112
        recordProducers := make([]tlv.RecordProducer, 0, 1)
4,173✔
113
        c.PartialSig.WhenSome(func(sig PartialSigWithNonceTLV) {
4,227✔
114
                recordProducers = append(recordProducers, &sig)
54✔
115
        })
54✔
116

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

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

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

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

136
        return WriteBytes(w, extraData)
4,172✔
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,392✔
144
        return MsgCommitSig
3,392✔
145
}
3,392✔
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.
151
func (c *CommitSig) TargetChanID() ChannelID {
×
152
        return c.ChanID
×
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