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

lightningnetwork / lnd / 13999301927

21 Mar 2025 07:18PM UTC coverage: 68.989% (+9.9%) from 59.126%
13999301927

push

github

web-flow
Merge pull request #9623 from Roasbeef/size-msg-test-msg

Size msg test msg

1461 of 1572 new or added lines in 43 files covered. (92.94%)

28 existing lines in 6 files now uncovered.

132898 of 192637 relevant lines covered (68.99%)

22200.59 hits per line

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

72.06
/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
)
11

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

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

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

31
        // QueryOptions is an optional feature bit vector that can be used to
32
        // specify additional query options.
33
        QueryOptions *QueryOptions
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
// NewQueryChannelRange creates a new empty QueryChannelRange message.
42
func NewQueryChannelRange() *QueryChannelRange {
×
43
        return &QueryChannelRange{
×
44
                ExtraData: make([]byte, 0),
×
45
        }
×
46
}
×
47

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

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

56
// Decode deserializes a serialized QueryChannelRange message stored in the
57
// passed io.Reader observing the specified protocol version.
58
//
59
// This is part of the lnwire.Message interface.
60
func (q *QueryChannelRange) Decode(r io.Reader, _ uint32) error {
202✔
61
        err := ReadElements(
202✔
62
                r, q.ChainHash[:], &q.FirstBlockHeight, &q.NumBlocks,
202✔
63
        )
202✔
64
        if err != nil {
207✔
65
                return err
5✔
66
        }
5✔
67

68
        var tlvRecords ExtraOpaqueData
197✔
69
        if err := ReadElements(r, &tlvRecords); err != nil {
197✔
70
                return err
×
71
        }
×
72

73
        var queryOptions QueryOptions
197✔
74
        typeMap, err := tlvRecords.ExtractRecords(&queryOptions)
197✔
75
        if err != nil {
243✔
76
                return err
46✔
77
        }
46✔
78

79
        // Set the corresponding TLV types if they were included in the stream.
80
        if val, ok := typeMap[QueryOptionsRecordType]; ok && val == nil {
246✔
81
                q.QueryOptions = &queryOptions
95✔
82
        }
95✔
83

84
        if len(tlvRecords) != 0 {
249✔
85
                q.ExtraData = tlvRecords
98✔
86
        }
98✔
87

88
        return nil
151✔
89
}
90

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

100
        if err := WriteUint32(w, q.FirstBlockHeight); err != nil {
128✔
101
                return err
×
102
        }
×
103

104
        if err := WriteUint32(w, q.NumBlocks); err != nil {
128✔
105
                return err
×
106
        }
×
107

108
        recordProducers := make([]tlv.RecordProducer, 0, 1)
128✔
109
        if q.QueryOptions != nil {
204✔
110
                recordProducers = append(recordProducers, q.QueryOptions)
76✔
111
        }
76✔
112
        err := EncodeMessageExtraData(&q.ExtraData, recordProducers...)
128✔
113
        if err != nil {
128✔
114
                return err
×
115
        }
×
116

117
        return WriteBytes(w, q.ExtraData)
128✔
118
}
119

120
// MsgType returns the integer uniquely identifying this message type on the
121
// wire.
122
//
123
// This is part of the lnwire.Message interface.
124
func (q *QueryChannelRange) MsgType() MessageType {
128✔
125
        return MsgQueryChannelRange
128✔
126
}
128✔
127

128
// SerializedSize returns the serialized size of the message in bytes.
129
//
130
// This is part of the lnwire.SizeableMessage interface.
NEW
131
func (q *QueryChannelRange) SerializedSize() (uint32, error) {
×
NEW
132
        msgCpy := *q
×
NEW
133
        return MessageSerializedSize(&msgCpy)
×
NEW
134
}
×
135

136
// LastBlockHeight returns the last block height covered by the range of a
137
// QueryChannelRange message.
138
func (q *QueryChannelRange) LastBlockHeight() uint32 {
264✔
139
        // Handle overflows by casting to uint64.
264✔
140
        lastBlockHeight := uint64(q.FirstBlockHeight) + uint64(q.NumBlocks) - 1
264✔
141
        if lastBlockHeight > math.MaxUint32 {
266✔
142
                return math.MaxUint32
2✔
143
        }
2✔
144
        return uint32(lastBlockHeight)
262✔
145
}
146

147
// WithTimestamps returns true if the query has asked for timestamps too.
148
func (q *QueryChannelRange) WithTimestamps() bool {
14✔
149
        if q.QueryOptions == nil {
24✔
150
                return false
10✔
151
        }
10✔
152

153
        queryOpts := RawFeatureVector(*q.QueryOptions)
4✔
154

4✔
155
        return queryOpts.IsSet(QueryOptionTimestampBit)
4✔
156
}
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