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

lightningnetwork / lnd / 16683051882

01 Aug 2025 07:03PM UTC coverage: 54.949% (-12.1%) from 67.047%
16683051882

Pull #9455

github

web-flow
Merge 3f1f50be8 into 37523b6cb
Pull Request #9455: discovery+lnwire: add support for DNS host name in NodeAnnouncement msg

144 of 226 new or added lines in 7 files covered. (63.72%)

23852 existing lines in 290 files now uncovered.

108751 of 197912 relevant lines covered (54.95%)

22080.83 hits per line

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

88.65
/routing/pathfind.go
1
package routing
2

3
import (
4
        "bytes"
5
        "container/heap"
6
        "errors"
7
        "fmt"
8
        "math"
9
        "sort"
10
        "time"
11

12
        "github.com/btcsuite/btcd/btcutil"
13
        sphinx "github.com/lightningnetwork/lightning-onion"
14
        "github.com/lightningnetwork/lnd/feature"
15
        "github.com/lightningnetwork/lnd/fn/v2"
16
        graphdb "github.com/lightningnetwork/lnd/graph/db"
17
        "github.com/lightningnetwork/lnd/graph/db/models"
18
        "github.com/lightningnetwork/lnd/lnutils"
19
        "github.com/lightningnetwork/lnd/lnwire"
20
        "github.com/lightningnetwork/lnd/record"
21
        "github.com/lightningnetwork/lnd/routing/route"
22
)
23

24
const (
25
        // infinity is used as a starting distance in our shortest path search.
26
        infinity = math.MaxInt64
27

28
        // RiskFactorBillionths controls the influence of time lock delta
29
        // of a channel on route selection. It is expressed as billionths
30
        // of msat per msat sent through the channel per time lock delta
31
        // block. See edgeWeight function below for more details.
32
        // The chosen value is based on the previous incorrect weight function
33
        // 1 + timelock + fee * fee. In this function, the fee penalty
34
        // diminishes the time lock penalty for all but the smallest amounts.
35
        // To not change the behaviour of path finding too drastically, a
36
        // relatively small value is chosen which is still big enough to give
37
        // some effect with smaller time lock values. The value may need
38
        // tweaking and/or be made configurable in the future.
39
        RiskFactorBillionths = 15
40

41
        // estimatedNodeCount is used to preallocate the path finding structures
42
        // to avoid resizing and copies. It should be number on the same order as
43
        // the number of active nodes in the network.
44
        estimatedNodeCount = 10000
45

46
        // fakeHopHintCapacity is the capacity we assume for hop hint channels.
47
        // This is a high number, which expresses that a hop hint channel should
48
        // be able to route payments.
49
        fakeHopHintCapacity = btcutil.Amount(10 * btcutil.SatoshiPerBitcoin)
50
)
51

52
// pathFinder defines the interface of a path finding algorithm.
53
type pathFinder = func(g *graphParams, r *RestrictParams,
54
        cfg *PathFindingConfig, self, source, target route.Vertex,
55
        amt lnwire.MilliSatoshi, timePref float64, finalHtlcExpiry int32) (
56
        []*unifiedEdge, float64, error)
57

58
var (
59
        // DefaultEstimator is the default estimator used for computing
60
        // probabilities in pathfinding.
61
        DefaultEstimator = AprioriEstimatorName
62

63
        // DefaultAttemptCost is the default fixed virtual cost in path finding
64
        // of a failed payment attempt. It is used to trade off potentially
65
        // better routes against their probability of succeeding.
66
        DefaultAttemptCost = lnwire.NewMSatFromSatoshis(100)
67

68
        // DefaultAttemptCostPPM is the default proportional virtual cost in
69
        // path finding weight units of executing a payment attempt that fails.
70
        // It is used to trade off potentially better routes against their
71
        // probability of succeeding. This parameter is expressed in parts per
72
        // million of the payment amount.
73
        //
74
        // It is impossible to pick a perfect default value. The current value
75
        // of 0.1% is based on the idea that a transaction fee of 1% is within
76
        // reasonable territory and that a payment shouldn't need more than 10
77
        // attempts.
78
        DefaultAttemptCostPPM = int64(1000)
79

80
        // DefaultMinRouteProbability is the default minimum probability for routes
81
        // returned from findPath.
82
        DefaultMinRouteProbability = float64(0.01)
83

84
        // DefaultAprioriHopProbability is the default a priori probability for
85
        // a hop.
86
        DefaultAprioriHopProbability = float64(0.6)
87
)
88

89
// edgePolicyWithSource is a helper struct to keep track of the source node
90
// of a channel edge. ChannelEdgePolicy only contains to destination node
91
// of the edge.
92
type edgePolicyWithSource struct {
93
        sourceNode route.Vertex
94
        edge       AdditionalEdge
95
}
96

97
// finalHopParams encapsulates various parameters for route construction that
98
// apply to the final hop in a route. These features include basic payment data
99
// such as amounts and cltvs, as well as more complex features like destination
100
// custom records and payment address.
101
type finalHopParams struct {
102
        amt      lnwire.MilliSatoshi
103
        totalAmt lnwire.MilliSatoshi
104

105
        // cltvDelta is the final hop's minimum CLTV expiry delta.
106
        //
107
        // NOTE that in the case of paying to a blinded path, this value will
108
        // be set to a duplicate of the blinded path's accumulated CLTV value.
109
        // We would then only need to use this value in the case where the
110
        // introduction node of the path is also the destination node.
111
        cltvDelta uint16
112

113
        records     record.CustomSet
114
        paymentAddr fn.Option[[32]byte]
115

116
        // metadata is additional data that is sent along with the payment to
117
        // the payee.
118
        metadata []byte
119
}
120

