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

lightningnetwork / lnd / 16569502135

28 Jul 2025 12:50PM UTC coverage: 67.251% (+0.02%) from 67.227%
16569502135

Pull #9455

github

web-flow
Merge b3899c4fd into 2e36f9b8b
Pull Request #9455: discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

179 of 208 new or added lines in 6 files covered. (86.06%)

105 existing lines in 23 files now uncovered.

135676 of 201746 relevant lines covered (67.25%)

21711.59 hits per line

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

73.75
/lnwire/closing_complete.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
)
10

11
// ClosingSigs houses the 3 possible signatures that can be sent when
12
// attempting to complete a cooperative channel closure. A signature will
13
// either include both outputs, or only one of the outputs from either side.
14
type ClosingSigs struct {
15
        // CloserNoClosee is a signature that excludes the output of the
16
        // clsoee.
17
        CloserNoClosee tlv.OptionalRecordT[tlv.TlvType1, Sig]
18

19
        // NoCloserClosee is a signature that excludes the output of the
20
        // closer.
21
        NoCloserClosee tlv.OptionalRecordT[tlv.TlvType2, Sig]
22

23
        // CloserAndClosee is a signature that includes both outputs.
24
        CloserAndClosee tlv.OptionalRecordT[tlv.TlvType3, Sig]
25
}
26

