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

lightningnetwork / lnd / 13586005509

28 Feb 2025 10:14AM UTC coverage: 68.629% (+9.9%) from 58.77%
13586005509

Pull #9521

github

web-flow
Merge 37d3a70a5 into 8532955b3
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

129950 of 189351 relevant lines covered (68.63%)

23726.46 hits per line

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

85.45
/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 {
6✔
20
        return tlv.SomeRecordT(
6✔
21
                tlv.NewRecordT[ShutdownNonceType, Musig2Nonce](nonce),
6✔
22
        )
6✔
23
}
6✔
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 {
19✔
54
        return &Shutdown{
19✔
55
                ChannelID: cid,
19✔
56
                Address:   addr,
19✔
57
        }
19✔
58
}
19✔
59

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

64
// Decode deserializes a serialized Shutdown from the passed io.Reader,
65
// observing the specified protocol version.
66
//
67
// This is part of the lnwire.Message interface.
68
func (s *Shutdown) Decode(r io.Reader, pver uint32) error {
190✔
69
        err := ReadElements(r, &s.ChannelID, &s.Address)
190✔
70
        if err != nil {
199✔
71
                return err
9✔
72
        }
9✔
73

74
        var tlvRecords ExtraOpaqueData
181✔
75
        if err := ReadElements(r, &tlvRecords); err != nil {
181✔
76
                return err
×
77
        }
×
78

79
        // Extract TLV records from the extra data field.
80
        musigNonce := s.ShutdownNonce.Zero()
181✔
81

181✔
82
        customRecords, parsed, extraData, err := ParseAndExtractCustomRecords(
181✔
83
                tlvRecords, &musigNonce,
181✔
84
        )
181✔
85
        if err != nil {
231✔
86
                return err
50✔
87
        }
50✔
88

89
        // Assign the parsed records back to the message.
90
        if _, ok := parsed[musigNonce.TlvType()]; ok {
178✔
91
                s.ShutdownNonce = tlv.SomeRecordT(musigNonce)
47✔
92
        }
47✔
93

94
        s.CustomRecords = customRecords
131✔
95
        s.ExtraData = extraData
131✔
96

131✔
97
        return nil
131✔
98
}
99

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

109
        if err := WriteDeliveryAddress(w, s.Address); err != nil {
118✔
110
                return err
×
111
        }
×
112

113
        // Only include nonce in extra data if present.
114
        var records []tlv.RecordProducer
118✔
115
        s.ShutdownNonce.WhenSome(
118✔
116
                func(nonce tlv.RecordT[ShutdownNonceType, Musig2Nonce]) {
163✔
117
                        records = append(records, &nonce)
45✔
118
                },
45✔
119
        )
120

121
        extraData, err := MergeAndEncode(records, s.ExtraData, s.CustomRecords)
118✔
122
        if err != nil {
118✔
123
                return err
×
124
        }
×
125

126
        return WriteBytes(w, extraData)
118✔
127
}
128

129
// MsgType returns the integer uniquely identifying this message type on the
130
// wire.
131
//
132
// This is part of the lnwire.Message interface.
133
func (s *Shutdown) MsgType() MessageType {
116✔
134
        return MsgShutdown
116✔
135
}
116✔
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