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

lightningnetwork / lnd / 9915780197

13 Jul 2024 12:30AM UTC coverage: 49.268% (-9.1%) from 58.413%
9915780197

push

github

web-flow
Merge pull request #8653 from ProofOfKeags/fn-prim

DynComms [0/n]: `fn` package additions

92837 of 188433 relevant lines covered (49.27%)

1.55 hits per line

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

65.45
/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
        // ExtraData is the set of data that was appended to this message to
49
        // fill out the full maximum transport message size. These fields can
50
        // be used to specify optional data such as custom TLV fields.
51
        ExtraData ExtraOpaqueData
52
}
53

54
// NewCommitSig creates a new empty CommitSig message.
55
func NewCommitSig() *CommitSig {
×
56
        return &CommitSig{
×
57
                ExtraData: make([]byte, 0),
×
58
        }
×
59
}
×
60

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

65
// Decode deserializes a serialized CommitSig message stored in the
66
// passed io.Reader observing the specified protocol version.
67
//
68
// This is part of the lnwire.Message interface.
69
func (c *CommitSig) Decode(r io.Reader, pver uint32) error {
3✔
70
        err := ReadElements(r,
3✔
71
                &c.ChanID,
3✔
72
                &c.CommitSig,
3✔
73
                &c.HtlcSigs,
3✔
74
        )
3✔
75
        if err != nil {
3✔
76
                return err
×
77
        }
×
78

79
        var tlvRecords ExtraOpaqueData
3✔
80
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
81
                return err
×
82
        }
×
83

84
        partialSig := c.PartialSig.Zero()
3✔
85
        typeMap, err := tlvRecords.ExtractRecords(&partialSig)
3✔
86
        if err != nil {
3✔
87
                return err
×
88
        }
×
89

90
        // Set the corresponding TLV types if they were included in the stream.
91
        if val, ok := typeMap[c.PartialSig.TlvType()]; ok && val == nil {
6✔
92
                c.PartialSig = tlv.SomeRecordT(partialSig)
3✔
93
        }
3✔
94

95
        if len(tlvRecords) != 0 {
6✔
96
                c.ExtraData = tlvRecords
3✔
97
        }
3✔
98

99
        return nil
3✔
100
}
101

102
// Encode serializes the target CommitSig into the passed io.Writer
103
// observing the protocol version specified.
104
//
105
// This is part of the lnwire.Message interface.
106
func (c *CommitSig) Encode(w *bytes.Buffer, pver uint32) error {
3✔
107
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
108
        c.PartialSig.WhenSome(func(sig PartialSigWithNonceTLV) {
6✔
109
                recordProducers = append(recordProducers, &sig)
3✔
110
        })
3✔
111
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
3✔
112
        if err != nil {
3✔
113
                return err
×
114
        }
×
115

116
        if err := WriteChannelID(w, c.ChanID); err != nil {
3✔
117
                return err
×
118
        }
×
119

120
        if err := WriteSig(w, c.CommitSig); err != nil {
3✔
121
                return err
×
122
        }
×
123

124
        if err := WriteSigs(w, c.HtlcSigs); err != nil {
3✔
125
                return err
×
126
        }
×
127

128
        return WriteBytes(w, c.ExtraData)
3✔
129
}
130

131
// MsgType returns the integer uniquely identifying this message type on the
132
// wire.
133
//
134
// This is part of the lnwire.Message interface.
135
func (c *CommitSig) MsgType() MessageType {
3✔
136
        return MsgCommitSig
3✔
137
}
3✔
138

139
// TargetChanID returns the channel id of the link for which this message is
140
// intended.
141
//
142
// NOTE: Part of peer.LinkUpdater interface.
143
func (c *CommitSig) TargetChanID() ChannelID {
3✔
144
        return c.ChanID
3✔
145
}
3✔
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