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

lightningnetwork / lnd / 13523316608

25 Feb 2025 02:12PM UTC coverage: 49.351% (-9.5%) from 58.835%
13523316608

Pull #9549

github

yyforyongyu
routing/chainview: refactor `TestFilteredChainView`

So each test has its own miner and chainView.
Pull Request #9549: Fix unit test flake `TestHistoricalConfDetailsTxIndex`

0 of 120 new or added lines in 1 file covered. (0.0%)

27196 existing lines in 434 files now uncovered.

100945 of 204543 relevant lines covered (49.35%)

1.54 hits per line

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

0.0
/channeldb/migration/lnwire21/channel_update.go
1
package lnwire
2

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

8
        "github.com/btcsuite/btcd/chaincfg/chainhash"
9
)
10

11
// ChanUpdateMsgFlags is a bitfield that signals whether optional fields are
12
// present in the ChannelUpdate.
13
type ChanUpdateMsgFlags uint8
14

15
const (
16
        // ChanUpdateRequiredMaxHtlc is a bit that indicates whether the
17
        // optional htlc_maximum_msat field is present in this ChannelUpdate.
18
        ChanUpdateRequiredMaxHtlc ChanUpdateMsgFlags = 1 << iota
19
)
20

21
// String returns the bitfield flags as a string.
22
func (c ChanUpdateMsgFlags) String() string {
×
23
        return fmt.Sprintf("%08b", c)
×
24
}
×
25

26
// HasMaxHtlc returns true if the htlc_maximum_msat option bit is set in the
27
// message flags.
UNCOV
28
func (c ChanUpdateMsgFlags) HasMaxHtlc() bool {
×
UNCOV
29
        return c&ChanUpdateRequiredMaxHtlc != 0
×
UNCOV
30
}
×
31

32
// ChanUpdateChanFlags is a bitfield that signals various options concerning a
33
// particular channel edge. Each bit is to be examined in order to determine
34
// how the ChannelUpdate message is to be interpreted.
35
type ChanUpdateChanFlags uint8
36

37
const (
38
        // ChanUpdateDirection indicates the direction of a channel update. If
39
        // this bit is set to 0 if Node1 (the node with the "smaller" Node ID)
40
        // is updating the channel, and to 1 otherwise.
41
        ChanUpdateDirection ChanUpdateChanFlags = 1 << iota
42

43
        // ChanUpdateDisabled is a bit that indicates if the channel edge
44
        // selected by the ChanUpdateDirection bit is to be treated as being
45
        // disabled.
46
        ChanUpdateDisabled
47
)
48

49
// IsDisabled determines whether the channel flags has the disabled bit set.
50
func (c ChanUpdateChanFlags) IsDisabled() bool {
×
51
        return c&ChanUpdateDisabled == ChanUpdateDisabled
×
52
}
×
53

54
// String returns the bitfield flags as a string.
55
func (c ChanUpdateChanFlags) String() string {
×
56
        return fmt.Sprintf("%08b", c)
×
57
}
×
58

59
// ChannelUpdate message is used after channel has been initially announced.
60
// Each side independently announces its fees and minimum expiry for HTLCs and
61
// other parameters. Also this message is used to redeclare initially set
62
// channel parameters.
63
type ChannelUpdate struct {
64
        // Signature is used to validate the announced data and prove the
65
        // ownership of node id.
66
        Signature Sig
67

68
        // ChainHash denotes the target chain that this channel was opened
69
        // within. This value should be the genesis hash of the target chain.
70
        // Along with the short channel ID, this uniquely identifies the
71
        // channel globally in a blockchain.
72
        ChainHash chainhash.Hash
73

74
        // ShortChannelID is the unique description of the funding transaction.
75
        ShortChannelID ShortChannelID
76

77
        // Timestamp allows ordering in the case of multiple announcements. We
78
        // should ignore the message if timestamp is not greater than
79
        // the last-received.
80
        Timestamp uint32
81

82
        // MessageFlags is a bitfield that describes whether optional fields
83
        // are present in this update. Currently, the least-significant bit
84
        // must be set to 1 if the optional field MaxHtlc is present.
85
        MessageFlags ChanUpdateMsgFlags
86

87
        // ChannelFlags is a bitfield that describes additional meta-data
88
        // concerning how the update is to be interpreted. Currently, the
89
        // least-significant bit must be set to 0 if the creating node
90
        // corresponds to the first node in the previously sent channel
91
        // announcement and 1 otherwise. If the second bit is set, then the
92
        // channel is set to be disabled.
93
        ChannelFlags ChanUpdateChanFlags
94

95
        // TimeLockDelta is the minimum number of blocks this node requires to
96
        // be added to the expiry of HTLCs. This is a security parameter
97
        // determined by the node operator. This value represents the required
98
        // gap between the time locks of the incoming and outgoing HTLC's set
99
        // to this node.
100
        TimeLockDelta uint16
101

102
        // HtlcMinimumMsat is the minimum HTLC value which will be accepted.
103
        HtlcMinimumMsat MilliSatoshi
104

105
        // BaseFee is the base fee that must be used for incoming HTLC's to
106
        // this particular channel. This value will be tacked onto the required
107
        // for a payment independent of the size of the payment.
108
        BaseFee uint32
109

110
        // FeeRate is the fee rate that will be charged per millionth of a
111
        // satoshi.
112
        FeeRate uint32
113

114
        // HtlcMaximumMsat is the maximum HTLC value which will be accepted.
115
        HtlcMaximumMsat MilliSatoshi
116

117
        // ExtraOpaqueData is the set of data that was appended to this
118
        // message, some of which we may not actually know how to iterate or
119
        // parse. By holding onto this data, we ensure that we're able to
120
        // properly validate the set of signatures that cover these new fields,
121
        // and ensure we're able to make upgrades to the network in a forwards
122
        // compatible manner.
123
        ExtraOpaqueData []byte
124
}
125