121
// newRoute constructs a route using the provided path and final hop constraints.
122
// Any destination specific fields from the final hop params  will be attached
123
// assuming the destination's feature vector signals support, otherwise this
124
// method will fail.  If the route is too long, or the selected path cannot
125
// support the fully payment including fees, then a non-nil error is returned.
126
// If the route is to a blinded path, the blindedPath parameter is used to
127
// back fill additional fields that are required for a blinded payment. This is
128
// done in a separate pass to keep our route construction simple, as blinded
129
// paths require zero expiry and amount values for intermediate hops (which
130
// makes calculating the totals during route construction difficult if we
131
// include blinded paths on the first pass).
132
//
133
// NOTE: The passed slice of unified edges MUST be sorted in forward order: from
134
// the source to the target node of the path finding attempt. It is assumed that
135
// any feature vectors on all hops have been validated for transitive
136
// dependencies.
137
// NOTE: If a non-nil blinded path is provided it is assumed to have been
138
// validated by the caller.
139
func newRoute(sourceVertex route.Vertex,
140
        pathEdges []*unifiedEdge, currentHeight uint32, finalHop finalHopParams,
141
        blindedPathSet *BlindedPaymentPathSet) (*route.Route, error) {
93✔
142

93✔
143
        var (
93✔
144
                hops []*route.Hop
93✔
145

93✔
146
                // totalTimeLock will accumulate the cumulative time lock
93✔
147
                // across the entire route. This value represents how long the
93✔
148
                // sender will need to wait in the *worst* case.
93✔
149
                totalTimeLock = currentHeight
93✔
150

93✔
151
                // nextIncomingAmount is the amount that will need to flow into
93✔
152
                // the *next* hop. Since we're going to be walking the route
93✔
153
                // backwards below, this next hop gets closer and closer to the
93✔
154
                // sender of the payment.
93✔
155
                nextIncomingAmount lnwire.MilliSatoshi
93✔
156

93✔
157
                blindedPayment *BlindedPayment
93✔
158
        )
93✔
159

93✔
160
        pathLength := len(pathEdges)
93✔
161

93✔
162
        // When paying to a blinded route we might have appended a dummy hop at
93✔
163
        // the end to make MPP payments possible via all paths of the blinded
93✔
164
        // route set. We always append a dummy hop when the internal pathfiner
93✔
165
        // looks for a route to a blinded path which is at least one hop long
93✔
166
        // (excluding the introduction point). We add this dummy hop so that
93✔
167
        // we search for a universal target but also respect potential mc
93✔
168
        // entries which might already be present for a particular blinded path.
93✔
169
        // However when constructing the Sphinx packet we need to remove this
93✔
170
        // dummy hop again which we do here.
93✔
171
        //
93✔
172
        // NOTE: The path length is always at least 1 because there must be one
93✔
173
        // edge from the source to the destination. However we check for > 0
93✔
174
        // just for robustness here.
93✔
175
        if blindedPathSet != nil && pathLength > 0 {
94✔
176
                finalBlindedPubKey := pathEdges[pathLength-1].policy.
1✔
177
                        ToNodePubKey()
1✔
178

1✔
179
                if IsBlindedRouteNUMSTargetKey(finalBlindedPubKey[:]) {
1✔
UNCOV
180
                        // If the last hop is the NUMS key for blinded paths, we
×
UNCOV
181
                        // remove the dummy hop from the route.
×
UNCOV
182
                        pathEdges = pathEdges[:pathLength-1]
×
UNCOV
183
                        pathLength--
×
UNCOV
184
                }
×
185
        }
186

187
        for i := pathLength - 1; i >= 0; i-- {
309✔
188
                // Now we'll start to calculate the items within the per-hop
216✔
189
                // payload for the hop this edge is leading to.
216✔
190
                edge := pathEdges[i].policy
216✔
191

216✔
192
                // If this is an edge from a blinded path and the
216✔
193
                // blindedPayment variable has not been set yet, then set it now
216✔
194
                // by extracting the corresponding blinded payment from the
216✔
195
                // edge.
216✔
196
                isBlindedEdge := pathEdges[i].blindedPayment != nil
216✔
197
                if isBlindedEdge && blindedPayment == nil {
217✔
198
                        blindedPayment = pathEdges[i].blindedPayment
1✔
199
                }
1✔
200

201
                // We'll calculate the amounts, timelocks, and fees for each hop
202
                // in the route. The base case is the final hop which includes
203
                // their amount and timelocks. These values will accumulate
204
                // contributions from the preceding hops back to the sender as
205
                // we compute the route in reverse.
206
                var (
216✔
207
                        amtToForward        lnwire.MilliSatoshi
216✔
208
                        fee                 int64
216✔
209
                        totalAmtMsatBlinded lnwire.MilliSatoshi
216✔
210
                        outgoingTimeLock    uint32
216✔
211
                        customRecords       record.CustomSet
216✔
212
                        mpp                 *record.MPP
216✔
213
                        metadata            []byte
216✔
214
                )
216✔
215

216✔
216
                // Define a helper function that checks this edge's feature
216✔
217
                // vector for support for a given feature. We assume at this
216✔
218
                // point that the feature vectors transitive dependencies have
216✔
219
                // been validated.
216✔
220
                supports := func(feature lnwire.FeatureBit) bool {
309✔
221
                        // If this edge comes from router hints, the features
93✔
222
                        // could be nil.
93✔
223
                        if edge.ToNodeFeatures == nil {
93✔
224
                                return false
×
225
                        }
×
226
                        return edge.ToNodeFeatures.HasFeature(feature)
93✔
227
                }
228

229
                if i == len(pathEdges)-1 {
309✔
230
                        // If this is the last hop, then the hop payload will
93✔
231
                        // contain the exact amount. In BOLT #4: Onion Routing
93✔
232
                        // Protocol / "Payload for the Last Node", this is
93✔
233
                        // detailed.
93✔
234
                        amtToForward = finalHop.amt
93✔
235

93✔
236
                        // Fee is not part of the hop payload, but only used for
93✔
237
                        // reporting through RPC. Set to zero for the final hop.
93✔
238
                        fee = 0
93✔
239

93✔
240
                        if blindedPathSet == nil {
185✔
241
                                totalTimeLock += uint32(finalHop.cltvDelta)
92✔
242
                        } else {
93✔
243
                                totalTimeLock += uint32(
1✔
244
                                        blindedPathSet.FinalCLTVDelta(),
1✔
245
                                )
1✔
246
                        }
1✔
247
                        outgoingTimeLock = totalTimeLock
93✔
248

93✔
249
                        // Attach any custom records to the final hop.
93✔
250
                        customRecords = finalHop.records
93✔
251

93✔
252
                        // If we're attaching a payment addr but the receiver
93✔
253
                        // doesn't support both TLV and payment addrs, fail.
93✔
254
                        payAddr := supports(lnwire.PaymentAddrOptional)
93✔
255
                        if !payAddr && finalHop.paymentAddr.IsSome() {
93✔
256
                                return nil, errors.New("cannot attach " +
×
257
                                        "payment addr")
×
258
                        }
×
259

260
                        // Otherwise attach the mpp record if it exists.
261
                        // TODO(halseth): move this to payment life cycle,
262
                        // where AMP options are set.
263
                        finalHop.paymentAddr.WhenSome(func(addr [32]byte) {
135✔
264
                                mpp = record.NewMPP(finalHop.totalAmt, addr)
42✔
265
                        })
42✔
266

267
                        metadata = finalHop.metadata
93✔
268

93✔
269
                        if blindedPathSet != nil {
94✔
270
                                totalAmtMsatBlinded = finalHop.totalAmt
1✔
271
                        }
1✔
272
                } else {
123✔
273
                        // The amount that the current hop needs to forward is
123✔
274
                        // equal to the incoming amount of the next hop.
123✔
275
                        amtToForward = nextIncomingAmount
123✔
276

123✔
277
                        // The fee that needs to be paid to the current hop is
123✔
278
                        // based on the amount that this hop needs to forward
123✔
279
                        // and its policy for the outgoing channel. This policy
123✔
280
                        // is stored as part of the incoming channel of
123✔
281
                        // the next hop.
123✔
282
                        outboundFee := pathEdges[i+1].policy.ComputeFee(
123✔
283
                                amtToForward,
123✔
284
                        )
123✔
285

123✔
286
                        inboundFee := pathEdges[i].inboundFees.CalcFee(
123✔
287
                                amtToForward + outboundFee,
123✔
288
                        )
123✔
289

123✔
290
                        fee = int64(outboundFee) + inboundFee
123✔
291
                        if fee < 0 {
125✔
292
                                fee = 0
2✔
293
                        }
2✔
294

295
                        // We'll take the total timelock of the preceding hop as
296
                        // the outgoing timelock or this hop. Then we'll
297
                        // increment the total timelock incurred by this hop.
298
                        outgoingTimeLock = totalTimeLock
123✔
299
                        totalTimeLock += uint32(
123✔
300
                                pathEdges[i+1].policy.TimeLockDelta,
123✔
301
                        )
123✔
302
                }
303

304
                // Since we're traversing the path backwards atm, we prepend
305
                // each new hop such that, the final slice of hops will be in
306
                // the forwards order.
307
                currentHop := &route.Hop{
216✔
308
                        PubKeyBytes:      edge.ToNodePubKey(),
216✔
309
                        ChannelID:        edge.ChannelID,
216✔
310
                        AmtToForward:     amtToForward,
216✔
311
                        OutgoingTimeLock: outgoingTimeLock,
216✔
312
                        CustomRecords:    customRecords,
216✔
313
                        MPP:              mpp,
216✔
314
                        Metadata:         metadata,
216✔
315
                        TotalAmtMsat:     totalAmtMsatBlinded,
216✔
316
                }
216✔
317

216✔
318
                hops = append([]*route.Hop{currentHop}, hops...)
216✔
319

216✔
320
                // Finally, we update the amount that needs to flow into the
216✔
321
                // *next* hop, which is the amount this hop needs to forward,
216✔
322
                // accounting for the fee that it takes.
216✔
323
                nextIncomingAmount = amtToForward + lnwire.MilliSatoshi(fee)
216✔
324
        }
325

326
        // If we are creating a route to a blinded path, we need to add some
327
        // additional data to the route that is required for blinded forwarding.
328
        // We do another pass on our edges to append this data.
329
        if blindedPathSet != nil {
94✔
330
                // If the passed in BlindedPaymentPathSet is non-nil but no
1✔
331
                // edge had a BlindedPayment attached, it means that the path
1✔
332
                // chosen was an introduction-node-only path. So in this case,
1✔
333
                // we can assume the relevant payment is the only one in the
1✔
334
                // payment set.
1✔
335
                if blindedPayment == nil {
1✔
UNCOV
336
                        var err error
×
UNCOV
337
                        blindedPayment, err = blindedPathSet.IntroNodeOnlyPath()
×
UNCOV
338
                        if err != nil {
×
339
                                return nil, err
×
340
                        }
×
341
                }
342

343
                var (
1✔
344
                        inBlindedRoute bool
1✔
345
                        dataIndex      = 0
1✔
346

1✔
347
                        blindedPath = blindedPayment.BlindedPath
1✔
348
                        introVertex = route.NewVertex(
1✔
349
                                blindedPath.IntroductionPoint,
1✔
350
                        )
1✔
351
                )
1✔
352

1✔
353
                for i, hop := range hops {
5✔
354
                        // Once we locate our introduction node, we know that
4✔
355
                        // every hop after this is part of the blinded route.
4✔
356
                        if bytes.Equal(hop.PubKeyBytes[:], introVertex[:]) {
5✔
357
                                inBlindedRoute = true
1✔
358
                                hop.BlindingPoint = blindedPath.BlindingPoint
1✔
359
                        }
1✔
360

361
                        // We don't need to modify edges outside of our blinded
362
                        // route.
363
                        if !inBlindedRoute {
5✔
364
                                continue
1✔
365
                        }
366

367
                        payload := blindedPath.BlindedHops[dataIndex].CipherText
3✔
368
                        hop.EncryptedData = payload
3✔
369

3✔
370
                        // All of the hops in a blinded route *except* the
3✔
371
                        // final hop should have zero amounts / time locks.
3✔
372
                        if i != len(hops)-1 {
5✔
373
                                hop.AmtToForward = 0
2✔
374
                                hop.OutgoingTimeLock = 0
2✔
375
                        }
2✔
376

377
                        dataIndex++
3✔
378
                }
379
        }
380

381
        // With the base routing data expressed as hops, build the full route
382
        newRoute, err := route.NewRouteFromHops(
93✔
383
                nextIncomingAmount, totalTimeLock, route.Vertex(sourceVertex),
93✔
384
                hops,
93✔
385
        )
93✔
386
        if err != nil {
93✔
387
                return nil, err
×
388
        }
×
389

390
        return newRoute, nil
93✔
391
}
392

