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

lightningnetwork / lnd / 11170835610

03 Oct 2024 10:41PM UTC coverage: 49.188% (-9.6%) from 58.738%
11170835610

push

github

web-flow
Merge pull request #9154 from ziggie1984/master

multi: bump btcd version.

3 of 6 new or added lines in 6 files covered. (50.0%)

26110 existing lines in 428 files now uncovered.

97359 of 197934 relevant lines covered (49.19%)

1.04 hits per line

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

78.18
/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 {
2✔
20
        return tlv.SomeRecordT(
2✔
21
                tlv.NewRecordT[ShutdownNonceType, Musig2Nonce](nonce),
2✔
22
        )
2✔
23
}
2✔
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 {
2✔
54
        return &Shutdown{
2✔
55
                ChannelID: cid,
2✔
56
                Address:   addr,
2✔
57
        }
2✔
58
}
2✔
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 {
2✔
69
        err := ReadElements(r, &s.ChannelID, &s.Address)
2✔
70
        if err != nil {
2✔
UNCOV
71
                return err
×
UNCOV
72
        }
×
73

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

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

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

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

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

2✔
97
        return nil
2✔
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 {
2✔
105
        if err := WriteChannelID(w, s.ChannelID); err != nil {
2✔
106
                return err
×
107
        }
×
108

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

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

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

126
        return WriteBytes(w, extraData)
2✔
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 {
2✔
134
        return MsgShutdown
2✔
135
}
2✔
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