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

lightningnetwork / lnd / 13982721865

21 Mar 2025 01:30AM UTC coverage: 58.587% (-0.5%) from 59.126%
13982721865

Pull #9623

github

web-flow
Merge 05a6b6838 into 5d921723b
Pull Request #9623: Size msg test msg

0 of 1572 new or added lines in 43 files covered. (0.0%)

17 existing lines in 5 files now uncovered.

96767 of 165169 relevant lines covered (58.59%)

1.82 hits per line

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

60.29
/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 {
3✔
61
        err := ReadElements(
3✔
62
                r, q.ChainHash[:], &q.FirstBlockHeight, &q.NumBlocks,
3✔
63
        )
3✔
64
        if err != nil {
3✔
65
                return err
×
66
        }
×
67

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

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

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

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

88
        return nil
3✔
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 {
3✔
96
        if err := WriteBytes(w, q.ChainHash[:]); err != nil {
3✔
97
                return err
×
98
        }
×
99

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

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

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

117
        return WriteBytes(w, q.ExtraData)
3✔
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 {
3✔
125
        return MsgQueryChannelRange
3✔
126
}
3✔
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 {
3✔
139
        // Handle overflows by casting to uint64.
3✔
140
        lastBlockHeight := uint64(q.FirstBlockHeight) + uint64(q.NumBlocks) - 1
3✔
141
        if lastBlockHeight > math.MaxUint32 {
3✔
142
                return math.MaxUint32
×
143
        }
×
144
        return uint32(lastBlockHeight)
3✔
145
}
146

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

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

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