393
// edgeWeight computes the weight of an edge. This value is used when searching
394
// for the shortest path within the channel graph between two nodes. Weight is
395
// is the fee itself plus a time lock penalty added to it. This benefits
396
// channels with shorter time lock deltas and shorter (hops) routes in general.
397
// RiskFactor controls the influence of time lock on route selection. This is
398
// currently a fixed value, but might be configurable in the future.
399
func edgeWeight(lockedAmt lnwire.MilliSatoshi, fee lnwire.MilliSatoshi,
400
        timeLockDelta uint16) int64 {
1,135✔
401
        // timeLockPenalty is the penalty for the time lock delta of this channel.
1,135✔
402
        // It is controlled by RiskFactorBillionths and scales proportional
1,135✔
403
        // to the amount that will pass through channel. Rationale is that it if
1,135✔
404
        // a twice as large amount gets locked up, it is twice as bad.
1,135✔
405
        timeLockPenalty := int64(lockedAmt) * int64(timeLockDelta) *
1,135✔
406
                RiskFactorBillionths / 1000000000
1,135✔
407

1,135✔
408
        return int64(fee) + timeLockPenalty
1,135✔
409
}
1,135✔
410

411
// graphParams wraps the set of graph parameters passed to findPath.
412
type graphParams struct {
413
        // graph is the ChannelGraph to be used during path finding.
414
        graph Graph
415

416
        // additionalEdges is an optional set of edges that should be
417
        // considered during path finding, that is not already found in the
418
        // channel graph. These can either be private edges for bolt 11 invoices
419
        // or blinded edges when a payment to a blinded path is made.
420
        additionalEdges map[route.Vertex][]AdditionalEdge
421

422
        // bandwidthHints is an interface that provides bandwidth hints that
423
        // can provide a better estimate of the current channel bandwidth than
424
        // what is found in the graph. It will override the capacities and
425
        // disabled flags found in the graph for local channels when doing
426
        // path finding if it has updated values for that channel. In
427
        // particular, it should be set to the current available sending
428
        // bandwidth for active local channels, and 0 for inactive channels.
429
        bandwidthHints bandwidthHints
430
}
431

432
// RestrictParams wraps the set of restrictions passed to findPath that the
433
// found path must adhere to.
434
type RestrictParams struct {
435
        // ProbabilitySource is a callback that is expected to return the
436
        // success probability of traversing the channel from the node.
437
        ProbabilitySource func(route.Vertex, route.Vertex,
438
                lnwire.MilliSatoshi, btcutil.Amount) float64
439

440
        // FeeLimit is a maximum fee amount allowed to be used on the path from
441
        // the source to the target.
442
        FeeLimit lnwire.MilliSatoshi
443

444
        // OutgoingChannelIDs is the list of channels that are allowed for the
445
        // first hop. If nil, any channel may be used.
446
        OutgoingChannelIDs []uint64
447

448
        // LastHop is the pubkey of the last node before the final destination
449
        // is reached. If nil, any node may be used.
450
        LastHop *route.Vertex
451

452
        // CltvLimit is the maximum time lock of the route excluding the final
453
        // ctlv. After path finding is complete, the caller needs to increase
454
        // all cltv expiry heights with the required final cltv delta.
455
        CltvLimit uint32
456

457
        // DestCustomRecords contains the custom records to drop off at the
458
        // final hop, if any.
459
        DestCustomRecords record.CustomSet
460

461
        // DestFeatures is a feature vector describing what the final hop
462
        // supports. If none are provided, pathfinding will try to inspect any
463
        // features on the node announcement instead.
464
        DestFeatures *lnwire.FeatureVector
465

466
        // PaymentAddr is a random 32-byte value generated by the receiver to
467
        // mitigate probing vectors and payment sniping attacks on overpaid
468
        // invoices.
469
        PaymentAddr fn.Option[[32]byte]
470

471
        // Amp signals to the pathfinder that this payment is an AMP payment
472
        // and therefore it needs to account for additional AMP data in the
473
        // final hop payload size calculation.
474
        Amp *AMPOptions
475

476
        // Metadata is additional data that is sent along with the payment to
477
        // the payee.
478
        Metadata []byte
479

480
        // BlindedPaymentPathSet is necessary to determine the hop size of the
481
        // last/exit hop.
482
        BlindedPaymentPathSet *BlindedPaymentPathSet
483

484
        // FirstHopCustomRecords includes any records that should be included in
485
        // the update_add_htlc message towards our peer.
486
        FirstHopCustomRecords lnwire.CustomRecords
487
}
488

489
// PathFindingConfig defines global parameters that control the trade-off in
490
// path finding between fees and probability.
491
type PathFindingConfig struct {
492
        // AttemptCost is the fixed virtual cost in path finding of a failed
493
        // payment attempt. It is used to trade off potentially better routes
494
        // against their probability of succeeding.
495
        AttemptCost lnwire.MilliSatoshi
496

497
        // AttemptCostPPM is the proportional virtual cost in path finding of a
498
        // failed payment attempt. It is used to trade off potentially better
499
        // routes against their probability of succeeding. This parameter is
500
        // expressed in parts per million of the total payment amount.
501
        AttemptCostPPM int64
502

503
        // MinProbability defines the minimum success probability of the
504
        // returned route.
505
        MinProbability float64
506
}
507

508
// getOutgoingBalance returns the maximum available balance in any of the
509
// channels of the given node. The second return parameters is the total
510
// available balance.
511
func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
512
        bandwidthHints bandwidthHints,
513
        g Graph) (lnwire.MilliSatoshi, lnwire.MilliSatoshi, error) {
180✔
514

180✔
515
        var max, total lnwire.MilliSatoshi
180✔
516
        cb := func(channel *graphdb.DirectedChannel) error {
625✔
517
                shortID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
445✔
518

445✔
519
                // This log line is needed to debug issues in case we do not
445✔
520
                // have a channel in our graph for some reason when evaluating
445✔
521
                // the local balance. Otherwise we could not tell whether all
445✔
522
                // channels are being evaluated.
445✔
523
                log.Tracef("Evaluating channel %v for local balance", shortID)
445✔
524

445✔
525
                if !channel.OutPolicySet {
445✔
526
                        log.Debugf("ShortChannelID=%v: has no out policy set, "+
×
527
                                "skipping", shortID)
×
528

×
529
                        return nil
×
530
                }
×
531

532
                chanID := channel.ChannelID
445✔
533

445✔
534
                // Enforce outgoing channel restriction.
445✔
535
                if outgoingChans != nil {
465✔
536
                        if _, ok := outgoingChans[chanID]; !ok {
32✔
537
                                return nil
12✔
538
                        }
12✔
539
                }
540

541
                bandwidth, ok := bandwidthHints.availableChanBandwidth(
433✔
542
                        chanID, 0,
433✔
543
                )
433✔
544

433✔
545
                // If the bandwidth is not available, use the channel capacity.
433✔
546
                // This can happen when a channel is added to the graph after
433✔
547
                // we've already queried the bandwidth hints.
433✔
548
                if !ok {
675✔
549
                        bandwidth = lnwire.NewMSatFromSatoshis(channel.Capacity)
242✔
550

242✔
551
                        log.Warnf("ShortChannelID=%v: not found in the local "+
242✔
552
                                "channels map of the bandwidth manager, "+
242✔
553
                                "using channel capacity=%v as bandwidth for "+
242✔
554
                                "this channel", shortID, bandwidth)
242✔
555
                }
242✔
556

557
                if bandwidth > max {
655✔
558
                        max = bandwidth
222✔
559
                }
222✔
560

561
                var overflow bool
433✔
562
                total, overflow = overflowSafeAdd(total, bandwidth)
433✔
563
                if overflow {
433✔
564
                        log.Warnf("ShortChannelID=%v: overflow detected, "+
×
565
                                "setting total to max value", shortID)
×
566

×
567
                        // If the current total and the bandwidth would
×
568
                        // overflow the maximum value, we set the total to the
×
569
                        // maximum value. Which is more milli-satoshis than are
×
570
                        // in existence anyway, so the actual value is
×
571
                        // irrelevant.
×
572
                        total = lnwire.MilliSatoshi(math.MaxUint64)
×
573
                }
×
574

575
                return nil
433✔
576
        }
577

578
        // Iterate over all channels of the to node.
579
        err := g.ForEachNodeDirectedChannel(
180✔
580
                node, cb, func() {
180✔
UNCOV
581
                        max = 0
×
UNCOV
582
                        total = 0
×
UNCOV
583
                },
×
584
        )
585
        if err != nil {
180✔
586
                return 0, 0, err
×
587
        }
×
588
        return max, total, err
180✔
589
}
590

591
// findPath attempts to find a path from the source node within the ChannelGraph
592
// to the target node that's capable of supporting a payment of `amt` value. The
593
// current approach implemented is modified version of Dijkstra's algorithm to
594
// find a single shortest path between the source node and the destination. The
595
// distance metric used for edges is related to the time-lock+fee costs along a
596
// particular edge. If a path is found, this function returns a slice of
597
// ChannelHop structs which encoded the chosen path from the target to the
598
// source. The search is performed backwards from destination node back to
599
// source. This is to properly accumulate fees that need to be paid along the
600
// path and accurately check the amount to forward at every node against the
601
// available bandwidth.
602
func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
603
        self, source, target route.Vertex, amt lnwire.MilliSatoshi,
