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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

74.14
/lnwire/shutdown.go
1
package lnwire
2

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

7
        "github.com/lightningnetwork/lnd/tlv"
8
)
9

10
type (
11
        // ShutdownNonceType is the type of the shutdown nonce TLV record.
12
        ShutdownNonceType = tlv.TlvType8
13

14
        // ShutdownNonceTLV is the TLV record that contains the shutdown nonce.
15
        ShutdownNonceTLV = tlv.OptionalRecordT[ShutdownNonceType, Musig2Nonce]
16
)
17

18
// SomeShutdownNonce returns a ShutdownNonceTLV with the given nonce.
19
func SomeShutdownNonce(nonce Musig2Nonce) ShutdownNonceTLV {
3✔
20
        return tlv.SomeRecordT(
3✔
21
                tlv.NewRecordT[ShutdownNonceType, Musig2Nonce](nonce),
3✔
22
        )
3✔
23
}
3✔
24

25
// Shutdown is sent by either side in order to initiate the cooperative closure
26
// of a channel. This message is sparse as both sides implicitly have the
27
// information necessary to construct a transaction that will send the settled
28
// funds of both parties to the final delivery addresses negotiated during the
29
// funding workflow.
30
type Shutdown struct {
31
        // ChannelID serves to identify which channel is to be closed.
32
        ChannelID ChannelID
33

34
        // Address is the script to which the channel funds will be paid.
35
        Address DeliveryAddress
36

37
        // ShutdownNonce is the nonce the sender will use to sign the first
38
        // co-op sign offer.
39
        ShutdownNonce ShutdownNonceTLV
40

41
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
42
        // intended for inclusion in the ExtraData field of the Shutdown
43
        // message.
44
        CustomRecords CustomRecords
45

46
        // ExtraData is the set of data that was appended to this message to
47
        // fill out the full maximum transport message size. These fields can
48
        // be used to specify optional data such as custom TLV fields.
49
        ExtraData ExtraOpaqueData
50
}
51

52
// NewShutdown creates a new Shutdown message.
53
func NewShutdown(cid ChannelID, addr DeliveryAddress) *Shutdown {
3✔
54
        return &Shutdown{
3✔
55
                ChannelID: cid,
3✔
56
                Address:   addr,
3✔
57
        }
3✔
58
}
3✔
59

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

64
// A compile-time check to ensure Shutdown implements the lnwire.SizeableMessage
65
// interface.
66
var _ SizeableMessage = (*Shutdown)(nil)
67

68
// Decode deserializes a serialized Shutdown from the passed io.Reader,
69
// observing the specified protocol version.
70
//
71
// This is part of the lnwire.Message interface.
72
func (s *Shutdown) Decode(r io.Reader, pver uint32) error {
3✔
73
        err := ReadElements(r, &s.ChannelID, &s.Address)
3✔
74
        if err != nil {
3✔
UNCOV
75
                return err
×
UNCOV
76
        }
×
77

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

83
        // Extract TLV records from the extra data field.
84
        musigNonce := s.ShutdownNonce.Zero()
3✔
85

3✔
86
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
3✔
87
                tlvRecords, &musigNonce,
3✔
88
        )
3✔
89
        if err != nil {
3✔
UNCOV
90
                return err
×
UNCOV
91
        }
×
92

93
        // Assign the parsed records back to the message.
94
        if _, ok := parsed[musigNonce.TlvType()]; ok {
6✔
95
                s.ShutdownNonce = tlv.SomeRecordT(musigNonce)
3✔
96
        }
3✔
97

98
        s.CustomRecords = customRecords
3✔
99
        s.ExtraData = extraData
3✔
100

3✔
101
        return nil
3✔
102
}
103

104
// Encode serializes the target Shutdown into the passed io.Writer observing
105
// the protocol version specified.
106
//
107
// This is part of the lnwire.Message interface.
108
func (s *Shutdown) Encode(w *bytes.Buffer, pver uint32) error {
3✔
109
        if err := WriteChannelID(w, s.ChannelID); err != nil {
3✔
110
                return err
×
111
        }
×
112

113
        if err := WriteDeliveryAddress(w, s.Address); err != nil {
3✔
114
                return err
×
115
        }
×
116

117
        // Only include nonce in extra data if present.
118
        var records []tlv.RecordProducer
3✔
119
        s.ShutdownNonce.WhenSome(
3✔
120
                func(nonce tlv.RecordT[ShutdownNonceType, Musig2Nonce]) {
6✔
121
                        records = append(records, &nonce)
3✔
122
                },
3✔
123
        )
124

125
        extraData, err := MergeAndEncode(records, s.ExtraData, s.CustomRecords)
3✔
126
        if err != nil {
3✔
127
                return err
×
128
        }
×
129

130
        return WriteBytes(w, extraData)
3✔
131
}
132

133
// MsgType returns the integer uniquely identifying this message type on the
134
// wire.
135
//
136
// This is part of the lnwire.Message interface.
137
func (s *Shutdown) MsgType() MessageType {
3✔
138
        return MsgShutdown
3✔
139
}
3✔
140

141
// SerializedSize returns the serialized size of the message in bytes.
142
//
143
// This is part of the lnwire.SizeableMessage interface.
UNCOV
144
func (s *Shutdown) SerializedSize() (uint32, error) {
×
UNCOV
145
        return MessageSerializedSize(s)
×
UNCOV
146
}
×
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