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

lightningnetwork / lnd / 17373151115

01 Sep 2025 09:13AM UTC coverage: 66.657% (-0.02%) from 66.678%
17373151115

Pull #10182

github

web-flow
Merge 48f9e78c3 into cd6971ea1
Pull Request #10182: Aux feature bits

45 of 108 new or added lines in 4 files covered. (41.67%)

83 existing lines in 16 files now uncovered.

136034 of 204080 relevant lines covered (66.66%)

21495.48 hits per line

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

67.27
/lnwire/init_message.go
1
package lnwire
2

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

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

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

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

30
        // AuxFeatures is an optional field that stores auxiliary feature bits
31
        // for custom channel negotiation. This is used by aux channel
32
        // implementations to negotiate custom channel behavior.
33
        AuxFeatures fn.Option[AuxFeatureBits]
34

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

41
// NewInitMessage creates new instance of init message object.
42
func NewInitMessage(gf *RawFeatureVector, f *RawFeatureVector) *Init {
113✔
43
        return &Init{
113✔
44
                GlobalFeatures: gf,
113✔
45
                Features:       f,
113✔
46
                ExtraData:      make([]byte, 0),
113✔
47
        }
113✔
48
}
113✔
49

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

54
// A compile time check to ensure Init implements the lnwire.SizeableMessage
55
// interface.
56
var _ SizeableMessage = (*Init)(nil)
57

58
// Decode deserializes a serialized Init message stored in the passed
59
// io.Reader observing the specified protocol version.
60
//
61
// This is part of the lnwire.Message interface.
62
func (msg *Init) Decode(r io.Reader, pver uint32) error {
164✔
63
        err := ReadElements(r,
164✔
64
                &msg.GlobalFeatures,
164✔
65
                &msg.Features,
164✔
66
                &msg.ExtraData,
164✔
67
        )
164✔
68
        if err != nil {
178✔
69
                return err
14✔
70
        }
14✔
71

72
        // Extract any TLV records from the extra data.
73
        var auxFeatures AuxFeatureBits
150✔
74
        auxFeaturesRecord := tlv.MakePrimitiveRecord(
150✔
75
                AuxFeatureBitsTLV, &auxFeatures,
150✔
76
        )
150✔
77

150✔
78
        typeMap, err := msg.ExtraData.ExtractRecords(&auxFeaturesRecord)
150✔
79
        if err != nil {
169✔
80
                return err
19✔
81
        }
19✔
82

83
        // If the aux features TLV was present, set it in the message.
84
        if val, ok := typeMap[AuxFeatureBitsTLV]; ok && val == nil {
131✔
NEW
85
                msg.AuxFeatures = fn.Some(auxFeatures)
×
NEW
86
        }
×
87

88
        return nil
131✔
89
}
90

91
// Encode serializes the target Init into the passed io.Writer observing
92
// the protocol version specified.
93
//
94
// This is part of the lnwire.Message interface.
95
func (msg *Init) Encode(w *bytes.Buffer, pver uint32) error {
128✔
96
        if err := WriteRawFeatureVector(w, msg.GlobalFeatures); err != nil {
128✔
97
                return err
×
98
        }
×
99

100
        if err := WriteRawFeatureVector(w, msg.Features); err != nil {
128✔
101
                return err
×
102
        }
×
103

104
        // If we have aux features, encode them into the extra data.
105
        recordProducers := make([]tlv.RecordProducer, 0, 1)
128✔
106
        msg.AuxFeatures.WhenSome(func(features AuxFeatureBits) {
128✔
NEW
107
                record := tlv.MakePrimitiveRecord(AuxFeatureBitsTLV, &features)
×
NEW
108
                recordProducers = append(recordProducers, &record)
×
NEW
109
        })
×
110

111
        if len(recordProducers) > 0 {
128✔
NEW
112
                err := EncodeMessageExtraData(
×
NEW
113
                        &msg.ExtraData, recordProducers...,
×
NEW
114
                )
×
NEW
115
                if err != nil {
×
NEW
116
                        return err
×
NEW
117
                }
×
118
        }
119

120
        return WriteBytes(w, msg.ExtraData)
128✔
121
}
122

123
// MsgType returns the integer uniquely identifying this message type on the
124
// wire.
125
//
126
// This is part of the lnwire.Message interface.
127
func (msg *Init) MsgType() MessageType {
128✔
128
        return MsgInit
128✔
129
}
128✔
130

131
// SerializedSize returns the serialized size of the message in bytes.
132
//
133
// This is part of the lnwire.SizeableMessage interface.
UNCOV
134
func (msg *Init) SerializedSize() (uint32, error) {
×
UNCOV
135
        return MessageSerializedSize(msg)
×
UNCOV
136
}
×
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