604
        timePref float64, finalHtlcExpiry int32) ([]*unifiedEdge, float64,
605
        error) {
186✔
606

186✔
607
        // Pathfinding can be a significant portion of the total payment
186✔
608
        // latency, especially on low-powered devices. Log several metrics to
186✔
609
        // aid in the analysis performance problems in this area.
186✔
610
        start := time.Now()
186✔
611
        nodesVisited := 0
186✔
612
        edgesExpanded := 0
186✔
613
        defer func() {
372✔
614
                timeElapsed := time.Since(start)
186✔
615
                log.Debugf("Pathfinding perf metrics: nodes=%v, edges=%v, "+
186✔
616
                        "time=%v", nodesVisited, edgesExpanded, timeElapsed)
186✔
617
        }()
186✔
618

619
        // If no destination features are provided, we will load what features
620
        // we have for the target node from our graph.
621
        features := r.DestFeatures
186✔
622
        if features == nil {
304✔
623
                var err error
118✔
624
                features, err = g.graph.FetchNodeFeatures(target)
118✔
625
                if err != nil {
118✔
626
                        return nil, 0, err
×
627
                }
×
628
        }
629

630
        // Ensure that the destination's features don't include unknown
631
        // required features.
632
        err := feature.ValidateRequired(features)
186✔
633
        if err != nil {
188✔
634
                log.Warnf("Pathfinding destination node features: %v", err)
2✔
635
                return nil, 0, errUnknownRequiredFeature
2✔
636
        }
2✔
637

638
        // Ensure that all transitive dependencies are set.
639
        err = feature.ValidateDeps(features)
184✔
640
        if err != nil {
186✔
641
                log.Warnf("Pathfinding destination node features: %v", err)
2✔
642
                return nil, 0, errMissingDependentFeature
2✔
643
        }
2✔
644

645
        // Now that we know the feature vector is well-formed, we'll proceed in
646
        // checking that it supports the features we need. If the caller has a
647
        // payment address to attach, check that our destination feature vector
648
        // supports them.
649
        if r.PaymentAddr.IsSome() &&
182✔
650
                !features.HasFeature(lnwire.PaymentAddrOptional) {
184✔
651

2✔
652
                return nil, 0, errNoPaymentAddr
2✔
653
        }
2✔
654

655
        // Set up outgoing channel map for quicker access.
656
        var outgoingChanMap map[uint64]struct{}
180✔
657
        if len(r.OutgoingChannelIDs) > 0 {
186✔
658
                outgoingChanMap = make(map[uint64]struct{})
6✔
659
                for _, outChan := range r.OutgoingChannelIDs {
14✔
660
                        outgoingChanMap[outChan] = struct{}{}
8✔
661
                }
8✔
662
        }
663

664
        // If we are routing from ourselves, check that we have enough local
665
        // balance available.
666
        if source == self {
360✔
667
                max, total, err := getOutgoingBalance(
180✔
668
                        self, outgoingChanMap, g.bandwidthHints, g.graph,
180✔
669
                )
180✔
670
                if err != nil {
180✔
671
                        return nil, 0, err
×
672
                }
×
673

674
                // If the total outgoing balance isn't sufficient, it will be
675
                // impossible to complete the payment.
676
                if total < amt {
183✔
677
                        log.Warnf("Not enough outbound balance to send "+
3✔
678
                                "htlc of amount: %v, only have local "+
3✔
679
                                "balance: %v", amt, total)
3✔
680

3✔
681
                        return nil, 0, errInsufficientBalance
3✔
682
                }
3✔
683

684
                // If there is only not enough capacity on a single route, it
685
                // may still be possible to complete the payment by splitting.
686
                if max < amt {
178✔
687
                        return nil, 0, errNoPathFound
1✔
688
                }
1✔
689
        }
690

691
        // First we'll initialize an empty heap which'll help us to quickly
692
        // locate the next edge we should visit next during our graph
693
        // traversal.
694
        nodeHeap := newDistanceHeap(estimatedNodeCount)
176✔
695

176✔
696
        // Holds the current best distance for a given node.
176✔
697
        distance := make(map[route.Vertex]*nodeWithDist, estimatedNodeCount)
176✔
698

176✔
699
        additionalEdgesWithSrc := make(map[route.Vertex][]*edgePolicyWithSource)
176✔
700
        for vertex, additionalEdges := range g.additionalEdges {
196✔
701
                // Edges connected to self are always included in the graph,
20✔
702
                // therefore can be skipped. This prevents us from trying
20✔
703
                // routes to malformed hop hints.
20✔
704
                if vertex == self {
24✔
705
                        continue
4✔
706
                }
707

708
                // Build reverse lookup to find incoming edges. Needed because
709
                // search is taken place from target to source.
710
                for _, additionalEdge := range additionalEdges {
32✔
711
                        outgoingEdgePolicy := additionalEdge.EdgePolicy()
16✔
712
                        toVertex := outgoingEdgePolicy.ToNodePubKey()
16✔
713

16✔
714
                        incomingEdgePolicy := &edgePolicyWithSource{
16✔
715
                                sourceNode: vertex,
16✔
716
                                edge:       additionalEdge,
16✔
717
                        }
16✔
718

16✔
719
                        additionalEdgesWithSrc[toVertex] =
16✔
720
                                append(additionalEdgesWithSrc[toVertex],
16✔
721
                                        incomingEdgePolicy)
16✔
722
                }
16✔
723
        }
724

725
        // The payload size of the final hop differ from intermediate hops
726
        // and depends on whether the destination is blinded or not.
727
        lastHopPayloadSize, err := lastHopPayloadSize(r, finalHtlcExpiry, amt)
176✔
728
        if err != nil {
176✔
729
                return nil, 0, err
×
730
        }
×
731

732
        // We can't always assume that the end destination is publicly
733
        // advertised to the network so we'll manually include the target node.
734
        // The target node charges no fee. Distance is set to 0, because this is
735
        // the starting point of the graph traversal. We are searching backwards
736
        // to get the fees first time right and correctly match channel
737
        // bandwidth.
738
        //
739
        // Don't record the initial partial path in the distance map and reserve
740
        // that key for the source key in the case we route to ourselves.
741
        partialPath := &nodeWithDist{
176✔
742
                dist:              0,
176✔
743
                weight:            0,
176✔
744
                node:              target,
176✔
745
                netAmountReceived: amt,
176✔
746
                incomingCltv:      finalHtlcExpiry,
176✔
747
                probability:       1,
176✔
748
                routingInfoSize:   lastHopPayloadSize,
176✔
749
        }
176✔
750

176✔
751
        // Calculate the absolute cltv limit. Use uint64 to prevent an overflow
176✔
752
        // if the cltv limit is MaxUint32.
176✔
753
        absoluteCltvLimit := uint64(r.CltvLimit) + uint64(finalHtlcExpiry)
176✔
754

176✔
755
        // Calculate the default attempt cost as configured globally.
176✔
756
        defaultAttemptCost := float64(
176✔
757
                cfg.AttemptCost +
176✔
758
                        amt*lnwire.MilliSatoshi(cfg.AttemptCostPPM)/1000000,
176✔
759
        )
176✔
760

176✔
761
        // Validate time preference value.
176✔
762
        if math.Abs(timePref) > 1 {
176✔
763
                return nil, 0, fmt.Errorf("time preference %v out of range "+
×
764
                        "[-1, 1]", timePref)
×
765
        }
×
766

767
        // Scale to avoid the extremes -1 and 1 which run into infinity issues.
768
        timePref *= 0.9
176✔
769

176✔
770
        // Apply time preference. At 0, the default attempt cost will
176✔
771
        // be used.
176✔
772
        absoluteAttemptCost := defaultAttemptCost * (1/(0.5-timePref/2) - 1)
176✔
773

176✔
774
        log.Debugf("Pathfinding absolute attempt cost: %v sats",
176✔
775
                absoluteAttemptCost/1000)
176✔
776

176✔
777
        // processEdge is a helper closure that will be used to make sure edges
176✔
778
        // satisfy our specific requirements.
176✔
779
        processEdge := func(fromVertex route.Vertex,
176✔
780
                edge *unifiedEdge, toNodeDist *nodeWithDist) {
1,428✔
781

1,252✔
782
                edgesExpanded++
1,252✔
783

1,252✔
784
                // Calculate inbound fee charged by "to" node. The exit hop
1,252✔
785
                // doesn't charge inbound fees. If the "to" node is the exit
1,252✔
786
                // hop, its inbound fees have already been set to zero by
1,252✔
787
                // nodeEdgeUnifier.
1,252✔
788
                inboundFee := edge.inboundFees.CalcFee(
1,252✔
789
                        toNodeDist.netAmountReceived,
1,252✔
790
                )
1,252✔
791

1,252✔
792
                // Make sure that the node total fee is never negative.
1,252✔
793
                // Routing nodes treat a total fee that turns out
1,252✔
794
                // negative as a zero fee and pathfinding should do the
1,252✔
795
                // same.
1,252✔
796
                minInboundFee := -int64(toNodeDist.outboundFee)
1,252✔
797
                if inboundFee < minInboundFee {
1,254✔
798
                        inboundFee = minInboundFee
2✔
799
                }
2✔
800

801
                // Calculate amount that the candidate node would have to send
802
                // out.
803
                amountToSend := toNodeDist.netAmountReceived +
1,252✔
804
                        lnwire.MilliSatoshi(inboundFee)
1,252✔
805

1,252✔
806
                // Check if accumulated fees would exceed fee limit when this
1,252✔
807
                // node would be added to the path.
1,252✔
808
                totalFee := int64(amountToSend) - int64(amt)
1,252✔
809

1,252✔
810
                log.Trace(lnutils.NewLogClosure(func() string {
1,252✔
811
                        return fmt.Sprintf(
×
812
                                "Checking fromVertex (%v) with "+
×
813
                                        "minInboundFee=%v, inboundFee=%v, "+
×
814
                                        "amountToSend=%v, amt=%v, totalFee=%v",
×
815
                                fromVertex, minInboundFee, inboundFee,
×
816
                                amountToSend, amt, totalFee,
×
817
                        )
×
818
                }))
×
819

820
                if totalFee > 0 && lnwire.MilliSatoshi(totalFee) > r.FeeLimit {
1,256✔
821
                        return
4✔
822
                }
4✔
823

824
                // Request the success probability for this edge.
825
                edgeProbability := r.ProbabilitySource(
1,248✔
826
                        fromVertex, toNodeDist.node, amountToSend,
1,248✔
827
                        edge.capacity,
1,248✔
828
                )
1,248✔
829

1,248✔
830
                log.Trace(lnutils.NewLogClosure(func() string {
1,248✔
831
                        return fmt.Sprintf("path finding probability: fromnode=%v,"+
×
832
                                " tonode=%v, amt=%v, cap=%v, probability=%v",
×
833
                                fromVertex, toNodeDist.node, amountToSend,
×
834
                                edge.capacity, edgeProbability)
×
835
                }))
×
836

837
                // If the probability is zero, there is no point in trying.
838
                if edgeProbability == 0 {
1,248✔
839
                        return
×
840
                }
×
841

842
                // Compute fee that fromVertex is charging. It is based on the
843
                // amount that needs to be sent to the next node in the route.
844
                //
845
                // Source node has no predecessor to pay a fee. Therefore set
846
                // fee to zero, because it should not be included in the fee
847
                // limit check and edge weight.
848
                //
849
                // Also determine the time lock delta that will be added to the
850
                // route if fromVertex is selected. If fromVertex is the source
851
                // node, no additional timelock is required.
852
                var (
1,248✔
853
                        timeLockDelta uint16
1,248✔
854
                        outboundFee   int64
1,248✔
855
                )
1,248✔
856

1,248✔
857
                if fromVertex != source {
2,352✔
858
                        outboundFee = int64(
1,104✔
859
                                edge.policy.ComputeFee(amountToSend),
1,104✔
860
                        )
1,104✔
861
                        timeLockDelta = edge.policy.TimeLockDelta
1,104✔
862
                }
1,104✔
863

864
                incomingCltv := toNodeDist.incomingCltv + int32(timeLockDelta)
1,248✔
865

1,248✔
866
                // Check that we are within our CLTV limit.
1,248✔
867
                if uint64(incomingCltv) > absoluteCltvLimit {
1,260✔
868
                        return
12✔
869
                }
12✔
870

871
                // netAmountToReceive is the amount that the node that is added
872
                // to the distance map needs to receive from a (to be found)
873
                // previous node in the route. The inbound fee of the receiving
874
                // node is already subtracted from this value. The previous node
875
                // will need to pay the amount that this node forwards plus the
876
                // fee it charges plus this node's inbound fee.
877
                netAmountToReceive := amountToSend +
1,236✔
878
                        lnwire.MilliSatoshi(outboundFee)
1,236✔
879

1,236✔
880
                // Calculate total probability of successfully reaching target
1,236✔
881
                // by multiplying the probabilities. Both this edge and the rest
1,236✔
882
                // of the route must succeed.
1,236✔
883
                probability := toNodeDist.probability * edgeProbability
1,236✔
884

1,236✔
885
                // If the probability is below the specified lower bound, we can
1,236✔
886
                // abandon this direction. Adding further nodes can only lower
1,236✔
887
                // the probability more.
1,236✔
888
                if probability < cfg.MinProbability {
1,337✔
889
                        return
101✔
890
                }
101✔
891

892
                // Calculate the combined fee for this edge. Dijkstra does not
893
                // support negative edge weights. Because this fee feeds into
894
                // the edge weight calculation, we don't allow it to be
895
                // negative.
896
                signedFee := inboundFee + outboundFee
1,135✔
897
                fee := lnwire.MilliSatoshi(0)
1,135✔
898
                if signedFee > 0 {
1,693✔
899
                        fee = lnwire.MilliSatoshi(signedFee)
558✔
900
                }
558✔
901

902
                // By adding fromVertex in the route, there will be an extra
903
                // weight composed of the fee that this node will charge and
904
                // the amount that will be locked for timeLockDelta blocks in
905
                // the HTLC that is handed out to fromVertex.
906
                weight := edgeWeight(amountToSend, fee, timeLockDelta)
1,135✔
907

1,135✔
908
                // Compute the tentative weight to this new channel/edge
1,135✔
909
                // which is the weight from our toNode to the target node
1,135✔
910
                // plus the weight of this edge.
1,135✔
911
                tempWeight := toNodeDist.weight + weight
1,135✔
912

1,135✔
913
                // Add an extra factor to the weight to take into account the
1,135✔
914
                // probability. Another reason why we rounded the fee up to zero
1,135✔
915
                // is to prevent a highly negative fee from cancelling out the
1,135✔
916
                // extra factor. We don't want an always-failing node to attract
1,135✔
917
                // traffic using a highly negative fee and escape penalization.
1,135✔
918
                tempDist := getProbabilityBasedDist(
1,135✔
919
                        tempWeight, probability,
1,135✔
920
                        absoluteAttemptCost,
1,135✔
921
                )
1,135✔
922

1,135✔
923
                // If there is already a best route stored, compare this
1,135✔
924
                // candidate route with the best route so far.
1,135✔
925
                current, ok := distance[fromVertex]
1,135✔
926
                if ok {
1,530✔
927
                        // If this route is worse than what we already found,
395✔
928
                        // skip this route.
395✔
929
                        if tempDist > current.dist {
700✔
930
                                return
305✔
931
                        }
305✔
932

933
                        // If the route is equally good and the probability
934
                        // isn't better, skip this route. It is important to
935
                        // also return if both cost and probability are equal,
936
                        // because otherwise the algorithm could run into an
937
                        // endless loop.
938
                        probNotBetter := probability <= current.probability
90✔
939
                        if tempDist == current.dist && probNotBetter {
149✔
940
                                return
59✔
941
                        }
59✔
942
                }
943

944
                // Calculate the total routing info size if this hop were to be
945
                // included. If we are coming from the source hop, the payload
946
                // size is zero, because the original htlc isn't in the onion
947
                // blob.
948
                //
949
                // NOTE: For blinded paths with the NUMS key as the last hop,
950
                // the payload size accounts for this dummy hop which is of
951
                // the same size as the real last hop. So we account for a
952
                // bigger size than the route is however we accept this
953
                // little inaccuracy here because we are over estimating by
954
                // 1 hop.
955
                var payloadSize uint64
771✔
956
                if fromVertex != source {
1,402✔
957
                        // In case the unifiedEdge does not have a payload size
631✔
958
                        // function supplied we request a graceful shutdown
631✔
959
                        // because this should never happen.
631✔
960
                        if edge.hopPayloadSizeFn == nil {
631✔
961
                                log.Criticalf("No payload size function "+
×
962
                                        "available for edge=%v unable to "+
×
963
                                        "determine payload size: %v", edge,
×
964
                                        ErrNoPayLoadSizeFunc)
×
965

×
966
                                return
×
967
                        }
×
968

969
                        payloadSize = edge.hopPayloadSizeFn(
631✔
970
                                amountToSend,
631✔
971
                                uint32(toNodeDist.incomingCltv),
631✔
972
                                edge.policy.ChannelID,
631✔
973
                        )
631✔
974
                }
975

976
                routingInfoSize := toNodeDist.routingInfoSize + payloadSize
771✔
977
                // Skip paths that would exceed the maximum routing info size.
771✔
978
                if routingInfoSize > sphinx.MaxPayloadSize {
777✔
979
                        return
6✔
980
                }
6✔
981

982
                // All conditions are met and this new tentative distance is
983
                // better than the current best known distance to this node.
984
                // The new better distance is recorded, and also our "next hop"
985
                // map is populated with this edge.
986
                withDist := &nodeWithDist{
765✔
987
                        dist:              tempDist,
765✔
988
                        weight:            tempWeight,
765✔
989
                        node:              fromVertex,
765✔
990
                        netAmountReceived: netAmountToReceive,
765✔
991
                        outboundFee:       lnwire.MilliSatoshi(outboundFee),
765✔
992
                        incomingCltv:      incomingCltv,
765✔
993
                        probability:       probability,
765✔
994
                        nextHop:           edge,
765✔
995
                        routingInfoSize:   routingInfoSize,
765✔
996
                }
765✔
997
                distance[fromVertex] = withDist
765✔
998

765✔
999
                // Either push withDist onto the heap if the node
765✔
1000
                // represented by fromVertex is not already on the heap OR adjust
765✔
1001
                // its position within the heap via heap.Fix.
765✔
1002
                nodeHeap.PushOrFix(withDist)
765✔
1003
        }
1004

1005
        // TODO(roasbeef): also add path caching
1006
        //  * similar to route caching, but doesn't factor in the amount
1007

1008
        // Cache features because we visit nodes multiple times.
1009
        featureCache := make(map[route.Vertex]*lnwire.FeatureVector)
176✔
1010

176✔
1011
        // getGraphFeatures returns (cached) node features from the graph.
176✔
1012
        getGraphFeatures := func(node route.Vertex) (*lnwire.FeatureVector,
176✔
1013
                error) {
1,432✔
1014

1,256✔
1015
                // Check cache for features of the fromNode.
1,256✔
1016
                fromFeatures, ok := featureCache[node]
1,256✔
1017
                if ok {
1,719✔
1018
                        return fromFeatures, nil
463✔
1019
                }
463✔
1020

1021
                // Fetch node features fresh from the graph.
1022
                fromFeatures, err := g.graph.FetchNodeFeatures(node)
793✔
1023
                if err != nil {
793✔
1024
                        return nil, err
×
1025
                }
×
1026

1027
                // Don't route through nodes that contain unknown required
1028
                // features and mark as nil in the cache.
1029
                err = feature.ValidateRequired(fromFeatures)
793✔
1030
                if err != nil {
795✔
1031
                        featureCache[node] = nil
2✔
1032
                        return nil, nil
2✔
1033
                }
2✔
1034

1035
                // Don't route through nodes that don't properly set all
1036
                // transitive feature dependencies and mark as nil in the cache.
1037
                err = feature.ValidateDeps(fromFeatures)
791✔
1038
                if err != nil {
793✔
1039
                        featureCache[node] = nil
2✔
1040
                        return nil, nil
2✔
1041
                }
2✔
1042

1043
                // Update cache.
1044
                featureCache[node] = fromFeatures
789✔
1045

789✔
1046
                return fromFeatures, nil
789✔
1047
        }
1048

1049
        routeToSelf := source == target
176✔
1050
        for {
871✔
1051
                nodesVisited++
695✔
1052

695✔
1053
                pivot := partialPath.node
695✔
1054
                isExitHop := partialPath.nextHop == nil
695✔
1055

695✔
1056
                // Create unified policies for all incoming connections. Don't
695✔
1057
                // use inbound fees for the exit hop.
695✔
1058
                u := newNodeEdgeUnifier(
695✔
1059
                        self, pivot, !isExitHop, outgoingChanMap,
695✔
1060
                )
695✔
1061

695✔
1062
                err := u.addGraphPolicies(g.graph)
695✔
1063
                if err != nil {
695✔
1064
                        return nil, 0, err
×
1065
                }
×
1066

1067
                // We add hop hints that were supplied externally.
1068
                for _, reverseEdge := range additionalEdgesWithSrc[pivot] {
711✔
1069
                        // Assume zero inbound fees for route hints. If inbound
16✔
1070
                        // fees would apply, they couldn't be communicated in
16✔
1071
                        // bolt11 invoices currently.
16✔
1072
                        inboundFee := models.InboundFee{}
16✔
1073

16✔
1074
                        // Hop hints don't contain a capacity. We set one here,
16✔
1075
                        // since a capacity is needed for probability
16✔
1076
                        // calculations. We set a high capacity to act as if
16✔
1077
                        // there is enough liquidity, otherwise the hint would
16✔
1078
                        // not have been added by a wallet.
16✔
1079
                        // We also pass the payload size function to the
16✔
1080
                        // graph data so that we calculate the exact payload
16✔
1081
                        // size when evaluating this hop for a route.
16✔
1082
                        u.addPolicy(
16✔
1083
                                reverseEdge.sourceNode,
16✔
1084
                                reverseEdge.edge.EdgePolicy(),
16✔
1085
                                inboundFee,
16✔
1086
                                fakeHopHintCapacity,
16✔
1087
                                reverseEdge.edge.IntermediatePayloadSize,
16✔
1088
                                reverseEdge.edge.BlindedPayment(),
16✔
1089
                        )
16✔
1090
                }
16✔
1091

1092
                netAmountReceived := partialPath.netAmountReceived
695✔
1093

695✔
1094
                // Expand all connections using the optimal policy for each
695✔
1095
                // connection.
695✔
1096
                for fromNode, edgeUnifier := range u.edgeUnifiers {
2,314✔
1097
                        // The target node is not recorded in the distance map.
1,619✔
1098
                        // Therefore we need to have this check to prevent
1,619✔
1099
                        // creating a cycle. Only when we intend to route to
1,619✔
1100
                        // self, we allow this cycle to form. In that case we'll
1,619✔
1101
                        // also break out of the search loop below.
1,619✔
1102
                        if !routeToSelf && fromNode == target {
1,948✔
1103
                                continue
329✔
1104
                        }
1105

1106
                        // Apply last hop restriction if set.
1107
                        if r.LastHop != nil &&
1,290✔
1108
                                pivot == target && fromNode != *r.LastHop {
1,294✔
1109

4✔
1110
                                continue
4✔
1111
                        }
1112

1113
                        edge := edgeUnifier.getEdge(
1,286✔
1114
                                netAmountReceived, g.bandwidthHints,
1,286✔
1115
                                partialPath.outboundFee,
1,286✔
1116
                        )
1,286✔
1117

1,286✔
1118
                        if edge == nil {
1,316✔
1119
                                continue
30✔
1120
                        }
1121

1122
                        // Get feature vector for fromNode.
1123
                        fromFeatures, err := getGraphFeatures(fromNode)
1,256✔
1124
                        if err != nil {
1,256✔
1125
                                return nil, 0, err
×
1126
                        }
×
1127

1128
                        // If there are no valid features, skip this node.
1129
                        if fromFeatures == nil {
1,260✔
1130
                                continue
4✔
1131
                        }
1132

1133
                        // Check if this candidate node is better than what we
1134
                        // already have.
1135
                        processEdge(fromNode, edge, partialPath)
1,252✔
1136
                }
1137

1138
                if nodeHeap.Len() == 0 {
735✔
1139
                        break
40✔
1140
                }
1141

1142
                // Fetch the node within the smallest distance from our source
1143
                // from the heap.
1144
                partialPath = heap.Pop(&nodeHeap).(*nodeWithDist)
655✔
1145

655✔
1146
                // If we've reached our source (or we don't have any incoming
655✔
1147
                // edges), then we're done here and can exit the graph
655✔
1148
                // traversal early.
655✔
1149
                if partialPath.node == source {
791✔
1150
                        break
136✔
1151
                }
1152
        }
1153

1154
        // Use the distance map to unravel the forward path from source to
1155
        // target.
1156
        var pathEdges []*unifiedEdge
176✔
1157
        currentNode := source
176✔
1158
        for {
556✔
1159
                // Determine the next hop forward using the next map.
380✔
1160
                currentNodeWithDist, ok := distance[currentNode]
380✔
1161
                if !ok {
420✔
1162
                        // If the node doesn't have a next hop it means we
40✔
1163
                        // didn't find a path.
40✔
1164
                        return nil, 0, errNoPathFound
40✔
1165
                }
40✔
1166

1167
                // Add the next hop to the list of path edges.
1168
                pathEdges = append(pathEdges, currentNodeWithDist.nextHop)
340✔
1169

340✔
1170
                // Advance current node.
340✔
1171
                currentNode = currentNodeWithDist.nextHop.policy.ToNodePubKey()
340✔
1172

340✔
1173
                // Check stop condition at the end of this loop. This prevents
340✔
1174
                // breaking out too soon for self-payments that have target set
340✔
1175
                // to source.
340✔
1176
                if currentNode == target {
476✔
1177
                        break
136✔
1178
                }
1179
        }
1180

1181
        // For the final hop, we'll set the node features to those determined
1182
        // above. These are either taken from the destination features, e.g.
1183
        // virtual or invoice features, or loaded as a fallback from the graph.
1184
        // The transitive dependencies were already validated above, so no need
1185
        // to do so now.
1186
        //
1187
        // NOTE: This may overwrite features loaded from the graph if
1188
        // destination features were provided. This is fine though, since our
1189
        // route construction does not care where the features are actually
1190
        // taken from. In the future we may wish to do route construction within
1191
        // findPath, and avoid using ChannelEdgePolicy altogether.
1192
        pathEdges[len(pathEdges)-1].policy.ToNodeFeatures = features
136✔
1193

136✔
1194
        log.Debugf("Found route: probability=%v, hops=%v, fee=%v",
136✔
1195
                distance[source].probability, len(pathEdges),
136✔
1196
                distance[source].netAmountReceived-amt)
136✔
1197

136✔
1198
        return pathEdges, distance[source].probability, nil
136✔
1199
}
1200

