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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

30.77
/lnwire/closing_sig.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/tlv"
9
        "pgregory.net/rapid"
10
)
11

12
// ClosingSig is sent in response to a ClosingComplete message. It carries the
13
// signatures of the closee to the closer.
14
type ClosingSig struct {
15
        // ChannelID serves to identify which channel is to be closed.
16
        ChannelID ChannelID
17

18
        // CloserScript is the script to which the channel funds will be paid
19
        // for the closer (the person sending the ClosingComplete) message.
20
        CloserScript DeliveryAddress
21

22
        // CloseeScript is the script to which the channel funds will be paid
23
        // (the person receiving the ClosingComplete message).
24
        CloseeScript DeliveryAddress
25

26
        // FeeSatoshis is the total fee in satoshis that the party to the
27
        // channel proposed for the close transaction.
28
        FeeSatoshis btcutil.Amount
29

30
        // LockTime is the locktime number to be used in the input spending the
31
        // funding transaction.
32
        LockTime uint32
33

34
        // ClosingSigs houses the 3 possible signatures that can be sent.
35
        ClosingSigs
36

37
        // ExtraData is the set of data that was appended to this message to
38
        // fill out the full maximum transport message size. These fields can
39
        // be used to specify optional data such as custom TLV fields.
40
        ExtraData ExtraOpaqueData
41
}
42

43
// Decode deserializes a serialized ClosingSig message stored in the passed
44
// io.Reader.
45
func (c *ClosingSig) Decode(r io.Reader, _ uint32) error {
3✔
46
        // First, read out all the fields that are hard coded into the message.
3✔
47
        err := ReadElements(
3✔
48
                r, &c.ChannelID, &c.CloserScript, &c.CloseeScript,
3✔
49
                &c.FeeSatoshis, &c.LockTime,
3✔
50
        )
3✔
51
        if err != nil {
3✔
UNCOV
52
                return err
×
UNCOV
53
        }
×
54

55
        // With the hard coded messages read, we'll now read out the TLV fields
56
        // of the message.
57
        var tlvRecords ExtraOpaqueData
3✔
58
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
59
                return err
×
60
        }
×
61

62
        if err := decodeClosingSigs(&c.ClosingSigs, tlvRecords); err != nil {
3✔
63
                return err
×
64
        }
×
65

66
        if len(tlvRecords) != 0 {
6✔
67
                c.ExtraData = tlvRecords
3✔
68
        }
3✔
69

70
        return nil
3✔
71
}
72

73
// Encode serializes the target ClosingSig into the passed io.Writer.
74
func (c *ClosingSig) Encode(w *bytes.Buffer, _ uint32) error {
3✔
75
        if err := WriteChannelID(w, c.ChannelID); err != nil {
3✔
76
                return err
×
77
        }
×
78

79
        if err := WriteDeliveryAddress(w, c.CloserScript); err != nil {
3✔
80
                return err
×
81
        }
×
82
        if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil {
3✔
83
                return err
×
84
        }
×
85

86
        if err := WriteSatoshi(w, c.FeeSatoshis); err != nil {
3✔
87
                return err
×
88
        }
×
89

90
        if err := WriteUint32(w, c.LockTime); err != nil {
3✔
91
                return err
×
92
        }
×
93

94
        recordProducers := closingSigRecords(&c.ClosingSigs)
3✔
95

3✔
96
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
3✔
97
        if err != nil {
3✔
98
                return err
×
99
        }
×
100

101
        return WriteBytes(w, c.ExtraData)
3✔
102
}
103

104
// MsgType returns the uint32 code which uniquely identifies this message as a
105
// ClosingSig message on the wire.
106
//
107
// This is part of the lnwire.Message interface.
108
func (c *ClosingSig) MsgType() MessageType {
3✔
109
        return MsgClosingSig
3✔
110
}
3✔
111

112
// SerializedSize returns the serialized size of the message in bytes.
113
//
114
// This is part of the lnwire.SizeableMessage interface.
NEW
115
func (c *ClosingSig) SerializedSize() (uint32, error) {
×
NEW
116
        return MessageSerializedSize(c)
×
NEW
117
}
×
118

119
// RandTestMessage populates the message with random data suitable for testing.
120
// It uses the rapid testing framework to generate random values.
121
//
122
// This is part of the TestMessage interface.
NEW
123
func (c *ClosingSig) RandTestMessage(t *rapid.T) Message {
×
NEW
124
        msg := &ClosingSig{
×
NEW
125
                ChannelID: RandChannelID(t),
×
NEW
126
                ExtraData: RandExtraOpaqueData(t, nil),
×
NEW
127
        }
×
NEW
128

×
NEW
129
        includeCloserNoClosee := rapid.Bool().Draw(t, "includeCloserNoClosee")
×
NEW
130
        includeNoCloserClosee := rapid.Bool().Draw(t, "includeNoCloserClosee")
×
NEW
131
        includeCloserAndClosee := rapid.Bool().Draw(t, "includeCloserAndClosee")
×
NEW
132

×
NEW
133
        // Ensure at least one signature is present.
×
NEW
134
        if !includeCloserNoClosee && !includeNoCloserClosee &&
×
NEW
135
                !includeCloserAndClosee {
×
NEW
136

×
NEW
137
                // If all are false, enable at least one randomly.
×
NEW
138
                choice := rapid.IntRange(0, 2).Draw(t, "sigChoice")
×
NEW
139
                switch choice {
×
NEW
140
                case 0:
×
NEW
141
                        includeCloserNoClosee = true
×
NEW
142
                case 1:
×
NEW
143
                        includeNoCloserClosee = true
×
NEW
144
                case 2:
×
NEW
145
                        includeCloserAndClosee = true
×
146
                }
147
        }
148

NEW
149
        if includeCloserNoClosee {
×
NEW
150
                sig := RandSignature(t)
×
NEW
151
                msg.CloserNoClosee = tlv.SomeRecordT(
×
NEW
152
                        tlv.NewRecordT[tlv.TlvType1, Sig](sig),
×
NEW
153
                )
×
NEW
154
        }
×
155

NEW
156
        if includeNoCloserClosee {
×
NEW
157
                sig := RandSignature(t)
×
NEW
158
                msg.NoCloserClosee = tlv.SomeRecordT(
×
NEW
159
                        tlv.NewRecordT[tlv.TlvType2, Sig](sig),
×
NEW
160
                )
×
NEW
161
        }
×
162

NEW
163
        if includeCloserAndClosee {
×
NEW
164
                sig := RandSignature(t)
×
NEW
165
                msg.CloserAndClosee = tlv.SomeRecordT(
×
NEW
166
                        tlv.NewRecordT[tlv.TlvType3, Sig](sig),
×
NEW
167
                )
×
NEW
168
        }
×
169

NEW
170
        return msg
×
171
}
172

173
// A compile time check to ensure ClosingSig implements the lnwire.Message
174
// interface.
175
var _ Message = (*ClosingSig)(nil)
176

177
// A compile time check to ensure ClosingSig implements the
178
// lnwire.SizeableMessage interface.
179
var _ SizeableMessage = (*ClosingSig)(nil)
180

181
// A compile time check to ensure ClosingSig implements the lnwire.TestMessage
182
// interface.
183
var _ TestMessage = (*ClosingSig)(nil)
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