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

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

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

57.81
/lnwire/gossip_timestamp_range.go
1
package lnwire
2

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

7
        "github.com/btcsuite/btcd/chaincfg/chainhash"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
// GossipTimestampRange is a message that allows the sender to restrict the set
12
// of future gossip announcements sent by the receiver. Nodes should send this
13
// if they have the gossip-queries feature bit active. Nodes are able to send
14
// new GossipTimestampRange messages to replace the prior window.
15
type GossipTimestampRange struct {
16
        // ChainHash denotes the chain that the sender wishes to restrict the
17
        // set of received announcements of.
18
        ChainHash chainhash.Hash
19

20
        // FirstTimestamp is the timestamp of the earliest announcement message
21
        // that should be sent by the receiver. This is only to be used for
22
        // querying message of gossip 1.0 which are timestamped using Unix
23
        // timestamps. FirstBlockHeight and BlockRange should be used to
24
        // query for announcement messages timestamped using block heights.
25
        FirstTimestamp uint32
26

27
        // TimestampRange is the horizon beyond the FirstTimestamp that any
28
        // announcement messages should be sent for. The receiving node MUST
29
        // NOT send any announcements that have a timestamp greater than
30
        // FirstTimestamp + TimestampRange. This is used together with
31
        // FirstTimestamp to query for gossip 1.0 messages timestamped with
32
        // Unix timestamps.
33
        TimestampRange uint32
34

35
        // FirstBlockHeight is the height of earliest announcement message that
36
        // should be sent by the receiver. This is used only for querying
37
        // announcement messages that use block heights as a timestamp.
38
        FirstBlockHeight tlv.OptionalRecordT[tlv.TlvType2, uint32]
39

40
        // BlockRange is the horizon beyond FirstBlockHeight that any
41
        // announcement messages should be sent for. The receiving node MUST NOT
42
        // send any announcements that have a timestamp greater than
43
        // FirstBlockHeight + BlockRange.
44
        BlockRange tlv.OptionalRecordT[tlv.TlvType4, uint32]
45

46
        // ExtraData is the set of data that was appended to this message to
47
        // fill out the full maximum transport message size. These fields can
48
        // be used to specify optional data such as custom TLV fields.
49
        ExtraData ExtraOpaqueData
50
}
51

52
// NewGossipTimestampRange creates a new empty GossipTimestampRange message.
53
func NewGossipTimestampRange() *GossipTimestampRange {
×
54
        return &GossipTimestampRange{}
×
55
}
×
56

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

61
// A compile time check to ensure GossipTimestampRange implements the
62
// lnwire.SizeableMessage interface.
63
var _ SizeableMessage = (*GossipTimestampRange)(nil)
64

65
// Decode deserializes a serialized GossipTimestampRange message stored in the
66
// passed io.Reader observing the specified protocol version.
67
//
68
// This is part of the lnwire.Message interface.
69
func (g *GossipTimestampRange) Decode(r io.Reader, _ uint32) error {
3✔
70
        err := ReadElements(r,
3✔
71
                g.ChainHash[:],
3✔
72
                &g.FirstTimestamp,
3✔
73
                &g.TimestampRange,
3✔
74
        )
3✔
75
        if err != nil {
3✔
UNCOV
76
                return err
×
UNCOV
77
        }
×
78

79
        var tlvRecords ExtraOpaqueData
3✔
80
        if err := ReadElements(r, &tlvRecords); err != nil {
3✔
81
                return err
×
82
        }
×
83

84
        var (
3✔
85
                firstBlock = tlv.ZeroRecordT[tlv.TlvType2, uint32]()
3✔
86
                blockRange = tlv.ZeroRecordT[tlv.TlvType4, uint32]()
3✔
87
        )
3✔
88
        typeMap, err := tlvRecords.ExtractRecords(&firstBlock, &blockRange)
3✔
89
        if err != nil {
3✔
UNCOV
90
                return err
×
UNCOV
91
        }
×
92

93
        if val, ok := typeMap[g.FirstBlockHeight.TlvType()]; ok && val == nil {
3✔
UNCOV
94
                g.FirstBlockHeight = tlv.SomeRecordT(firstBlock)
×
UNCOV
95
        }
×
96
        if val, ok := typeMap[g.BlockRange.TlvType()]; ok && val == nil {
3✔
UNCOV
97
                g.BlockRange = tlv.SomeRecordT(blockRange)
×
UNCOV
98
        }
×
99

100
        if len(tlvRecords) != 0 {
3✔
UNCOV
101
                g.ExtraData = tlvRecords
×
UNCOV
102
        }
×
103

104
        return nil
3✔
105
}
106

107
// Encode serializes the target GossipTimestampRange into the passed io.Writer
108
// observing the protocol version specified.
109
//
110
// This is part of the lnwire.Message interface.
111
func (g *GossipTimestampRange) Encode(w *bytes.Buffer, pver uint32) error {
3✔
112
        if err := WriteBytes(w, g.ChainHash[:]); err != nil {
3✔
113
                return err
×
114
        }
×
115

116
        if err := WriteUint32(w, g.FirstTimestamp); err != nil {
3✔
117
                return err
×
118
        }
×
119

120
        if err := WriteUint32(w, g.TimestampRange); err != nil {
3✔
121
                return err
×
122
        }
×
123

124
        recordProducers := make([]tlv.RecordProducer, 0, 2)
3✔
125
        g.FirstBlockHeight.WhenSome(
3✔
126
                func(height tlv.RecordT[tlv.TlvType2, uint32]) {
3✔
UNCOV
127
                        recordProducers = append(recordProducers, &height)
×
UNCOV
128
                },
×
129
        )
130
        g.BlockRange.WhenSome(
3✔
131
                func(blockRange tlv.RecordT[tlv.TlvType4, uint32]) {
3✔
UNCOV
132
                        recordProducers = append(recordProducers, &blockRange)
×
UNCOV
133
                },
×
134
        )
135
        err := EncodeMessageExtraData(&g.ExtraData, recordProducers...)
3✔
136
        if err != nil {
3✔
137
                return err
×
138
        }
×
139

140
        return WriteBytes(w, g.ExtraData)
3✔
141
}
142

143
// MsgType returns the integer uniquely identifying this message type on the
144
// wire.
145
//
146
// This is part of the lnwire.Message interface.
147
func (g *GossipTimestampRange) MsgType() MessageType {
3✔
148
        return MsgGossipTimestampRange
3✔
149
}
3✔
150

151
// SerializedSize returns the serialized size of the message in bytes.
152
//
153
// This is part of the lnwire.SizeableMessage interface.
154
func (g *GossipTimestampRange) SerializedSize() (uint32, error) {
3✔
155
        return MessageSerializedSize(g)
3✔
156
}
3✔
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