1201
// blindedPathRestrictions are a set of constraints to adhere to when
1202
// choosing a set of blinded paths to this node.
1203
type blindedPathRestrictions struct {
1204
        // minNumHops is the minimum number of hops to include in a blinded
1205
        // path. This doesn't include our node, so if the minimum is 1, then
1206
        // the path will contain at minimum our node along with an introduction
1207
        // node hop. A minimum of 0 will include paths where this node is the
1208
        // introduction node and so should be used with caution.
1209
        minNumHops uint8
1210

1211
        // maxNumHops is the maximum number of hops to include in a blinded
1212
        // path. This doesn't include our node, so if the maximum is 1, then
1213
        // the path will contain our node along with an introduction node hop.
1214
        maxNumHops uint8
1215

1216
        // nodeOmissionSet holds a set of node IDs of nodes that we should
1217
        // ignore during blinded path selection.
1218
        nodeOmissionSet fn.Set[route.Vertex]
1219

1220
        // incomingChainedChannels holds the chained channels list specified
1221
        // via scid (short channel id) starting from a channel which points to
1222
        // the receiver node.
1223
        incomingChainedChannels []uint64
1224
}
1225

1226
// blindedHop holds the information about a hop we have selected for a blinded
1227
// path.
1228
type blindedHop struct {
1229
        vertex       route.Vertex
1230
        channelID    uint64
1231
        edgeCapacity btcutil.Amount
1232
}
1233