126
// A compile time check to ensure ChannelUpdate implements the lnwire.Message
127
// interface.
128
var _ Message = (*ChannelUpdate)(nil)
129

130
// Decode deserializes a serialized ChannelUpdate stored in the passed
131
// io.Reader observing the specified protocol version.
132
//
133
// This is part of the lnwire.Message interface.
UNCOV
134
func (a *ChannelUpdate) Decode(r io.Reader, pver uint32) error {
×
UNCOV
135
        err := ReadElements(r,
×
UNCOV
136
                &a.Signature,
×
UNCOV
137
                a.ChainHash[:],
×
UNCOV
138
                &a.ShortChannelID,
×
UNCOV
139
                &a.Timestamp,
×
UNCOV
140
                &a.MessageFlags,
×
UNCOV
141
                &a.ChannelFlags,
×
UNCOV
142
                &a.TimeLockDelta,
×
UNCOV
143
                &a.HtlcMinimumMsat,
×
UNCOV
144
                &a.BaseFee,
×
UNCOV
145
                &a.FeeRate,
×
UNCOV
146
        )
×
UNCOV
147
        if err != nil {
×
148
                return err
×
149
        }
×
150

151
        // Now check whether the max HTLC field is present and read it if so.
UNCOV
152
        if a.MessageFlags.HasMaxHtlc() {
×
153
                if err := ReadElements(r, &a.HtlcMaximumMsat); err != nil {
×
154
                        return err
×
155
                }
×
156
        }
157

158
        // Now that we've read out all the fields that we explicitly know of,
159
        // we'll collect the remainder into the ExtraOpaqueData field. If there
160
        // aren't any bytes, then we'll snip off the slice to avoid carrying
161
        // around excess capacity.
UNCOV
162
        a.ExtraOpaqueData, err = io.ReadAll(r)
×
UNCOV
163
        if err != nil {
×
164
                return err
×
165
        }
×
UNCOV
166
        if len(a.ExtraOpaqueData) == 0 {
×
UNCOV
167
                a.ExtraOpaqueData = nil
×
UNCOV
168
        }
×
169

UNCOV
170
        return nil
×
171
}
172

173
// Encode serializes the target ChannelUpdate into the passed io.Writer
174
// observing the protocol version specified.
175
//
176
// This is part of the lnwire.Message interface.
UNCOV
177
func (a *ChannelUpdate) Encode(w io.Writer, pver uint32) error {
×
UNCOV
178
        err := WriteElements(w,
×
UNCOV
179
                a.Signature,
×
UNCOV
180
                a.ChainHash[:],
×
UNCOV
181
                a.ShortChannelID,
×
UNCOV
182
                a.Timestamp,
×
UNCOV
183
                a.MessageFlags,
×
UNCOV
184
                a.ChannelFlags,
×
UNCOV
185
                a.TimeLockDelta,
×
UNCOV
186
                a.HtlcMinimumMsat,
×
UNCOV
187
                a.BaseFee,
×
UNCOV
188
                a.FeeRate,
×
UNCOV
189
        )
×
UNCOV
190
        if err != nil {
×
191
                return err
×
192
        }
×
193

194
        // Now append optional fields if they are set. Currently, the only
195
        // optional field is max HTLC.
UNCOV
196
        if a.MessageFlags.HasMaxHtlc() {
×
197
                if err := WriteElements(w, a.HtlcMaximumMsat); err != nil {
×
198
                        return err
×
199
                }
×
200
        }
201

202
        // Finally, append any extra opaque data.
UNCOV
203
        return WriteElements(w, a.ExtraOpaqueData)
×
204
}
205

206
// MsgType returns the integer uniquely identifying this message type on the
207
// wire.
208
//
209
// This is part of the lnwire.Message interface.
210
func (a *ChannelUpdate) MsgType() MessageType {
×
211
        return MsgChannelUpdate
×
212
}
×
213

214
// MaxPayloadLength returns the maximum allowed payload size for this message
215
// observing the specified protocol version.
216
//
217
// This is part of the lnwire.Message interface.
218
func (a *ChannelUpdate) MaxPayloadLength(pver uint32) uint32 {
×
219
        return 65533
×
220
}
×
221

222
// DataToSign is used to retrieve part of the announcement message which should
223
// be signed.
224
func (a *ChannelUpdate) DataToSign() ([]byte, error) {
×
225

×
226
        // We should not include the signatures itself.
×
227
        var w bytes.Buffer
×
228
        err := WriteElements(&w,
×
229
                a.ChainHash[:],
×
230
                a.ShortChannelID,
×
231
                a.Timestamp,
×
232
                a.MessageFlags,
×
233
                a.ChannelFlags,
×
234
                a.TimeLockDelta,
×
235
                a.HtlcMinimumMsat,
×
236
                a.BaseFee,
×
237
                a.FeeRate,
×
238
        )
×
239
        if err != nil {
×
240
                return nil, err
×
241
        }
×
242

243
        // Now append optional fields if they are set. Currently, the only
244
        // optional field is max HTLC.
245
        if a.MessageFlags.HasMaxHtlc() {
×
246
                if err := WriteElements(&w, a.HtlcMaximumMsat); err != nil {
×
247
                        return nil, err
×
248
                }
×
249
        }
250

251
        // Finally, append any extra opaque data.
252
        if err := WriteElements(&w, a.ExtraOpaqueData); err != nil {
×
253
                return nil, err
×
254
        }
×
255

256
        return w.Bytes(), nil
×
257
}
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