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

lightningnetwork / lnd / 19155841408

07 Nov 2025 02:03AM UTC coverage: 66.675% (-0.04%) from 66.712%
19155841408

Pull #10352

github

web-flow
Merge e4313eba8 into 096ab65b1
Pull Request #10352: [WIP] chainrpc: return Unavailable while notifier starts

137328 of 205965 relevant lines covered (66.68%)

21333.36 hits per line

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

80.0
/lnwire/init_message.go
1
package lnwire
2

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

8
// Init is the first message reveals the features supported or required by this
9
// node. Nodes wait for receipt of the other's features to simplify error
10
// diagnosis where features are incompatible. Each node MUST wait to receive
11
// init before sending any other messages.
12
type Init struct {
13
        // GlobalFeatures is a legacy feature vector used for backwards
14
        // compatibility with older nodes. Any features defined here should be
15
        // merged with those presented in Features.
16
        GlobalFeatures *RawFeatureVector
17

18
        // Features is a feature vector containing the features supported by
19
        // the remote node.
20
        //
21
        // NOTE: Older nodes may place some features in GlobalFeatures, but all
22
        // new features are to be added in Features. When handling an Init
23
        // message, any GlobalFeatures should be merged into the unified
24
        // Features field.
25
        Features *RawFeatureVector
26

27
        // CustomRecords maps TLV types to byte slices, storing arbitrary data
28
        // intended for inclusion in the ExtraData field of the init message.
29
        CustomRecords CustomRecords
30

31
        // ExtraData is the set of data that was appended to this message to
32
        // fill out the full maximum transport message size. These fields can
33
        // be used to specify optional data such as custom TLV fields.
34
        ExtraData ExtraOpaqueData
35
}
36

37
// NewInitMessage creates new instance of init message object.
38
func NewInitMessage(gf *RawFeatureVector, f *RawFeatureVector) *Init {
113✔
39
        return &Init{
113✔
40
                GlobalFeatures: gf,
113✔
41
                Features:       f,
113✔
42
        }
113✔
43
}
113✔
44

45
// A compile time check to ensure Init implements the lnwire.Message
46
// interface.
47
var _ Message = (*Init)(nil)
48

49
// A compile time check to ensure Init implements the lnwire.SizeableMessage
50
// interface.
51
var _ SizeableMessage = (*Init)(nil)
52

53
// Decode deserializes a serialized Init message stored in the passed
54
// io.Reader observing the specified protocol version.
55
//
56
// This is part of the lnwire.Message interface.
57
func (msg *Init) Decode(r io.Reader, pver uint32) error {
165✔
58
        var msgExtraData ExtraOpaqueData
165✔
59

165✔
60
        err := ReadElements(r,
165✔
61
                &msg.GlobalFeatures,
165✔
62
                &msg.Features,
165✔
63
                &msgExtraData,
165✔
64
        )
165✔
65
        if err != nil {
179✔
66
                return err
14✔
67
        }
14✔
68

69
        customRecords, _, extraDData, err := ParseAndExtractCustomRecords(
151✔
70
                msgExtraData,
151✔
71
        )
151✔
72
        if err != nil {
170✔
73
                return err
19✔
74
        }
19✔
75

76
        msg.CustomRecords = customRecords
132✔
77
        msg.ExtraData = extraDData
132✔
78

132✔
79
        return nil
132✔
80
}
81

82
// Encode serializes the target Init into the passed io.Writer observing
83
// the protocol version specified.
84
//
85
// This is part of the lnwire.Message interface.
86
func (msg *Init) Encode(w *bytes.Buffer, pver uint32) error {
129✔
87
        if err := WriteRawFeatureVector(w, msg.GlobalFeatures); err != nil {
129✔
88
                return err
×
89
        }
×
90

91
        if err := WriteRawFeatureVector(w, msg.Features); err != nil {
129✔
92
                return err
×
93
        }
×
94

95
        extraData, err := MergeAndEncode(nil, msg.ExtraData, msg.CustomRecords)
129✔
96
        if err != nil {
129✔
97
                return err
×
98
        }
×
99

100
        return WriteBytes(w, extraData)
129✔
101
}
102

103
// MsgType returns the integer uniquely identifying this message type on the
104
// wire.
105
//
106
// This is part of the lnwire.Message interface.
107
func (msg *Init) MsgType() MessageType {
128✔
108
        return MsgInit
128✔
109
}
128✔
110

111
// SerializedSize returns the serialized size of the message in bytes.
112
//
113
// This is part of the lnwire.SizeableMessage interface.
114
func (msg *Init) SerializedSize() (uint32, error) {
×
115
        return MessageSerializedSize(msg)
×
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