1234
// findBlindedPaths does a depth first search from the target node to find a set
1235
// of blinded paths to the target node given the set of restrictions. This
1236
// function will select and return any candidate path. A candidate path is a
1237
// path to the target node with a size determined by the given hop number
1238
// constraints where all the nodes on the path signal the route blinding feature
1239
// _and_ the introduction node for the path has more than one public channel.
1240
// Any filtering of paths based on payment value or success probabilities is
1241
// left to the caller.
1242
func findBlindedPaths(g Graph, target route.Vertex,
1243
        restrictions *blindedPathRestrictions) ([][]blindedHop, error) {
19✔
1244

19✔
1245
        // Sanity check the restrictions.
19✔
1246
        if restrictions.minNumHops > restrictions.maxNumHops {
19✔
1247
                return nil, fmt.Errorf("maximum number of blinded path hops "+
×
1248
                        "(%d) must be greater than or equal to the minimum "+
×
1249
                        "number of hops (%d)", restrictions.maxNumHops,
×
1250
                        restrictions.minNumHops)
×
1251
        }
×
1252

1253
        var (
19✔
1254
                // The target node is always the last hop in the path, and so
19✔
1255
                // we add it to the incoming path from the get-go. Any additions
19✔
1256
                // to the slice should be prepended.
19✔
1257
                incomingPath = []blindedHop{{
19✔
1258
                        vertex: target,
19✔
1259
                }}
19✔
1260

19✔
1261
                // supportsRouteBlinding is a list of nodes that we can assume
19✔
1262
                // support route blinding without needing to rely on the feature
19✔
1263
                // bits announced in their node announcement. Since we are
19✔
1264
                // finding a path to the target node, we can assume it supports
19✔
1265
                // route blinding.
19✔
1266
                supportsRouteBlinding = map[route.Vertex]bool{
19✔
1267
                        target: true,
19✔
1268
                }
19✔
1269

19✔
1270
                visited          = make(map[route.Vertex]bool)
19✔
1271
                nextTarget       = target
19✔
1272
                haveIncomingPath = len(restrictions.incomingChainedChannels) > 0
19✔
1273

19✔
1274
                // errChanFound is an error variable we return from the DB
19✔
1275
                // iteration call below when we have found the channel we are
19✔
1276
                // looking for. This lets us exit the iteration early.
19✔
1277
                errChanFound = errors.New("found incoming channel")
19✔
1278
        )
19✔
1279
        for _, chanID := range restrictions.incomingChainedChannels {
30✔
1280
                // Mark that we have visited this node so that we don't revisit
11✔
1281
                // it later on when we call "processNodeForBlindedPath".
11✔
1282
                visited[nextTarget] = true
11✔
1283

11✔
1284
                var (
11✔
1285
                        incomingPathReset []blindedHop
11✔
1286
                        nextTargetReset   = nextTarget
11✔
1287
                )
11✔
1288
                err := g.ForEachNodeDirectedChannel(
11✔
1289
                        nextTarget,
11✔
1290
                        func(channel *graphdb.DirectedChannel) error {
31✔
1291
                                // This is not the right channel, continue to
20✔
1292
                                // the node's other channels.
20✔
1293
                                if channel.ChannelID != chanID {
29✔
1294
                                        return nil
9✔
1295
                                }
9✔
1296

1297
                                // We found the channel in question. Prepend it
1298
                                // to the incoming path.
1299
                                incomingPathReset = append([]blindedHop{
11✔
1300
                                        {
11✔
1301
                                                vertex:       channel.OtherNode,
11✔
1302
                                                channelID:    channel.ChannelID,
11✔
1303
                                                edgeCapacity: channel.Capacity,
11✔
1304
                                        },
11✔
1305
                                }, incomingPathReset...)
11✔
1306

11✔
1307
                                // Update the target node.
11✔
1308
                                nextTargetReset = channel.OtherNode
11✔
1309

11✔
1310
                                return errChanFound
11✔
1311
                        }, func() {
×
1312
                                incomingPathReset = nil
×
1313
                                nextTargetReset = nextTarget
×
1314
                        },
×
1315
                )
1316
                // We expect errChanFound to be returned if the channel in
1317
                // question was found.
1318
                if !errors.Is(err, errChanFound) && err != nil {
11✔
1319
                        return nil, err
×
1320
                } else if err == nil {
11✔
UNCOV
1321
                        return nil, fmt.Errorf("incoming channel %d is not "+
×
UNCOV
1322
                                "seen as owned by node %v", chanID, nextTarget)
×
UNCOV
1323
                }
×
1324
                nextTarget = nextTargetReset
11✔
1325
                incomingPath = append(incomingPathReset, incomingPath...)
11✔
1326

11✔
1327
                // Check that the user didn't accidentally add a channel that
11✔
1328
                // is owned by a node in the node omission set.
11✔
1329
                if restrictions.nodeOmissionSet.Contains(nextTarget) {
12✔
1330
                        return nil, fmt.Errorf("node %v cannot simultaneously "+
1✔
1331
                                "be included in the omission set and in the "+
1✔
1332
                                "partially specified path", nextTarget)
1✔
1333
                }
1✔
1334

1335
                // Check that we have not already visited the next target node
1336
                // since this would mean a circular incoming path.
1337
                if visited[nextTarget] {
11✔
1338
                        return nil, fmt.Errorf("a circular route cannot be " +
1✔
1339
                                "specified for the incoming blinded path")
1✔
1340
                }
1✔
1341

1342
                supportsRouteBlinding[nextTarget] = true
9✔
1343
        }
1344

1345
        // A helper closure which checks if the node in question has advertised
1346
        // that it supports route blinding.
1347
        nodeSupportsRouteBlinding := func(node route.Vertex) (bool, error) {
103✔
1348
                if supportsRouteBlinding[node] {
103✔
1349
                        return true, nil
17✔
1350
                }
17✔
1351

1352
                features, err := g.FetchNodeFeatures(node)
69✔
1353
                if err != nil {
69✔
1354
                        return false, err
×
1355
                }
×
1356

1357
                return features.HasFeature(lnwire.RouteBlindingOptional), nil
69✔
1358
        }
1359

1360
        // This function will have some recursion. We will spin out from the
1361
        // target node & append edges to the paths until we reach various exit
1362
        // conditions such as: The maxHops number being reached or reaching
1363
        // a node that doesn't have any other edges - in that final case, the
1364
        // whole path should be ignored.
1365
        //
1366
        // NOTE: any paths returned will end at the "nextTarget" node meaning
1367
        // that if we have a fixed list of incoming chained channels, then this
1368
        // fixed list must be appended to any of the returned paths.
1369
        paths, _, err := processNodeForBlindedPath(
17✔
1370
                g, nextTarget, nodeSupportsRouteBlinding, visited, restrictions,
17✔
1371
        )
17✔
1372
        if err != nil {
17✔
1373
                return nil, err
×
1374
        }
×
1375

1376
        // Reverse each path so that the order is correct (from introduction
1377
        // node to last hop node) and then append the incoming path (if any was
1378
        // specified) to the end of the path.
1379
        orderedPaths := make([][]blindedHop, 0, len(paths))
17✔
1380
        for _, path := range paths {
56✔
1381
                sort.Slice(path, func(i, j int) bool {
75✔
1382
                        return j < i
36✔
1383
                })
36✔
1384

1385
                orderedPaths = append(
39✔
1386
                        orderedPaths, append(path, incomingPath...),
39✔
1387
                )
39✔
1388
        }
1389

1390
        // There is a chance we have an incoming path that by itself satisfies
1391
        // the minimum hop restriction. In that case, we add it as its own path.
1392
        if haveIncomingPath &&
17✔
1393
                len(incomingPath) > int(restrictions.minNumHops) {
22✔
1394

5✔
1395
                orderedPaths = append(orderedPaths, incomingPath)
5✔
1396
        }
5✔
1397

1398
        // Handle the special case that allows a blinded path with the
1399
        // introduction node as the destination node. This only applies if no
1400
        // incoming path was specified since in that case, by definition, the
1401
        // caller wants a non-zero length blinded path.
1402
        if restrictions.minNumHops == 0 && !haveIncomingPath {
19✔
1403
                singleHopPath := [][]blindedHop{{{vertex: target}}}
2✔
1404

2✔
1405
                orderedPaths = append(
2✔
1406
                        orderedPaths, singleHopPath...,
2✔
1407
                )
2✔
1408
        }
2✔
1409

1410
        return orderedPaths, err
17✔
1411
}
1412

