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

lightningnetwork / lnd / 13593508312

28 Feb 2025 05:41PM UTC coverage: 58.287% (-10.4%) from 68.65%
13593508312

Pull #9458

github

web-flow
Merge d40067c0c into f1182e433
Pull Request #9458: multi+server.go: add initial permissions for some peers

346 of 548 new or added lines in 10 files covered. (63.14%)

27412 existing lines in 442 files now uncovered.

94709 of 162488 relevant lines covered (58.29%)

1.81 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 {
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
// 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 {
3✔
69
        err := ReadElements(r, &s.ChannelID, &s.Address)
3✔
70
        if err != nil {
3✔
UNCOV
71
                return err
×
UNCOV
72
        }
×
73

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

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

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

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

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

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

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

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

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

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