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

lightningnetwork / lnd / 13980275562

20 Mar 2025 10:06PM UTC coverage: 58.6% (-10.2%) from 68.789%
13980275562

Pull #9623

github

web-flow
Merge b9b960345 into 09b674508
Pull Request #9623: Size msg test msg

0 of 1518 new or added lines in 42 files covered. (0.0%)

26603 existing lines in 443 files now uncovered.

96807 of 165200 relevant lines covered (58.6%)

1.82 hits per line

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

44.57
/lnwire/query_channel_range.go
1
package lnwire
2

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

8
        "github.com/btcsuite/btcd/chaincfg/chainhash"
9
        "github.com/lightningnetwork/lnd/tlv"
10
        "pgregory.net/rapid"
11
)
12

13
// QueryChannelRange is a message sent by a node in order to query the
14
// receiving node of the set of open channel they know of with short channel
15
// ID's after the specified block height, capped at the number of blocks beyond
16
// that block height. This will be used by nodes upon initial connect to
17
// synchronize their views of the network.
18
type QueryChannelRange struct {
19
        // ChainHash denotes the target chain that we're trying to synchronize
20
        // channel graph state for.
21
        ChainHash chainhash.Hash
22

23
        // FirstBlockHeight is the first block in the query range. The
24
        // responder should send all new short channel IDs from this block
25
        // until this block plus the specified number of blocks.
26
        FirstBlockHeight uint32
27

28
        // NumBlocks is the number of blocks beyond the first block that short
29
        // channel ID's should be sent for.
30
        NumBlocks uint32
31

32
        // QueryOptions is an optional feature bit vector that can be used to
33
        // specify additional query options.
34
        QueryOptions *QueryOptions
35

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

42
// NewQueryChannelRange creates a new empty QueryChannelRange message.
43
func NewQueryChannelRange() *QueryChannelRange {
×
44
        return &QueryChannelRange{
×
45
                ExtraData: make([]byte, 0),
×
46
        }
×
47
}
×
48

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

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

57
// A compile time check to ensure QueryChannelRange implements the lnwire.TestMessage
58
// interface.
59
var _ TestMessage = (*QueryChannelRange)(nil)
60

61
// Decode deserializes a serialized QueryChannelRange message stored in the
62
// passed io.Reader observing the specified protocol version.
63
//
64
// This is part of the lnwire.Message interface.
65
func (q *QueryChannelRange) Decode(r io.Reader, _ uint32) error {
3✔
66
        err := ReadElements(
3✔
67
                r, q.ChainHash[:], &q.FirstBlockHeight, &q.NumBlocks,
3✔
68
        )
3✔
69
        if err != nil {
3✔
UNCOV
70
                return err
×
UNCOV
71
        }
×
72

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

78
        var queryOptions QueryOptions
3✔
79
        typeMap, err := tlvRecords.ExtractRecords(&queryOptions)
3✔
80
        if err != nil {
3✔
UNCOV
81
                return err
×
UNCOV
82
        }
×
83

84
        // Set the corresponding TLV types if they were included in the stream.
85
        if val, ok := typeMap[QueryOptionsRecordType]; ok && val == nil {
6✔
86
                q.QueryOptions = &queryOptions
3✔
87
        }
3✔
88

89
        if len(tlvRecords) != 0 {
6✔
90
                q.ExtraData = tlvRecords
3✔
91
        }
3✔
92

93
        return nil
3✔
94
}
95

96
// Encode serializes the target QueryChannelRange into the passed io.Writer
97
// observing the protocol version specified.
98
//
99
// This is part of the lnwire.Message interface.
100
func (q *QueryChannelRange) Encode(w *bytes.Buffer, _ uint32) error {
3✔
101
        if err := WriteBytes(w, q.ChainHash[:]); err != nil {
3✔
102
                return err
×
103
        }
×
104

105
        if err := WriteUint32(w, q.FirstBlockHeight); err != nil {
3✔
106
                return err
×
107
        }
×
108

109
        if err := WriteUint32(w, q.NumBlocks); err != nil {
3✔
110
                return err
×
111
        }
×
112

113
        recordProducers := make([]tlv.RecordProducer, 0, 1)
3✔
114
        if q.QueryOptions != nil {
6✔
115
                recordProducers = append(recordProducers, q.QueryOptions)
3✔
116
        }
3✔
117
        err := EncodeMessageExtraData(&q.ExtraData, recordProducers...)
3✔
118
        if err != nil {
3✔
119
                return err
×
120
        }
×
121

122
        return WriteBytes(w, q.ExtraData)
3✔
123
}
124

125
// MsgType returns the integer uniquely identifying this message type on the
126
// wire.
127
//
128
// This is part of the lnwire.Message interface.
129
func (q *QueryChannelRange) MsgType() MessageType {
3✔
130
        return MsgQueryChannelRange
3✔
131
}
3✔
132

133
// SerializedSize returns the serialized size of the message in bytes.
134
//
135
// This is part of the lnwire.SizeableMessage interface.
NEW
136
func (q *QueryChannelRange) SerializedSize() (uint32, error) {
×
NEW
137
        msgCpy := *q
×
NEW
138
        return MessageSerializedSize(&msgCpy)
×
NEW
139
}
×
140

141
// LastBlockHeight returns the last block height covered by the range of a
142
// QueryChannelRange message.
143
func (q *QueryChannelRange) LastBlockHeight() uint32 {
3✔
144
        // Handle overflows by casting to uint64.
3✔
145
        lastBlockHeight := uint64(q.FirstBlockHeight) + uint64(q.NumBlocks) - 1
3✔
146
        if lastBlockHeight > math.MaxUint32 {
3✔
UNCOV
147
                return math.MaxUint32
×
UNCOV
148
        }
×
149
        return uint32(lastBlockHeight)
3✔
150
}
151

152
// WithTimestamps returns true if the query has asked for timestamps too.
153
func (q *QueryChannelRange) WithTimestamps() bool {
3✔
154
        if q.QueryOptions == nil {
3✔
UNCOV
155
                return false
×
UNCOV
156
        }
×
157

158
        queryOpts := RawFeatureVector(*q.QueryOptions)
3✔
159

3✔
160
        return queryOpts.IsSet(QueryOptionTimestampBit)
3✔
161
}
162

163
// RandTestMessage populates the message with random data suitable for testing.
164
// It uses the rapid testing framework to generate random values.
165
//
166
// This is part of the TestMessage interface.
NEW
167
func (q *QueryChannelRange) RandTestMessage(t *rapid.T) Message {
×
NEW
168
        msg := &QueryChannelRange{
×
NEW
169
                FirstBlockHeight: uint32(rapid.IntRange(0, 1000000).Draw(
×
NEW
170
                        t, "firstBlockHeight"),
×
NEW
171
                ),
×
NEW
172
                NumBlocks: uint32(rapid.IntRange(1, 10000).Draw(
×
NEW
173
                        t, "numBlocks"),
×
NEW
174
                ),
×
NEW
175
                ExtraData: RandExtraOpaqueData(t, nil),
×
NEW
176
        }
×
NEW
177

×
NEW
178
        // Generate chain hash
×
NEW
179
        chainHash := RandChainHash(t)
×
NEW
180
        var chainHashObj chainhash.Hash
×
NEW
181
        copy(chainHashObj[:], chainHash[:])
×
NEW
182
        msg.ChainHash = chainHashObj
×
NEW
183

×
NEW
184
        // Randomly include QueryOptions
×
NEW
185
        if rapid.Bool().Draw(t, "includeQueryOptions") {
×
NEW
186
                queryOptions := &QueryOptions{}
×
NEW
187
                *queryOptions = QueryOptions(*RandFeatureVector(t))
×
NEW
188
                msg.QueryOptions = queryOptions
×
NEW
189
        }
×
190

NEW
191
        return msg
×
192
}
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