1413
// processNodeForBlindedPath is a recursive function that traverses the graph
1414
// in a depth first manner searching for a set of blinded paths to the given
1415
// node.
1416
func processNodeForBlindedPath(g Graph, node route.Vertex,
1417
        supportsRouteBlinding func(vertex route.Vertex) (bool, error),
1418
        alreadyVisited map[route.Vertex]bool,
1419
        restrictions *blindedPathRestrictions) ([][]blindedHop, bool, error) {
234✔
1420

234✔
1421
        // If we have already visited the maximum number of hops, then this path
234✔
1422
        // is complete and we can exit now.
234✔
1423
        if len(alreadyVisited) > int(restrictions.maxNumHops) {
339✔
1424
                return nil, false, nil
105✔
1425
        }
105✔
1426

1427
        // If we have already visited this peer on this path, then we skip
1428
        // processing it again.
1429
        if alreadyVisited[node] {
168✔
1430
                return nil, false, nil
39✔
1431
        }
39✔
1432

1433
        // If we have explicitly been told to ignore this node for blinded paths
1434
        // then we skip it too.
1435
        if restrictions.nodeOmissionSet.Contains(node) {
94✔
1436
                return nil, false, nil
4✔
1437
        }
4✔
1438

1439
        supports, err := supportsRouteBlinding(node)
86✔
1440
        if err != nil {
86✔
1441
                return nil, false, err
×
1442
        }
×
1443
        if !supports {
92✔
1444
                return nil, false, nil
6✔
1445
        }
6✔
1446

1447
        // At this point, copy the alreadyVisited map.
1448
        visited := make(map[route.Vertex]bool, len(alreadyVisited))
80✔
1449
        for r := range alreadyVisited {
192✔
1450
                visited[r] = true
112✔
1451
        }
112✔
1452

1453
        // Add this node the visited set.
1454
        visited[node] = true
80✔
1455

80✔
1456
        var (
80✔
1457
                hopSets   [][]blindedHop
80✔
1458
                chanCount int
80✔
1459
        )
80✔
1460

80✔
1461
        // Now, iterate over the node's channels in search for paths to this
80✔
1462
        // node that can be used for blinded paths
80✔
1463
        err = g.ForEachNodeDirectedChannel(
80✔
1464
                node,
80✔
1465
                func(channel *graphdb.DirectedChannel) error {
297✔
1466
                        // Keep track of how many incoming channels this node
217✔
1467
                        // has. We only use a node as an introduction node if it
217✔
1468
                        // has channels other than the one that lead us to it.
217✔
1469
                        chanCount++
217✔
1470

217✔
1471
                        // Process each channel peer to gather any paths that
217✔
1472
                        // lead to the peer.
217✔
1473
                        nextPaths, hasMoreChans, err := processNodeForBlindedPath( //nolint:ll
217✔
1474
                                g, channel.OtherNode, supportsRouteBlinding,
217✔
1475
                                visited, restrictions,
217✔
1476
                        )
217✔
1477
                        if err != nil {
217✔
1478
                                return err
×
1479
                        }
×
1480

1481
                        hop := blindedHop{
217✔
1482
                                vertex:       channel.OtherNode,
217✔
1483
                                channelID:    channel.ChannelID,
217✔
1484
                                edgeCapacity: channel.Capacity,
217✔
1485
                        }
217✔
1486

217✔
1487
                        // For each of the paths returned, unwrap them and
217✔
1488
                        // append this hop to them.
217✔
1489
                        for _, path := range nextPaths {
250✔
1490
                                hopSets = append(
33✔
1491
                                        hopSets,
33✔
1492
                                        append([]blindedHop{hop}, path...),
33✔
1493
                                )
33✔
1494
                        }
33✔
1495

1496
                        // If this node does have channels other than the one
1497
                        // that lead to it, and if the hop count up to this node
1498
                        // meets the minHop requirement, then we also add a
1499
                        // path that starts at this node.
1500
                        if hasMoreChans &&
217✔
1501
                                len(visited) >= int(restrictions.minNumHops) {
256✔
1502

39✔
1503
                                hopSets = append(hopSets, []blindedHop{hop})
39✔
1504
                        }
39✔
1505

1506
                        return nil
217✔
1507
                }, func() {
×
1508
                        hopSets = nil
×
1509
                        chanCount = 0
×
1510
                },
×
1511
        )
1512
        if err != nil {
80✔
1513
                return nil, false, err
×
1514
        }
×
1515

1516
        return hopSets, chanCount > 1, nil
80✔
1517
}
1518