27
// ClosingComplete is sent by either side to kick off the process of obtaining
28
// a valid signature on a c o-operative channel closure of their choice.
29
type ClosingComplete struct {
30
        // ChannelID serves to identify which channel is to be closed.
31
        ChannelID ChannelID
32

33
        // CloserScript is the script to which the channel funds will be paid
34
        // for the closer (the person sending the ClosingComplete) message.
35
        CloserScript DeliveryAddress
36

37
        // CloseeScript is the script to which the channel funds will be paid
38
        // (the person receiving the ClosingComplete message).
39
        CloseeScript DeliveryAddress
40

41
        // FeeSatoshis is the total fee in satoshis that the party to the
42
        // channel would like to propose for the close transaction.
43
        FeeSatoshis btcutil.Amount
44

45
        // LockTime is the locktime number to be used in the input spending the
46
        // funding transaction.
47
        LockTime uint32
48

49
        // ClosingSigs houses the 3 possible signatures that can be sent.
50
        ClosingSigs
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
// decodeClosingSigs decodes the closing sig TLV records in the passed
59
// ExtraOpaqueData.
60
func decodeClosingSigs(c *ClosingSigs, tlvRecords ExtraOpaqueData) error {
203✔
61
        sig1 := c.CloserNoClosee.Zero()
203✔
62
        sig2 := c.NoCloserClosee.Zero()
203✔
63
        sig3 := c.CloserAndClosee.Zero()
203✔
64

203✔
65
        typeMap, err := tlvRecords.ExtractRecords(&sig1, &sig2, &sig3)
203✔
66
        if err != nil {
203✔
67
                return err
×
68
        }
×
69

70
        // TODO(roasbeef): helper func to made decode of the optional vals
71
        // easier?
72

73
        if val, ok := typeMap[c.CloserNoClosee.TlvType()]; ok && val == nil {
307✔
74
                c.CloserNoClosee = tlv.SomeRecordT(sig1)
104✔
75
        }
104✔
76
        if val, ok := typeMap[c.NoCloserClosee.TlvType()]; ok && val == nil {
316✔
77
                c.NoCloserClosee = tlv.SomeRecordT(sig2)
113✔
78
        }
113✔
79
        if val, ok := typeMap[c.CloserAndClosee.TlvType()]; ok && val == nil {
309✔
80
                c.CloserAndClosee = tlv.SomeRecordT(sig3)
106✔
81
        }
106✔
82

83
        return nil
203✔
84
}
85

86
// Decode deserializes a serialized ClosingComplete message stored in the
87
// passed io.Reader.
88
func (c *ClosingComplete) Decode(r io.Reader, _ uint32) error {
162✔
89
        // First, read out all the fields that are hard coded into the message.
162✔
90
        err := ReadElements(
162✔
91
                r, &c.ChannelID, &c.CloserScript, &c.CloseeScript,
162✔
92
                &c.FeeSatoshis, &c.LockTime,
162✔
93
        )
162✔
94
        if err != nil {
221✔
95
                return err
59✔
96
        }
59✔
97

98
        // With the hard coded messages read, we'll now read out the TLV fields
99
        // of the message.
100
        var tlvRecords ExtraOpaqueData
103✔
101
        if err := ReadElements(r, &tlvRecords); err != nil {
103✔
102
                return err
×
103
        }
×
104

105
        if err := decodeClosingSigs(&c.ClosingSigs, tlvRecords); err != nil {
103✔
106
                return err
×
107
        }
×
108

109
        if len(tlvRecords) != 0 {
206✔
110
                c.ExtraData = tlvRecords
103✔
111
        }
103✔
112

113
        return nil
103✔
114
}
115

116
// closingSigRecords returns the set of records that encode the closing sigs,
117
// if present.
118
func closingSigRecords(c *ClosingSigs) []tlv.RecordProducer {
203✔
119
        recordProducers := make([]tlv.RecordProducer, 0, 3)
203✔
120
        c.CloserNoClosee.WhenSome(func(sig tlv.RecordT[tlv.TlvType1, Sig]) {
307✔
121
                recordProducers = append(recordProducers, &sig)
104✔
122
        })
104✔
123
        c.NoCloserClosee.WhenSome(func(sig tlv.RecordT[tlv.TlvType2, Sig]) {
316✔
124
                recordProducers = append(recordProducers, &sig)
113✔
125
        })
113✔
126
        c.CloserAndClosee.WhenSome(func(sig tlv.RecordT[tlv.TlvType3, Sig]) {
309✔
127
                recordProducers = append(recordProducers, &sig)
106✔
128
        })
106✔
129

130
        return recordProducers
203✔
131
}
132

133
// Encode serializes the target ClosingComplete into the passed io.Writer.
134
func (c *ClosingComplete) Encode(w *bytes.Buffer, _ uint32) error {
103✔
135
        if err := WriteChannelID(w, c.ChannelID); err != nil {
103✔
136
                return err
×
137
        }
×
138

139
        if err := WriteDeliveryAddress(w, c.CloserScript); err != nil {
103✔
140
                return err
×
141
        }
×
142
        if err := WriteDeliveryAddress(w, c.CloseeScript); err != nil {
103✔
143
                return err
×
144
        }
×
145

146
        if err := WriteSatoshi(w, c.FeeSatoshis); err != nil {
103✔
147
                return err
×
148
        }
×
149

150
        if err := WriteUint32(w, c.LockTime); err != nil {
103✔
151
                return err
×
152
        }
×
153

154
        recordProducers := closingSigRecords(&c.ClosingSigs)
103✔
155

103✔
156
        err := EncodeMessageExtraData(&c.ExtraData, recordProducers...)
103✔
157
        if err != nil {
103✔
158
                return err
×
159
        }
×
160

161
        return WriteBytes(w, c.ExtraData)
103✔
162
}
163

164
// MsgType returns the uint32 code which uniquely identifies this message as a
165
// ClosingComplete message on the wire.
166
//
167
// This is part of the lnwire.Message interface.
168
func (c *ClosingComplete) MsgType() MessageType {
103✔
169
        return MsgClosingComplete
103✔
170
}
103✔
171

172
// SerializedSize returns the serialized size of the message in bytes.
173
//
174
// This is part of the lnwire.SizeableMessage interface.
UNCOV
175
func (c *ClosingComplete) SerializedSize() (uint32, error) {
×
UNCOV
176
        return MessageSerializedSize(c)
×
UNCOV
177
}
×
178

179
// A compile time check to ensure ClosingComplete implements the lnwire.Message
180
// interface.
181
var _ Message = (*ClosingComplete)(nil)
182

183
// A compile time check to ensure ClosingComplete implements the
184
// lnwire.SizeableMessage interface.
185
var _ SizeableMessage = (*ClosingComplete)(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