1519
// getProbabilityBasedDist converts a weight into a distance that takes into
1520
// account the success probability and the (virtual) cost of a failed payment
1521
// attempt.
1522
//
1523
// Derivation:
1524
//
1525
// Suppose there are two routes A and B with fees Fa and Fb and success
1526
// probabilities Pa and Pb.
1527
//
1528
// Is the expected cost of trying route A first and then B lower than trying the
1529
// other way around?
1530
//
1531
// The expected cost of A-then-B is: Pa*Fa + (1-Pa)*Pb*(c+Fb)
1532
//
1533
// The expected cost of B-then-A is: Pb*Fb + (1-Pb)*Pa*(c+Fa)
1534
//
1535
// In these equations, the term representing the case where both A and B fail is
1536
// left out because its value would be the same in both cases.
1537
//
1538
// Pa*Fa + (1-Pa)*Pb*(c+Fb) < Pb*Fb + (1-Pb)*Pa*(c+Fa)
1539
//
1540
// Pa*Fa + Pb*c + Pb*Fb - Pa*Pb*c - Pa*Pb*Fb < Pb*Fb + Pa*c + Pa*Fa - Pa*Pb*c - Pa*Pb*Fa
1541
//
1542
// Removing terms that cancel out:
1543
// Pb*c - Pa*Pb*Fb < Pa*c - Pa*Pb*Fa
1544
//
1545
// Divide by Pa*Pb:
1546
// c/Pa - Fb < c/Pb - Fa
1547
//
1548
// Move terms around:
1549
// Fa + c/Pa < Fb + c/Pb
1550
//
1551
// So the value of F + c/P can be used to compare routes.
1552
func getProbabilityBasedDist(weight int64, probability float64,
1553
        penalty float64) int64 {
1,135✔
1554

1,135✔
1555
        // Prevent divide by zero by returning early.
1,135✔
1556
        if probability == 0 {
1,135✔
1557
                return infinity
×
1558
        }
×
1559

1560
        // Calculate distance.
1561
        dist := float64(weight) + penalty/probability
1,135✔
1562

1,135✔
1563
        // Avoid cast if an overflow would occur. The maxFloat constant is
1,135✔
1564
        // chosen to stay well below the maximum float64 value that is still
1,135✔
1565
        // convertible to int64.
1,135✔
1566
        const maxFloat = 9000000000000000000
1,135✔
1567
        if dist > maxFloat {
1,135✔
1568
                return infinity
×
1569
        }
×
1570

1571
        return int64(dist)
1,135✔
1572
}
1573

1574
// lastHopPayloadSize calculates the payload size of the final hop in a route.
1575
// It depends on the tlv types which are present and also whether the hop is
1576
// part of a blinded route or not.
1577
func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
1578
        amount lnwire.MilliSatoshi) (uint64, error) {
179✔
1579

179✔
1580
        if r.BlindedPaymentPathSet != nil {
181✔
1581
                paymentPath, err := r.BlindedPaymentPathSet.
2✔
1582
                        LargestLastHopPayloadPath()
2✔
1583
                if err != nil {
2✔
1584
                        return 0, err
×
1585
                }
×
1586

1587
                blindedPath := paymentPath.BlindedPath.BlindedHops
2✔
1588
                blindedPoint := paymentPath.BlindedPath.BlindingPoint
2✔
1589

2✔
1590
                encryptedData := blindedPath[len(blindedPath)-1].CipherText
2✔
1591
                finalHop := route.Hop{
2✔
1592
                        AmtToForward:     amount,
2✔
1593
                        OutgoingTimeLock: uint32(finalHtlcExpiry),
2✔
1594
                        EncryptedData:    encryptedData,
2✔
1595
                }
2✔
1596
                if len(blindedPath) == 1 {
3✔
1597
                        finalHop.BlindingPoint = blindedPoint
1✔
1598
                }
1✔
1599

1600
                // The final hop does not have a short chanID set.
1601
                return finalHop.PayloadSize(0), nil
2✔
1602
        }
1603

1604
        var mpp *record.MPP
177✔
1605
        r.PaymentAddr.WhenSome(func(addr [32]byte) {
228✔
1606
                mpp = record.NewMPP(amount, addr)
51✔
1607
        })
51✔
1608

1609
        var amp *record.AMP
177✔
1610
        if r.Amp != nil {
178✔
1611
                // The AMP payload is not easy accessible at this point but we
1✔
1612
                // are only interested in the size of the payload so we just use
1✔
1613
                // the AMP record dummy.
1✔
1614
                amp = &record.MaxAmpPayLoadSize
1✔
1615
        }
1✔
1616

1617
        finalHop := route.Hop{
177✔
1618
                AmtToForward:     amount,
177✔
1619
                OutgoingTimeLock: uint32(finalHtlcExpiry),
177✔
1620
                CustomRecords:    r.DestCustomRecords,
177✔
1621
                MPP:              mpp,
177✔
1622
                AMP:              amp,
177✔
1623
                Metadata:         r.Metadata,
177✔
1624
        }
177✔
1625

177✔
1626
        // The final hop does not have a short chanID set.
177✔
1627
        return finalHop.PayloadSize(0), nil
177✔
1628
}
1629

1630
// overflowSafeAdd adds two MilliSatoshi values and returns the result. If an
1631
// overflow could occur, zero is returned instead and the boolean is set to
1632
// true.
1633
func overflowSafeAdd(x, y lnwire.MilliSatoshi) (lnwire.MilliSatoshi, bool) {
433✔
1634
        if y > math.MaxUint64-x {
433✔
1635
                // Overflow would occur, return 0 and set overflow flag.
×
1636
                return 0, true
×
1637
        }
×
1638

1639
        return x + y, false
433✔
1640
}
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